Skip to content

Commit 5701c45

Browse files
committed
Simplify retrieving value of sourcedir property in
*.ipkg file by extracting the lookup to a function `idris-ipkg-buffer-sourcedir` Additionaly match also underscore and dash in ipkg sourcedir regexp
1 parent dc3063a commit 5701c45

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

idris-ipkg-mode.el

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,6 @@
8686
(defconst idris-ipkg-font-lock-defaults
8787
`(,idris-ipkg-keywords))
8888

89-
(defconst idris-ipkg-sourcedir-re
90-
"^sourcedir\\s-*=\\s-*\"?\\([a-zA-Z/0-9]+\\)\"?")
91-
;; "^\\s-*sourcedir\\s-*=\\s-*\\(\\sw+\\)"
92-
9389
;;; Completion
9490

9591
(defun idris-ipkg-find-keyword ()
@@ -141,19 +137,17 @@
141137
(idris-clear-file-link-overlays 'idris-ipkg-mode)
142138
(let ((src-dir (idris-ipkg-buffer-src-dir (file-name-directory (buffer-file-name)))))
143139
;; Make the sourcedir clickable
144-
(save-excursion
145-
(goto-char (point-min))
146-
(when (and (file-exists-p src-dir)
147-
(file-directory-p src-dir)
148-
(re-search-forward idris-ipkg-sourcedir-re nil t))
149-
(let ((start (match-beginning 1))
150-
(end (match-end 1))
151-
(map (make-sparse-keymap)))
152-
(define-key map [mouse-2] #'(lambda ()
153-
(interactive)
154-
(dired src-dir)))
155-
(idris-make-file-link-overlay start end map
156-
(concat "mouse-2: dired " src-dir)))))
140+
(when (and (file-exists-p src-dir)
141+
(file-directory-p src-dir)
142+
(idris-ipkg-buffer-sourcedir-point))
143+
(let ((start (match-beginning 1))
144+
(end (match-end 1))
145+
(map (make-sparse-keymap)))
146+
(define-key map [mouse-2] #'(lambda ()
147+
(interactive)
148+
(dired src-dir)))
149+
(idris-make-file-link-overlay start end map
150+
(concat "mouse-2: dired " src-dir))))
157151
;; Make the modules clickable
158152
(save-excursion
159153
(goto-char (point-min))
@@ -303,13 +297,17 @@ arguments."
303297
(interactive)
304298
(idris-kill-buffer idris-ipkg-build-buffer-name))
305299

306-
(defun idris-ipkg-buffer-src-dir (basename)
300+
(defun idris-ipkg-buffer-sourcedir-point ()
301+
"Return nil or a point at the end of sourcedir value in the current ipkg file."
307302
(save-excursion
308303
(goto-char (point-min))
309-
(if-let ((found (re-search-forward idris-ipkg-sourcedir-re nil t)))
310-
(concat (file-name-directory basename)
311-
(buffer-substring-no-properties (match-beginning 1) (match-end 1)))
312-
(file-name-directory basename))))
304+
(re-search-forward "^sourcedir\\s-*=\\s-*\"?\\([A-Za-z0-9_-]+\\)\"?" nil t)))
305+
306+
(defun idris-ipkg-buffer-src-dir (basename)
307+
(if (idris-ipkg-buffer-sourcedir-point)
308+
(concat (file-name-directory basename)
309+
(buffer-substring-no-properties (match-beginning 1) (match-end 1)))
310+
(file-name-directory basename)))
313311

314312
(defun idris-ipkg-find-src-dir (&optional ipkg-file)
315313
(let ((found (or (and ipkg-file (list ipkg-file))

0 commit comments

Comments
 (0)