Skip to content

Commit

Permalink
Added search argument options for each search tool (#271)
Browse files Browse the repository at this point in the history
  • Loading branch information
DeeeeLAN authored and jacktasia committed Mar 8, 2019
1 parent fc4b472 commit 25b1606
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 11 deletions.
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -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 `""`).
* `(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).

Expand Down
31 changes: 24 additions & 7 deletions dumb-jump.el
Expand Up @@ -214,9 +214,21 @@ or most optimal searcher."
:group 'dumb-jump
:type 'boolean)

(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-git-grep-search-args
""
"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: \"\""
: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)

Expand Down Expand Up @@ -2465,6 +2477,8 @@ searcher symbol."
(if (s-ends-with? ".gz" cur-file)
" --search-zip"
"")
(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
"--ignore-dir" (--map (shell-quote-argument (s-replace proj-dir "" it)) exclude-paths)))
Expand Down Expand Up @@ -2518,7 +2532,9 @@ 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"
(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
"-g" (--map (shell-quote-argument (concat "!" (s-replace proj-dir "" it))) exclude-paths)))
Expand All @@ -2533,9 +2549,10 @@ 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
"")
(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)))
(exclude-args (s-join " "
Expand Down
24 changes: 20 additions & 4 deletions test/dumb-jump-test.el
Expand Up @@ -159,17 +159,33 @@
(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-extra-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 "--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 --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 ()
;; 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)
(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"))
Expand Down

0 comments on commit 25b1606

Please sign in to comment.