Closed gizmomogwai closed 2 weeks ago
Came here looking for this.
My VCS is centralized. So all files are symlinks to cached files in server.
I always need to add --follow
option to the rg/ag/etc commands.
I also use the --ignore-file
option in rg.
May be "%s --color=ansi --line-number --no-heading --follow --with-filename %s %s %s %s -- %s ."
in deadgrep--format-command
be made a defcustom?
I ended up with this for now:
(defconst modi/deadgrep--rg-args
`("--color=ansi"
"--line-number"
"--no-heading"
"--with-filename"
"--no-ignore-vcs" ;Ignore files/dirs ONLY from `.ignore'
"--follow" ;Follow symlinks
"%s" ;--fixed-strings and/or --word-regexp
"%s" ;--smart-case / --case-sensitive / --ignore-case
"%s" ;file type
"%s" ;context
"--ignore-file" ,(expand-file-name ".ignore" (getenv "HOME")))
"rg arguments used in the `deadgrep' package.")
;; Thu Aug 23 15:51:37 EDT 2018 - kmodi
;; Overriding the original `deadgrep--format-command' as I need to
;; add few extra `rg' options.
;; https://github.com/Wilfred/deadgrep/issues/24
(defun modi/deadgrep--format-command (search-term search-type case context)
"Return a command string that we can execute in a shell
to obtain ripgrep results."
(format
(mapconcat #'identity
(append '("%s") ;`deadgrep-executable'
modi/deadgrep--rg-args
'("-- %s .")) ;search term
" ")
deadgrep-executable
(cond
((eq search-type 'string)
"--fixed-strings")
((eq search-type 'words)
"--fixed-strings --word-regexp")
((eq search-type 'regexp)
"")
(t
(error "Unknown search type: %s" search-type)))
(cond
((eq case 'smart)
"--smart-case")
((eq case 'sensitive)
"--case-sensitive")
((eq case 'ignore)
"--ignore-case")
(t
(error "Unknown case: %s" case)))
;; TODO: pass this as an argument.
(cond
((eq deadgrep--file-type 'all)
"")
((eq (car-safe deadgrep--file-type) 'type)
(format "--type %s" (cdr deadgrep--file-type)))
((eq (car-safe deadgrep--file-type) 'glob)
(format "--type-add 'custom:%s' --type custom"
(cdr deadgrep--file-type)))
(t
(error "Unknown file-type: %S" deadgrep--file-type)))
(if context
(format "--before-context %s --after-context %s"
(car context) (cdr context))
"")
(shell-quote-argument search-term)))
(advice-add 'deadgrep--format-command :override #'modi/deadgrep--format-command)
An even better way (for now):
(defconst modi/deadgrep--rg-extra-args
`("--no-ignore-vcs" ;Ignore files/dirs ONLY from `.ignore'
"--follow" ;Follow symlinks
"--ignore-file" ,(expand-file-name ".ignore" (getenv "HOME")))
"Extra rg arguments to be added to `deadgrep--format-command' output.")
;; Thu Aug 23 15:51:37 EDT 2018 - kmodi
;; Adding extra arguments to the ones
;; already in `deadgrep--format-command' --
;; https://github.com/Wilfred/deadgrep/issues/24
(defun modi/deadgrep--format-command-advice (orig-ret-val)
"Add arguments from `modi/deadgrep--rg-extra-args' to ORIG-RET-VAL."
(replace-regexp-in-string
(format "\\`\\(%s \\)\\(.*\\)\\'" (regexp-quote deadgrep-executable))
(concat "\\1"
(mapconcat #'identity modi/deadgrep--rg-extra-args " ")
" \\2")
orig-ret-val))
(advice-add 'deadgrep--format-command :filter-return #'modi/deadgrep--format-command-advice)
Putting those settings into variables also opens up the door for https://www.gnu.org/software/emacs/manual/html_node/emacs/Directory-Variables.html so that you could configure the defaults on a per project basis.
OK, I think the best solution here is:
I'm not sure whether the other ripgrep options make sense as being exposed in the UI. I do use --hidden or --unrestricted occasionally from the CLI, but not very often. It's a little complex because --glob
overrides --no-hidden
, and we already expose globbing.
I might proceed with the above, and if there's any interest in more options within the UI, we can follow up in another issue :)
Was looking for a way to add --hidden
as a repository I'm working with has a .somethingsomething
directory, and since this is under Windows, the authors didn't meant . as "hidden".
I think the defadvice
above can get me what I need but it would be nice to have a defcustom or option in the UI for this.
This is an excellent tool, but I'm surprised it's this difficult to search through hidden files. Am I wrong in thinking this should be easier to configure? Was imagining something like:
(setq deadgrep-search-hidden t)
@wpcarro for your reference this is the advice I ended up using:
(defun deadgrep--format-command-patch (rg-command)
"Add --hidden to rg-command."
(replace-regexp-in-string "^rg " "rg --hidden " rg-command))
(advice-add 'deadgrep--format-command :filter-return #'deadgrep--format-command-patch))
I have that in the config
section of the use-package
declaration.
@sebasmonia thanks for sharing. I'll need to use this for now. I'm still quite surprised that using advice
is the recommended approach for something like toggling --hidden
for a library this popular.
I think transient would fit for the purpose (providing user customizable command line arguments), and many are familiar with it through Magit. (I am not sure whether it meets the original request though)
@Wilfred What do you think about adding transient interface to deadgrep
?
An idea, the C-u
call could invoke the transient menu to tune parameters.
(Currently it opens the deadgrep buffer but doesn't run rg)
@sebasmonia Thanks for the comment. I'm playing deadgrep+transient. For now, I'm considering to provide separate command with keeping the current interface as is.
I too am surprised by the lack of ability to specify options. I needed --ignore-file.
Since latest changes in the package, the workaround should be
(defun deadgrep--include-args (rg-args)
(push "--hidden" rg-args) ;; consider hidden folders/files
(push "--follow" rg-args) ;; follow symlink
)
(advice-add 'deadgrep--arguments :filter-return #'deadgrep--include-args)
FYI you can override the .gitignore file using .rgignore for the purpose of allowing files to be searched by rg.
https://github.com/BurntSushi/ripgrep/blob/master/GUIDE.md#automatic-filtering
I've finally added the ability to search hidden files, thanks for the feedback here.
I think the vast majority of folks wanted that option specifically. Feel free to open issues if there are other options that you need and deadgrep-extra-arguments
isn't sufficient.
Thanks a lot, will update immediately!!!
The ui is already really good, but i would love to have this option in place (especially for searching through my .emacs.d folder, which is in a git)