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

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

[elpa] externals/xr c98bb7b 03/10: Handle whitespace and word syntax sub


From: Mattias Engdegård
Subject: [elpa] externals/xr c98bb7b 03/10: Handle whitespace and word syntax subsumption in one place
Date: Sun, 3 May 2020 11:13:07 -0400 (EDT)

branch: externals/xr
commit c98bb7bcf319bca7c42038c51a92ed78f5e439d7
Author: Mattias Engdegård <address@hidden>
Commit: Mattias Engdegård <address@hidden>

    Handle whitespace and word syntax subsumption in one place
    
    Use the more elaborate code already in place for charsets.
---
 xr.el | 33 +++++++++++++++++----------------
 1 file changed, 17 insertions(+), 16 deletions(-)

diff --git a/xr.el b/xr.el
index 3e09ac0..fa89862 100644
--- a/xr.el
+++ b/xr.el
@@ -1042,22 +1042,23 @@ A-SETS and B-SETS are arguments to `any'."
 
 (defun xr--syntax-superset-of-rx-p (syntax negated rx)
   "Whether SYNTAX, possibly NEGATED, is a superset of RX."
-  ;; Syntax tables vary, but we make a (quite conservative) guess.
-  (let* ((always-set
-           ;; Characters we think always will be in the syntax set.
-           '((whitespace " \t")
-             (word "A-Za-z0-9")
-             (open-parenthesis "([")
-             (close-parenthesis "])")))
-         (never-set
-           ;; Characters we think never will be in the syntax set.
-           '((whitespace "!-~")
-             (punctuation "A-Za-z0-9")
-             (open-parenthesis "\x00- A-Za-z0-9")
-             (close-parenthesis "\x00- A-Za-z0-9")))
-         (set (assq syntax (if negated never-set always-set))))
-    (and set
-         (xr--char-superset-of-rx-p (cdr set) nil rx))))
+  (cond
+   ((eq syntax 'whitespace) (xr--char-superset-of-rx-p '(space) negated rx))
+   ((eq syntax 'word)       (xr--char-superset-of-rx-p '(word) negated rx))
+   (t
+    ;; Syntax tables vary, but we make a fairly conservative guess.
+    (let* ((always-set
+            ;; Characters we think always will be in the syntax set.
+            '((open-parenthesis "([")
+              (close-parenthesis "])")))
+           (never-set
+            ;; Characters we think never will be in the syntax set.
+            '((punctuation "A-Za-z0-9")   ; NOT the same as [:punct:]!
+              (open-parenthesis "\000-\037A-Za-z0-9" " \177")
+              (close-parenthesis "\000-\037A-Za-z0-9" " \177")))
+           (set (assq syntax (if negated never-set always-set))))
+      (and set
+           (xr--char-superset-of-rx-p (cdr set) nil rx))))))
 
 (defun xr--expand-strings (rx)
   "Expand strings to characters or seqs of characters.



reply via email to

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