[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/urgrep f5b41c672b 106/115: Use `rx` in several places
From: |
ELPA Syncer |
Subject: |
[elpa] externals/urgrep f5b41c672b 106/115: Use `rx` in several places |
Date: |
Wed, 10 May 2023 03:00:49 -0400 (EDT) |
branch: externals/urgrep
commit f5b41c672be0f2c6d4827c3ed389d9d3702b7b0f
Author: Jim Porter <jporterbugs@gmail.com>
Commit: Jim Porter <jporterbugs@gmail.com>
Use `rx` in several places
---
urgrep.el | 109 ++++++++++++++++++++++++++++++++++++--------------------------
1 file changed, 63 insertions(+), 46 deletions(-)
diff --git a/urgrep.el b/urgrep.el
index c0c3947dd4..a23803c409 100644
--- a/urgrep.el
+++ b/urgrep.el
@@ -251,7 +251,7 @@ as in `urgrep-command'."
(save-match-data
;; Hide excessive part of rgrep command.
(when (string-match
- "^find \\(\\(?:-H \\)?\\. -type d .*\\(?:\\\\)\\|\")\"\\)\\)"
+ (rx bol "find " (group (*? nonl)) " " (or "-exec" "-print"))
command)
(put-text-property (match-beginning 1) (match-end 1)
'abbreviated-command t command)))
@@ -708,13 +708,20 @@ line number."
(looking-at "[0-9]+\\([=-]\\).*$")))
(defvar urgrep-mode-font-lock-keywords
- `(("^Urgrep started.*"
+ `(((rx bol "Urgrep started" (* nonl))
(0 '(face nil compilation-message nil help-echo nil mouse-face nil) t))
- ("^Urgrep finished with \\(?:\\(\\(?:[0-9]+ \\)?match\\(?:es\\)?
found\\)\\|\\(no matches found\\)\\).*"
+ ((rx bol "Urgrep finished with "
+ (group (or (seq (? (+ digit) " ") (or "match" "matches"))
+ "no matches")
+ " found")
+ (* nonl))
(0 '(face nil compilation-message nil help-echo nil mouse-face nil) t)
(1 'urgrep-match-count nil t)
(2 'compilation-warning nil t))
- ("^Urgrep \\(exited
abnormally\\|interrupt\\|killed\\|terminated\\)\\(?:.*with code
\\([0-9]+\\)\\)?.*"
+ ((rx bol "Urgrep "
+ (group (or "exited abnormally" "interrupt" "killed" "terminated"))
+ (? (* nonl) " with code " (group (+ digit)))
+ (* nonl))
(0 '(face nil compilation-message nil help-echo nil mouse-face nil) t)
(1 'compilation-error)
(2 'compilation-error nil t))
@@ -772,21 +779,22 @@ versions, it's half-open. Use this to adjust the value
as needed in
(defconst urgrep-regexp-alist
;; XXX: Try to rely on ANSI escapes as with the match highlight?
`(;; Ungrouped matches
- (,(concat
- "^\\(?:"
- ;; Parse using a null terminator after the filename when possible.
- "\\(?1:[^\0\n]+\\)\\(?3:\0\\)\\(?2:[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.
- "\\(?1:[^\n]+?[^\n/]\\):\\(?2:[1-9][0-9]*\\)"
- "\\):")
+ (,(rx bol
+ (or ;; Parse using a null terminator after the filename when
possible.
+ (seq (group-n 1 (+ (not (any "\0" "\n"))))
+ (group-n 3 "\0") (group-n 2 (+ digit)))
+ ;; Fallback if we can't use null terminators after the filename.
+ ;; Require line numbers to start with a nonzero digit to allow
+ ;; ":0" in filenames.
+ (seq (group-n 1 (+? nonl) (not (any "\n" "/")))
+ ":" (group-n 2 (any "1-9") (* digit))))
+ ":")
1 2 (,#'urgrep--column-begin . ,#'urgrep--column-end)
nil nil
(3 '(face nil display ":")))
;; Grouped matches
- ("^\\([1-9][0-9]*\\):"
+ (,(rx bol (group (any "1-9") (* digit)) ":")
,#'urgrep--grouped-filename 1
(,#'urgrep--column-begin . ,#'urgrep--column-end)))
"Regexp used to match results.
@@ -823,39 +831,48 @@ See `compilation-error-regexp-alist' for format details.")
(defun urgrep-filter ()
"Handle match highlighting escape sequences inserted by the process.
This function is called from `compilation-filter-hook'."
- (save-excursion
- (forward-line 0)
- (let ((end (point)) beg)
- (goto-char compilation-filter-start)
+ (rx-let ((ansi-sgr (&rest rest)
+ (seq "\033[" rest "m")))
+ (save-excursion
(forward-line 0)
- (setq beg (point))
- ;; Only operate on whole lines so we don't get caught with part of an
- ;; escape sequence in one chunk and the rest in another.
- (when (< (point) end)
- (setq end (copy-marker end))
- ;; Highlight matches and delete ANSI escapes.
- (while (re-search-forward
- (concat "\\(?:"
- "\033\\[0?1;31m" ; Find the escapes together...
- "\\|"
- "\033\\[1m\033\\[31m" ; ... or apart.
- "\\)\\(.*?\n?\\)\033\\[0?m")
- end 1)
- (replace-match
- (propertize (match-string 1) 'face nil 'font-lock-face
'urgrep-match)
- t t)
- (cl-incf urgrep-num-matches-found))
- ;; Highlight matching filenames and delete ANSI escapes.
- (goto-char beg)
- (while (re-search-forward "\033\\[35m\\(.*?\\)\033\\[0?m" end 1)
- (replace-match
- (propertize (match-string 1) 'face nil 'font-lock-face 'urgrep-hit
- 'urgrep-file-name t)
- t t))
- ;; Delete all remaining escape sequences.
- (goto-char beg)
- (while (re-search-forward "\033\\[[0-9;]*[mK]" end 1)
- (replace-match "" t t))))))
+ (let ((end (point)) beg)
+ (goto-char compilation-filter-start)
+ (forward-line 0)
+ (setq beg (point))
+ ;; Only operate on whole lines so we don't get caught with part of an
+ ;; escape sequence in one chunk and the rest in another.
+ (when (< (point) end)
+ (setq end (copy-marker end))
+ ;; Highlight matches and delete ANSI escapes.
+ (while (re-search-forward
+ (rx (or ;; Find the escapes together...
+ (ansi-sgr (or "01" "1") ";31")
+ ;; ... or apart.
+ (seq (ansi-sgr (or "01" "1"))
+ (ansi-sgr "31")))
+ (group (*? nonl) (? "\n"))
+ (ansi-sgr (? "0")))
+ end 1)
+ (replace-match
+ (propertize (match-string 1) 'face nil
+ 'font-lock-face 'urgrep-match)
+ t t)
+ (cl-incf urgrep-num-matches-found))
+ ;; Highlight matching filenames and delete ANSI escapes.
+ (goto-char beg)
+ (while (re-search-forward
+ (rx (ansi-sgr "35") (group (*? nonl)) (ansi-sgr (? "0")))
+ end 1)
+ (replace-match
+ (propertize (match-string 1) 'face nil 'font-lock-face 'urgrep-hit
+ 'urgrep-file-name t)
+ t t))
+ ;; Delete all remaining escape sequences.
+ (goto-char beg)
+ (while (re-search-forward
+ (rx "\033[" (* (any digit ";")) (any "m" "K"))
+ end 1)
+ (replace-match "" t t)))))))
(define-compilation-mode urgrep-mode "Urgrep"
"A compilation mode for various grep-like tools."
- [elpa] externals/urgrep eb5191bfd5 097/115: Update copyright year, (continued)
- [elpa] externals/urgrep eb5191bfd5 097/115: Update copyright year, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 43c82e84ec 082/115: Add CI for Emacs 27.1, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 3082d89bd9 099/115: Add support for abbreviating the command in urgrep buffers, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep b5b426e9ca 084/115: Fix hiding excessive part of rgrep command in Emacs 28, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 56acdfe434 087/115: Improve how we wait for urgrep to finish in tests, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 30cc9e363e 085/115: Fix context-line detection for find/grep, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 0b036cdcf4 100/115: Improve explanation of `C-u C-u` for choosing directory, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 6614dfe651 102/115: Update checkout action in CI, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 01fbe92f2c 103/115: In tests, wait for grep to finish before doing any checks, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 99e1de4eb1 105/115: Fix an edge case when unable to get the grouped filename for highlighting, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep f5b41c672b 106/115: Use `rx` in several places,
ELPA Syncer <=
- [elpa] externals/urgrep 91e3807239 109/115: Properly evaluate rx forms, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 1d4bdca3d8 111/115: Add package keywords and such, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 61ef67450b 114/115: Assign copyright to the FSF, ELPA Syncer, 2023/05/10