From: Juri Linkov <juri@jurta.org>
To: bug-gnu-emacs@gnu.org
Subject: bug#4301: rgrep/lgrep defaults
Date: Mon, 31 Aug 2009 22:59:02 +0300 [thread overview]
Message-ID: <87ljkzsqk9.fsf@mail.jurta.org> (raw)
Currently rgep/lgrep proposes to search in C files by default.
This default value assumes that majority of Emacs users prefer searching
only in C files. This can't be true. So the current default value is
useless. I think a better default value is to search _all_ files, where
all includes hidden dot files as well. rgrep already searches in dot
files, but lgrep doesn't. To remove this inconsistency we could bind
"all" to "* .*" in `grep-files-aliases'. Placing it first makes it the
default value which reads clear and understandable in the default prompt as:
Search for "text" in files (default all):
instead of the current:
Search for "text" in files (default ch):
"asm" could be moved to the bottom of the list of default values
in `grep-files-aliases', so this less frequent alias comes last
when retrieving via M-n. Also this requires removing ("ch" "el")
from the pre-defined default of `grep-files-history' and moving
("ch" "el") higher in `grep-files-aliases'.
Another inconsistency is that rgrep provides the default command that
ignores vcs directories, but doesn't ignore vcs files like ".v",
backup files "~" "\\`#" "\\`.#" and other ignorable files from
`completion-ignored-extensions'. This can be improved by adding
new customizable variable `grep-find-ignored-files' where the nil
option disables it easily. The same nil option is also useful for
`grep-find-ignored-directories' to disable it at once than deleting
every value from the default list one by one.
For rgrep, `grep-find-ignored-files' means mapping its list to
something like
\(-name .\#\* -o -name \*\~ -o -name \*.o -o ... \) -prune -o
For lgrep, `grep-find-ignored-files' means mapping its list to
something like
grep --exclude=.\#\* --exclude=\*\~ --exclude=\*.o ...
Below is a patch that implements this:
Index: lisp/progmodes/grep.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/progmodes/grep.el,v
retrieving revision 1.106
diff -c -w -b -r1.106 grep.el
*** lisp/progmodes/grep.el 30 Aug 2009 23:46:09 -0000 1.106
--- lisp/progmodes/grep.el 31 Aug 2009 19:54:27 -0000
***************
*** 176,193 ****
:group 'grep)
(defcustom grep-files-aliases
! '(("asm" . "*.[sS]")
("c" . "*.c")
("cc" . "*.cc *.cxx *.cpp *.C *.CC *.c++")
("cchh" . "*.cc *.[ch]xx *.[ch]pp *.[CHh] *.CC *.HH *.[ch]++")
("hh" . "*.hxx *.hpp *.[Hh] *.HH *.h++")
- ("ch" . "*.[ch]")
- ("el" . "*.el")
("h" . "*.h")
("l" . "[Cc]hange[Ll]og*")
("m" . "[Mm]akefile*")
("tex" . "*.tex")
! ("texi" . "*.texi"))
"*Alist of aliases for the FILES argument to `lgrep' and `rgrep'."
:type 'alist
:group 'grep)
--- 176,194 ----
:group 'grep)
(defcustom grep-files-aliases
! '(("all" . "* .*")
! ("el" . "*.el")
! ("ch" . "*.[ch]")
("c" . "*.c")
("cc" . "*.cc *.cxx *.cpp *.C *.CC *.c++")
("cchh" . "*.cc *.[ch]xx *.[ch]pp *.[CHh] *.CC *.HH *.[ch]++")
("hh" . "*.hxx *.hpp *.[Hh] *.HH *.h++")
("h" . "*.h")
("l" . "[Cc]hange[Ll]og*")
("m" . "[Mm]akefile*")
("tex" . "*.tex")
! ("texi" . "*.texi")
! ("asm" . "*.[sS]"))
"*Alist of aliases for the FILES argument to `lgrep' and `rgrep'."
:type 'alist
:group 'grep)
***************
*** 197,203 ****
"*List of names of sub-directories which `rgrep' shall not recurse into.
If an element is a cons cell, the car is called on the search directory
to determine whether cdr should not be recursed into."
! :type '(repeat string)
:group 'grep)
(defcustom grep-error-screen-columns nil
--- 198,217 ----
"*List of names of sub-directories which `rgrep' shall not recurse into.
If an element is a cons cell, the car is called on the search directory
to determine whether cdr should not be recursed into."
! :type '(choice (repeat :tag "Ignored directories" string)
! (const :tag "No ignored directories" nil))
! :group 'grep)
!
! (defcustom grep-find-ignored-files
! (cons ".#*" (delq nil (mapcar (lambda (s)
! (unless (string-match-p "/\\'" s)
! (concat "*" s)))
! completion-ignored-extensions)))
! "*List of names of file names which `rgrep' and `lgrep' shall exclude.
! If an element is a cons cell, the car is called on the search directory
! to determine whether cdr should not be excluded."
! :type '(choice (repeat :tag "Ignored file" string)
! (const :tag "No ignored files" nil))
:group 'grep)
(defcustom grep-error-screen-columns nil
***************
*** 421,427 ****
;; History of lgrep and rgrep regexp and files args.
(defvar grep-regexp-history nil)
! (defvar grep-files-history '("ch" "el"))
;;;###autoload
(defun grep-process-setup ()
--- 435,441 ----
;; History of lgrep and rgrep regexp and files args.
(defvar grep-regexp-history nil)
! (defvar grep-files-history nil)
;;;###autoload
(defun grep-process-setup ()
***************
*** 524,530 ****
(format "%s %s " grep-program grep-options)))
(unless grep-template
(setq grep-template
! (format "%s <C> %s <R> <F>" grep-program grep-options)))
(unless grep-find-use-xargs
(setq grep-find-use-xargs
(cond
--- 538,544 ----
(format "%s %s " grep-program grep-options)))
(unless grep-template
(setq grep-template
! (format "%s <X> <C> %s <R> <F>" grep-program grep-options)))
(unless grep-find-use-xargs
(setq grep-find-use-xargs
(cond
***************
*** 753,760 ****
(fn (and bn
(stringp bn)
(file-name-nondirectory bn)))
! (default
! (or (and fn
(let ((aliases grep-files-aliases)
alias)
(while aliases
--- 767,774 ----
(fn (and bn
(stringp bn)
(file-name-nondirectory bn)))
! (default-alias
! (and fn
(let ((aliases grep-files-aliases)
alias)
(while aliases
***************
*** 763,772 ****
(if (string-match (wildcard-to-regexp (cdr alias)) fn)
(setq aliases nil)
(setq alias nil)))
! (cdr alias)))
(and fn
(let ((ext (file-name-extension fn)))
! (and ext (concat "*." ext))))
(car grep-files-history)
(car (car grep-files-aliases))))
(files (read-string
--- 777,790 ----
(if (string-match (wildcard-to-regexp (cdr alias)) fn)
(setq aliases nil)
(setq alias nil)))
! (cdr alias))))
! (default-extension
(and fn
(let ((ext (file-name-extension fn)))
! (and ext (concat "*." ext)))))
! (default
! (or default-alias
! default-extension
(car grep-files-history)
(car (car grep-files-aliases))))
(files (read-string
***************
*** 774,780 ****
"\" in files"
(if default (concat " (default " default ")"))
": ")
! nil 'grep-files-history default)))
(and files
(or (cdr (assoc files grep-files-aliases))
files))))
--- 792,801 ----
"\" in files"
(if default (concat " (default " default ")"))
": ")
! nil 'grep-files-history
! (delete-dups
! (delq nil (append (list default default-alias default-extension)
! (mapcar 'car grep-files-aliases)))))))
(and files
(or (cdr (assoc files grep-files-aliases))
files))))
***************
*** 822,828 ****
(setq command (grep-expand-template
grep-template
regexp
! files))
(when command
(if confirm
(setq command
--- 843,862 ----
(setq command (grep-expand-template
grep-template
regexp
! files
! nil
! (and grep-find-ignored-files
! (concat " --exclude="
! (mapconcat
! #'(lambda (ignore)
! (cond ((stringp ignore)
! (shell-quote-argument ignore))
! ((consp ignore)
! (and (funcall (car ignore) dir)
! (shell-quote-argument
! (cdr ignore))))))
! grep-find-ignored-files
! " --exclude=")))))
(when command
(if confirm
(setq command
***************
*** 893,898 ****
--- 927,933 ----
" "
(shell-quote-argument ")"))
dir
+ (concat
(and grep-find-ignored-directories
(concat (shell-quote-argument "(")
;; we should use shell-quote-argument here
***************
*** 911,917 ****
" -o -path ")
" "
(shell-quote-argument ")")
! " -prune -o ")))))
(when command
(if confirm
(setq command
--- 946,969 ----
" -o -path ")
" "
(shell-quote-argument ")")
! " -prune -o "))
! (and grep-find-ignored-files
! (concat (shell-quote-argument "(")
! ;; we should use shell-quote-argument here
! " -name "
! (mapconcat
! #'(lambda (ignore)
! (cond ((stringp ignore)
! (shell-quote-argument ignore))
! ((consp ignore)
! (and (funcall (car ignore) dir)
! (shell-quote-argument
! (cdr ignore))))))
! grep-find-ignored-files
! " -o -name ")
! " "
! (shell-quote-argument ")")
! " -prune -o "))))))
(when command
(if confirm
(setq command
--
Juri Linkov
http://www.jurta.org/emacs/
next reply other threads:[~2009-08-31 19:59 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <873a3m3cv5.fsf@mail.jurta.org>
2009-08-31 19:59 ` Juri Linkov [this message]
2009-09-10 1:07 ` bug#4301: rgrep/lgrep defaults Juri Linkov
2009-12-07 17:45 ` bug#4301: marked as done (rgrep/lgrep defaults) Emacs bug Tracking System
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87ljkzsqk9.fsf@mail.jurta.org \
--to=juri@jurta.org \
--cc=4301@emacsbugs.donarmstrong.com \
--cc=bug-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.