aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/cedet/semantic/symref/grep.el2
-rw-r--r--lisp/progmodes/grep.el90
-rw-r--r--lisp/progmodes/xref.el2
3 files changed, 43 insertions, 51 deletions
diff --git a/lisp/cedet/semantic/symref/grep.el b/lisp/cedet/semantic/symref/grep.el
index df71508da7c..f7c72bfb0be 100644
--- a/lisp/cedet/semantic/symref/grep.el
+++ b/lisp/cedet/semantic/symref/grep.el
@@ -193,7 +193,7 @@ This shell should support pipe redirect syntax."
193 "Parse one line of grep output, and return it as a match list. 193 "Parse one line of grep output, and return it as a match list.
194Moves cursor to end of the match." 194Moves cursor to end of the match."
195 (pcase-let 195 (pcase-let
196 ((`(,grep-re ,file-group ,line-group . ,_) (car (grep-regexp-alist)))) 196 ((`(,grep-re ,file-group ,line-group . ,_) (car grep-regexp-alist)))
197 (cond ((eq (oref tool :resulttype) 'file) 197 (cond ((eq (oref tool :resulttype) 'file)
198 ;; Search for files 198 ;; Search for files
199 (when (re-search-forward "^\\([^\n]+\\)$" nil t) 199 (when (re-search-forward "^\\([^\n]+\\)$" nil t)
diff --git a/lisp/progmodes/grep.el b/lisp/progmodes/grep.el
index 2ddaf884bce..466b524c79d 100644
--- a/lisp/progmodes/grep.el
+++ b/lisp/progmodes/grep.el
@@ -31,7 +31,6 @@
31 31
32(require 'compile) 32(require 'compile)
33 33
34
35(defgroup grep nil 34(defgroup grep nil
36 "Run `grep' and display the results." 35 "Run `grep' and display the results."
37 :group 'tools 36 :group 'tools
@@ -366,53 +365,44 @@ A grep buffer becomes most recent when you select Grep mode in it.
366Notice that using \\[next-error] or \\[compile-goto-error] modifies 365Notice that using \\[next-error] or \\[compile-goto-error] modifies
367`compilation-last-buffer' rather than `grep-last-buffer'.") 366`compilation-last-buffer' rather than `grep-last-buffer'.")
368 367
369(defconst grep--regexp-alist-column
370 ;; Calculate column positions (col . end-col) of first grep match on a line
371 (cons
372 (lambda ()
373 (when grep-highlight-matches
374 (let* ((beg (match-end 0))
375 (end (save-excursion (goto-char beg) (line-end-position)))
376 (mbeg (text-property-any beg end 'font-lock-face 'grep-match-face)))
377 (when mbeg
378 (- mbeg beg)))))
379 (lambda ()
380 (when grep-highlight-matches
381 (let* ((beg (match-end 0))
382 (end (save-excursion (goto-char beg) (line-end-position)))
383 (mbeg (text-property-any beg end 'font-lock-face 'grep-match-face))
384 (mend (and mbeg (next-single-property-change mbeg 'font-lock-face nil end))))
385 (when mend
386 (- mend beg)))))))
387(defconst grep--regexp-alist-bin-matcher
388 '("^Binary file \\(.+\\) matches$" 1 nil nil 0 1))
389(defconst grep-with-null-regexp-alist
390 `(("^\\([^\0]+\\)\\(\0\\)\\([0-9]+\\):" 1 3 ,grep--regexp-alist-column nil nil
391 (2 '(face unspecified display ":")))
392 ,grep--regexp-alist-bin-matcher)
393 "Regexp used to match grep hits.
394See `compilation-error-regexp-alist'.")
395(defconst grep-fallback-regexp-alist
396 `(;; Use a tight regexp to handle weird file names (with colons
397 ;; in them) as well as possible. E.g., use [1-9][0-9]* rather
398 ;; than [0-9]+ so as to accept ":034:" in file names.
399 ("^\\(.*?[^/\n]\\):[ \t]*\\([1-9][0-9]*\\)[ \t]*:"
400 1 2 ,grep--regexp-alist-column)
401 ,grep--regexp-alist-bin-matcher)
402 "Regexp used to match grep hits when `--null' is not supported.
403See `compilation-error-regexp-alist'.")
404
405(defvaralias 'grep-regex-alist 'grep-with-null-regexp-alist)
406(make-obsolete-variable
407 'grep-regex-alist "Call `grep-regexp-alist' instead." "26.1")
408
409;;;###autoload 368;;;###autoload
410(defun grep-regexp-alist () 369(defconst grep-regexp-alist
411 "Return a regexp alist to match grep hits. 370 `((,(concat "^\\(?:"
412The regexp used depends on `grep-use-null-filename-separator'. 371 ;; Parse using NUL characters when `--null' is used.
413See `compilation-error-regexp-alist' for format details." 372 ;; Note that we must still assume no newlines in
414 (if grep-use-null-filename-separator 373 ;; filenames due to "foo: Is a directory." type
415 grep-with-null-regexp-alist grep-fallback-regexp-alist)) 374 ;; messages.
375 "\\(?1:[^\0\n]+\\)\\(?3:\0\\)\\(?2:[0-9]+\\):"
376 "\\|"
377 ;; Fallback if `--null' is not used, use a tight regexp
378 ;; to handle weird file names (with colons in them) as
379 ;; well as possible. E.g., use [1-9][0-9]* rather than
380 ;; [0-9]+ so as to accept ":034:" in file names.
381 "\\(?1:[^\n:]+?[^\n/:]\\):[\t ]*\\(?2:[1-9][0-9]*\\)[\t ]*:"
382 "\\)")
383 1 2
384 ;; Calculate column positions (col . end-col) of first grep match on a line
385 (,(lambda ()
386 (when grep-highlight-matches
387 (let* ((beg (match-end 0))
388 (end (save-excursion (goto-char beg) (line-end-position)))
389 (mbeg (text-property-any beg end 'font-lock-face 'grep-match-face)))
390 (when mbeg
391 (- mbeg beg)))))
392 .
393 ,(lambda ()
394 (when grep-highlight-matches
395 (let* ((beg (match-end 0))
396 (end (save-excursion (goto-char beg) (line-end-position)))
397 (mbeg (text-property-any beg end 'font-lock-face 'grep-match-face))
398 (mend (and mbeg (next-single-property-change mbeg 'font-lock-face nil end))))
399 (when mend
400 (- mend beg))))))
401 nil nil
402 (3 '(face nil display ":")))
403 ("^Binary file \\(.+\\) matches$" 1 nil nil 0 1))
404 "Regexp used to match grep hits.
405See `compilation-error-regexp-alist' for format details.")
416 406
417(defvar grep-first-column 0 ; bug#10594 407(defvar grep-first-column 0 ; bug#10594
418 "Value to use for `compilation-first-column' in grep buffers.") 408 "Value to use for `compilation-first-column' in grep buffers.")
@@ -451,7 +441,9 @@ See `compilation-error-regexp-alist' for format details."
451 (2 grep-error-face nil t)) 441 (2 grep-error-face nil t))
452 ;; "filename-linenumber-" format is used for context lines in GNU grep, 442 ;; "filename-linenumber-" format is used for context lines in GNU grep,
453 ;; "filename=linenumber=" for lines with function names in "git grep -p". 443 ;; "filename=linenumber=" for lines with function names in "git grep -p".
454 ("^.+?[-=][0-9]+[-=].*\n" (0 grep-context-face))) 444 ("^.+?\\([-=\0]\\)[0-9]+\\([-=]\\).*\n" (0 grep-context-face)
445 (1 (if (eq (char-after (match-beginning 1)) ?\0)
446 `(face nil display ,(match-string 2))))))
455 "Additional things to highlight in grep output. 447 "Additional things to highlight in grep output.
456This gets tacked on the end of the generated expressions.") 448This gets tacked on the end of the generated expressions.")
457 449
@@ -781,7 +773,7 @@ This function is called from `compilation-filter-hook'."
781 (set (make-local-variable 'compilation-error-face) 773 (set (make-local-variable 'compilation-error-face)
782 grep-hit-face) 774 grep-hit-face)
783 (set (make-local-variable 'compilation-error-regexp-alist) 775 (set (make-local-variable 'compilation-error-regexp-alist)
784 (grep-regexp-alist)) 776 grep-regexp-alist)
785 ;; compilation-directory-matcher can't be nil, so we set it to a regexp that 777 ;; compilation-directory-matcher can't be nil, so we set it to a regexp that
786 ;; can never match. 778 ;; can never match.
787 (set (make-local-variable 'compilation-directory-matcher) '("\\`a\\`")) 779 (set (make-local-variable 'compilation-directory-matcher) '("\\`a\\`"))
diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el
index cc9b794c5a0..35a5c8862f4 100644
--- a/lisp/progmodes/xref.el
+++ b/lisp/progmodes/xref.el
@@ -929,7 +929,7 @@ IGNORES is a list of glob patterns."
929 (expand-file-name dir) 929 (expand-file-name dir)
930 ignores)) 930 ignores))
931 (buf (get-buffer-create " *xref-grep*")) 931 (buf (get-buffer-create " *xref-grep*"))
932 (`(,grep-re ,file-group ,line-group . ,_) (car (grep-regexp-alist))) 932 (`(,grep-re ,file-group ,line-group . ,_) (car grep-regexp-alist))
933 (status nil) 933 (status nil)
934 (hits nil)) 934 (hits nil))
935 (with-current-buffer buf 935 (with-current-buffer buf