From 7c662c3a8ecc50e65b13db3b2caf5da8db275812 Mon Sep 17 00:00:00 2001 From: Marek L Date: Thu, 4 Jul 2024 21:44:59 +0100 Subject: [PATCH 1/4] Revert "[ fix ] revert regexp for ipkg source dirs." This reverts commit ecd9c9b13fc4e9ac367179156e342c5712759fcb. --- idris-ipkg-mode.el | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/idris-ipkg-mode.el b/idris-ipkg-mode.el index 597341c..d4e81fd 100644 --- a/idris-ipkg-mode.el +++ b/idris-ipkg-mode.el @@ -87,9 +87,8 @@ `(,idris-ipkg-keywords)) (defconst idris-ipkg-sourcedir-re -;; "^sourcedir\\s-*=\\s-*\"?\\([a-zA-Z/0-9]+\\)\"?" - "^\\s-*sourcedir\\s-*=\\s-*\\(\\sw+\\)" -) + "^sourcedir\\s-*=\\s-*\"?\\([a-zA-Z/0-9]+\\)\"?") +;; "^\\s-*sourcedir\\s-*=\\s-*\\(\\sw+\\)" ;;; Completion From dc3063a4d6f8abc0f624309b52dcace419349ff9 Mon Sep 17 00:00:00 2001 From: Marek L Date: Sat, 22 Jun 2024 15:03:24 +0100 Subject: [PATCH 2/4] Simplify `idris-ipkg-buffer-src-dir` by using `if-let` --- idris-ipkg-mode.el | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/idris-ipkg-mode.el b/idris-ipkg-mode.el index d4e81fd..64d0707 100644 --- a/idris-ipkg-mode.el +++ b/idris-ipkg-mode.el @@ -306,12 +306,10 @@ arguments." (defun idris-ipkg-buffer-src-dir (basename) (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))))) + (if-let ((found (re-search-forward idris-ipkg-sourcedir-re nil t))) + (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)) From 5701c45671714dfe7b0b7b8fbabf38a17cacf6cc Mon Sep 17 00:00:00 2001 From: Marek L Date: Sat, 22 Jun 2024 15:30:49 +0100 Subject: [PATCH 3/4] 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 --- idris-ipkg-mode.el | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/idris-ipkg-mode.el b/idris-ipkg-mode.el index 64d0707..8c90d3a 100644 --- a/idris-ipkg-mode.el +++ b/idris-ipkg-mode.el @@ -86,10 +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 () @@ -141,19 +137,17 @@ (idris-clear-file-link-overlays 'idris-ipkg-mode) (let ((src-dir (idris-ipkg-buffer-src-dir (file-name-directory (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)) @@ -303,13 +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)) - (if-let ((found (re-search-forward idris-ipkg-sourcedir-re nil t))) - (concat (file-name-directory basename) - (buffer-substring-no-properties (match-beginning 1) (match-end 1))) - (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)) From 0b49be4374f4eac9ae0b14795980d9493d5be1af Mon Sep 17 00:00:00 2001 From: Marek L Date: Sat, 13 Jul 2024 18:45:03 +0100 Subject: [PATCH 4/4] Remove unecessary function call `file-name-directory` Why: It is called inside of the `idris-ipkg-buffer-src-dir` function. --- idris-ipkg-mode.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/idris-ipkg-mode.el b/idris-ipkg-mode.el index 8c90d3a..36b5fe3 100644 --- a/idris-ipkg-mode.el +++ b/idris-ipkg-mode.el @@ -135,7 +135,7 @@ "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 (when (and (file-exists-p src-dir) (file-directory-p src-dir)