emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/urgrep 7e00d57a8b 1/4: Use `rx` constructs in a few mor


From: ELPA Syncer
Subject: [elpa] externals/urgrep 7e00d57a8b 1/4: Use `rx` constructs in a few more places
Date: Sat, 13 May 2023 15:59:01 -0400 (EDT)

branch: externals/urgrep
commit 7e00d57a8bf17bbcd18afaf16cf2772e21d39691
Author: Jim Porter <jporterbugs@gmail.com>
Commit: Jim Porter <jporterbugs@gmail.com>

    Use `rx` constructs in a few more places
---
 urgrep-wgrep.el | 33 +++++++++++++++------------------
 urgrep.el       | 17 ++++++++++-------
 2 files changed, 25 insertions(+), 25 deletions(-)

diff --git a/urgrep-wgrep.el b/urgrep-wgrep.el
index 31766ded97..ff0736e979 100644
--- a/urgrep-wgrep.el
+++ b/urgrep-wgrep.el
@@ -29,32 +29,29 @@
 
 ;;; Code:
 
+(require 'urgrep)
 (require 'text-property-search)
 
 (defvar urgrep-wgrep--grouped-result-regexp
-  (concat "^\\(?:"
-          ;; A match or context line.
-          "\\(?2:[1-9][0-9]*\\)[:=-]"
-          "\\|"
-          ;; A separator line.
-          "\\(?3:--$\\)"
-          "\\)")
+  (rx bol (or ;; A match or context line.
+              (seq (group-n 2 urgrep-regular-number) (any ":=-"))
+              ;; A separator line.
+              (group-n 3 "--" eol)))
   "The regexp to use to match results using grouped output.
 Group 2 is the line number, and group 3 is the \"--\" separator used when
 displaying context.  Group 1 is unused.")
 
 (defvar urgrep-wgrep--ungrouped-result-regexp
-  (concat "^\\(?:"
-          ;; A match or context line using a null terminator after the 
filename.
-          "\\(?1:[^\0\n]+\\)\0\\(?2:[0-9]+\\)[:=-]"
-          "\\|"
-          ;; A match or context line without a null terminator; see also
-          ;; `urgrep-regexp-alist'.
-          "\\(?1:[^\n]*?[^\n/]\\)[:=-]\\(?2:[1-9][0-9]*\\)[:=-]"
-          "\\|"
-          ;; A separator line.
-          "\\(?3:--$\\)"
-          "\\)")
+  (rx bol (or ;; A match or context line using a null terminator after the
+              ;; filename.
+              (seq (group-n 1 (+ (not (any "\0" "\n")))) "\0"
+                   (group-n 2 (+ digit)) (any ":=-"))
+              ;; A match or context line without a null terminator; see also
+              ;; `urgrep-regexp-alist'.
+              (seq (group-n 1 (+? nonl) (not (any "\n" "/"))) (any ":=-")
+                   (group-n 2 urgrep-regular-number) (any ":=-"))
+              ;; A separator line.
+              (group-n 3 "--" eol)))
     "The regexp to use to match results using ungrouped output.
 Group 1 is the filename, group 2 is the line number, and group 3 is the \"--\"
 separator used when displaying context.")
diff --git a/urgrep.el b/urgrep.el
index fa6a2f3cd3..504bcb88cf 100644
--- a/urgrep.el
+++ b/urgrep.el
@@ -203,6 +203,8 @@ one for each `:abbreviate' key found."
        (with-temp-buffer ,@body)
      ,@body))
 
+(rx-define urgrep-regular-number (seq (any "1-9") (* digit)))
+
 
 ;; Urgrep tools
 
@@ -687,12 +689,13 @@ line number."
       (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:[=-]\\).*$")))
+        (looking-at (rx (literal file-name)
+                        (or (group-n 2 "\0") (any ":=-"))
+                        (+ digit) (group-n 1 (any "=-"))
+                        (* nonl) eol)))
     ;; Grouped result.
-    (looking-at "[0-9]+\\([=-]\\).*$")))
+    (looking-at (rx (+ digit) (group (any "=-")) (* nonl) eol)
+                "[0-9]+\\([=-]\\).*$")))
 
 (defvar urgrep-mode-font-lock-keywords
   `((,(rx bol "Urgrep started" (* nonl))
@@ -773,14 +776,14 @@ versions, it's half-open.  Use this to adjust the value 
as needed in
               ;; 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))))
+                   ":" (group-n 2 urgrep-regular-number)))
           ":")
      1 2 (,#'urgrep--column-begin . ,#'urgrep--column-end)
      nil nil
      (3 '(face nil display ":")))
 
     ;; Grouped matches
-    (,(rx bol (group (any "1-9") (* digit)) ":")
+    (,(rx bol (group urgrep-regular-number) ":")
      ,#'urgrep--grouped-filename 1
      (,#'urgrep--column-begin . ,#'urgrep--column-end)))
   "Regexp used to match results.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]