[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/xr 19fe170 5/5: Merge adjacent ranges
From: |
Stefan Monnier |
Subject: |
[elpa] externals/xr 19fe170 5/5: Merge adjacent ranges |
Date: |
Tue, 5 Feb 2019 10:52:06 -0500 (EST) |
branch: externals/xr
commit 19fe170232793a27447c4f4d5e2755b1bade32d0
Author: Mattias Engdegård <address@hidden>
Commit: Mattias Engdegård <address@hidden>
Merge adjacent ranges
Transform "[a-zA-Z]" into (any "a-zA-Z") instead of (any "a-z" "A-Z")
for terseness; readability is unlikely to suffer.
Suggested by Clément Pit-Claudel.
---
xr.el | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/xr.el b/xr.el
index fe03ae1..3c8e3d3 100644
--- a/xr.el
+++ b/xr.el
@@ -85,8 +85,14 @@
;; become (97 . 122) when printed.
;; TODO: Possibly convert "[0-9]" to digit, and
;; "[0-9a-fA-F]" (and permutations) to hex-digit.
- (push range set)
- (goto-char (match-end 0))))
+ (goto-char (match-end 0))
+ (let ((prev (car set)))
+ ;; Merge with preceding range if any.
+ (if (and (stringp prev)
+ (>= (length prev) 3)
+ (eq (aref prev 1) ?-))
+ (setq set (cons (concat prev range) (cdr set)))
+ (push range set)))))
((looking-at (rx eos))
(error "Unterminated character alternative"))
;; plain character (including ^ or -)
@@ -599,7 +605,9 @@ Returns nil."
(xr--expect "[a-z-+/*%0-4[:xdigit:]]"
'(any "a-z" "-" "+/*%" "0-4" xdigit))
(xr--expect "[^]A-Za-z-]*"
- '(zero-or-more (not (any "]" "A-Z" "a-z" "-"))))
+ '(zero-or-more (not (any "]" "A-Za-z" "-"))))
+ (xr--expect "[+*%A-Ka-k0-3${-}]"
+ '(any "+*%" "A-Ka-k0-3" "$" "{-}"))
(xr--expect ""
"")
(xr--expect "a\\|"