Comments (16)
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)
from deadgrep.
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?
from deadgrep.
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.
from deadgrep.
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.
from deadgrep.
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)
from deadgrep.
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)
from deadgrep.
OK, I think the best solution here is:
- Provide a variable to allow users to provide additional arguments to ripgrep
- Rename 'all' to 'any' in the UI, to avoid confusion (ripgrep still honours .gitignore)
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 :)
from deadgrep.
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.
from deadgrep.
@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.
from deadgrep.
@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.
from deadgrep.
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
?
from 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)
from deadgrep.
@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.
from deadgrep.
I too am surprised by the lack of ability to specify options. I needed --ignore-file.
from deadgrep.
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)
from deadgrep.
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
from deadgrep.
Related Issues (20)
- Jump to an existing buffer if switching directory matches an existing results buffer
- Is there a way to support archives (-z flag)?
- Jump to exact point of search term HOT 3
- push the relevant button HOT 1
- cl-no-applicable-method error HOT 4
- T, C key binding are not supported (Get Error in mini buffer: T is undefined and C is undefined) HOT 5
- Fix: Buffer name `*deadgrep search_term /directory*' is in use
- Re-use existing `*deadgrep ...*` buffer HOT 5
- How to search filename with pattern? HOT 2
- file-remote-p: Wrong type argument: stringp, (Git "~/.emacs.d/") HOT 1
- deadgrep faces not registered until first run HOT 1
- [Feature Request] optional flags with magit-like menu?
- [Question] Is the search in directory recursive? HOT 1
- Simple search don't work HOT 4
- Feature idea: ability to identify several file types HOT 1
- [Feature Request] Add keybinding to cycle File search type HOT 2
- question: how to config deadgrep's result window not using split window? HOT 1
- how to set deadgrep-executable? HOT 1
- Question: Syntax highlight (defferent mode for each file) in results HOT 2
- [Package Idea]: An extension for XREF that works like this package?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from deadgrep.