From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#4982: rgrep can't deal with .gz files Date: Tue, 24 Nov 2009 19:04:43 +0200 Organization: JURTA Message-ID: <87fx84ujec.fsf@mail.jurta.org> References: <876391imuv.fsf@mail.jurta.org> <874oolxaeq.fsf@jidanni.org> Reply-To: Juri Linkov , 4982@emacsbugs.donarmstrong.com NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1259083763 28070 80.91.229.12 (24 Nov 2009 17:29:23 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 24 Nov 2009 17:29:23 +0000 (UTC) Cc: 4982@emacsbugs.donarmstrong.com To: jidanni@jidanni.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Nov 24 18:29:16 2009 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1NCzCS-0007jD-Nn for geb-bug-gnu-emacs@m.gmane.org; Tue, 24 Nov 2009 18:29:13 +0100 Original-Received: from localhost ([127.0.0.1]:59405 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NCzCS-0003wD-8P for geb-bug-gnu-emacs@m.gmane.org; Tue, 24 Nov 2009 12:29:12 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NCzAv-00036H-ID for bug-gnu-emacs@gnu.org; Tue, 24 Nov 2009 12:27:38 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NCzAp-00030s-0m for bug-gnu-emacs@gnu.org; Tue, 24 Nov 2009 12:27:35 -0500 Original-Received: from [199.232.76.173] (port=46265 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NCzAo-00030Q-OJ for bug-gnu-emacs@gnu.org; Tue, 24 Nov 2009 12:27:30 -0500 Original-Received: from rzlab.ucr.edu ([138.23.92.77]:55393) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1NCzAl-0001XB-Pr for bug-gnu-emacs@gnu.org; Tue, 24 Nov 2009 12:27:28 -0500 Original-Received: from rzlab.ucr.edu (rzlab.ucr.edu [127.0.0.1]) by rzlab.ucr.edu (8.14.3/8.14.3/Debian-5) with ESMTP id nAOHRL1X003786; Tue, 24 Nov 2009 09:27:25 -0800 Original-Received: (from debbugs@localhost) by rzlab.ucr.edu (8.14.3/8.14.3/Submit) id nAOHPIV9003724; Tue, 24 Nov 2009 09:25:18 -0800 Resent-Date: Tue, 24 Nov 2009 09:25:18 -0800 X-Loop: owner@emacsbugs.donarmstrong.com Resent-From: Juri Linkov Resent-To: bug-submit-list@donarmstrong.com Resent-CC: Emacs Bugs 2Resent-Date: Tue, 24 Nov 2009 17:25:18 +0000 Resent-Message-ID: Resent-Sender: owner@emacsbugs.donarmstrong.com X-Emacs-PR-Message: followup 4982 X-Emacs-PR-Package: emacs X-Emacs-PR-Keywords: Original-Received: via spool by 4982-submit@emacsbugs.donarmstrong.com id=B4982.12590829422966 (code B ref 4982); Tue, 24 Nov 2009 17:25:18 +0000 Original-Received: (at 4982) by emacsbugs.donarmstrong.com; 24 Nov 2009 17:15:42 +0000 X-Spam-Bayes: score:0.5 Bayes not run. spammytokens:Tokens not available. hammytokens:Tokens not available. Original-Received: from mx1.starman.ee (smtp-out3.starman.ee [85.253.0.5]) by rzlab.ucr.edu (8.14.3/8.14.3/Debian-5) with ESMTP id nAOHFeVg002950 for <4982@emacsbugs.donarmstrong.com>; Tue, 24 Nov 2009 09:15:41 -0800 X-Virus-Scanned: by Amavisd-New at mx1.starman.ee Original-Received: from mail.starman.ee (82.131.34.225.cable.starman.ee [82.131.34.225]) by mx1.starman.ee (Postfix) with ESMTP id 31B713F412C; Tue, 24 Nov 2009 19:15:34 +0200 (EET) In-Reply-To: <874oolxaeq.fsf@jidanni.org> (jidanni@jidanni.org's message of "Tue, 24 Nov 2009 04:18:21 +0800") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (x86_64-pc-linux-gnu) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) Resent-Date: Tue, 24 Nov 2009 12:27:35 -0500 X-BeenThere: bug-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:32882 Archived-At: > JL> So you don't see yellow matches? > OK, I do if I mouseover them. By the way, some ugliness now that I set > grep-command to zgrep: > > gzip: stdout: Broken pipe > ./libchewing3-data_0.3.0-2_i386.deb:Binary file (standard input) matches > > gzip: stdout: Broken pipe > ./Nokia_3315_APAC_UG_En.pdf:Binary file (standard input) matches Yes, zgrep incorrectly processes non-gzipped files. To search recursively in gzipped files, I created a new command `zrgrep'. It works like `rgrep' but uses `zgrep' for `grep-program', sets the default file name to `*.gz', and sets `grep-highlight-matches' to `always'." Other changes in the patch below include: 1. grep-highlight-matches has two new options `always' and `auto'. This allows `zrgrep' to override the default value with `always'. 2. Move Windows/DOS specific --colors settings handling from `grep-process-setup' to `grep-compute-defaults'. Index: lisp/progmodes/grep.el =================================================================== RCS file: /sources/emacs/emacs/lisp/progmodes/grep.el,v retrieving revision 1.111 diff -c -r1.111 grep.el *** lisp/progmodes/grep.el 19 Nov 2009 17:37:25 -0000 1.111 --- lisp/progmodes/grep.el 24 Nov 2009 17:04:11 -0000 *************** *** 69,90 **** :group 'grep) (defcustom grep-highlight-matches 'auto-detect ! "If t, use special markers to highlight grep matches. Some grep programs are able to surround matches with special markers in grep output. Such markers can be used to highlight matches in grep mode. ! This option sets the environment variable GREP_COLOR to specify markers for highlighting and GREP_OPTIONS to add the --color option in front of any explicit grep options before starting the grep. In interactive usage, the actual value of this variable is set up ! by `grep-compute-defaults'; to change the default value, use ! Customize or call the function `grep-apply-setting'." :type '(choice (const :tag "Do not highlight matches with grep markers" nil) (const :tag "Highlight matches with grep markers" t) (other :tag "Not Set" auto-detect)) :set 'grep-apply-setting :version "22.1" --- 69,102 ---- :group 'grep) (defcustom grep-highlight-matches 'auto-detect ! "Use special markers to highlight grep matches. Some grep programs are able to surround matches with special markers in grep output. Such markers can be used to highlight matches in grep mode. ! This option sets the environment variable GREP_COLORS to specify markers for highlighting and GREP_OPTIONS to add the --color option in front of any explicit grep options before starting the grep. + When this option is `auto', grep uses `--color=auto' to highlight + matches only when it outputs to a terminal (when `grep' is the last + command in the pipe), thus avoiding the use of any potentially-harmful + escape sequences when standard output goes to a file or pipe. + + To make grep highlight matches even into a pipe, you need the option + `always' that forces grep to use `--color=always' to unconditionally + output escape sequences. + In interactive usage, the actual value of this variable is set up ! by `grep-compute-defaults' when the default value is `auto-detect'. ! To change the default value, use Customize or call the function ! `grep-apply-setting'." :type '(choice (const :tag "Do not highlight matches with grep markers" nil) (const :tag "Highlight matches with grep markers" t) + (const :tag "Use --color=always" always) + (const :tag "Use --color=auto" auto) (other :tag "Not Set" auto-detect)) :set 'grep-apply-setting :version "22.1" *************** *** 442,460 **** (defun grep-process-setup () "Setup compilation variables and buffer for `grep'. Set up `compilation-exit-message-function' and run `grep-setup-hook'." ! (unless (or (not grep-highlight-matches) (eq grep-highlight-matches t)) (grep-compute-defaults)) ! (when (eq grep-highlight-matches t) ;; `setenv' modifies `process-environment' let-bound in `compilation-start' ;; Any TERM except "dumb" allows GNU grep to use `--color=auto' (setenv "TERM" "emacs-grep") - ;; `--color=auto' emits escape sequences on a tty rather than on a pipe, - ;; thus allowing to use multiple grep filters on the command line - ;; and to output escape sequences only on the final grep output (setenv "GREP_OPTIONS" (concat (getenv "GREP_OPTIONS") ! ;; Windows and DOS pipes fail `isatty' detection in Grep. ! " --color=" (if (memq system-type '(windows-nt ms-dos)) "always" "auto"))) ;; GREP_COLOR is used in GNU grep 2.5.1, but deprecated in later versions (setenv "GREP_COLOR" "01;31") --- 454,469 ---- (defun grep-process-setup () "Setup compilation variables and buffer for `grep'. Set up `compilation-exit-message-function' and run `grep-setup-hook'." ! (when (eq grep-highlight-matches 'auto-detect) (grep-compute-defaults)) ! (unless (or (eq grep-highlight-matches 'auto-detect) ! (null grep-highlight-matches)) ;; `setenv' modifies `process-environment' let-bound in `compilation-start' ;; Any TERM except "dumb" allows GNU grep to use `--color=auto' (setenv "TERM" "emacs-grep") (setenv "GREP_OPTIONS" (concat (getenv "GREP_OPTIONS") ! " --color=" (if (eq grep-highlight-matches 'always) "always" "auto"))) ;; GREP_COLOR is used in GNU grep 2.5.1, but deprecated in later versions (setenv "GREP_COLOR" "01;31") *************** *** 579,592 **** (t (format "%s . -type f -print | %s %s" find-program xargs-program gcmd)))))))) ! (unless (or (not grep-highlight-matches) (eq grep-highlight-matches t)) (setq grep-highlight-matches (with-temp-buffer (and (grep-probe grep-program '(nil t nil "--help")) (progn (goto-char (point-min)) (search-forward "--color" nil t)) ! t)))) ;; Save defaults for this host. (setq grep-host-defaults-alist --- 588,603 ---- (t (format "%s . -type f -print | %s %s" find-program xargs-program gcmd)))))))) ! (when (eq grep-highlight-matches 'auto-detect) (setq grep-highlight-matches (with-temp-buffer (and (grep-probe grep-program '(nil t nil "--help")) (progn (goto-char (point-min)) (search-forward "--color" nil t)) ! ;; Windows and DOS pipes fail `isatty' detection in Grep. ! (if (memq system-type '(windows-nt ms-dos)) ! 'always 'auto))))) ;; Save defaults for this host. (setq grep-host-defaults-alist *************** *** 978,983 **** --- 993,1030 ---- (if (eq next-error-last-buffer (current-buffer)) (setq default-directory dir))))))) + ;;;###autoload + (defun zrgrep (regexp &optional files dir confirm grep-find-template) + "Recursively grep for REGEXP in gzipped FILES in tree rooted at DIR. + Like `rgrep' but uses `zgrep' for `grep-program', sets the default + file name to `*.gz', and sets `grep-highlight-matches' to `always'." + (interactive + (let ((grep-program "zgrep") + (grep-find-command nil) + (grep-find-template nil) + (grep-host-defaults-alist nil) + (grep-files-aliases '(("*.gz" . "*.gz") ; for `grep-read-files' + ("all" . "* .*")))) + ;; Recompute defaults using let-bound values above. + (grep-compute-defaults) + (cond + ((and grep-find-command (equal current-prefix-arg '(16))) + (list (read-from-minibuffer "Run: " grep-find-command + nil nil 'grep-find-history))) + ((not grep-find-template) + (error "grep.el: No `grep-find-template' available")) + (t (let* ((regexp (grep-read-regexp)) + (files (grep-read-files regexp)) + (dir (read-directory-name "Base directory: " + nil default-directory t)) + (confirm (equal current-prefix-arg '(4)))) + (list regexp files dir confirm grep-find-template)))))) + ;; Set `grep-highlight-matches' to `always' + ;; since `zgrep' puts filters in the grep output. + (let ((grep-highlight-matches 'always)) + ;; `rgrep' uses the dynamically bound value `grep-find-template' + ;; from the argument `grep-find-template' whose value is computed + ;; in the `interactive' spec. + (rgrep regexp files dir confirm))) ;;;###autoload (defalias 'rzgrep 'zrgrep) (provide 'grep) -- Juri Linkov http://www.jurta.org/emacs/