|
87 | 87 | (defconst idris-ipkg-font-lock-defaults |
88 | 88 | `(,idris-ipkg-keywords)) |
89 | 89 |
|
90 | | -(defconst idris-ipkg-sourcedir-re |
91 | | - "^sourcedir\\s-*=\\s-*\"?\\([a-zA-Z/0-9]+\\)\"?") |
92 | | -;; "^\\s-*sourcedir\\s-*=\\s-*\\(\\sw+\\)" |
93 | | - |
94 | 90 | ;;; Completion |
95 | 91 |
|
96 | 92 | (defun idris-ipkg-find-keyword () |
|
142 | 138 | (idris-clear-file-link-overlays 'idris-ipkg-mode) |
143 | 139 | (let ((src-dir (idris-ipkg-buffer-src-dir (file-name-directory (buffer-file-name))))) |
144 | 140 | ;; 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)))) |
158 | 152 | ;; Make the modules clickable |
159 | 153 | (save-excursion |
160 | 154 | (goto-char (point-min)) |
@@ -304,13 +298,17 @@ arguments." |
304 | 298 | (interactive) |
305 | 299 | (idris-kill-buffer idris-ipkg-build-buffer-name)) |
306 | 300 |
|
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." |
308 | 303 | (save-excursion |
309 | 304 | (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))) |
314 | 312 |
|
315 | 313 | (defun idris-ipkg-find-src-dir (&optional ipkg-file) |
316 | 314 | (let ((found (or (and ipkg-file (list ipkg-file)) |
|
0 commit comments