Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make extra arguments customizable #138

Merged
merged 1 commit into from
Sep 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading