From 0ce27f5ee03cf4f5bdf5c557ee90ebe4a8c50c0e Mon Sep 17 00:00:00 2001 From: Dillan Mills Date: Thu, 7 Mar 2019 11:22:23 -0700 Subject: [PATCH 01/11] added extra-args options --- README.md | 3 +++ dumb-jump.el | 53 ++++++++++++++++++++++++++++++------------ test/dumb-jump-test.el | 31 +++++++++++++++++++++--- 3 files changed, 69 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 2ff0323..40f5b81 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,9 @@ If you want to stop a directory from registering as the project root (and have D * `(setq dumb-jump-aggressive nil)` to only automatically jump if there's only one match and otherwise present you with a list. This defaults to `t`, which means it will try its best to guess where you want to jump and only if it can't then give you a list of matches. * `(setq dumb-jump-use-visible-window nil)` if `t` (the default) when you're using multiple windows/panes and the file to jump to is already open in one of those windows then dumb jump will focus that window and jump there instead of within your current window. * `(setq dumb-jump-prefer-searcher 'rg)` to let Dumb Jump know your searcher preference. If set this will still use `git-grep` if it's a git project (because it's the fastest), but will you use whatever you set here in any other situation. If not set Dumb Jump will follow the same order as mentioned in the `dumb-jump-force-searcher` description. At this time setting this value is only necessary if you prefer `rg` but have `ag` installed too. +* `(setq dumb-jump-git-grep-search-args "")` to set additional command line arguments when using git-grep for searching (defaults to `"--untracked"`). +* `(setq dumb-jump-ag-search-args "")` to set additional command line arguments when using ag for searching (defaults to `""`). +* `(setq dumb-jump-rg-search-args "")` to set additional command line arguments when using rg for searching (defaults to `"--pcre2"`). #### If your project has multi-line method signatures [you should use `ag`](https://github.com/jacktasia/dumb-jump/issues/129) or [`rg` with a version higher than `0.10`](https://github.com/jacktasia/dumb-jump/issues/255). diff --git a/dumb-jump.el b/dumb-jump.el index bb4e99b..437e2a1 100644 --- a/dumb-jump.el +++ b/dumb-jump.el @@ -208,15 +208,33 @@ or most optimal searcher." :group 'dumb-jump :type 'boolean) -(defcustom dumb-jump-git-grep-search-untracked - t - "If non-nil Dumb Jump will also search untracked files when using searcher git-grep." +;; (defcustom dumb-jump-git-grep-search-untracked +;; t +;; "If non-nil Dumb Jump will also search untracked files when using searcher git-grep." +;; :group 'dumb-jump +;; :type 'boolean) + +;; (defcustom dumb-jump-git-grep-search-untracked-args +;; "--untracked" +;; "If non-nil Dumb Jump will also search untracked files when using searcher git-grep." +;; :group 'dumb-jump +;; :type 'boolean) + +(defcustom dumb-jump-git-grep-search-args + "--untracked" + "Appends the passed arguments to the git-grep search function. Default: \"--untracked\"" :group 'dumb-jump - :type 'boolean) + :type 'string) -(defcustom dumb-jump-git-grep-search-untracked-args - " --untracked" - "If dumb-jump-git-grep-search-untracked is non-nil Dumb Jump will add these arguments." +(defcustom dumb-jump-ag-search-args + "" + "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\"" :group 'dumb-jump :type 'string) @@ -2461,10 +2479,11 @@ searcher symbol." (proj-dir (file-name-as-directory proj)) ;; TODO: --search-zip always? in case the include is the in gz area like emacs lisp code. (cmd (concat dumb-jump-ag-cmd - " --nocolor --nogroup" + " --nocolor --nogroup " (if (s-ends-with? ".gz" cur-file) - " --search-zip" + "--search-zip " "") + dumb-jump-search-args (s-join "" (--map (format " --%s" it) agtypes)))) (exclude-args (dumb-jump-arg-joiner "--ignore-dir" (--map (shell-quote-argument (s-replace proj-dir "" it)) exclude-paths))) @@ -2518,7 +2537,8 @@ Using ag to search only the files found via git-grep literal symbol search." (rgtypes (dumb-jump-get-rg-type-by-language lang)) (proj-dir (file-name-as-directory proj)) (cmd (concat dumb-jump-rg-cmd - " --color never --no-heading --line-number -U --pcre2" + " --color never --no-heading --line-number -U " + dumb-jump-rg-search-args (s-join "" (--map (format " --type %s" it) rgtypes)))) (exclude-args (dumb-jump-arg-joiner "-g" (--map (shell-quote-argument (concat "!" (s-replace proj-dir "" it))) exclude-paths))) @@ -2532,11 +2552,14 @@ Using ag to search only the files found via git-grep literal symbol search." (let* ((filled-regexes (dumb-jump-populate-regexes look-for regexes 'git-grep)) (ggtypes (when (f-ext cur-file) (dumb-jump-get-git-grep-type-by-language lang))) (cmd (concat dumb-jump-git-grep-cmd - " --color=never --line-number" - (if dumb-jump-git-grep-search-untracked - dumb-jump-git-grep-search-untracked-args - "") - " -E")) + " --color=never --line-number " + ;; (if dumb-jump-git-grep-search-untracked + ;; dumb-jump-git-grep-search-untracked-args " " + ;; "") + (if (= (length dumb-jump-git-grep-search-args) 0) + "" + dumb-jump-git-grep-search-args " ") + "-E")) (fileexps (s-join " " (--map (shell-quote-argument (format "%s/*.%s" proj it)) ggtypes))) (exclude-args (s-join " " (--map (shell-quote-argument (concat ":(exclude)" it)) diff --git a/test/dumb-jump-test.el b/test/dumb-jump-test.el index ad856ae..7023e64 100644 --- a/test/dumb-jump-test.el +++ b/test/dumb-jump-test.el @@ -159,15 +159,40 @@ (expected (concat "git grep --color=never --line-number --untracked -E " (shell-quote-argument expected-regexes) " -- ./\\*.el ./\\*.el.gz \\:\\(exclude\\)one \\:\\(exclude\\)two \\:\\(exclude\\)three"))) (should (string= expected (dumb-jump-generate-git-grep-command "tester" "blah.el" "." regexes "elisp" excludes))))) -(ert-deftest dumb-jump-generate-git-grep-command-no-ctx-untracked-override () - ;; --recurse-submodules +;; (ert-deftest dumb-jump-generate-git-grep-command-no-ctx-untracked-override () +;; ;; --recurse-submodules +;; (let* ((regexes (dumb-jump-get-contextual-regexes "elisp" nil 'git-grep)) +;; (expected-regexes "\\((defun|cl-defun)\\s+tester($|[^a-zA-Z0-9\\?\\*-])|\\(defvar\\b\\s*tester($|[^a-zA-Z0-9\\?\\*-])|\\(defcustom\\b\\s*tester($|[^a-zA-Z0-9\\?\\*-])|\\(setq\\b\\s*tester($|[^a-zA-Z0-9\\?\\*-])|\\(tester\\s+|\\((defun|cl-defun)\\s*.+\\(?\\s*tester($|[^a-zA-Z0-9\\?\\*-])\\s*\\)?") +;; (excludes '("one" "two" "three")) +;; (dumb-jump-git-grep-search-untracked-args " --untracked --recurse-submodules") +;; (expected (concat "git grep --color=never --line-number --untracked --recurse-submodules -E " (shell-quote-argument expected-regexes) " -- ./\\*.el ./\\*.el.gz \\:\\(exclude\\)one \\:\\(exclude\\)two \\:\\(exclude\\)three"))) +;; (should (string= expected (dumb-jump-generate-git-grep-command "tester" "blah.el" "." regexes "elisp" excludes))))) + +(ert-deftest dumb-jump-generate-git-grep-command-no-ctx-extra-args () + ;; git-grep args (let* ((regexes (dumb-jump-get-contextual-regexes "elisp" nil 'git-grep)) (expected-regexes "\\((defun|cl-defun)\\s+tester($|[^a-zA-Z0-9\\?\\*-])|\\(defvar\\b\\s*tester($|[^a-zA-Z0-9\\?\\*-])|\\(defcustom\\b\\s*tester($|[^a-zA-Z0-9\\?\\*-])|\\(setq\\b\\s*tester($|[^a-zA-Z0-9\\?\\*-])|\\(tester\\s+|\\((defun|cl-defun)\\s*.+\\(?\\s*tester($|[^a-zA-Z0-9\\?\\*-])\\s*\\)?") (excludes '("one" "two" "three")) - (dumb-jump-git-grep-search-untracked-args " --untracked --recurse-submodules") + (dumb-jump-git-grep-search-args "--untracked --recurse-submodules") (expected (concat "git grep --color=never --line-number --untracked --recurse-submodules -E " (shell-quote-argument expected-regexes) " -- ./\\*.el ./\\*.el.gz \\:\\(exclude\\)one \\:\\(exclude\\)two \\:\\(exclude\\)three"))) (should (string= expected (dumb-jump-generate-git-grep-command "tester" "blah.el" "." regexes "elisp" excludes))))) +(ert-deftest dumb-jump-generate-ag-command-no-ctx-extra-args () + ;; ag args + (let* ((regexes (dumb-jump-get-contextual-regexes "elisp" nil 'ag)) + (expected-regexes "\\((defun|cl-defun)\\s+tester(?![a-zA-Z0-9\\?\\*-])|\\(defvar\\b\\s*tester(?![a-zA-Z0-9\\?\\*-])|\\(defcustom\\b\\s*tester(?![a-zA-Z0-9\\?\\*-])|\\(setq\\b\\s*tester(?![a-zA-Z0-9\\?\\*-])|\\(tester\\s+|\\((defun|cl-defun)\\s*.+\\(?\\s*tester(?![a-zA-Z0-9\\?\\*-])\\s*\\)?") + (dumb-jump-ag-search-args "--follow") + (expected (concat "ag --nocolor --nogroup --follow --ignore-dir this/is/excluded " (shell-quote-argument expected-regexes) " ."))) + (should (string= expected (dumb-jump-generate-ag-command "tester" "blah.el" "." regexes "elisp"))))) + +(ert-deftest dumb-jump-generate-rg-command-no-ctx-extra-args () + ;; rg-args + (let* ((regexes (dumb-jump-get-contextual-regexes "elisp" nil 'rg)) + (expected-regexes "\\((defun|cl-defun)\\s+tester($|[^a-zA-Z0-9\\?\\*-])|\\(defvar\\b\\s*tester($|[^a-zA-Z0-9\\?\\*-])|\\(defcustom\\b\\s*tester($|[^a-zA-Z0-9\\?\\*-])|\\(setq\\b\\s*tester($|[^a-zA-Z0-9\\?\\*-])|\\(tester\\s+|\\((defun|cl-defun)\\s*.+\\(?\\s*tester($|[^a-zA-Z0-9\\?\\*-])\\s*\\)?") + (dumb-jump-rg-search-args "--no-pcre2 --follow") + (expected (concat "rg --color never --no-heading --line-number -U --no-pcre2 --follow --type elisp " (shell-quote-argument expected-regexes) " ."))) + (should (string= expected (dumb-jump-generate-rg-command "tester" "blah.el" "." regexes "elisp" nil))))) + (ert-deftest dumb-jump-generate-git-grep-command-not-search-untracked-test () (let* ((dumb-jump-git-grep-search-untracked nil) (regexes (dumb-jump-get-contextual-regexes "elisp" nil 'git-grep)) From 8389b8fc4a45693f0c31be1ba9cb86153c7d1b93 Mon Sep 17 00:00:00 2001 From: Dillan Mills Date: Thu, 7 Mar 2019 11:29:04 -0700 Subject: [PATCH 02/11] fix not-search-untracked test --- test/dumb-jump-test.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/dumb-jump-test.el b/test/dumb-jump-test.el index 7023e64..1a76c0f 100644 --- a/test/dumb-jump-test.el +++ b/test/dumb-jump-test.el @@ -194,7 +194,7 @@ (should (string= expected (dumb-jump-generate-rg-command "tester" "blah.el" "." regexes "elisp" nil))))) (ert-deftest dumb-jump-generate-git-grep-command-not-search-untracked-test () - (let* ((dumb-jump-git-grep-search-untracked nil) + (let* ((dumb-jump-git-grep-search-args "") (regexes (dumb-jump-get-contextual-regexes "elisp" nil 'git-grep)) (expected-regexes "\\((defun|cl-defun)\\s+tester($|[^a-zA-Z0-9\\?\\*-])|\\(defvar\\b\\s*tester($|[^a-zA-Z0-9\\?\\*-])|\\(defcustom\\b\\s*tester($|[^a-zA-Z0-9\\?\\*-])|\\(setq\\b\\s*tester($|[^a-zA-Z0-9\\?\\*-])|\\(tester\\s+|\\((defun|cl-defun)\\s*.+\\(?\\s*tester($|[^a-zA-Z0-9\\?\\*-])\\s*\\)?") (excludes '("one" "two" "three")) From ecbfb79fc5368949bad4f67cf8e7bcb870be269f Mon Sep 17 00:00:00 2001 From: Dillan Mills Date: Thu, 7 Mar 2019 13:08:03 -0700 Subject: [PATCH 03/11] fix wrong variable name --- dumb-jump.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dumb-jump.el b/dumb-jump.el index 437e2a1..a7e0a0e 100644 --- a/dumb-jump.el +++ b/dumb-jump.el @@ -2483,7 +2483,7 @@ searcher symbol." (if (s-ends-with? ".gz" cur-file) "--search-zip " "") - dumb-jump-search-args + dumb-jump-ag-search-args (s-join "" (--map (format " --%s" it) agtypes)))) (exclude-args (dumb-jump-arg-joiner "--ignore-dir" (--map (shell-quote-argument (s-replace proj-dir "" it)) exclude-paths))) From 74f22dd35edef121e4c15de0fbea2d2a72777e66 Mon Sep 17 00:00:00 2001 From: Dillan Mills Date: Thu, 7 Mar 2019 13:21:21 -0700 Subject: [PATCH 04/11] fixed spacing --- dumb-jump.el | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/dumb-jump.el b/dumb-jump.el index a7e0a0e..5188cb0 100644 --- a/dumb-jump.el +++ b/dumb-jump.el @@ -2479,11 +2479,13 @@ searcher symbol." (proj-dir (file-name-as-directory proj)) ;; TODO: --search-zip always? in case the include is the in gz area like emacs lisp code. (cmd (concat dumb-jump-ag-cmd - " --nocolor --nogroup " + " --nocolor --nogroup" (if (s-ends-with? ".gz" cur-file) - "--search-zip " + " --search-zip" "") - dumb-jump-ag-search-args + (if (= (length dumb-jump-ag-search-args) 0) + "" + " " dumb-jump-git-ag-args) (s-join "" (--map (format " --%s" it) agtypes)))) (exclude-args (dumb-jump-arg-joiner "--ignore-dir" (--map (shell-quote-argument (s-replace proj-dir "" it)) exclude-paths))) @@ -2537,8 +2539,10 @@ Using ag to search only the files found via git-grep literal symbol search." (rgtypes (dumb-jump-get-rg-type-by-language lang)) (proj-dir (file-name-as-directory proj)) (cmd (concat dumb-jump-rg-cmd - " --color never --no-heading --line-number -U " - dumb-jump-rg-search-args + " --color never --no-heading --line-number -U" + (if (= (length dumb-jump-rg-search-args) 0) + "" + " " dumb-jump-rg-search-args) (s-join "" (--map (format " --type %s" it) rgtypes)))) (exclude-args (dumb-jump-arg-joiner "-g" (--map (shell-quote-argument (concat "!" (s-replace proj-dir "" it))) exclude-paths))) @@ -2552,14 +2556,14 @@ Using ag to search only the files found via git-grep literal symbol search." (let* ((filled-regexes (dumb-jump-populate-regexes look-for regexes 'git-grep)) (ggtypes (when (f-ext cur-file) (dumb-jump-get-git-grep-type-by-language lang))) (cmd (concat dumb-jump-git-grep-cmd - " --color=never --line-number " + " --color=never --line-number" ;; (if dumb-jump-git-grep-search-untracked ;; dumb-jump-git-grep-search-untracked-args " " ;; "") (if (= (length dumb-jump-git-grep-search-args) 0) "" - dumb-jump-git-grep-search-args " ") - "-E")) + " " dumb-jump-git-grep-search-args) + " -E")) (fileexps (s-join " " (--map (shell-quote-argument (format "%s/*.%s" proj it)) ggtypes))) (exclude-args (s-join " " (--map (shell-quote-argument (concat ":(exclude)" it)) From 73d90c20d5aec1dc4ae2ec04f8645e540af5e926 Mon Sep 17 00:00:00 2001 From: Dillan Mills Date: Thu, 7 Mar 2019 13:27:45 -0700 Subject: [PATCH 05/11] fixed missing nil in test --- test/dumb-jump-test.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/dumb-jump-test.el b/test/dumb-jump-test.el index 1a76c0f..6f5efe0 100644 --- a/test/dumb-jump-test.el +++ b/test/dumb-jump-test.el @@ -183,7 +183,7 @@ (expected-regexes "\\((defun|cl-defun)\\s+tester(?![a-zA-Z0-9\\?\\*-])|\\(defvar\\b\\s*tester(?![a-zA-Z0-9\\?\\*-])|\\(defcustom\\b\\s*tester(?![a-zA-Z0-9\\?\\*-])|\\(setq\\b\\s*tester(?![a-zA-Z0-9\\?\\*-])|\\(tester\\s+|\\((defun|cl-defun)\\s*.+\\(?\\s*tester(?![a-zA-Z0-9\\?\\*-])\\s*\\)?") (dumb-jump-ag-search-args "--follow") (expected (concat "ag --nocolor --nogroup --follow --ignore-dir this/is/excluded " (shell-quote-argument expected-regexes) " ."))) - (should (string= expected (dumb-jump-generate-ag-command "tester" "blah.el" "." regexes "elisp"))))) + (should (string= expected (dumb-jump-generate-ag-command "tester" "blah.el" "." regexes "elisp" nil))))) (ert-deftest dumb-jump-generate-rg-command-no-ctx-extra-args () ;; rg-args From 64222e6b1f40e8567360b820e066aa58e1751c70 Mon Sep 17 00:00:00 2001 From: Dillan Mills Date: Thu, 7 Mar 2019 13:30:56 -0700 Subject: [PATCH 06/11] concat the preceding space --- dumb-jump.el | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dumb-jump.el b/dumb-jump.el index 5188cb0..7c98826 100644 --- a/dumb-jump.el +++ b/dumb-jump.el @@ -2485,7 +2485,7 @@ searcher symbol." "") (if (= (length dumb-jump-ag-search-args) 0) "" - " " dumb-jump-git-ag-args) + (concat " " dumb-jump-git-ag-args)) (s-join "" (--map (format " --%s" it) agtypes)))) (exclude-args (dumb-jump-arg-joiner "--ignore-dir" (--map (shell-quote-argument (s-replace proj-dir "" it)) exclude-paths))) @@ -2542,7 +2542,7 @@ Using ag to search only the files found via git-grep literal symbol search." " --color never --no-heading --line-number -U" (if (= (length dumb-jump-rg-search-args) 0) "" - " " dumb-jump-rg-search-args) + (concat " " dumb-jump-rg-search-args)) (s-join "" (--map (format " --type %s" it) rgtypes)))) (exclude-args (dumb-jump-arg-joiner "-g" (--map (shell-quote-argument (concat "!" (s-replace proj-dir "" it))) exclude-paths))) @@ -2562,7 +2562,7 @@ Using ag to search only the files found via git-grep literal symbol search." ;; "") (if (= (length dumb-jump-git-grep-search-args) 0) "" - " " dumb-jump-git-grep-search-args) + (concat " " dumb-jump-git-grep-search-args)) " -E")) (fileexps (s-join " " (--map (shell-quote-argument (format "%s/*.%s" proj it)) ggtypes))) (exclude-args (s-join " " From bb1e5f2d66b09673d90a42ab33a3bc1dbbf15a83 Mon Sep 17 00:00:00 2001 From: Dillan Mills Date: Thu, 7 Mar 2019 13:40:43 -0700 Subject: [PATCH 07/11] fixed bad variable name --- dumb-jump.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dumb-jump.el b/dumb-jump.el index 7c98826..22f285b 100644 --- a/dumb-jump.el +++ b/dumb-jump.el @@ -2485,7 +2485,7 @@ searcher symbol." "") (if (= (length dumb-jump-ag-search-args) 0) "" - (concat " " dumb-jump-git-ag-args)) + (concat " " dumb-jump-ag-search-args)) (s-join "" (--map (format " --%s" it) agtypes)))) (exclude-args (dumb-jump-arg-joiner "--ignore-dir" (--map (shell-quote-argument (s-replace proj-dir "" it)) exclude-paths))) From e75382e763c8439d08278db11a9900fe29bcc7dd Mon Sep 17 00:00:00 2001 From: Dillan Mills Date: Thu, 7 Mar 2019 13:53:06 -0700 Subject: [PATCH 08/11] fixed ag test --- test/dumb-jump-test.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/dumb-jump-test.el b/test/dumb-jump-test.el index 6f5efe0..9e0d4a4 100644 --- a/test/dumb-jump-test.el +++ b/test/dumb-jump-test.el @@ -182,7 +182,7 @@ (let* ((regexes (dumb-jump-get-contextual-regexes "elisp" nil 'ag)) (expected-regexes "\\((defun|cl-defun)\\s+tester(?![a-zA-Z0-9\\?\\*-])|\\(defvar\\b\\s*tester(?![a-zA-Z0-9\\?\\*-])|\\(defcustom\\b\\s*tester(?![a-zA-Z0-9\\?\\*-])|\\(setq\\b\\s*tester(?![a-zA-Z0-9\\?\\*-])|\\(tester\\s+|\\((defun|cl-defun)\\s*.+\\(?\\s*tester(?![a-zA-Z0-9\\?\\*-])\\s*\\)?") (dumb-jump-ag-search-args "--follow") - (expected (concat "ag --nocolor --nogroup --follow --ignore-dir this/is/excluded " (shell-quote-argument expected-regexes) " ."))) + (expected (concat "ag --nocolor --nogroup --follow --elisp " (shell-quote-argument expected-regexes) " ."))) (should (string= expected (dumb-jump-generate-ag-command "tester" "blah.el" "." regexes "elisp" nil))))) (ert-deftest dumb-jump-generate-rg-command-no-ctx-extra-args () From f4d118c7a96178e54cb5544f4581f28fd21fdc9a Mon Sep 17 00:00:00 2001 From: jack Date: Thu, 7 Mar 2019 21:37:14 -0800 Subject: [PATCH 09/11] bring back `dumb-jump-git-grep-search-untracked` + separate git grep search args --- README.md | 2 +- dumb-jump.el | 29 ++++++++++------------------- test/dumb-jump-test.el | 13 ++----------- 3 files changed, 13 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 40f5b81..fb64f99 100644 --- a/README.md +++ b/README.md @@ -123,7 +123,7 @@ If you want to stop a directory from registering as the project root (and have D * `(setq dumb-jump-aggressive nil)` to only automatically jump if there's only one match and otherwise present you with a list. This defaults to `t`, which means it will try its best to guess where you want to jump and only if it can't then give you a list of matches. * `(setq dumb-jump-use-visible-window nil)` if `t` (the default) when you're using multiple windows/panes and the file to jump to is already open in one of those windows then dumb jump will focus that window and jump there instead of within your current window. * `(setq dumb-jump-prefer-searcher 'rg)` to let Dumb Jump know your searcher preference. If set this will still use `git-grep` if it's a git project (because it's the fastest), but will you use whatever you set here in any other situation. If not set Dumb Jump will follow the same order as mentioned in the `dumb-jump-force-searcher` description. At this time setting this value is only necessary if you prefer `rg` but have `ag` installed too. -* `(setq dumb-jump-git-grep-search-args "")` to set additional command line arguments when using git-grep for searching (defaults to `"--untracked"`). +* `(setq dumb-jump-git-grep-search-args "")` to set additional command line arguments when using git-grep for searching. * `(setq dumb-jump-ag-search-args "")` to set additional command line arguments when using ag for searching (defaults to `""`). * `(setq dumb-jump-rg-search-args "")` to set additional command line arguments when using rg for searching (defaults to `"--pcre2"`). diff --git a/dumb-jump.el b/dumb-jump.el index 22f285b..abe5feb 100644 --- a/dumb-jump.el +++ b/dumb-jump.el @@ -208,20 +208,14 @@ or most optimal searcher." :group 'dumb-jump :type 'boolean) -;; (defcustom dumb-jump-git-grep-search-untracked -;; t -;; "If non-nil Dumb Jump will also search untracked files when using searcher git-grep." -;; :group 'dumb-jump -;; :type 'boolean) - -;; (defcustom dumb-jump-git-grep-search-untracked-args -;; "--untracked" -;; "If non-nil Dumb Jump will also search untracked files when using searcher git-grep." -;; :group 'dumb-jump -;; :type 'boolean) +(defcustom dumb-jump-git-grep-search-untracked + t + "If non-nil Dumb Jump will also search untracked files when using searcher git-grep." + :group 'dumb-jump + :type 'boolean) (defcustom dumb-jump-git-grep-search-args - "--untracked" + "" "Appends the passed arguments to the git-grep search function. Default: \"--untracked\"" :group 'dumb-jump :type 'string) @@ -2540,8 +2534,7 @@ Using ag to search only the files found via git-grep literal symbol search." (proj-dir (file-name-as-directory proj)) (cmd (concat dumb-jump-rg-cmd " --color never --no-heading --line-number -U" - (if (= (length dumb-jump-rg-search-args) 0) - "" + (when (not (s-blank? dumb-jump-rg-search-args)) (concat " " dumb-jump-rg-search-args)) (s-join "" (--map (format " --type %s" it) rgtypes)))) (exclude-args (dumb-jump-arg-joiner @@ -2557,11 +2550,9 @@ Using ag to search only the files found via git-grep literal symbol search." (ggtypes (when (f-ext cur-file) (dumb-jump-get-git-grep-type-by-language lang))) (cmd (concat dumb-jump-git-grep-cmd " --color=never --line-number" - ;; (if dumb-jump-git-grep-search-untracked - ;; dumb-jump-git-grep-search-untracked-args " " - ;; "") - (if (= (length dumb-jump-git-grep-search-args) 0) - "" + (when dumb-jump-git-grep-search-untracked + " --untracked") + (when (not (s-blank? dumb-jump-git-grep-search-args)) (concat " " dumb-jump-git-grep-search-args)) " -E")) (fileexps (s-join " " (--map (shell-quote-argument (format "%s/*.%s" proj it)) ggtypes))) diff --git a/test/dumb-jump-test.el b/test/dumb-jump-test.el index 9e0d4a4..70fdd68 100644 --- a/test/dumb-jump-test.el +++ b/test/dumb-jump-test.el @@ -159,21 +159,11 @@ (expected (concat "git grep --color=never --line-number --untracked -E " (shell-quote-argument expected-regexes) " -- ./\\*.el ./\\*.el.gz \\:\\(exclude\\)one \\:\\(exclude\\)two \\:\\(exclude\\)three"))) (should (string= expected (dumb-jump-generate-git-grep-command "tester" "blah.el" "." regexes "elisp" excludes))))) -;; (ert-deftest dumb-jump-generate-git-grep-command-no-ctx-untracked-override () -;; ;; --recurse-submodules -;; (let* ((regexes (dumb-jump-get-contextual-regexes "elisp" nil 'git-grep)) -;; (expected-regexes "\\((defun|cl-defun)\\s+tester($|[^a-zA-Z0-9\\?\\*-])|\\(defvar\\b\\s*tester($|[^a-zA-Z0-9\\?\\*-])|\\(defcustom\\b\\s*tester($|[^a-zA-Z0-9\\?\\*-])|\\(setq\\b\\s*tester($|[^a-zA-Z0-9\\?\\*-])|\\(tester\\s+|\\((defun|cl-defun)\\s*.+\\(?\\s*tester($|[^a-zA-Z0-9\\?\\*-])\\s*\\)?") -;; (excludes '("one" "two" "three")) -;; (dumb-jump-git-grep-search-untracked-args " --untracked --recurse-submodules") -;; (expected (concat "git grep --color=never --line-number --untracked --recurse-submodules -E " (shell-quote-argument expected-regexes) " -- ./\\*.el ./\\*.el.gz \\:\\(exclude\\)one \\:\\(exclude\\)two \\:\\(exclude\\)three"))) -;; (should (string= expected (dumb-jump-generate-git-grep-command "tester" "blah.el" "." regexes "elisp" excludes))))) - (ert-deftest dumb-jump-generate-git-grep-command-no-ctx-extra-args () - ;; git-grep args (let* ((regexes (dumb-jump-get-contextual-regexes "elisp" nil 'git-grep)) (expected-regexes "\\((defun|cl-defun)\\s+tester($|[^a-zA-Z0-9\\?\\*-])|\\(defvar\\b\\s*tester($|[^a-zA-Z0-9\\?\\*-])|\\(defcustom\\b\\s*tester($|[^a-zA-Z0-9\\?\\*-])|\\(setq\\b\\s*tester($|[^a-zA-Z0-9\\?\\*-])|\\(tester\\s+|\\((defun|cl-defun)\\s*.+\\(?\\s*tester($|[^a-zA-Z0-9\\?\\*-])\\s*\\)?") (excludes '("one" "two" "three")) - (dumb-jump-git-grep-search-args "--untracked --recurse-submodules") + (dumb-jump-git-grep-search-args "--recurse-submodules") (expected (concat "git grep --color=never --line-number --untracked --recurse-submodules -E " (shell-quote-argument expected-regexes) " -- ./\\*.el ./\\*.el.gz \\:\\(exclude\\)one \\:\\(exclude\\)two \\:\\(exclude\\)three"))) (should (string= expected (dumb-jump-generate-git-grep-command "tester" "blah.el" "." regexes "elisp" excludes))))) @@ -195,6 +185,7 @@ (ert-deftest dumb-jump-generate-git-grep-command-not-search-untracked-test () (let* ((dumb-jump-git-grep-search-args "") + (dumb-jump-git-grep-search-untracked nil) (regexes (dumb-jump-get-contextual-regexes "elisp" nil 'git-grep)) (expected-regexes "\\((defun|cl-defun)\\s+tester($|[^a-zA-Z0-9\\?\\*-])|\\(defvar\\b\\s*tester($|[^a-zA-Z0-9\\?\\*-])|\\(defcustom\\b\\s*tester($|[^a-zA-Z0-9\\?\\*-])|\\(setq\\b\\s*tester($|[^a-zA-Z0-9\\?\\*-])|\\(tester\\s+|\\((defun|cl-defun)\\s*.+\\(?\\s*tester($|[^a-zA-Z0-9\\?\\*-])\\s*\\)?") (excludes '("one" "two" "three")) From 96239261d091ccec2d034a8c64a655f82dc9d57d Mon Sep 17 00:00:00 2001 From: Dillan Mills Date: Fri, 8 Mar 2019 09:34:52 -0700 Subject: [PATCH 10/11] fixed a couple comments --- README.md | 2 +- dumb-jump.el | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index fb64f99..5e8d183 100644 --- a/README.md +++ b/README.md @@ -123,7 +123,7 @@ If you want to stop a directory from registering as the project root (and have D * `(setq dumb-jump-aggressive nil)` to only automatically jump if there's only one match and otherwise present you with a list. This defaults to `t`, which means it will try its best to guess where you want to jump and only if it can't then give you a list of matches. * `(setq dumb-jump-use-visible-window nil)` if `t` (the default) when you're using multiple windows/panes and the file to jump to is already open in one of those windows then dumb jump will focus that window and jump there instead of within your current window. * `(setq dumb-jump-prefer-searcher 'rg)` to let Dumb Jump know your searcher preference. If set this will still use `git-grep` if it's a git project (because it's the fastest), but will you use whatever you set here in any other situation. If not set Dumb Jump will follow the same order as mentioned in the `dumb-jump-force-searcher` description. At this time setting this value is only necessary if you prefer `rg` but have `ag` installed too. -* `(setq dumb-jump-git-grep-search-args "")` to set additional command line arguments when using git-grep for searching. +* `(setq dumb-jump-git-grep-search-args "")` to set additional command line arguments when using git-grep for searching (defaults to `""`). * `(setq dumb-jump-ag-search-args "")` to set additional command line arguments when using ag for searching (defaults to `""`). * `(setq dumb-jump-rg-search-args "")` to set additional command line arguments when using rg for searching (defaults to `"--pcre2"`). diff --git a/dumb-jump.el b/dumb-jump.el index abe5feb..ec7a1ff 100644 --- a/dumb-jump.el +++ b/dumb-jump.el @@ -216,7 +216,7 @@ or most optimal searcher." (defcustom dumb-jump-git-grep-search-args "" - "Appends the passed arguments to the git-grep search function. Default: \"--untracked\"" + "Appends the passed arguments to the git-grep search function. Default: \"\"" :group 'dumb-jump :type 'string) @@ -2477,8 +2477,7 @@ searcher symbol." (if (s-ends-with? ".gz" cur-file) " --search-zip" "") - (if (= (length dumb-jump-ag-search-args) 0) - "" + (when (not (s-blank? dumb-jump-ag-search-args)) (concat " " dumb-jump-ag-search-args)) (s-join "" (--map (format " --%s" it) agtypes)))) (exclude-args (dumb-jump-arg-joiner From 01128d06819f9d115fb9abb1135a65f5f53277e9 Mon Sep 17 00:00:00 2001 From: Dillan Mills Date: Fri, 8 Mar 2019 13:45:25 -0700 Subject: [PATCH 11/11] slightly better SV class handle declaration regex --- dumb-jump.el | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/dumb-jump.el b/dumb-jump.el index ec7a1ff..19f8640 100644 --- a/dumb-jump.el +++ b/dumb-jump.el @@ -1173,7 +1173,7 @@ or most optimal searcher." (:type "type" :supports ("ag" "grep" "rg" "git-grep") :language "systemverilog" :regex "\\s*class\\s+\\bJJJ\\b" :tests ("virtual class test;" "class test;" "class test extends some_class") - :not ("virtual class testing;" "class test2;")) + :not ("virtual class testing;" "class test2;" "class some_test" "class some_class extends test")) (:type "type" :supports ("ag" "grep" "rg" "git-grep") :language "systemverilog" :regex "\\s*task\\s+\\bJJJ\\b" @@ -1190,10 +1190,11 @@ or most optimal searcher." :tests ("function Matrix test ;" "function Matrix test;") :not ("function test blah")) + ;; matches SV class handle declarations (:type "function" :supports ("ag" "rg" "git-grep") :language "systemverilog" - :regex "[^\\s]+\\s+\\bJJJ\\b" - :tests ("some_class_name test" "another_class_name test ;") - :not ("test some_class_name")) + :regex "^\\s*[^\\s]*\\s*[^\\s]+\\s+\\bJJJ\\b" + :tests ("some_class_name test" " another_class_name test ;" "some_class test[];" "some_class #(1) test") + :not ("test some_class_name" "class some_class extends test")) ;; vhdl (:type "type" :supports ("ag" "grep" "rg" "git-grep") :language "vhdl"