emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master 7ddd08b: Omit/rewrite useless regexp repetitions


From: Paul Eggert
Subject: [Emacs-diffs] master 7ddd08b: Omit/rewrite useless regexp repetitions
Date: Fri, 12 Apr 2019 22:43:47 -0400 (EDT)

branch: master
commit 7ddd08bd3ebc48998062a7d29274cf080256a48f
Author: Paul Eggert <address@hidden>
Commit: Paul Eggert <address@hidden>

    Omit/rewrite useless regexp repetitions
    
    Problem reported by Mattias Engdegård in:
    https://lists.gnu.org/r/emacs-devel/2019-04/msg00527.html
    * lisp/align.el (align-rules-list):
    * lisp/cedet/srecode/srt-mode.el (srecode-font-lock-keywords):
    * lisp/emacs-lisp/copyright.el (copyright-regexp):
    * lisp/erc/erc-backend.el (JOIN):
    * lisp/erc/erc-goodies.el (erc-unmorse):
    * lisp/mail/mail-extr.el (mail-extr-telephone-extension-pattern):
    * lisp/net/tramp-adb.el (tramp-adb-prompt):
    * lisp/org/org-table.el (org-table-range-regexp):
    * lisp/progmodes/idlwave.el (idlwave-where):
    * lisp/progmodes/verilog-mode.el (verilog-declaration-re-2-no-macro)
    (verilog-declaration-re-2-macro, verilog-delete-auto-buffer)
    (verilog-auto-inst-port):
    * lisp/url/url-misc.el (url-data):
    Omit or rewrite useless repetitions that risk being very slow in
    the backtracking regexp engine in Emacs.
---
 lisp/align.el                  | 2 +-
 lisp/cedet/srecode/srt-mode.el | 2 +-
 lisp/emacs-lisp/copyright.el   | 2 +-
 lisp/erc/erc-backend.el        | 2 +-
 lisp/erc/erc-goodies.el        | 2 +-
 lisp/mail/mail-extr.el         | 2 +-
 lisp/net/tramp-adb.el          | 2 +-
 lisp/org/org-table.el          | 4 ++--
 lisp/progmodes/idlwave.el      | 4 ++--
 lisp/progmodes/verilog-mode.el | 8 ++++----
 lisp/url/url-misc.el           | 2 +-
 11 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/lisp/align.el b/lisp/align.el
index fd88d0e..443237b 100644
--- a/lisp/align.el
+++ b/lisp/align.el
@@ -411,7 +411,7 @@ The possible settings for `align-region-separate' are:
     (c-variable-declaration
      (regexp   . ,(concat "[*&0-9A-Za-z_]>?[&*]*\\(\\s-+[*&]*\\)"
                          "[A-Za-z_][0-9A-Za-z:_]*\\s-*\\(\\()\\|"
-                         "=[^=\n].*\\|(.*)\\|\\(\\[.*\\]\\)*\\)?"
+                         "=[^=\n].*\\|(.*)\\|\\(\\[.*\\]\\)*\\)"
                          "\\s-*[;,]\\|)\\s-*$\\)"))
      (group    . 1)
      (modes    . align-c++-modes)
diff --git a/lisp/cedet/srecode/srt-mode.el b/lisp/cedet/srecode/srt-mode.el
index 2ad7ffc..6bf2d51 100644
--- a/lisp/cedet/srecode/srt-mode.el
+++ b/lisp/cedet/srecode/srt-mode.el
@@ -64,7 +64,7 @@
 (defvar srecode-font-lock-keywords
   '(
     ;; Template
-    ("^\\(template\\)\\s-+\\(\\w*\\)\\(\\( \\(:\\w+\\)\\|\\)+\\)$"
+    ("^\\(template\\)\\s-+\\(\\w*\\)\\(\\( \\(:\\w+\\)\\)*\\)$"
      (1 font-lock-keyword-face)
      (2 font-lock-function-name-face)
      (3 font-lock-builtin-face ))
diff --git a/lisp/emacs-lisp/copyright.el b/lisp/emacs-lisp/copyright.el
index 2726bbc..be33583 100644
--- a/lisp/emacs-lisp/copyright.el
+++ b/lisp/emacs-lisp/copyright.el
@@ -52,7 +52,7 @@ This is useful for ChangeLogs."
 (defcustom copyright-regexp
  "\\(©\\|@copyright{}\\|[Cc]opyright\\s *:?\\s *\\(?:(C)\\)?\
 \\|[Cc]opyright\\s *:?\\s *©\\)\
-\\s *\\(?:[^0-9\n]*\\s *\\)?\
+\\s *[^0-9\n]*\\s *\
 \\([1-9]\\([-0-9, ';/*%#\n\t]\\|\\s<\\|\\s>\\)*[0-9]+\\)"
   "What your copyright notice looks like.
 The second \\( \\) construct must match the years."
diff --git a/lisp/erc/erc-backend.el b/lisp/erc/erc-backend.el
index 2854cde..210830a 100644
--- a/lisp/erc/erc-backend.el
+++ b/lisp/erc/erc-backend.el
@@ -1285,7 +1285,7 @@ add things to `%s' instead."
     (pcase-let ((`(,nick ,login ,host)
                  (erc-parse-user (erc-response.sender parsed))))
       ;; strip the stupid combined JOIN facility (IRC 2.9)
-      (if (string-match "^\\(.*\\)?\^g.*$" chnl)
+      (if (string-match "^\\(.*\\)\^g.*$" chnl)
           (setq chnl (match-string 1 chnl)))
       (save-excursion
         (let* ((str (cond
diff --git a/lisp/erc/erc-goodies.el b/lisp/erc/erc-goodies.el
index 117b678..884c594 100644
--- a/lisp/erc/erc-goodies.el
+++ b/lisp/erc/erc-goodies.el
@@ -548,7 +548,7 @@ channel that has weird people talking in morse to each 
other.
 
 See also `unmorse-region'."
   (goto-char (point-min))
-  (when (re-search-forward "[.-]+\\([.-]*/? *\\)+[.-]+/?" nil t)
+  (when (re-search-forward "[.-]+[./ -]*[.-]/?" nil t)
     (save-restriction
       (narrow-to-region (match-beginning 0) (match-end 0))
       ;; Turn " / " into "  "
diff --git a/lisp/mail/mail-extr.el b/lisp/mail/mail-extr.el
index cb57d8e..a0b9688 100644
--- a/lisp/mail/mail-extr.el
+++ b/lisp/mail/mail-extr.el
@@ -383,7 +383,7 @@ by translating things like \"address@hidden" into 
\"address@hidden"."
 ;; Matches telephone extensions.
 (defconst mail-extr-telephone-extension-pattern
   (purecopy
-   "\\(\\([Ee]xt\\|\\|[Tt]ph\\|[Tt]el\\|[Xx]\\).?\\)? *\\+?[0-9][- 0-9]+"))
+   "\\(\\([Ee]xt\\|[Tt]ph\\|[Tt]el\\|[Xx]\\).?\\)? *\\+?[0-9][- 0-9]+"))
 
 ;; Matches ham radio call signs.
 ;; Help from: Mat Maessen N2NJZ <address@hidden>, Mark Feit
diff --git a/lisp/net/tramp-adb.el b/lisp/net/tramp-adb.el
index db9acbf..f3aa55f 100644
--- a/lisp/net/tramp-adb.el
+++ b/lisp/net/tramp-adb.el
@@ -53,7 +53,7 @@ It is used for TCP/IP devices."
   "When this method name is used, forward all calls to Android Debug Bridge.")
 
 (defcustom tramp-adb-prompt
-  
"^\\(?:[[:digit:]]*|?\\)?\\(?:[[:alnum:]\e;address@hidden:alnum:]]*[^#\\$]*\\)?[#\\$][[:space:]]"
+  
"^[[:digit:]]*|?\\(?:[[:alnum:]\e;address@hidden:alnum:]]*[^#\\$]*\\)?[#\\$][[:space:]]"
   "Regexp used as prompt in almquist shell."
   :type 'string
   :version "24.4"
diff --git a/lisp/org/org-table.el b/lisp/org/org-table.el
index b6e864f..147527d 100644
--- a/lisp/org/org-table.el
+++ b/lisp/org/org-table.el
@@ -484,8 +484,8 @@ Line numbers are counted from the beginning of the table.  
This
 variable is initialized with `org-table-analyze'.")
 
 (defconst org-table-range-regexp
-  
"@\\([-+]?I*[-+]?[0-9]*\\)?\\(\\$[-+]?[0-9]+\\)?\\(address@hidden([-+]?I*[-+]?[0-9]*\\)?\\(\\$[-+]?[0-9]+\\)?\\)?"
-  ;;   1                        2                    3          4              
          5
+  
"@\\([-+]?I*[-+]?[0-9]*\\)\\(\\$[-+]?[0-9]+\\)?\\(address@hidden([-+]?I*[-+]?[0-9]*\\)\\(\\$[-+]?[0-9]+\\)?\\)?"
+  ;;   1                       2                    3          4               
        5
   "Regular expression for matching ranges in formulas.")
 
 (defconst org-table-range-regexp2
diff --git a/lisp/progmodes/idlwave.el b/lisp/progmodes/idlwave.el
index bded09d..6f56ce0 100644
--- a/lisp/progmodes/idlwave.el
+++ b/lisp/progmodes/idlwave.el
@@ -6454,10 +6454,10 @@ ARROW:  Location of the arrow"
      ((string-match "\\`[ \t]*\\(pro\\|function\\)\\>"
                    match-string)
       nil)
-     ((string-match "OBJ_NEW([ \t]*['\"]\\([a-zA-Z0-9$_]*\\)?\\'"
+     ((string-match "OBJ_NEW([ \t]*['\"][a-zA-Z0-9$_]*\\'"
                    match-string)
       (setq cw 'class))
-     ((string-match "\\<inherits\\s-+\\([a-zA-Z0-9$_]*\\)?\\'"
+     ((string-match "\\<inherits\\s-+[a-zA-Z0-9$_]*\\'"
                    match-string)
       (setq cw 'class))
      ((and func
diff --git a/lisp/progmodes/verilog-mode.el b/lisp/progmodes/verilog-mode.el
index 9226291..e75e584 100644
--- a/lisp/progmodes/verilog-mode.el
+++ b/lisp/progmodes/verilog-mode.el
@@ -2761,12 +2761,12 @@ find the errors."
 (defconst verilog-declaration-re-2-no-macro
   (concat "\\s-*" verilog-declaration-re
          "\\s-*\\(\\(" verilog-optional-signed-range-re "\\)\\|\\(" 
verilog-delay-re "\\)"
-         "\\)?"))
+         "\\)"))
 (defconst verilog-declaration-re-2-macro
   (concat "\\s-*" verilog-declaration-re
          "\\s-*\\(\\(" verilog-optional-signed-range-re "\\)\\|\\(" 
verilog-delay-re "\\)"
          "\\|\\(" verilog-macroexp-re "\\)"
-         "\\)?"))
+         "\\)"))
 (defconst verilog-declaration-re-1-macro
   (concat "^" verilog-declaration-re-2-macro))
 
@@ -10810,7 +10810,7 @@ Intended for internal use inside a 
`verilog-save-font-no-change-functions' block
                              'verilog-delete-auto-star-all)
   ;; Remove template comments ... anywhere in case was pasted after AUTOINST 
removed
   (goto-char (point-min))
-  (while (re-search-forward "\\s-*// \\(Templated\\|Implicit \\.\\*\\)\\([ 
\tLT0-9]*\\| LHS: .*\\)?$" nil t)
+  (while (re-search-forward "\\s-*// \\(Templated\\|Implicit \\.\\*\\)\\([ 
\tLT0-9]*\\| LHS: .*\\)$" nil t)
     (replace-match ""))
 
   ;; Final customize
@@ -11412,7 +11412,7 @@ If PAR-VALUES replace final strings with these 
parameter values."
     (when tpl-ass
       ;; Evaluate @"(lispcode)"
       (when (string-match "@\".*[^\\]\"" tpl-net)
-       (while (string-match "@\"\\(\\([^\\\"]*\\(\\\\.\\)*\\)*\\)\"" tpl-net)
+       (while (string-match "@\"\\(\\([^\\\"]\\|\\\\.\\)*\\)\"" tpl-net)
          (setq tpl-net
                (concat
                 (substring tpl-net 0 (match-beginning 0))
diff --git a/lisp/url/url-misc.el b/lisp/url/url-misc.el
index 4969cba..aa44ea7 100644
--- a/lisp/url/url-misc.el
+++ b/lisp/url/url-misc.el
@@ -88,7 +88,7 @@
        (encoding "8bit")
        (data nil))
     (save-excursion
-      (if (not (string-match "\\([^,]*\\)?," desc))
+      (if (not (string-match "\\([^,]*\\)," desc))
          (error "Malformed data URL: %s" desc)
        (setq mediatype (match-string 1 desc)
              data (url-unhex-string (substring desc (match-end 0))))



reply via email to

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