From 3ba4a280ab14dc08e9f5111dc5f5ed69bc82918e Mon Sep 17 00:00:00 2001 From: Pierre-Andre Date: Tue, 18 Jan 2022 19:32:06 +0100 Subject: [PATCH 1/5] add org src block feature --- dumb-jump.el | 131 +++++++++++++++++++++++++------ test/data/proj1/src/org/test.org | 24 ++++++ test/dumb-jump-test.el | 36 +++++++++ 3 files changed, 168 insertions(+), 23 deletions(-) create mode 100644 test/data/proj1/src/org/test.org diff --git a/dumb-jump.el b/dumb-jump.el index b65df13..09667c6 100644 --- a/dumb-jump.el +++ b/dumb-jump.el @@ -251,6 +251,12 @@ or most optimal searcher." :group 'dumb-jump :type 'string) +(defcustom dumb-jump-search-type-org-only-org + t + "If non nil restrict type ag/rg to org file. +If nil add also the language type of current src block" + :group 'dumb-jump + :type 'boolean) (defcustom dumb-jump-find-rules '((:type "function" :supports ("ag" "grep" "rg" "git-grep") :language "elisp" @@ -2038,9 +2044,9 @@ for user to select. Filters PROJ path from files for display." ((and (eq dumb-jump-selector 'helm) (fboundp 'helm)) (helm :sources (helm-make-source "Jump to: " 'helm-source-sync - :action '(("Jump to match" . dumb-jump-result-follow)) - :candidates (-zip choices results) - :persistent-action 'dumb-jump-helm-persist-action) + :action '(("Jump to match" . dumb-jump-result-follow)) + :candidates (-zip choices results) + :persistent-action 'dumb-jump-helm-persist-action) :buffer "*helm dumb jump choices*")) (t (dumb-jump-to-selected results choices (popup-menu* choices)))))) @@ -2067,27 +2073,101 @@ to keep looking for another root." (defun dumb-jump-get-language (file) "Get language from FILE extension and then fallback to using 'major-mode' name." - (let* ((languages (-distinct - (--map (plist-get it :language) - dumb-jump-find-rules))) - (language (or (dumb-jump-get-language-from-mode) + (let* ((language (or (dumb-jump-get-language-from-mode) (dumb-jump-get-language-by-filename file) (dumb-jump-get-mode-base-name)))) - (if (member language languages) + ; src edit buffer ? org-edit-src-exit + (if (and (fboundp 'org-src-edit-buffer-p) + (org-src-edit-buffer-p)) + ;; set the composite language + (let* ((beg org-src--beg-marker) + (source-buffer (marker-buffer beg))) + (with-current-buffer source-buffer + (setq language (dumb-jump-get-language-in-org))) + ;; save+exit the sub-editing buffer and search in project + (org-edit-src-exit)) + (if (string= language "org") + (setq language (dumb-jump-get-language-in-org)))) + (if (member language (-distinct + (--map (plist-get it :language) + dumb-jump-find-rules))) language (format ".%s file" (or (file-name-extension file) ""))))) +(defun dumb-jump-get-language-in-org () + "In org mode, if inside a src block return +associated language or org when outside a src block." + (let ((lang (nth 0 (org-babel-get-src-block-info)))) + ; if lang exists then create a composite language + (if lang + (dumb-jump-make-composite-language + "org" + (if (dumb-jump-get-language-from-aliases lang) + (dumb-jump-get-language-from-aliases lang) lang) + "org" "org" "org") + "org"))) + +(defun dumb-jump-add-language-to-proplist (newlang proplist lang) + "Return nil if NEWLANG is already in PROPLIST or (if not) +return a new proplist. The new proplis is PROPLIS +where a NEWLANG plist(s) is (are) added to PROPLIST. +The plist(s) value of NEWLANG is (are) copied from +those of LANG and LANG is replaced by NEWLANG." + (let ((alreadyuptodate + (--filter (string= newlang (plist-get it :language)) + proplist))) + (if alreadyuptodate + nil + (--splice + (string= lang (plist-get it :language)) + (list it (plist-put (copy-tree it) :language newlang)) + proplist)))) + +(defun dumb-jump-make-composite-language (mode lang extension agtype rgtype) + "Concat one MODE (usually the string org) with a LANG (c or python or etc) +to make a composite language of the form cPLUSorg or pythonPLUSorg or etc. +Modify `dumb-jump-find-rules' and `dumb-jump-language-file-exts' accordingly +(using EXTENSION AGTYPE RGTYPE)" + (let* ((complang (concat lang "PLUS" mode)) + (alreadyextension (--filter (and + (string= complang (plist-get it :language)) + (string= extension (plist-get it :ext)) + (string= agtype (plist-get it :agtype)) + (string= rgtype (plist-get it :rgtype))) + dumb-jump-language-file-exts)) + (newfindrule (dumb-jump-add-language-to-proplist complang dumb-jump-find-rules lang)) + (newfileexts (dumb-jump-add-language-to-proplist complang dumb-jump-language-file-exts lang))) + ;; add (if needed) composite language to dumb-jump-find-rules + (if newfindrule + (set-default 'dumb-jump-find-rules newfindrule)) + ;; add (if needed) composite language to dumb-jump-language-file-exts + (if (not dumb-jump-search-type-org-only-org) + (if newfileexts + (set-default 'dumb-jump-language-file-exts newfileexts))) + ;; add (if needed) a new extension to dumb-jump-language-file-exts + (if (not alreadyextension) + (set-default 'dumb-jump-language-file-exts + (cons `(:language ,complang :ext ,extension :agtype ,agtype :rgtype ,rgtype) + dumb-jump-language-file-exts))) + complang)) + +(defun dumb-jump-get-language-from-aliases (lang) + "Extract the lang from aliases." + (let* ((lookup '(sh "shell" shell "shell" cperl "perl" + matlab "matlab" octave "matlab" + emacs-lisp "elisp" elisp "elisp" + R "r" r "r")) + (result (plist-get lookup (intern lang)))) + (if result result nil))) + (defun dumb-jump-get-mode-base-name () "Get the base name of the mode." (s-replace "-mode" "" (symbol-name major-mode))) (defun dumb-jump-get-language-from-mode () "Extract the language from the 'major-mode' name. Currently just everything before '-mode'." - (let* ((lookup '(sh "shell" cperl "perl" matlab "matlab" octave "matlab")) - (m (dumb-jump-get-mode-base-name)) - (result (plist-get lookup (intern m)))) - result)) - + (let ((m (dumb-jump-get-mode-base-name))) + (dumb-jump-get-language-from-aliases m))) (defun dumb-jump-get-language-by-filename (file) "Get the programming language from the FILE." @@ -2097,7 +2177,7 @@ to keep looking for another root." (result (--filter (s-ends-with? (concat "." (plist-get it :ext)) filename) dumb-jump-language-file-exts))) - (when result + (when (and result (eq (length result) 1)) (plist-get (car result) :language)))) (defun dumb-jump-issue-result (issue) @@ -2105,7 +2185,8 @@ to keep looking for another root." `(:results nil :lang nil :symbol nil :ctx-type nil :file nil :root nil :issue ,(intern issue))) (defun dumb-jump-get-results (&optional prompt) - "Run dumb-jump-fetch-results if searcher installed, buffer is saved, and there's a symbol under point." + "Run dumb-jump-fetch-results if searcher installed, buffer is saved, +and there's a symbol under point." (cond ((not (or (dumb-jump-ag-installed?) (dumb-jump-rg-installed?) @@ -2312,7 +2393,7 @@ current file." ;; multiple results so let the user pick from a list ;; unless the match is in the current file (dumb-jump-handle-results results (plist-get info :file) proj-root (plist-get info :ctx-type) - look-for use-tooltip prefer-external)) + look-for use-tooltip prefer-external lang)) ((= result-count 0) (dumb-jump-message "'%s' %s %s declaration not found." look-for (if (s-blank? lang) "with unknown language so" lang) (plist-get info :ctx-type)))))) @@ -2390,15 +2471,16 @@ given the LANG of the current file." results))) (defun dumb-jump-handle-results - (results cur-file proj-root ctx-type look-for use-tooltip prefer-external) + (results cur-file proj-root ctx-type look-for use-tooltip prefer-external &optional language) "Handle the searchers results. RESULTS is a list of property lists with the searcher's results. CUR-FILE is the current file within PROJ-ROOT. CTX-TYPE is a string of the current context. LOOK-FOR is the symbol we're jumping for. USE-TOOLTIP shows a preview instead of jumping. -PREFER-EXTERNAL will sort current file last." - (let* ((processed (dumb-jump-process-results results cur-file proj-root ctx-type look-for use-tooltip prefer-external)) +PREFER-EXTERNAL will sort current file last +LANGUAGE is an optional language to pass to `dumb-jump-process-results'." + (let* ((processed (dumb-jump-process-results results cur-file proj-root ctx-type look-for use-tooltip prefer-external language)) (results (plist-get processed :results)) (do-var-jump (plist-get processed :do-var-jump)) (var-to-jump (plist-get processed :var-to-jump)) @@ -2421,16 +2503,18 @@ PREFER-EXTERNAL will sort current file last." (dumb-jump-prompt-user-for-choice proj-root match-cur-file-front))))) (defun dumb-jump-process-results - (results cur-file proj-root ctx-type _look-for _use-tooltip prefer-external) + (results cur-file proj-root ctx-type _look-for _use-tooltip prefer-external &optional language) "Process (filter, sort, ...) the searchers results. RESULTS is a list of property lists with the searcher's results. CUR-FILE is the current file within PROJ-ROOT. CTX-TYPE is a string of the current context. LOOK-FOR is the symbol we're jumping for. USE-TOOLTIP shows a preview instead of jumping. -PREFER-EXTERNAL will sort current file last." +PREFER-EXTERNAL will sort current file last. +LANGUAGE is the optional given language, if nil it will be found by +dumb-jump-get-language-by-filename." "Figure which of the RESULTS to jump to. Favoring the CUR-FILE" - (let* ((lang (dumb-jump-get-language-by-filename cur-file)) + (let* ((lang (if language language (dumb-jump-get-language-by-filename cur-file))) (match-sorted (-sort (lambda (x y) (< (plist-get x :diff) (plist-get y :diff))) results)) (match-no-comments (dumb-jump-filter-no-start-comments match-sorted lang)) @@ -3091,7 +3175,8 @@ Using ag to search only the files found via git-grep literal symbol search." (plist-get info :ctx-type) look-for nil - nil)) + nil + lang)) (results (plist-get processed :results)) (do-var-jump (plist-get processed :do-var-jump)) (var-to-jump (plist-get processed :var-to-jump)) diff --git a/test/data/proj1/src/org/test.org b/test/data/proj1/src/org/test.org new file mode 100644 index 0000000..a1b7747 --- /dev/null +++ b/test/data/proj1/src/org/test.org @@ -0,0 +1,24 @@ +* python +#+begin_src python :results none :session "ses1" :exports code :comments org + a=1 + blabla(x) + b=1 + c=2 + d=3 + e=3 + def blabla(x): + return x +#+end_src + +* R + #+begin_src R :file toto.png :results graphics file :session :exports both :comments org + plot(1, blabla(1)) + blabla(2) + #+end_src + + #+begin_src R :results none :session :exports code :comments org + blabla(x) + blabla <- function(x) { + x*x + } + #+end_src diff --git a/test/dumb-jump-test.el b/test/dumb-jump-test.el index bbad6a2..aa6ce27 100644 --- a/test/dumb-jump-test.el +++ b/test/dumb-jump-test.el @@ -1042,6 +1042,42 @@ (mock (dumb-jump-goto-file-line * 6 18)) (should (string= cpp-file (dumb-jump-go))))))) +(ert-deftest dumb-jump-org-test1 () + (let ((org-file (f-join test-data-dir-proj1 "src" "org" "test.org"))) + (with-current-buffer (find-file-noselect org-file t) + (goto-char (point-min)) + (forward-line 3) + (forward-char 2) + (with-mock + (mock (dumb-jump-goto-file-line * 9 6)) + (should (string= org-file (dumb-jump-go))))))) + +(ert-deftest dumb-jump-org-test2 () + (let ((org-file (f-join test-data-dir-proj1 "src" "org" "test.org"))) + (with-current-buffer (find-file-noselect org-file t) + (goto-char (point-min)) + (forward-line 14) + (forward-char 10) + (with-mock + (mock (dumb-jump-goto-file-line * 21 2)) + (should (string= org-file (dumb-jump-go))))))) + +(ert-deftest dumb-jump-org-issue135 () + (require 'org) + (require 'ob-python) + (org-babel-do-load-languages 'org-babel-load-languages '((python . t))) + (let ((org-file (f-join test-data-dir-proj1 "src" "org" "test.org"))) + (with-current-buffer (find-file-noselect org-file t) + (goto-char (point-min)) + (forward-line 3) + (forward-char 2) + (org-edit-src-code) + (with-mock + (mock (dumb-jump-goto-file-line * 9 6)) + (should (string= org-file (dumb-jump-go))))))) + + + ;; This test verifies that having ".dumbjumpignore" files in the two sub-projects will make it find ;; the "multiproj" folder as project root since it has a ".dumbjump" file. The two sub-projects have ;; a dummy ".git" folder to signify it as a repository that would normally become the root without From eb08812760aebc86cd3785bd75bf217fef12223a Mon Sep 17 00:00:00 2001 From: Pierre-Andre Date: Sat, 29 Jan 2022 11:39:48 +0100 Subject: [PATCH 2/5] Org: include comments from Phikal --- dumb-jump.el | 62 +++++++++++++++++++++++----------------------------- 1 file changed, 27 insertions(+), 35 deletions(-) diff --git a/dumb-jump.el b/dumb-jump.el index 09667c6..97bb466 100644 --- a/dumb-jump.el +++ b/dumb-jump.el @@ -50,7 +50,7 @@ (require 'cl-lib) (defgroup dumb-jump nil - "Easily jump to project function and variable definitions" + "Easily jump to project function and variable definitions." :group 'tools :group 'convenience) @@ -235,19 +235,19 @@ or most optimal searcher." (defcustom dumb-jump-git-grep-search-args "" - "Appends the passed arguments to the git-grep search function. Default: \"\"" + "Appends the passed arguments to the git-grep search function. Default: \"\"." :group 'dumb-jump :type 'string) (defcustom dumb-jump-ag-search-args "" - "Appends the passed arguments to the ag search function. Default: \"\"" + "Appends the passed arguments to the ag search function. Default: \"\"." :group 'dumb-jump :type 'string) (defcustom dumb-jump-rg-search-args "--pcre2" - "Appends the passed arguments to the rg search function. Default: \"--pcre2\"" + "Appends the passed arguments to the rg search function. Default: \"--pcre2\"." :group 'dumb-jump :type 'string) @@ -1777,8 +1777,8 @@ If `nil` always show list of more than 1 match." (defcustom dumb-jump-confirm-jump-to-modified-file t - "If t, confirm before jumping to a modified file (which may lead to an -inaccurate jump). If nil, jump without confirmation but print a warning." + "If t, confirm before jumping to a modified file (which may lead to an inaccurate jump). +If nil, jump without confirmation but print a warning." :group 'dumb-jump :type 'boolean) @@ -1850,7 +1850,7 @@ inaccurate jump). If nil, jump without confirmation but print a warning." (buffer-substring-no-properties (point-min) (point-max)))) (defun dumb-jump-run-test-temp-file (test thefile realcmd) - "Write content to the temporary file, run cmd on it, return result" + "Write content to the temporary file, run cmd on it, return result." (with-temp-buffer (insert test) (write-file thefile nil) @@ -1866,8 +1866,8 @@ Because git grep must be given a file as input, not just a string." (dumb-jump-run-test-temp-file test thefile (concat cmd " " thefile)))) (defun dumb-jump-run-ag-test (test cmd) - "Use TEST as input, but first write it into temporary file -and then run ag on it. The difference is that ag ignores multiline + "Use TEST as input, but first write it into temporary file and then run ag on it. +The difference is that ag ignores multiline matches when passed input from stdin, which is a crucial feature." (let ((thefile ".ag.test")) (dumb-jump-run-test-temp-file test thefile (concat cmd " " thefile)))) @@ -2025,8 +2025,8 @@ This is the persistent action (\\[helm-execute-persistent-action]) for helm." (s-trim (plist-get result :context)))) (defun dumb-jump-ivy-jump-to-selected (results choices _proj) - "Offer CHOICES as candidates through `ivy-read', then execute -`dumb-jump-result-follow' on the selected choice. Ignore _PROJ." + "Offer CHOICES as candidates through `ivy-read', then execute `dumb-jump-result-follow' on the selected choice. +Ignore _PROJ." (ivy-read "Jump to: " (-zip choices results) :action (lambda (cand) (dumb-jump-result-follow (cdr cand))) @@ -2098,7 +2098,7 @@ to keep looking for another root." "In org mode, if inside a src block return associated language or org when outside a src block." (let ((lang (nth 0 (org-babel-get-src-block-info)))) - ; if lang exists then create a composite language +;; if lang exists then create a composite language (if lang (dumb-jump-make-composite-language "org" @@ -2113,15 +2113,12 @@ return a new proplist. The new proplis is PROPLIS where a NEWLANG plist(s) is (are) added to PROPLIST. The plist(s) value of NEWLANG is (are) copied from those of LANG and LANG is replaced by NEWLANG." - (let ((alreadyuptodate - (--filter (string= newlang (plist-get it :language)) - proplist))) - (if alreadyuptodate - nil + (unless (--filter (string= newlang (plist-get it :language)) + proplist) (--splice (string= lang (plist-get it :language)) (list it (plist-put (copy-tree it) :language newlang)) - proplist)))) + proplist))) (defun dumb-jump-make-composite-language (mode lang extension agtype rgtype) "Concat one MODE (usually the string org) with a LANG (c or python or etc) @@ -2138,27 +2135,25 @@ Modify `dumb-jump-find-rules' and `dumb-jump-language-file-exts' accordingly (newfindrule (dumb-jump-add-language-to-proplist complang dumb-jump-find-rules lang)) (newfileexts (dumb-jump-add-language-to-proplist complang dumb-jump-language-file-exts lang))) ;; add (if needed) composite language to dumb-jump-find-rules - (if newfindrule + (when newfindrule (set-default 'dumb-jump-find-rules newfindrule)) ;; add (if needed) composite language to dumb-jump-language-file-exts - (if (not dumb-jump-search-type-org-only-org) - (if newfileexts + (unless dumb-jump-search-type-org-only-org + (when newfileexts (set-default 'dumb-jump-language-file-exts newfileexts))) ;; add (if needed) a new extension to dumb-jump-language-file-exts - (if (not alreadyextension) + (unless alreadyextension (set-default 'dumb-jump-language-file-exts (cons `(:language ,complang :ext ,extension :agtype ,agtype :rgtype ,rgtype) dumb-jump-language-file-exts))) complang)) (defun dumb-jump-get-language-from-aliases (lang) - "Extract the lang from aliases." - (let* ((lookup '(sh "shell" shell "shell" cperl "perl" - matlab "matlab" octave "matlab" - emacs-lisp "elisp" elisp "elisp" - R "r" r "r")) - (result (plist-get lookup (intern lang)))) - (if result result nil))) + "Extract the lang from LANG and aliases." + (assoc-default lang '(("sh" . "shell") ("shell" . "shell") ("cperl" . "perl") + ("matlab" . "matlab") ("octave" . "matlab") + ("emacs-lisp" . "elisp") ("elisp" . "elisp") + ("R" . "r") ("r" . "r")))) (defun dumb-jump-get-mode-base-name () "Get the base name of the mode." @@ -2185,8 +2180,7 @@ Modify `dumb-jump-find-rules' and `dumb-jump-language-file-exts' accordingly `(:results nil :lang nil :symbol nil :ctx-type nil :file nil :root nil :issue ,(intern issue))) (defun dumb-jump-get-results (&optional prompt) - "Run dumb-jump-fetch-results if searcher installed, buffer is saved, -and there's a symbol under point." + "Run dumb-jump-fetch-results if searcher installed, buffer is saved, and there's a symbol under point." (cond ((not (or (dumb-jump-ag-installed?) (dumb-jump-rg-installed?) @@ -2763,9 +2757,7 @@ searcher symbol." (dumb-jump-generators-by-searcher 'grep)))) (defun dumb-jump-shell-command-switch () - "Yields the shell command switch to use for the current - `shell-file-name' in order to not load the shell profile/RC for - speeding up things." + "Yields the shell command switch to use for the current `shell-file-name' in order to not load the shell profile/RC for speeding up things." (let ((base-name (downcase (file-name-base shell-file-name)))) (cond ((or (string-equal "zsh" base-name) @@ -3125,7 +3117,7 @@ Using ag to search only the files found via git-grep literal symbol search." ;;;###autoload (define-minor-mode dumb-jump-mode - "Minor mode for jumping to variable and function definitions" + "Minor mode for jumping to variable and function definitions." :global t :keymap dumb-jump-mode-map) From 7cb85a85403b64abe5df90e19acdd2e0c6b61abe Mon Sep 17 00:00:00 2001 From: Pierre-Andre Date: Sat, 29 Jan 2022 15:30:01 +0100 Subject: [PATCH 3/5] Org: undo all checkdoc issues, org-mode src block only --- dumb-jump.el | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/dumb-jump.el b/dumb-jump.el index 97bb466..9988c6a 100644 --- a/dumb-jump.el +++ b/dumb-jump.el @@ -50,7 +50,7 @@ (require 'cl-lib) (defgroup dumb-jump nil - "Easily jump to project function and variable definitions." + "Easily jump to project function and variable definitions" :group 'tools :group 'convenience) @@ -235,19 +235,19 @@ or most optimal searcher." (defcustom dumb-jump-git-grep-search-args "" - "Appends the passed arguments to the git-grep search function. Default: \"\"." + "Appends the passed arguments to the git-grep search function. Default: \"\"" :group 'dumb-jump :type 'string) (defcustom dumb-jump-ag-search-args "" - "Appends the passed arguments to the ag search function. Default: \"\"." + "Appends the passed arguments to the ag search function. Default: \"\"" :group 'dumb-jump :type 'string) (defcustom dumb-jump-rg-search-args "--pcre2" - "Appends the passed arguments to the rg search function. Default: \"--pcre2\"." + "Appends the passed arguments to the rg search function. Default: \"--pcre2\"" :group 'dumb-jump :type 'string) @@ -1777,8 +1777,8 @@ If `nil` always show list of more than 1 match." (defcustom dumb-jump-confirm-jump-to-modified-file t - "If t, confirm before jumping to a modified file (which may lead to an inaccurate jump). -If nil, jump without confirmation but print a warning." + "If t, confirm before jumping to a modified file (which may lead to an +inaccurate jump). If nil, jump without confirmation but print a warning." :group 'dumb-jump :type 'boolean) @@ -1850,7 +1850,7 @@ If nil, jump without confirmation but print a warning." (buffer-substring-no-properties (point-min) (point-max)))) (defun dumb-jump-run-test-temp-file (test thefile realcmd) - "Write content to the temporary file, run cmd on it, return result." + "Write content to the temporary file, run cmd on it, return result" (with-temp-buffer (insert test) (write-file thefile nil) @@ -1866,8 +1866,8 @@ Because git grep must be given a file as input, not just a string." (dumb-jump-run-test-temp-file test thefile (concat cmd " " thefile)))) (defun dumb-jump-run-ag-test (test cmd) - "Use TEST as input, but first write it into temporary file and then run ag on it. -The difference is that ag ignores multiline + "Use TEST as input, but first write it into temporary file +and then run ag on it. The difference is that ag ignores multiline matches when passed input from stdin, which is a crucial feature." (let ((thefile ".ag.test")) (dumb-jump-run-test-temp-file test thefile (concat cmd " " thefile)))) @@ -2025,8 +2025,8 @@ This is the persistent action (\\[helm-execute-persistent-action]) for helm." (s-trim (plist-get result :context)))) (defun dumb-jump-ivy-jump-to-selected (results choices _proj) - "Offer CHOICES as candidates through `ivy-read', then execute `dumb-jump-result-follow' on the selected choice. -Ignore _PROJ." + "Offer CHOICES as candidates through `ivy-read', then execute +`dumb-jump-result-follow' on the selected choice. Ignore _PROJ." (ivy-read "Jump to: " (-zip choices results) :action (lambda (cand) (dumb-jump-result-follow (cdr cand))) @@ -2044,9 +2044,9 @@ for user to select. Filters PROJ path from files for display." ((and (eq dumb-jump-selector 'helm) (fboundp 'helm)) (helm :sources (helm-make-source "Jump to: " 'helm-source-sync - :action '(("Jump to match" . dumb-jump-result-follow)) - :candidates (-zip choices results) - :persistent-action 'dumb-jump-helm-persist-action) + :action '(("Jump to match" . dumb-jump-result-follow)) + :candidates (-zip choices results) + :persistent-action 'dumb-jump-helm-persist-action) :buffer "*helm dumb jump choices*")) (t (dumb-jump-to-selected results choices (popup-menu* choices)))))) @@ -2757,7 +2757,9 @@ searcher symbol." (dumb-jump-generators-by-searcher 'grep)))) (defun dumb-jump-shell-command-switch () - "Yields the shell command switch to use for the current `shell-file-name' in order to not load the shell profile/RC for speeding up things." + "Yields the shell command switch to use for the current + `shell-file-name' in order to not load the shell profile/RC for + speeding up things." (let ((base-name (downcase (file-name-base shell-file-name)))) (cond ((or (string-equal "zsh" base-name) @@ -3117,7 +3119,7 @@ Using ag to search only the files found via git-grep literal symbol search." ;;;###autoload (define-minor-mode dumb-jump-mode - "Minor mode for jumping to variable and function definitions." + "Minor mode for jumping to variable and function definitions" :global t :keymap dumb-jump-mode-map) From 3e0999051255a6a09c36e5342177b1899406b438 Mon Sep 17 00:00:00 2001 From: Pierre-Andre Date: Mon, 7 Feb 2022 17:00:13 +0100 Subject: [PATCH 4/5] Org: remove call to org-internal function --- dumb-jump.el | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/dumb-jump.el b/dumb-jump.el index 9988c6a..22b379c 100644 --- a/dumb-jump.el +++ b/dumb-jump.el @@ -2079,15 +2079,10 @@ to keep looking for another root." ; src edit buffer ? org-edit-src-exit (if (and (fboundp 'org-src-edit-buffer-p) (org-src-edit-buffer-p)) - ;; set the composite language - (let* ((beg org-src--beg-marker) - (source-buffer (marker-buffer beg))) - (with-current-buffer source-buffer - (setq language (dumb-jump-get-language-in-org))) - ;; save+exit the sub-editing buffer and search in project - (org-edit-src-exit)) - (if (string= language "org") - (setq language (dumb-jump-get-language-in-org)))) + (progn (setq language "org") + (org-edit-src-exit))) + (if (string= language "org") + (setq language (dumb-jump-get-language-in-org))) (if (member language (-distinct (--map (plist-get it :language) dumb-jump-find-rules))) From 186675260bee073092d713aac14fe09751ad5efd Mon Sep 17 00:00:00 2001 From: Pierre-Andre Date: Fri, 4 Mar 2022 10:59:38 +0100 Subject: [PATCH 5/5] new tests to cope with old versions of AG and orgmode --- dumb-jump.el | 4 +++- test/dumb-jump-test.el | 28 ++++++++++++++++++++++------ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/dumb-jump.el b/dumb-jump.el index 22b379c..b00240b 100644 --- a/dumb-jump.el +++ b/dumb-jump.el @@ -2080,7 +2080,9 @@ to keep looking for another root." (if (and (fboundp 'org-src-edit-buffer-p) (org-src-edit-buffer-p)) (progn (setq language "org") - (org-edit-src-exit))) + (org-edit-src-exit) + (if (version< org-version "9") + (save-buffer)))) (if (string= language "org") (setq language (dumb-jump-get-language-in-org))) (if (member language (-distinct diff --git a/test/dumb-jump-test.el b/test/dumb-jump-test.el index aa6ce27..676a9c0 100644 --- a/test/dumb-jump-test.el +++ b/test/dumb-jump-test.el @@ -1043,30 +1043,43 @@ (should (string= cpp-file (dumb-jump-go))))))) (ert-deftest dumb-jump-org-test1 () - (let ((org-file (f-join test-data-dir-proj1 "src" "org" "test.org"))) + (let ((org-file (f-join test-data-dir-proj1 "src" "org" "test.org")) + (oldpar dumb-jump-force-searcher)) + (setq dumb-jump-force-searcher 'rg) (with-current-buffer (find-file-noselect org-file t) (goto-char (point-min)) (forward-line 3) (forward-char 2) (with-mock (mock (dumb-jump-goto-file-line * 9 6)) - (should (string= org-file (dumb-jump-go))))))) + (should (string= org-file (dumb-jump-go))))) + (setq dumb-jump-force-searcher oldpar))) (ert-deftest dumb-jump-org-test2 () - (let ((org-file (f-join test-data-dir-proj1 "src" "org" "test.org"))) + (let ((org-file (f-join test-data-dir-proj1 "src" "org" "test.org")) + (oldpar dumb-jump-force-searcher)) + (setq dumb-jump-force-searcher 'rg) (with-current-buffer (find-file-noselect org-file t) (goto-char (point-min)) (forward-line 14) (forward-char 10) (with-mock (mock (dumb-jump-goto-file-line * 21 2)) - (should (string= org-file (dumb-jump-go))))))) + (should (string= org-file (dumb-jump-go))))) + (setq dumb-jump-force-searcher oldpar))) (ert-deftest dumb-jump-org-issue135 () (require 'org) (require 'ob-python) (org-babel-do-load-languages 'org-babel-load-languages '((python . t))) - (let ((org-file (f-join test-data-dir-proj1 "src" "org" "test.org"))) + (let ((org-file (f-join test-data-dir-proj1 "src" "org" "test.org")) + (oldpar dumb-jump-force-searcher) + (oldproject dumb-jump-project)) + ;; in docker test AG version is 0.3 and 2.1.0 is needed + (setq dumb-jump-force-searcher 'rg) + ;; old version of org does not lead to point to the right directory + (if (version< org-version "9") + (setq dumb-jump-project (f-join test-data-dir-proj1 "src" "org"))) (with-current-buffer (find-file-noselect org-file t) (goto-char (point-min)) (forward-line 3) @@ -1074,7 +1087,10 @@ (org-edit-src-code) (with-mock (mock (dumb-jump-goto-file-line * 9 6)) - (should (string= org-file (dumb-jump-go))))))) + (should (string= org-file (dumb-jump-go))))) + (setq dumb-jump-force-searcher oldpar) + (if (version< org-version "9") + (setq dumb-jump-project oldproject))))