branch: externals/xr commit 5b53cc9efe25b668ce0c7263c1b8cf50c999a6cb Author: Mattias Engdegård <matti...@acm.org> Commit: Mattias Engdegård <matti...@acm.org>
Warn about two-character ranges like [*-+] --- xr-test.el | 5 +++++ xr.el | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/xr-test.el b/xr-test.el index 8948c2a..644eedf 100644 --- a/xr-test.el +++ b/xr-test.el @@ -349,6 +349,7 @@ (10 . "Ranges `I-L' and `I-M' overlap") (16 . "Ranges `a-e' and `b-d' overlap") (22 . "Ranges `g-k' and `i-n' overlap") + (25 . "Two-character range `s-t'") (29 . "Character `3' included in range `3-7'")))) (should (equal (xr-lint "[a[:digit:]b[:punct:]c[:digit:]]") '((22 . "Duplicated character class `[:digit:]'")))) @@ -362,6 +363,10 @@ '((4 . "Suspect `[' in char alternative")))) (should (equal (xr-lint "[^][-].]") nil)) + (should (equal (xr-lint "[0-1]") + nil)) + (should (equal (xr-lint "[^]-][]-^]") + '((6 . "Two-character range `]-^'")))) ) (ert-deftest xr-skip-set () diff --git a/xr.el b/xr.el index 4828b45..d2a65d1 100644 --- a/xr.el +++ b/xr.el @@ -98,6 +98,10 @@ (push (vector ?\] end (point)) intervals) (xr--report warnings (point) (format "Reversed range `%s' matches nothing" + (xr--escape-string (match-string 0) nil)))) + (when (eq end ?^) + (xr--report warnings (point) + (format "Two-character range `%s'" (xr--escape-string (match-string 0) nil))))) (goto-char (match-end 0))) ;; Initial ] @@ -133,6 +137,12 @@ (xr--report warnings (point) (format "Reversed range `%s' matches nothing" (xr--escape-string (match-string 0) nil))))) + ;; Suppress warnings about ranges between adjacent digits, + ;; like [0-1], as they are common and harmless. + (when (and (= end (1+ start)) (not (<= ?0 start end ?9))) + (xr--report warnings (point) + (format "Two-character range `%s'" + (xr--escape-string (match-string 0) nil)))) (goto-char (match-end 0)))) ((looking-at (rx eos)) (error "Unterminated character alternative"))