]> git.eshelyaron.com Git - emacs.git/commitdiff
2019-03-26 regex cleanup
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 27 Mar 2019 02:06:36 +0000 (19:06 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Wed, 27 Mar 2019 02:07:21 +0000 (19:07 -0700)
Problems reported by Mattias Engdegård in:
https://lists.gnu.org/r/emacs-devel/2019-03/msg01028.html
* lisp/align.el (align-rules-list):
* lisp/speedbar.el (speedbar-check-read-only, speedbar-check-vc):
* lisp/vc/diff-mode.el (diff-add-change-log-entries-other-window):
* lisp/woman.el (woman-parse-numeric-arg):
Put "-" at end of character alternatives, since a range was not intended.
* lisp/erc/erc.el (font-lock):
* lisp/mail/footnote.el (cl-seq):
Avoid duplicate character alternatives by using cl-seq API.
* lisp/mail/footnote.el (footnote--current-regexp):
* lisp/textmodes/css-mode.el (css--font-lock-keywords):
Avoid repetition of repetition.
* lisp/net/webjump.el (webjump-url-encode):
Add ~ to character alternatives, and rewrite confusing range.
* lisp/progmodes/verilog-mode.el (verilog-compiler-directives)
(verilog-assignment-operator-re):
Remove duplicate.
* lisp/progmodes/verilog-mode.el (verilog-preprocessor-re):
* lisp/textmodes/css-mode.el (css--font-lock-keywords):
Don’t escape a char that doesn’t need it.
* lisp/textmodes/picture.el (picture-tab-chars): In docstring,
do not say regexp characters will be quoted; merely say in
another way that the syntax is that of character alternatives.
(picture-set-tab-stops, picture-tab-search): Don’t attempt
to regexp-quote picture-tab-chars.
(picture-tab-search): Quote \ in picture-tab-chars for
skip-chars-backwards, which treats \ differently than
regexp character alternatives do.

lisp/align.el
lisp/erc/erc.el
lisp/mail/footnote.el
lisp/net/webjump.el
lisp/progmodes/verilog-mode.el
lisp/speedbar.el
lisp/textmodes/css-mode.el
lisp/textmodes/picture.el
lisp/vc/diff-mode.el
lisp/woman.el

index a81498be5d0d2c35b15cb00087c87e0496aea519..fd88d0eda42cf57792d3d43c280c49d10cca343e 100644 (file)
@@ -438,7 +438,7 @@ The possible settings for `align-region-separate' are:
      (tab-stop . nil))
 
     (perl-assignment
-     (regexp   . ,(concat "[^=!^&*-+<>/| \t\n]\\(\\s-*\\)=[~>]?"
+     (regexp   . ,(concat "[^=!^&*+<>/| \t\n-]\\(\\s-*\\)=[~>]?"
                          "\\(\\s-*\\)\\([^>= \t\n]\\|$\\)"))
      (group    . (1 2))
      (modes    . align-perl-modes)
index bcaa3e4525897b1f3e26ad0076b89242ea335b8c..e34487de273ee26ba1d23eb30bd6d9b6224f4058 100644 (file)
@@ -67,6 +67,7 @@
 (load "erc-loaddefs" nil t)
 
 (eval-when-compile (require 'cl-lib))
+(require 'cl-seq)
 (require 'font-lock)
 (require 'pp)
 (require 'thingatpt)
@@ -2522,10 +2523,8 @@ Returns NICK unmodified unless `erc-lurker-trim-nicks' is
 non-nil."
   (if erc-lurker-trim-nicks
       (replace-regexp-in-string
-       (format "[%s]"
-               (mapconcat (lambda (char)
-                            (regexp-quote (char-to-string char)))
-                          erc-lurker-ignore-chars ""))
+       (regexp-opt (cl-delete-duplicates
+                   (mapcar #'char-to-string erc-lurker-ignore-chars)))
        "" nick)
     nick))
 
index a7802929dca8066628db8ecffdb445ea7fc243db..7f88e30120def4661b873d20e732b0f6a15805a4 100644 (file)
@@ -64,6 +64,7 @@
 ;;; Code:
 
 (eval-when-compile (require 'cl-lib))
+(require 'cl-seq)
 (defvar filladapt-token-table)
 
 (defgroup footnote nil
@@ -363,7 +364,9 @@ Use Unicode characters for footnoting."
     ("ק" "ר" "ש" "ת" "תק" "תר" "תש" "תת" "תתק")))
 
 (defconst footnote-hebrew-numeric-regex
-  (concat "[" (apply #'concat (apply #'append footnote-hebrew-numeric)) "']+"))
+  (concat "[" (cl-delete-duplicates
+              (apply #'concat (apply #'append footnote-hebrew-numeric)))
+         "']+"))
 ;; (defconst footnote-hebrew-numeric-regex "\\([אבגדהוזחט]'\\)?\\(ת\\)?\\(ת\\)?\\([קרשת]\\)?\\([טיכלמנסעפצ]\\)?\\([אבגדהוזחט]\\)?")
 
 (defun footnote--hebrew-numeric (n)
@@ -457,9 +460,14 @@ Conversion is done based upon the current selected style."
 
 (defun footnote--current-regexp ()
   "Return the regexp of the index of the current style."
-  (concat (nth 2 (or (assq footnote-style footnote-style-alist)
-                    (nth 0 footnote-style-alist)))
-         "*"))
+  (let ((regexp (nth 2 (or (assq footnote-style footnote-style-alist)
+                          (nth 0 footnote-style-alist)))))
+    (concat
+     ;; Hack to avoid repetition of repetition.
+     (if (string-match "[^\\]\\\\\\{2\\}*[*+?]\\'" regexp)
+        (substring regexp 0 -1)
+       regexp)
+     "*")))
 
 (defun footnote--refresh-footnotes (&optional index-regexp)
   "Redraw all footnotes.
index 40df23e174a2ffa910e214c0a7ea7bd90503b026..e297b9d610814dfef6e9bfd0f2383ecf52e7e56b 100644 (file)
@@ -342,7 +342,7 @@ Please submit bug reports and other feedback to the author, Neil W. Van Dyke
   (mapconcat (lambda (c)
                (let ((s (char-to-string c)))
                  (cond ((string= s " ") "+")
-                       ((string-match "[a-zA-Z_.-/]" s) s)
+                      ((string-match "[a-zA-Z_./~-]" s) s)
                        (t (upcase (format "%%%02x" c))))))
              (encode-coding-string str 'utf-8)
              ""))
index 9e241c70e7695a93934fbe2b159591b9a0606791..f55cf0002d02b296e225711d3b3d3f1cad3ae3f1 100644 (file)
@@ -2053,7 +2053,7 @@ find the errors."
       "`resetall" "`timescale" "`unconnected_drive" "`undef" "`undefineall"
       ;; compiler directives not covered by IEEE 1800
       "`case" "`default" "`endfor" "`endprotect" "`endswitch" "`endwhile" "`for"
-      "`format" "`if" "`let" "`protect" "`switch" "`timescale" "`time_scale"
+      "`format" "`if" "`let" "`protect" "`switch" "`time_scale"
       "`while"
       ))
   "List of Verilog compiler directives.")
@@ -2414,9 +2414,7 @@ find the errors."
      '(
        ;; blocking assignment_operator
        "=" "+=" "-=" "*=" "/=" "%=" "&=" "|=" "^=" "<<=" ">>=" "<<<=" ">>>="
-       ;; non blocking assignment operator
-       "<="
-       ;; comparison
+       ;; comparison (also nonblocking assignment "<=")
        "==" "!=" "===" "!==" "<=" ">=" "==?" "!=?" "<->"
        ;; event_trigger
        "->" "->>"
@@ -2973,7 +2971,7 @@ find the errors."
      "\\<\\(`pragma\\)\\>\\s-+.+$"
      "\\)\\|\\(?:"
      ;; `timescale time_unit / time_precision
-     "\\<\\(`timescale\\)\\>\\s-+10\\{0,2\\}\\s-*[munpf]?s\\s-*\\/\\s-*10\\{0,2\\}\\s-*[munpf]?s"
+     "\\<\\(`timescale\\)\\>\\s-+10\\{0,2\\}\\s-*[munpf]?s\\s-*/\\s-*10\\{0,2\\}\\s-*[munpf]?s"
      "\\)\\|\\(?:"
      ;; `define and `if can span multiple lines if line ends in '\'. NOTE: `if is not IEEE 1800-2012
      ;; from http://www.emacswiki.org/emacs/MultilineRegexp
index 399ef4557b8974e2b1591e15f787cd7a6f531e74..4823e4ba5652b0bbd7e87ffb64b932e9363ea5f1 100644 (file)
@@ -2849,7 +2849,7 @@ indicator, then do not add a space."
        (progn
          (goto-char speedbar-ro-to-do-point)
          (while (and (not (input-pending-p))
-                     (re-search-forward "^\\([0-9]+\\):\\s-*[[<][+-?][]>] "
+                     (re-search-forward "^\\([0-9]+\\):\\s-*[[<][+?-][]>] "
                                         nil t))
            (setq speedbar-ro-to-do-point (point))
            (let ((f (speedbar-line-file)))
@@ -2900,7 +2900,7 @@ to add more types of version control systems."
        (progn
          (goto-char speedbar-vc-to-do-point)
          (while (and (not (input-pending-p))
-                     (re-search-forward "^\\([0-9]+\\):\\s-*\\[[+-?]\\] "
+                     (re-search-forward "^\\([0-9]+\\):\\s-*\\[[+?-]\\] "
                                         nil t))
            (setq speedbar-vc-to-do-point (point))
            (if (speedbar-check-vc-this-line (match-string 1))
index cddcdc0947bf29edb6d14cbba23f95ee7751461d..57ecc9788ebf647a1e120b9a1f525ff3c5605235 100644 (file)
@@ -892,7 +892,7 @@ cannot be completed sensibly: `custom-ident',
     (,(concat "@" css-ident-re) (0 font-lock-builtin-face))
     ;; Selectors.
     ;; Allow plain ":root" as a selector.
-    ("^[ \t]*\\(:root\\)\\(?:[\n \t]*\\)*{" (1 'css-selector keep))
+    ("^[ \t]*\\(:root\\)\\(?:[\n \t]*\\){" (1 'css-selector keep))
     ;; FIXME: attribute selectors don't work well because they may contain
     ;; strings which have already been highlighted as f-l-string-face and
     ;; thus prevent this highlighting from being applied (actually now that
@@ -915,7 +915,7 @@ cannot be completed sensibly: `custom-ident',
        "\\(?:\\(:" (regexp-opt (append css-pseudo-class-ids
                                        css-pseudo-element-ids)
                                t)
-       "\\|\\::" (regexp-opt css-pseudo-element-ids t) "\\)"
+       "\\|::" (regexp-opt css-pseudo-element-ids t) "\\)"
        "\\(?:([^)]+)\\)?"
        (if (not sassy)
            "[^:{}()\n]*"
index f0e30135f1607da20f6d001bfb662f44728e9919..b5208494674167f87c3775ba8e51a83bbf2ca167 100644 (file)
@@ -387,7 +387,8 @@ Interactively, ARG is the numeric argument, and defaults to 1."
 \\[picture-set-tab-stops] and \\[picture-tab-search].
 The syntax for this variable is like the syntax used inside of `[...]'
 in a regular expression--but without the `[' and the `]'.
-It is NOT a regular expression, any regexp special characters will be quoted.
+It is NOT a regular expression, and should follow the usual
+rules for the contents of a character alternative.
 It defines a set of \"interesting characters\" to look for when setting
 \(or searching for) tab stops, initially \"!-~\" (all printing characters).
 For example, suppose that you are editing a table which is formatted thus:
@@ -425,7 +426,7 @@ stops computed are displayed in the minibuffer with `:' at each stop."
       (if arg
          (setq tabs (or (default-value 'tab-stop-list)
                         (indent-accumulate-tab-stops (window-width))))
-       (let ((regexp (concat "[ \t]+[" (regexp-quote picture-tab-chars) "]")))
+       (let ((regexp (concat "[ \t]+[" picture-tab-chars "]")))
          (beginning-of-line)
          (let ((bol (point)))
            (end-of-line)
@@ -433,8 +434,8 @@ stops computed are displayed in the minibuffer with `:' at each stop."
              (skip-chars-forward " \t")
              (setq tabs (cons (current-column) tabs)))
            (if (null tabs)
-               (error "No characters in set %s on this line"
-                      (regexp-quote picture-tab-chars))))))
+               (error "No characters in set [%s] on this line"
+                      picture-tab-chars)))))
       (setq tab-stop-list tabs)
       (let ((blurb (make-string (1+ (nth (1- (length tabs)) tabs)) ?\ )))
        (while tabs
@@ -455,12 +456,13 @@ If no such character is found, move to beginning of line."
               (progn
                 (beginning-of-line)
                 (skip-chars-backward
-                 (concat "^" (regexp-quote picture-tab-chars))
+                 (concat "^" (replace-regexp-in-string
+                              "\\\\" "\\\\" picture-tab-chars nil t))
                  (point-min))
                 (not (bobp))))
          (move-to-column target))
       (if (re-search-forward
-          (concat "[ \t]+[" (regexp-quote picture-tab-chars) "]")
+          (concat "[ \t]+[" picture-tab-chars "]")
           (line-end-position)
           'move)
          (setq target (1- (current-column)))
index b67caab7f5045cc2058bfd4dc1295bc7eec13a8a..dbde284da84c15ea718ae068e408685feff60554 100644 (file)
@@ -2213,7 +2213,7 @@ I.e. like `add-change-log-entry-other-window' but applied to all hunks."
                  ;; `add-change-log-entry-other-window' works better in
                  ;; that case.
                  (re-search-forward
-                  (concat "\n[!+-<>]"
+                 (concat "\n[!+<>-]"
                           ;; If the hunk is a context hunk with an empty first
                           ;; half, recognize the "--- NNN,MMM ----" line
                           "\\(-- [0-9]+\\(,[0-9]+\\)? ----\n"
index a351f788ece38737e85136c305f8f356ed928786..39d9b806d2748c1e5397e44821def1aa74ae162c 100644 (file)
@@ -3511,7 +3511,7 @@ The expression may be an argument in quotes."
   (let ((value (if (looking-at "[+-]") 0 (woman-parse-numeric-value)))
        op)
     (while (cond
-           ((looking-at "[+-/*%]")     ; arithmetic operators
+           ((looking-at "[+/*%-]")     ; arithmetic operators
             (forward-char)
             (setq op (intern-soft (match-string 0)))
             (setq value (funcall op value (woman-parse-numeric-value))))