Skip to content

Commit

Permalink
Merge pull request #138 from gvol/customizable-arguments
Browse files Browse the repository at this point in the history
Make extra arguments customizable
  • Loading branch information
Wilfred committed Sep 9, 2023
2 parents f720ce8 + 9757533 commit 60e48d3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
22 changes: 20 additions & 2 deletions deadgrep.el
Original file line number Diff line number Diff line change
Expand Up @@ -667,16 +667,34 @@ with a text face property `deadgrep-match-face'."
(setq text (substring-no-properties text))
(apply #'make-text-button text nil :type type properties))

(defcustom deadgrep-extra-arguments
'("--no-config")
"List defining extra arguments passed to deadgrep.
Many arguments are important to how deadgrep parses the output
and some are added programmatically, like those for search type,
case sensitivity, and context.
However, some arguments do not fall into either of those cases,
and they can be added here. Things like `--search-zip' to search
compressed files, or `--follow' to follow symlinks.
Sometimes settings in your config file can cause problems, which
is why `--no-config' is included here by default."
:type '(list string)
:group 'deadgrep)

(defun deadgrep--arguments (search-term search-type case context)
"Return a list of command line arguments that we can execute in a shell
to obtain ripgrep results."
(let (args)
;; We put the extra arguments first so that later arguments will
;; override them, preventing a user from accidentally breaking
;; ripgrep by specifying --heading, for example.
(let ((args (copy-sequence deadgrep-extra-arguments)))
(push "--color=ansi" args)
(push "--line-number" args)
(push "--no-heading" args)
(push "--no-column" args)
(push "--with-filename" args)
(push "--no-config" args)

(cond
((eq search-type 'string)
Expand Down
6 changes: 3 additions & 3 deletions test/deadgrep-unit-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -464,17 +464,17 @@ edit mode."
(ert-deftest deadgrep--arguments ()
(should
(equal (deadgrep--arguments "foo" 'regexp 'smart nil)
'("--color=ansi" "--line-number" "--no-heading" "--no-column" "--with-filename" "--no-config" "--smart-case" "--" "foo" ".")))
'("--no-config" "--color=ansi" "--line-number" "--no-heading" "--no-column" "--with-filename" "--smart-case" "--" "foo" ".")))

(let ((deadgrep--file-type '(type . "elisp")))
(should
(equal (deadgrep--arguments "foo" 'string 'sensitive '(1 . 0))
'("--color=ansi" "--line-number" "--no-heading" "--no-column" "--with-filename" "--no-config" "--fixed-strings" "--case-sensitive" "--type=elisp" "--before-context=1" "--after-context=0" "--" "foo" "."))))
'("--no-config" "--color=ansi" "--line-number" "--no-heading" "--no-column" "--with-filename" "--fixed-strings" "--case-sensitive" "--type=elisp" "--before-context=1" "--after-context=0" "--" "foo" "."))))

(let ((deadgrep--file-type '(glob . "*.el")))
(should
(equal (deadgrep--arguments "foo" 'words 'ignore '(3 . 2))
'("--color=ansi" "--line-number" "--no-heading" "--no-column" "--with-filename" "--no-config" "--fixed-strings" "--word-regexp" "--ignore-case" "--type-add=custom:*.el" "--type=custom" "--before-context=3" "--after-context=2" "--" "foo" ".")))))
'("--no-config" "--color=ansi" "--line-number" "--no-heading" "--no-column" "--with-filename" "--fixed-strings" "--word-regexp" "--ignore-case" "--type-add=custom:*.el" "--type=custom" "--before-context=3" "--after-context=2" "--" "foo" ".")))))

(ert-deftest deadgrep--arguments-error-cases ()
(should-error
Expand Down

0 comments on commit 60e48d3

Please sign in to comment.