[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/urgrep 7453367e6d 065/115: Avoid false-positives when l
From: |
ELPA Syncer |
Subject: |
[elpa] externals/urgrep 7453367e6d 065/115: Avoid false-positives when looking for context lines in results |
Date: |
Wed, 10 May 2023 03:00:44 -0400 (EDT) |
branch: externals/urgrep
commit 7453367e6d4d1544f972eccd470a2ab2c715e349
Author: Jim Porter <jporterbugs@gmail.com>
Commit: Jim Porter <jporterbugs@gmail.com>
Avoid false-positives when looking for context lines in results
This takes advantage of the propertization in `urgrep-filter' to reliably
detect what parts of a line are the filename vs what parts aren't.
---
urgrep.el | 44 ++++++++++++++++++++++++++++++++++----------
1 file changed, 34 insertions(+), 10 deletions(-)
diff --git a/urgrep.el b/urgrep.el
index cfe0925d5e..37a883075d 100644
--- a/urgrep.el
+++ b/urgrep.el
@@ -590,7 +590,28 @@ If EDIT-COMMAND is non-nil, the search can be edited."
help-echo "Number of matches so far")
"]"))
-(defvar urgrep-mode-font-lock-keywords
+(defun urgrep-mode--looking-at-context-line ()
+ "Return t if looking at a grep-like context line.
+
+If so, this function sets the match data, with the first match group
+indicating the separator between the line number and the match, and
+the second group indicating the separator between the file name and
+line number."
+ ;; Use the `urgrep-file-name' property set by `urgrep-filter' to reliably
+ ;; detect if the result was printed in grouped or ungrouped format.
+ (if (get-text-property (point) 'urgrep-file-name)
+ ;; Ungrouped result.
+ (let* ((file-name-end (next-single-property-change
+ (point) 'urgrep-file-name))
+ (file-name (buffer-substring-no-properties (point)
file-name-end)))
+ (looking-at (concat
+ (regexp-quote file-name)
+ "\\(?:\\(?2:\0\\)\\|[:=-]\\)"
+ "[0-9]+\\(?1:[=-]\\).*$")))
+ ;; Grouped result.
+ (looking-at "[0-9]+\\([=-]\\).*$")))
+
+(setq urgrep-mode-font-lock-keywords
`(("^Urgrep started.*"
(0 '(face nil compilation-message nil help-echo nil mouse-face nil) t))
("^Urgrep finished with \\(?:\\(\\(?:[0-9]+ \\)?match\\(?:es\\)?
found\\)\\|\\(no matches found\\)\\).*"
@@ -602,15 +623,18 @@ If EDIT-COMMAND is non-nil, the search can be edited."
(1 'compilation-error)
(2 'compilation-error nil t))
;; Highlight context lines of various flavors.
- (,(concat
- "^\\(?:"
- ;; Parse using a null terminator after the filename when possible.
- "[^\0\n]+\\(\0\\)[0-9]+"
- "\\|"
- ;; Fallback if we can't use null terminators after the filename.
- ;; Use [1-9][0-9]* rather than [0-9]+ to allow ":0" in filenames.
- "\\(?:[^\n]*?[^\n/][:=-]\\)?[1-9][0-9]*"
- "\\)\\([=-]\\).*$")
+ ((lambda (limit)
+ (unless (bolp) (forward-line))
+ ;; Search line-by-line until we're looking at something that
+ ;; looks like a context line.
+ (catch 'found
+ (while (< (point) limit)
+ (when (urgrep-mode--looking-at-context-line)
+ (goto-char (match-end 0))
+ (throw 'found t))
+ (forward-line)))
+ ;; Only return non-nil if point is still within the limit.
+ (< (point) limit))
(0 'urgrep-context t)
(1 `(face nil display ,(match-string 2)) nil t))
;; Hide excessive part of rgrep command.
- [elpa] externals/urgrep dbb2c2caeb 095/115: Wrap some docstring lines with "\", (continued)
- [elpa] externals/urgrep dbb2c2caeb 095/115: Wrap some docstring lines with "\", ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 9949a5b296 094/115: Use connection-local variables for caching the tool to use for each host, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 569c52f504 083/115: Allow overriding EMACS during tests, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep d479dc5ad6 104/115: Remove unnecessary/wrong Git grep color settings, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep d0012b9fcb 112/115: Tweak tests so they only work around Emacs bug#58265 on older versions, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 392e4bcb98 008/115: Don't inherit from compilation-minor-mode to avoid its menu, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep c7a3cc5b30 015/115: Be less aggressive with shell-quoting on MS Windows, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep bfab29d1d7 014/115: Add support for searches starting with "-", ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 814ad5c60d 038/115: Update tests to work on MS Windows, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 86c36492b9 064/115: Include a description of how to enable wgrep support in the README, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 7453367e6d 065/115: Avoid false-positives when looking for context lines in results,
ELPA Syncer <=
- [elpa] externals/urgrep 593d209a31 067/115: Search in untracked files with git grep, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 1c08b41324 078/115: s/TRAMP/Tramp/g, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 6df13a8dee 071/115: Add support for urgrep command in Eshell, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 11e1f7474e 079/115: Add CI configuration, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep a7d87da8b5 096/115: Slight improvements to docstrings for defcustoms, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 1172efb5a2 107/115: Don't allow using an unknown tool in `urgrep-command`, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 7823d384e6 115/115: Add .elpaignore, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep e5d485de84 034/115: Improve behavior of `urgrep' to allow passing options and add `urgrep-run-command', ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 31fe7d5e5c 022/115: Cache the default tool per-host and allow users to override the tool preferences, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 4fec944d51 016/115: Fix output of git-grep and grep on Linux, ELPA Syncer, 2023/05/10