From a6fae71f7f1ea5774a85f4b4238c9d7e4ed4e132 Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Sun, 30 Jul 2017 11:07:01 -0400 Subject: [PATCH v1] Don't take multiples lines of grep output as a single filename (Bug#27873) * lisp/progmodes/grep.el (grep-with-null-regexp-alist): Exclude newlines from the filename part of the regexp. We must assume filenames don't have newlines to avoid ambiguity with "foo is a directory" messages. Use 'face nil' instead of 'face unspecified', the latter causes errors (albeit demoted to messsages). Also renumber FILE and LINE regexp groups to match the without-null regexp. (grep-without-null-regexp-alist): Rename from `grep-fallback-regexp-alist'. --- lisp/progmodes/grep.el | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lisp/progmodes/grep.el b/lisp/progmodes/grep.el index 4723290fbe..483a1c49ff 100644 --- a/lisp/progmodes/grep.el +++ b/lisp/progmodes/grep.el @@ -384,16 +384,22 @@ (defconst grep--regexp-alist-column (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]+\\)\\([\0:]\\)" 1 3 ,grep--regexp-alist-column nil nil - (2 '(face unspecified display ":")) - (4 '(face unspecified display ":"))) + `(;; Use explicit numbering to keep FILE and LINE groups the same + ;; for both regexp alists. + ("^\\(?1:[^\0\n]+\\)\\(?3:\0\\)\\(?2:[0-9]+\\)\\(?4:[\0:]\\)" + 1 2 ,grep--regexp-alist-column nil nil + (3 '(face nil display ":")) + (4 '(face nil display ":"))) ,grep--regexp-alist-bin-matcher) "Regexp used to match grep hits. See `compilation-error-regexp-alist'.") -(defconst grep-fallback-regexp-alist + +(defconst grep-without-null-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. @@ -401,7 +407,8 @@ (defconst grep-fallback-regexp-alist 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'.") +See `compilation-error-regexp-alist' and +`grep-use-null-filename-separator'.") (defvaralias 'grep-regex-alist 'grep-with-null-regexp-alist) (make-obsolete-variable -- 2.11.1