Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reintroduce ipkg sourcedir regexp for Idris2 and further simplify related code. #636

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 21 additions & 26 deletions idris-ipkg-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,6 @@
(defconst idris-ipkg-font-lock-defaults
`(,idris-ipkg-keywords))

(defconst idris-ipkg-sourcedir-re
;; "^sourcedir\\s-*=\\s-*\"?\\([a-zA-Z/0-9]+\\)\"?"
"^\\s-*sourcedir\\s-*=\\s-*\\(\\sw+\\)"
)

;;; Completion

(defun idris-ipkg-find-keyword ()
Expand Down Expand Up @@ -140,21 +135,19 @@
"Make all modules with existing files clickable, where clicking opens them."
(interactive)
(idris-clear-file-link-overlays 'idris-ipkg-mode)
(let ((src-dir (idris-ipkg-buffer-src-dir (file-name-directory (buffer-file-name)))))
(let ((src-dir (idris-ipkg-buffer-src-dir (buffer-file-name))))
;; Make the sourcedir clickable
(save-excursion
(goto-char (point-min))
(when (and (file-exists-p src-dir)
(file-directory-p src-dir)
(re-search-forward idris-ipkg-sourcedir-re nil t))
(let ((start (match-beginning 1))
(end (match-end 1))
(map (make-sparse-keymap)))
(define-key map [mouse-2] #'(lambda ()
(interactive)
(dired src-dir)))
(idris-make-file-link-overlay start end map
(concat "mouse-2: dired " src-dir)))))
(when (and (file-exists-p src-dir)
(file-directory-p src-dir)
(idris-ipkg-buffer-sourcedir-point))
(let ((start (match-beginning 1))
(end (match-end 1))
(map (make-sparse-keymap)))
(define-key map [mouse-2] #'(lambda ()
(interactive)
(dired src-dir)))
(idris-make-file-link-overlay start end map
(concat "mouse-2: dired " src-dir))))
;; Make the modules clickable
(save-excursion
(goto-char (point-min))
Expand Down Expand Up @@ -304,15 +297,17 @@ arguments."
(interactive)
(idris-kill-buffer idris-ipkg-build-buffer-name))

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

(defun idris-ipkg-buffer-src-dir (basename)
(if (idris-ipkg-buffer-sourcedir-point)
(concat (file-name-directory basename)
(buffer-substring-no-properties (match-beginning 1) (match-end 1)))
(file-name-directory basename)))

(defun idris-ipkg-find-src-dir (&optional ipkg-file)
(let ((found (or (and ipkg-file (list ipkg-file))
Expand Down
Loading