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