[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/urgrep d57fa3facf 1/2: Add support for searching in hid
From: |
ELPA Syncer |
Subject: |
[elpa] externals/urgrep d57fa3facf 1/2: Add support for searching in hidden files (or not) |
Date: |
Sat, 10 Jun 2023 21:59:24 -0400 (EDT) |
branch: externals/urgrep
commit d57fa3facf89a52aedfde8839bf38918c48eb11e
Author: Jim Porter <jporterbugs@gmail.com>
Commit: Jim Porter <jporterbugs@gmail.com>
Add support for searching in hidden files (or not)
---
NEWS.md | 6 +++
README.md | 1 +
urgrep-tests.el | 117 ++++++++++++++++++++++++++++++++++++--------------------
urgrep-wgrep.el | 4 +-
urgrep.el | 97 ++++++++++++++++++++++++++++++++--------------
5 files changed, 154 insertions(+), 71 deletions(-)
diff --git a/NEWS.md b/NEWS.md
index 01ad5fcc59..0142889ba9 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,5 +1,11 @@
# Urgrep News
+## v0.2.0 (in progress)
+
+### New features
+- Add support for toggling whether to search in hidden files (`M-s h` in the
+ search prompt, or `urgrep-search-hidden-files` globally)
+
## v0.1.1 (2023-06-07)
- Fix Eshell integration
diff --git a/README.md b/README.md
index 819846e39d..4a537d580d 100644
--- a/README.md
+++ b/README.md
@@ -39,6 +39,7 @@ Isearch-like key bindings to let you modify the search's
behavior:
|:----------------------------|:-----------------------------------------|
| <kbd>M-s</kbd> <kbd>r</kbd> | Toggle regexp search |
| <kbd>M-s</kbd> <kbd>c</kbd> | Toggle case sensitivity |
+| <kbd>M-s</kbd> <kbd>h</kbd> | Toggle searching in hidden files |
| <kbd>M-s</kbd> <kbd>f</kbd> | Set wildcards to filter files¹ |
| <kbd>M-s</kbd> <kbd>C</kbd> | Set number of lines of context² |
| <kbd>M-s</kbd> <kbd>B</kbd> | Set number of lines of leading context² |
diff --git a/urgrep-tests.el b/urgrep-tests.el
index e3dfe8c777..52de32c789 100644
--- a/urgrep-tests.el
+++ b/urgrep-tests.el
@@ -187,6 +187,11 @@ joined to compare against COMMAND."
(urgrep-command "foo" :tool tool :context '(2 . 4))
(append common-args '("--heading" "--break" "-B2" "-A4" "-i" "-F" "-e"
"foo")))
+ ;; Hidden files
+ (urgrep-tests/check-command
+ (urgrep-command "foo" :tool tool :hidden t)
+ (append common-args '("--hidden" "--heading" "--break" "-i" "-F" "-e"
+ "foo")))
;; File wildcard
(urgrep-tests/check-command
(urgrep-command "foo" :tool tool :files "*.el")
@@ -258,6 +263,10 @@ joined to compare against COMMAND."
(urgrep-tests/check-command
(urgrep-command "foo" :tool tool :context '(2 . 4))
(append common-args '("--heading" "-B2" "-A4" "-i" "-F" "--" "foo")))
+ ;; Hidden files
+ (urgrep-tests/check-command
+ (urgrep-command "foo" :tool tool :hidden t)
+ (append common-args '("--hidden" "--heading" "-i" "-F" "--" "foo")))
;; File wildcard
(urgrep-tests/check-command
(urgrep-command "foo" :tool tool :files "*.el")
@@ -343,70 +352,80 @@ joined to compare against COMMAND."
(let ((tool (assq 'ack urgrep-tools))
(common-args '("ack" "--color" "--color-filename=magenta"
"--color-lineno=clear" "--color-colno=clear"
- "--color-match=bold red")))
+ "--color-match=bold red"))
+ (no-hidden-args '("--ignore-dir=match:/^\\./"
+ "--ignore-file=match:/^\\./")))
;; String/case
(urgrep-tests/check-command
(urgrep-command "foo" :tool tool)
- (append common-args '("--group" "-i" "-Q" "--" "foo")))
+ (append common-args no-hidden-args '("--group" "-i" "-Q" "--" "foo")))
(urgrep-tests/check-command
(urgrep-command "Foo" :tool tool)
- (append common-args '("--group" "-Q" "--" "Foo")))
+ (append common-args no-hidden-args '("--group" "-Q" "--" "Foo")))
(let ((case-fold-search nil))
(urgrep-tests/check-command
(urgrep-command "foo" :tool tool)
- (append common-args '("--group" "-Q" "--" "foo"))))
+ (append common-args no-hidden-args '("--group" "-Q" "--" "foo"))))
(urgrep-tests/check-command
(urgrep-command "foo" :tool tool :case-fold t)
- (append common-args '("--group" "-i" "-Q" "--" "foo")))
+ (append common-args no-hidden-args '("--group" "-i" "-Q" "--" "foo")))
(urgrep-tests/check-command
(urgrep-command "foo" :tool tool :case-fold nil)
- (append common-args '("--group" "-Q" "--" "foo")))
+ (append common-args no-hidden-args '("--group" "-Q" "--" "foo")))
(urgrep-tests/check-command
(urgrep-command "foo" :tool tool :case-fold 'smart)
- (append common-args '("--group" "-i" "-Q" "--" "foo")))
+ (append common-args no-hidden-args '("--group" "-i" "-Q" "--" "foo")))
(urgrep-tests/check-command
(urgrep-command "Foo" :tool tool :case-fold 'smart)
- (append common-args '("--group" "-Q" "--" "Foo")))
+ (append common-args no-hidden-args '("--group" "-Q" "--" "Foo")))
;; Group
(urgrep-tests/check-command
(urgrep-command "foo" :tool tool :group nil)
- (append common-args '("--nogroup" "-i" "-Q" "--" "foo")))
+ (append common-args no-hidden-args '("--nogroup" "-i" "-Q" "--" "foo")))
;; Regexp
(urgrep-tests/check-command
(urgrep-command "(foo)" :tool tool :regexp t)
- (append common-args '("--group" "-i" "--" "\\(foo\\)")))
+ (append common-args no-hidden-args '("--group" "-i" "--" "\\(foo\\)")))
(urgrep-tests/check-command
(urgrep-command "(foo)" :tool tool :regexp 'bre)
- (append common-args '("--group" "-i" "--" "\\(foo\\)")))
+ (append common-args no-hidden-args '("--group" "-i" "--" "\\(foo\\)")))
(urgrep-tests/check-command
(urgrep-command "(foo)" :tool tool :regexp 'ere)
- (append common-args '("--group" "-i" "--" "(foo)")))
+ (append common-args no-hidden-args '("--group" "-i" "--" "(foo)")))
(urgrep-tests/check-command
(urgrep-command "(foo)" :tool tool :regexp 'pcre)
- (append common-args '("--group" "-i" "--" "(foo)")))
+ (append common-args no-hidden-args '("--group" "-i" "--" "(foo)")))
;; Context
(urgrep-tests/check-command
(urgrep-command "foo" :tool tool :context 3)
- (append common-args '("--group" "-C3" "-i" "-Q" "--" "foo")))
+ (append common-args no-hidden-args '("--group" "-C3" "-i" "-Q" "--"
+ "foo")))
(urgrep-tests/check-command
(urgrep-command "foo" :tool tool :context '(3 . 3))
- (append common-args '("--group" "-C3" "-i" "-Q" "--" "foo")))
+ (append common-args no-hidden-args '("--group" "-C3" "-i" "-Q" "--"
+ "foo")))
(urgrep-tests/check-command
(urgrep-command "foo" :tool tool :context '(2 . 4))
- (append common-args '("--group" "-B2" "-A4" "-i" "-Q" "--" "foo")))
+ (append common-args no-hidden-args '("--group" "-B2" "-A4" "-i" "-Q" "--"
+ "foo")))
+ ;; Hidden files
+ (urgrep-tests/check-command
+ (urgrep-command "foo" :tool tool :hidden t)
+ (append common-args '("--group" "-i" "-Q" "--" "foo")))
;; File wildcard
(urgrep-tests/check-command
(urgrep-command "foo" :tool tool :files "*.el")
- (append common-args '("-G" "^[^\\000]*\\.el$" "--group" "-i" "-Q" "--"
- "foo")))
+ (append common-args no-hidden-args '("-G" "^[^\\000]*\\.el$" "--group"
"-i"
+ "-Q" "--" "foo")))
(urgrep-tests/check-command
(urgrep-command "foo" :tool tool :files '("*.c" "*.h"))
- (append common-args '("-G" "^[^\\000]*\\.(c|h)$" "--group" "-i" "-Q" "--"
- "foo")))
+ (append common-args no-hidden-args '("-G" "^[^\\000]*\\.(c|h)$" "--group"
+ "-i" "-Q" "--" "foo")))
;; Color
(urgrep-tests/check-command
(urgrep-command "foo" :tool tool :color nil)
- (append '("ack" "--nocolor" "--group" "-i" "-Q" "--" "foo")))))
+ (append '("ack" "--nocolor") no-hidden-args
+ '("--group" "-i" "-Q" "--" "foo")))))
(ert-deftest urgrep-tests/command/git-grep ()
(let ((tool (assq 'git-grep urgrep-tools))
@@ -416,72 +435,88 @@ joined to compare against COMMAND."
"-c" "color.grep.lineNumber=" "-c" "color.grep.column="
"-c" "color.grep.selected=" "-c" "color.grep.separator="
"grep" "--color" "--no-index" "--exclude-standard"
"-n"))
- (group-args '("--heading" "--break")))
+ (group-args '("--heading" "--break"))
+ (no-hidden-args '(":!.*")))
;; String/case
(urgrep-tests/check-command
(urgrep-command "foo" :tool tool)
- (append common-args group-args '("-i" "-F" "-e" "foo" "--")))
+ (append common-args group-args '("-i" "-F" "-e" "foo" "--")
+ no-hidden-args))
(urgrep-tests/check-command
(urgrep-command "Foo" :tool tool)
- (append common-args group-args '("-F" "-e" "Foo" "--")))
+ (append common-args group-args '("-F" "-e" "Foo" "--") no-hidden-args))
(let ((case-fold-search nil))
(urgrep-tests/check-command
(urgrep-command "foo" :tool tool)
- (append common-args group-args '("-F" "-e" "foo" "--"))))
+ (append common-args group-args '("-F" "-e" "foo" "--") no-hidden-args)))
(urgrep-tests/check-command
(urgrep-command "foo" :tool tool :case-fold t)
- (append common-args group-args '("-i" "-F" "-e" "foo" "--")))
+ (append common-args group-args '("-i" "-F" "-e" "foo" "--")
+ no-hidden-args))
(urgrep-tests/check-command
(urgrep-command "foo" :tool tool :case-fold nil)
- (append common-args group-args '("-F" "-e" "foo" "--")))
+ (append common-args group-args '("-F" "-e" "foo" "--") no-hidden-args))
(urgrep-tests/check-command
(urgrep-command "foo" :tool tool :case-fold 'smart)
- (append common-args group-args '("-i" "-F" "-e" "foo" "--")))
+ (append common-args group-args '("-i" "-F" "-e" "foo" "--")
+ no-hidden-args))
(urgrep-tests/check-command
(urgrep-command "Foo" :tool tool :case-fold 'smart)
- (append common-args group-args '("-F" "-e" "Foo" "--")))
+ (append common-args group-args '("-F" "-e" "Foo" "--") no-hidden-args))
;; Group
(urgrep-tests/check-command
(urgrep-command "foo" :tool tool :group nil)
- (append common-args '("-i" "-F" "-e" "foo" "--")))
+ (append common-args '("-i" "-F" "-e" "foo" "--") no-hidden-args))
;; Regexp
(urgrep-tests/check-command
(urgrep-command "(foo)" :tool tool :regexp t)
- (append common-args group-args '("-i" "-G" "-e" "(foo)" "--")))
+ (append common-args group-args '("-i" "-G" "-e" "(foo)" "--")
+ no-hidden-args))
(urgrep-tests/check-command
(urgrep-command "(foo)" :tool tool :regexp 'bre)
- (append common-args group-args '("-i" "-G" "-e" "(foo)" "--")))
+ (append common-args group-args '("-i" "-G" "-e" "(foo)" "--")
+ no-hidden-args))
(urgrep-tests/check-command
(urgrep-command "(foo)" :tool tool :regexp 'ere)
- (append common-args group-args '("-i" "-E" "-e" "(foo)" "--")))
+ (append common-args group-args '("-i" "-E" "-e" "(foo)" "--")
+ no-hidden-args))
(urgrep-tests/check-command
(urgrep-command "(foo)" :tool tool :regexp 'pcre)
- (append common-args group-args '("-i" "-P" "-e" "(foo)" "--")))
+ (append common-args group-args '("-i" "-P" "-e" "(foo)" "--")
+ no-hidden-args))
;; Context
(urgrep-tests/check-command
(urgrep-command "foo" :tool tool :context 3)
- (append common-args group-args '("-C3" "-i" "-F" "-e" "foo" "--")))
+ (append common-args group-args '("-C3" "-i" "-F" "-e" "foo" "--")
+ no-hidden-args))
(urgrep-tests/check-command
(urgrep-command "foo" :tool tool :context '(3 . 3))
- (append common-args group-args '("-C3" "-i" "-F" "-e" "foo" "--")))
+ (append common-args group-args '("-C3" "-i" "-F" "-e" "foo" "--")
+ no-hidden-args))
(urgrep-tests/check-command
(urgrep-command "foo" :tool tool :context '(2 . 4))
- (append common-args group-args '("-B2" "-A4" "-i" "-F" "-e" "foo" "--")))
+ (append common-args group-args '("-B2" "-A4" "-i" "-F" "-e" "foo" "--")
+ no-hidden-args))
+ ;; Hidden files
+ (urgrep-tests/check-command
+ (urgrep-command "foo" :tool tool :hidden t)
+ (append common-args group-args '("-i" "-F" "-e" "foo" "--")))
;; File wildcard
(urgrep-tests/check-command
(urgrep-command "foo" :tool tool :files "*.el")
- (append common-args group-args '("-i" "-F" "-e" "foo" "--" "*.el")))
+ (append common-args group-args '("-i" "-F" "-e" "foo" "--") no-hidden-args
+ '("*.el")))
(urgrep-tests/check-command
(urgrep-command "foo" :tool tool :files '("*.c" "*.h"))
- (append common-args group-args '("-i" "-F" "-e" "foo" "--" "*.c" "*.h")))
+ (append common-args group-args '("-i" "-F" "-e" "foo" "--") no-hidden-args
+ '("*.c" "*.h")))
;; Color
(urgrep-tests/check-command
(urgrep-command "foo" :tool tool :color nil)
(append
'("git" "--no-pager" "grep" "--no-color" "--no-index"
"--exclude-standard" "-n")
- group-args
- '("-i" "-F" "-e" "foo" "--")))))
+ group-args '("-i" "-F" "-e" "foo" "--") no-hidden-args))))
(ert-deftest urgrep-tests/command/grep ()
(let ((tool (assq 'grep urgrep-tools))
diff --git a/urgrep-wgrep.el b/urgrep-wgrep.el
index e99a9c1381..80495fd841 100644
--- a/urgrep-wgrep.el
+++ b/urgrep-wgrep.el
@@ -4,9 +4,9 @@
;; Author: Jim Porter
;; URL: https://github.com/jimporter/urgrep
-;; Version: 0.1.2-git
+;; Version: 0.2.0-git
;; Keywords: grep, search
-;; Package-Requires: ((urgrep "0.1.2-git") (wgrep "2.3.4"))
+;; Package-Requires: ((urgrep "0.2.0-git") (wgrep "2.3.4"))
;; This file is NOT part of GNU Emacs.
diff --git a/urgrep.el b/urgrep.el
index fab2b88469..8b0fb4a563 100644
--- a/urgrep.el
+++ b/urgrep.el
@@ -4,7 +4,7 @@
;; Author: Jim Porter
;; URL: https://github.com/jimporter/urgrep
-;; Version: 0.1.2-git
+;; Version: 0.2.0-git
;; Keywords: grep, search
;; Package-Requires: ((emacs "27.1") (compat "29.1.0.1") (project "0.3.0"))
@@ -80,6 +80,11 @@ Valid values are nil (case-sensitive), t (case-insensitive),
`smart'
(const :tag "Case insensitive" t))
:group 'urgrep)
+(defcustom urgrep-search-hidden-files nil
+ "If non-nil, default to searching in hidden files."
+ :type 'boolean
+ :group 'urgrep)
+
(defcustom urgrep-context-lines 0
"Number of lines of context to show.
If this is an integer, show that many lines of context on either
@@ -215,11 +220,11 @@ one for each `:abbreviate' key found."
((or `(,c . ,c) (and c (pred numberp))) (list (format "-C%d" c)))
(`(,b . ,a) (list (format "-B%d" b) (format "-A%d" a)))))
-(cl-defun urgrep--rgrep-command (query &key tool regexp case-fold files context
- color &allow-other-keys)
+(cl-defun urgrep--rgrep-command (query &key tool regexp case-fold hidden files
+ context color &allow-other-keys)
"Get the command to run for QUERY when using rgrep.
-Optional keys TOOL, REGEXP, CASE-FOLD, FILES, CONTEXT, and COLOR are
-as in `urgrep-command'."
+Optional keys TOOL, REGEXP, CASE-FOLD, HIDDEN, FILES, CONTEXT,
+and COLOR are as in `urgrep-command'."
(grep-compute-defaults)
;; Locally add options to `grep-find-template' that grep.el isn't aware of.
(let ((grep-find-template grep-find-template)
@@ -234,16 +239,25 @@ as in `urgrep-command'."
((string-match "<C>" grep-find-template)))
(setq grep-find-template
(replace-match (concat "<C> " args) t t grep-find-template))))
- (let* ((case-fold-search nil)
- (command (rgrep-default-command query files nil)))
- (save-match-data
- ;; Hide excessive part of rgrep command.
- (when (string-match
- (rx bol "find " (group (*? nonl)) " " (or "-exec" "-print"))
- command)
- (put-text-property (match-beginning 1) (match-end 1)
- 'abbreviated-command t command)))
- command)))
+ (let ((case-fold-search nil)
+ (grep-find-ignored-directories grep-find-ignored-directories)
+ (grep-find-ignored-files grep-find-ignored-files))
+ (unless hidden
+ (setq grep-find-ignored-directories
+ (cons ".*" (seq-filter (lambda (s) (not (string-prefix-p "." s)))
+ grep-find-ignored-directories))
+ grep-find-ignored-files
+ (cons ".*" (seq-filter (lambda (s) (not (string-prefix-p "." s)))
+ grep-find-ignored-files))))
+ (let ((command (rgrep-default-command query files nil)))
+ (save-match-data
+ ;; Hide excessive part of rgrep command.
+ (when (string-match
+ (rx bol "find " (group (*? nonl)) " " (or "-exec" "-print"))
+ command)
+ (put-text-property (match-beginning 1) (match-end 1)
+ 'abbreviated-command t command)))
+ command))))
(defun urgrep--rgrep-process-setup ()
"Set up environment variables for rgrep.
@@ -261,12 +275,14 @@ See also `grep-process-setup'."
(executable-name . "ugrep")
(regexp-syntax bre ere pcre)
(arguments executable (:abbreviate color "-n" "--ignore-files")
- file-wildcards group context case-fold regexp "-e" query)
+ hidden-file file-wildcards group context case-fold regexp "-e"
+ query)
(regexp-arguments ('bre '("-G"))
('ere '("-E"))
('pcre '("-P"))
(_ '("-F")))
(case-fold-arguments ((pred identity) '("-i")))
+ (hidden-file-arguments ((pred identity) '("--hidden")))
(file-wildcards-arguments
((and x (pred identity))
(mapcar (lambda (i) (concat "--include=" i)) x)))
@@ -279,10 +295,11 @@ See also `grep-process-setup'."
(ripgrep
(executable-name . "rg")
(regexp-syntax pcre)
- (arguments executable (:abbreviate color) file-wildcards group context
- case-fold regexp "--" query)
+ (arguments executable (:abbreviate color) hidden-file file-wildcards group
+ context case-fold regexp "--" query)
(regexp-arguments ('nil '("-F")))
(case-fold-arguments ((pred identity) '("-i")))
+ (hidden-file-arguments ((pred identity) '("--hidden")))
(file-wildcards-arguments
((and x (pred identity))
(flatten-list (mapcar (lambda (i) (cons "-g" i)) x))))
@@ -298,11 +315,12 @@ See also `grep-process-setup'."
(ag
(executable-name . "ag")
(regexp-syntax pcre)
- (arguments executable (:abbreviate color) file-wildcards group context
- case-fold regexp "--" query)
+ (arguments executable (:abbreviate color) hidden-file file-wildcards group
+ context case-fold regexp "--" query)
(regexp-arguments ('nil '("-Q")))
(case-fold-arguments ('nil '("-s"))
(_ '("-i")))
+ (hidden-file-arguments ((pred identity) '("--hidden")))
(file-wildcards-arguments
((and x (pred identity))
(list "-G" (urgrep--wildcards-to-regexp x 'pcre))))
@@ -315,10 +333,12 @@ See also `grep-process-setup'."
(ack
(executable-name . "ack")
(regexp-syntax pcre)
- (arguments executable (:abbreviate color) file-wildcards group context
- case-fold regexp "--" query)
+ (arguments executable (:abbreviate color) hidden-file file-wildcards group
+ context case-fold regexp "--" query)
(regexp-arguments ('nil '("-Q")))
(case-fold-arguments ((pred identity) '("-i")))
+ (hidden-file-arguments ('nil '("--ignore-dir=match:/^\\./"
+ "--ignore-file=match:/^\\./")))
(file-wildcards-arguments
((and x (pred identity))
(list "-G" (urgrep--wildcards-to-regexp x 'pcre))))
@@ -338,13 +358,15 @@ See also `grep-process-setup'."
(regexp-syntax bre ere pcre)
(arguments executable (:abbreviate "--no-pager" color "--no-index"
"--exclude-standard" "-n")
- group context case-fold regexp "-e" query "--" file-wildcards)
+ group context case-fold regexp "-e" query "--" hidden-file
+ file-wildcards)
(abbreviations "grep")
(regexp-arguments ('bre '("-G"))
('ere '("-E"))
('pcre '("-P"))
(_ '("-F")))
(case-fold-arguments ((pred identity) '("-i")))
+ (hidden-file-arguments ('nil '(":!.*")))
(file-wildcards-arguments (x x))
(group-arguments ((pred identity) '("--heading" "--break")))
(context-arguments . ,urgrep--context-arguments)
@@ -499,8 +521,8 @@ in `urgrep-tools'. Otherwise, return TOOL as-is."
(t (car tool-syntaxes)))))
;;;###autoload
-(cl-defun urgrep-command (query &key tool regexp (case-fold 'inherit) files
- (group t) (context 0) (color t)
+(cl-defun urgrep-command (query &key tool regexp (case-fold 'inherit) hidden
+ files (group t) (context 0) (color t)
(directory default-directory))
"Return a command to use to search for QUERY.
Several keyword arguments can be supplied to adjust the resulting
@@ -517,6 +539,8 @@ strings), `bre' (basic regexp), `ere' (extend regexp),
`pcre'
CASE-FOLD: determine whether QUERY is case-sensitive or not; possible
values are as `urgrep-case-fold', defaulting to `inherit'.
+HIDDEN: non-nil to search in hidden files; defaults to nil.
+
FILES: a wildcard (or list of wildcards) to limit the files searched.
GROUP: show results grouped by filename (t, the default), or if nil,
@@ -547,8 +571,8 @@ DIRECTORY: the directory to search in, or nil to use the
;; Build the command arguments.
(if cmd-fun
(funcall cmd-fun query :tool tool :regexp regexp-syntax
- :case-fold case-fold :files files :group group
- :context context :color color)
+ :case-fold case-fold :hidden hidden :files files
+ :group group :context context :color color)
(let ((arguments (urgrep--get-prop 'arguments tool))
(abbrev (urgrep--get-prop 'abbreviations tool))
(props `((executable . ,(urgrep--get-prop 'executable-name
tool))
@@ -558,6 +582,7 @@ DIRECTORY: the directory to search in, or nil to use the
k tool v "-arguments")))
`((regexp . ,tool-re-syntax)
(case-fold . ,case-fold)
+ (hidden-file . ,hidden)
(file-wildcards . ,files)
(group . ,group)
(context . ,context)
@@ -1031,6 +1056,17 @@ future searches."
(setq urgrep-context-lines (cons before-lines after-lines)))
(when (window-minibuffer-p) (urgrep--update-search-prompt)))
+(defun urgrep-toggle-search-hidden-files ()
+ "Toggle whether or not to search in hidden files.
+Within the `urgrep' search prompt, this sets the value only for the
+current search. Outside the prompt, this sets the value for all
+future searches."
+ (interactive)
+ (message (if (setq urgrep-search-hidden-files
+ (not urgrep-search-hidden-files))
+ "search hidden"
+ "exclude hidden")))
+
(defun urgrep-set-file-wildcards (files)
"Set the FILES (a wildcard or list thereof) to search.
Within the `urgrep' search prompt, this sets the value only for the
@@ -1048,6 +1084,7 @@ future searches."
(define-key map "\M-sr" #'urgrep-toggle-regexp)
(define-key map "\M-sc" #'urgrep-toggle-case-fold)
(define-key map "\M-sf" #'urgrep-set-file-wildcards)
+ (define-key map "\M-sh" #'urgrep-toggle-search-hidden-files)
(define-key map "\M-sC" #'urgrep-set-context)
(define-key map "\M-sB" #'urgrep-set-before-context)
(define-key map "\M-sA" #'urgrep-set-after-context)
@@ -1055,6 +1092,7 @@ future searches."
(cl-defun urgrep--read-query (initial &key tool (regexp urgrep-search-regexp)
(case-fold urgrep-case-fold)
+ (hidden urgrep-search-hidden-files)
(files urgrep-file-wildcards)
(group urgrep-group-matches)
(context urgrep-context-lines)
@@ -1066,6 +1104,7 @@ command. TOOL, REGEXP, CASE-FOLD, FILES, GROUP, CONTEXT,
and DIRECTORY
(let* ((default-directory directory)
(urgrep-search-regexp regexp)
(urgrep-case-fold case-fold)
+ (urgrep-search-hidden-files hidden)
(urgrep-file-wildcards files)
(urgrep-context-lines context)
(default (and (not initial) (urgrep--search-default)))
@@ -1076,7 +1115,8 @@ command. TOOL, REGEXP, CASE-FOLD, FILES, GROUP, CONTEXT,
and DIRECTORY
'urgrep-search-history default)))
(query (if (equal query "") default query)))
(list query :tool (urgrep-get-tool tool) :regexp urgrep-search-regexp
- :case-fold urgrep-case-fold :files urgrep-file-wildcards :group group
+ :case-fold urgrep-case-fold :hidden urgrep-search-hidden-files
+ :files urgrep-file-wildcards :group group
:context urgrep-context-lines :directory directory)))
(defun urgrep--read-command (command)
@@ -1121,6 +1161,7 @@ Type \\[urgrep-set-context] to set the number of context
lines.
lines. Without a prefix, prompt for the number.
Type \\[urgrep-set-before-context] to set the number of before context lines.
Type \\[urgrep-set-after-context] to set the number of after context lines.
+Type \\[urgrep-toggle-search-hidden-files] to toggle searching in hidden files.
Type \\[urgrep-set-file-wildcards] to set a wildcard to filter the files \
searched."
(interactive