unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: npostavs@users.sourceforge.net
To: Dmitry Gutov <dgutov@yandex.ru>
Cc: 27840@debbugs.gnu.org, Tom Tromey <tom@tromey.com>
Subject: bug#27840: 26.0.50; vc-git-grep stopped working on git master
Date: Wed, 02 Aug 2017 23:09:57 -0400	[thread overview]
Message-ID: <87wp6l73ei.fsf@users.sourceforge.net> (raw)
In-Reply-To: <17696669-9155-d7d2-ffe3-97bb62ceb733@yandex.ru> (Dmitry Gutov's message of "Tue, 1 Aug 2017 16:36:17 +0300")

[-- Attachment #1: Type: text/plain, Size: 489 bytes --]

Dmitry Gutov <dgutov@yandex.ru> writes:

> Alternatively, one regexp would have to handle both versions, with and
> without null (merging grep-with-null-regexp-alist and
> grep-fallback-regexp-alist together, if it's at all possible).

It is possible, the regexp gets a bit more complicated and the
without-null case can now become confused by files containing NUL bytes,
but that's probably fairly rare and things do get simpler again for
callers.  Seems like the best solution overall.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch --]
[-- Type: text/x-diff, Size: 6264 bytes --]

From a556574087226edd1f2aa9f3834a5dfb7968080c Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs@gmail.com>
Date: Sun, 30 Jul 2017 11:07:01 -0400
Subject: [PATCH v2] Merge null and without-null regexp alists (Bug#27840,
 Bug#27873)

* lisp/progmodes/grep.el (grep--regexp-alist-column)
(grep--regexp-alist-bin-matcher, grep-with-null-regexp-alist)
(grep-fallback-regexp-alist): Remove.
(grep-regexp-alist): Recombine their contents here.
(grep-mode):
* lisp/progmodes/xref.el (xref-collect-matches): Use the variable
`grep-regexp-alist' rather than the function.
---
 lisp/progmodes/grep.el | 86 ++++++++++++++++++++++----------------------------
 lisp/progmodes/xref.el |  2 +-
 2 files changed, 39 insertions(+), 49 deletions(-)

diff --git a/lisp/progmodes/grep.el b/lisp/progmodes/grep.el
index 61b82df46a..466b524c79 100644
--- a/lisp/progmodes/grep.el
+++ b/lisp/progmodes/grep.el
@@ -31,7 +31,6 @@
 
 (require 'compile)
 
-
 (defgroup grep nil
   "Run `grep' and display the results."
   :group 'tools
@@ -366,53 +365,44 @@ (defvar grep-last-buffer nil
 Notice that using \\[next-error] or \\[compile-goto-error] modifies
 `compilation-last-buffer' rather than `grep-last-buffer'.")
 
-(defconst grep--regexp-alist-column
-  ;; Calculate column positions (col . end-col) of first grep match on a line
-  (cons
-   (lambda ()
-     (when grep-highlight-matches
-       (let* ((beg (match-end 0))
-              (end (save-excursion (goto-char beg) (line-end-position)))
-              (mbeg (text-property-any beg end 'font-lock-face 'grep-match-face)))
-         (when mbeg
-           (- mbeg beg)))))
-   (lambda ()
-     (when grep-highlight-matches
-       (let* ((beg (match-end 0))
-              (end (save-excursion (goto-char beg) (line-end-position)))
-              (mbeg (text-property-any beg end 'font-lock-face 'grep-match-face))
-              (mend (and mbeg (next-single-property-change mbeg 'font-lock-face nil end))))
-         (when mend
-           (- mend beg)))))))
-(defconst grep--regexp-alist-bin-matcher
-  '("^Binary file \\(.+\\) matches$" 1 nil nil 0 1))
-(defconst grep-with-null-regexp-alist
-  `(("^\\([^\0]+\\)\\(\0\\)\\([0-9]+\\):" 1 3 ,grep--regexp-alist-column nil nil
-     (2 '(face unspecified display ":")))
-    ,grep--regexp-alist-bin-matcher)
-  "Regexp used to match grep hits.
-See `compilation-error-regexp-alist'.")
-(defconst grep-fallback-regexp-alist
-  `(;; Use a tight regexp to handle weird file names (with colons
-    ;; in them) as well as possible.  E.g., use [1-9][0-9]* rather
-    ;; than [0-9]+ so as to accept ":034:" in file names.
-    ("^\\(.*?[^/\n]\\):[ \t]*\\([1-9][0-9]*\\)[ \t]*:"
-     1 2 ,grep--regexp-alist-column)
-    ,grep--regexp-alist-bin-matcher)
-  "Regexp used to match grep hits when `--null' is not supported.
-See `compilation-error-regexp-alist'.")
-
-(defvaralias 'grep-regex-alist 'grep-with-null-regexp-alist)
-(make-obsolete-variable
- 'grep-regex-alist "Call `grep-regexp-alist' instead." "26.1")
-
 ;;;###autoload
-(defun grep-regexp-alist ()
-  "Return a regexp alist to match grep hits.
-The regexp used depends on `grep-use-null-filename-separator'.
-See `compilation-error-regexp-alist' for format details."
-  (if grep-use-null-filename-separator
-      grep-with-null-regexp-alist grep-fallback-regexp-alist))
+(defconst grep-regexp-alist
+  `((,(concat "^\\(?:"
+              ;; Parse using NUL characters when `--null' is used.
+              ;; Note that we must still assume no newlines in
+              ;; filenames due to "foo: Is a directory." type
+              ;; messages.
+              "\\(?1:[^\0\n]+\\)\\(?3:\0\\)\\(?2:[0-9]+\\):"
+              "\\|"
+              ;; Fallback if `--null' is not used, use a tight regexp
+              ;; to handle weird file names (with colons in them) as
+              ;; well as possible.  E.g., use [1-9][0-9]* rather than
+              ;; [0-9]+ so as to accept ":034:" in file names.
+              "\\(?1:[^\n:]+?[^\n/:]\\):[\t ]*\\(?2:[1-9][0-9]*\\)[\t ]*:"
+              "\\)")
+     1 2
+     ;; Calculate column positions (col . end-col) of first grep match on a line
+     (,(lambda ()
+         (when grep-highlight-matches
+           (let* ((beg (match-end 0))
+                  (end (save-excursion (goto-char beg) (line-end-position)))
+                  (mbeg (text-property-any beg end 'font-lock-face 'grep-match-face)))
+             (when mbeg
+               (- mbeg beg)))))
+      .
+      ,(lambda ()
+         (when grep-highlight-matches
+           (let* ((beg (match-end 0))
+                  (end (save-excursion (goto-char beg) (line-end-position)))
+                  (mbeg (text-property-any beg end 'font-lock-face 'grep-match-face))
+                  (mend (and mbeg (next-single-property-change mbeg 'font-lock-face nil end))))
+             (when mend
+               (- mend beg))))))
+     nil nil
+     (3 '(face nil display ":")))
+    ("^Binary file \\(.+\\) matches$" 1 nil nil 0 1))
+  "Regexp used to match grep hits.
+See `compilation-error-regexp-alist' for format details.")
 
 (defvar grep-first-column 0		; bug#10594
   "Value to use for `compilation-first-column' in grep buffers.")
@@ -783,7 +773,7 @@ (define-compilation-mode grep-mode "Grep"
   (set (make-local-variable 'compilation-error-face)
        grep-hit-face)
   (set (make-local-variable 'compilation-error-regexp-alist)
-       (grep-regexp-alist))
+       grep-regexp-alist)
   ;; compilation-directory-matcher can't be nil, so we set it to a regexp that
   ;; can never match.
   (set (make-local-variable 'compilation-directory-matcher) '("\\`a\\`"))
diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el
index cc9b794c5a..35a5c8862f 100644
--- a/lisp/progmodes/xref.el
+++ b/lisp/progmodes/xref.el
@@ -929,7 +929,7 @@ (defun xref-collect-matches (regexp files dir ignores)
                                      (expand-file-name dir)
                                      ignores))
        (buf (get-buffer-create " *xref-grep*"))
-       (`(,grep-re ,file-group ,line-group . ,_) (car (grep-regexp-alist)))
+       (`(,grep-re ,file-group ,line-group . ,_) (car grep-regexp-alist))
        (status nil)
        (hits nil))
     (with-current-buffer buf
-- 
2.11.1


  reply	other threads:[~2017-08-03  3:09 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-26 17:57 bug#27840: 26.0.50; vc-git-grep stopped working on git master Tom Tromey
2017-07-26 23:32 ` npostavs
2017-07-27 13:23   ` Dmitry Gutov
2017-07-30 18:08     ` npostavs
2017-08-01 13:36       ` Dmitry Gutov
2017-08-03  3:09         ` npostavs [this message]
2017-08-04  0:59           ` Dmitry Gutov
2017-08-04 22:31             ` npostavs
2017-08-07  0:39               ` npostavs

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87wp6l73ei.fsf@users.sourceforge.net \
    --to=npostavs@users.sourceforge.net \
    --cc=27840@debbugs.gnu.org \
    --cc=dgutov@yandex.ru \
    --cc=tom@tromey.com \
    /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 public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).