Skip to content

Commit b9442ea

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 7c2b875 commit b9442ea

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
@@ -87,10 +87,6 @@
8787
(defconst idris-ipkg-font-lock-defaults
8888
`(,idris-ipkg-keywords))
8989

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

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

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

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

0 commit comments

Comments
 (0)