branch: externals/hyperbole commit f1ede2a4b7c91ce39d82b8122e5bb50f4e04e24a Merge: 8fa9e4e198 63eb11702e Author: Robert Weiner <r...@gnu.org> Commit: GitHub <nore...@github.com>
Merge pull request #564 from rswgnu/fix-ripgrep-msg-problem Add file exist check in ripgrep-msg and a test case --- ChangeLog | 6 ++++++ hibtypes.el | 7 ++++--- test/hibtypes-tests.el | 28 +++++++++++++++++++++++++++- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8c5a236c28..5233c20b93 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2024-08-23 Mats Lidell <ma...@gnu.org> + +* hibtypes.el (ripgrep-msg): Add check of file exist. + +* test/hibtypes-tests.el (ibtypes::ripgrep-msg-test): Test ripgrep-msg. + 2024-08-18 Bob Weiner <r...@gnu.org> * hywiki.el (hywiki-maybe-at-wikiword-beginning): Fix to handle word diff --git a/hibtypes.el b/hibtypes.el index faeaac5ea9..677daa95c2 100644 --- a/hibtypes.el +++ b/hibtypes.el @@ -3,7 +3,7 @@ ;; Author: Bob Weiner ;; ;; Orig-Date: 19-Sep-91 at 20:45:31 -;; Last-Mod: 18-Aug-24 at 09:14:53 by Mats Lidell +;; Last-Mod: 23-Aug-24 at 21:32:09 by Mats Lidell ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -996,8 +996,9 @@ than a helm completion buffer)." (while (and (= (forward-line -1) 0) (looking-at "[1-9][0-9]*[-:]\\|--$"))) (unless (or (looking-at "[1-9][0-9]*[-:]\\|--$") - (and (setq file (buffer-substring-no-properties (line-beginning-position) (line-end-position))) - (string-empty-p (string-trim file)))) + (and (setq file (string-trim (buffer-substring-no-properties (line-beginning-position) (match-beginning 0)))) + (or (string-empty-p file) + (not (file-exists-p file))))) (ibut:label-set (concat file ":" line-num)) (hact 'hib-link-to-file-line file line-num))))))) diff --git a/test/hibtypes-tests.el b/test/hibtypes-tests.el index 5d0c334f70..acac882990 100644 --- a/test/hibtypes-tests.el +++ b/test/hibtypes-tests.el @@ -3,7 +3,7 @@ ;; Author: Mats Lidell <ma...@gnu.org> ;; ;; Orig-Date: 20-Feb-21 at 23:45:00 -;; Last-Mod: 5-Aug-24 at 17:37:57 by Mats Lidell +;; Last-Mod: 10-Aug-24 at 23:27:05 by Mats Lidell ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -297,7 +297,33 @@ ;; ipython-stack-frame ;; ripgrep-msg +(ert-deftest ibtypes::ripgrep-msg-test () + "Verify `ripgrep-msg'." + ;; Date is picked up as a line number but file existence test before + ;; concluding it is a button save it from being identified as + ;; a ripgrep-msg. + (with-temp-buffer + (insert "one two three\n2024-07-30 line\n") + (goto-line 2) + (should-not (eq (hattr:get (hbut:at-p) 'actype) 'hib-link-to-file-line)) + (should-not (ibtypes::ripgrep-msg))) + ;; Regular ripgrep-msg case. + (with-temp-buffer + (insert "hibtypes.el\n20: line\n") + (goto-line 2) + (mocklet (((hib-link-to-file-line "hibtypes.el" "20") => t) + ((file-exists-p "hibtypes.el") => t)) + (should (eq (hattr:get (hbut:at-p) 'actype) 'hib-link-to-file-line)) + (should (ibtypes::ripgrep-msg)))) + + ;; Regular match but file does not exist case. + (with-temp-buffer + (insert "unknown-file\n20: line\n") + (goto-line 2) + (should-not (eq (hattr:get (hbut:at-p) 'actype) 'hib-link-to-file-line)) + (should-not (ibtypes::ripgrep-msg)))) + ;; grep-msg ;; debugger-source