Browse Source

Backport commit 770f76f05 from Emacs

Make regexps smaller and faster by removing terms that are superfluous
by virtue of standing next to another term that matches more.  See
https://lists.gnu.org/archive/html/emacs-devel/2020-01/msg00949.html
for details.

* lisp/ob-core.el (org-babel-remove-result):
* lisp/ob-fortran.el (org-babel-fortran-ensure-main-wrap):
* lisp/org-capture.el (org-capture-set-target-location):
* lisp/org-compat.el (org-maybe-keyword-time-regexp):
* lisp/org-table.el (org-table-expand-lhs-ranges):
Remove subsumed repetitions.

Remove subsumed repetitions in regexps
770f76f050376bbd77a3cc8cf44db57cf855a27c
Mattias Engdegård
Thu Feb 20 16:05:18 2020 +0100
Mattias Engdegård 5 years ago
parent
commit
b78583a1c1
5 changed files with 5 additions and 5 deletions
  1. 1 1
      lisp/ob-core.el
  2. 1 1
      lisp/ob-fortran.el
  3. 1 1
      lisp/org-capture.el
  4. 1 1
      lisp/org-compat.el
  5. 1 1
      lisp/org-table.el

+ 1 - 1
lisp/ob-core.el

@@ -2439,7 +2439,7 @@ INFO may provide the values of these header arguments (in the
     (when location
     (when location
       (save-excursion
       (save-excursion
         (goto-char location)
         (goto-char location)
-	(when (looking-at (concat org-babel-result-regexp ".*$"))
+	(when (looking-at org-babel-result-regexp)
 	  (delete-region
 	  (delete-region
 	   (if keep-keyword (line-beginning-position 2)
 	   (if keep-keyword (line-beginning-position 2)
 	     (save-excursion
 	     (save-excursion

+ 1 - 1
lisp/ob-fortran.el

@@ -107,7 +107,7 @@ its header arguments."
 
 
 (defun org-babel-fortran-ensure-main-wrap (body params)
 (defun org-babel-fortran-ensure-main-wrap (body params)
   "Wrap body in a \"program ... end program\" block if none exists."
   "Wrap body in a \"program ... end program\" block if none exists."
-  (if (string-match "^[ \t]*program[ \t]*.*" (capitalize body))
+  (if (string-match "^[ \t]*program\\>" (capitalize body))
       (let ((vars (org-babel--get-vars params)))
       (let ((vars (org-babel--get-vars params)))
 	(when vars (error "Cannot use :vars if `program' statement is present"))
 	(when vars (error "Cannot use :vars if `program' statement is present"))
 	body)
 	body)

+ 1 - 1
lisp/org-capture.el

@@ -1034,7 +1034,7 @@ Store them in the capture property list."
 			 (apply #'encode-time 0 0
 			 (apply #'encode-time 0 0
 				org-extend-today-until
 				org-extend-today-until
 				(cl-cdddr (decode-time prompt-time))))
 				(cl-cdddr (decode-time prompt-time))))
-			((string-match "\\([^ ]+\\)--?[^ ]+[ ]+\\(.*\\)"
+			((string-match "\\([^ ]+\\)-[^ ]+[ ]+\\(.*\\)"
 				       org-read-date-final-answer)
 				       org-read-date-final-answer)
 			 ;; Replace any time range by its start.
 			 ;; Replace any time range by its start.
 			 (apply #'encode-time
 			 (apply #'encode-time

+ 1 - 1
lisp/org-compat.el

@@ -639,7 +639,7 @@ use of this function is for the stuck project list."
 
 
 (defconst org-maybe-keyword-time-regexp
 (defconst org-maybe-keyword-time-regexp
   (concat "\\(\\<\\(\\(?:CLO\\(?:CK\\|SED\\)\\|DEADLINE\\|SCHEDULED\\):\\)\\)?"
   (concat "\\(\\<\\(\\(?:CLO\\(?:CK\\|SED\\)\\|DEADLINE\\|SCHEDULED\\):\\)\\)?"
-	  " *\\([[<][0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} ?[^]\r\n>]*?[]>]"
+	  " *\\([[<][0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} [^]\r\n>]*[]>]"
 	  "\\|"
 	  "\\|"
 	  "<%%([^\r\n>]*>\\)")
 	  "<%%([^\r\n>]*>\\)")
   "Matches a timestamp, possibly preceded by a keyword.")
   "Matches a timestamp, possibly preceded by a keyword.")

+ 1 - 1
lisp/org-table.el

@@ -3163,7 +3163,7 @@ function assumes the table is already analyzed (i.e., using
       (let ((lhs (car e))
       (let ((lhs (car e))
 	    (rhs (cdr e)))
 	    (rhs (cdr e)))
 	(cond
 	(cond
-	 ((string-match-p "\\`@-?[-+0-9]+\\$-?[0-9]+\\'" lhs)
+	 ((string-match-p "\\`@[-+0-9]+\\$-?[0-9]+\\'" lhs)
 	  ;; This just refers to one fixed field.
 	  ;; This just refers to one fixed field.
 	  (push e res))
 	  (push e res))
 	 ((string-match-p "\\`[a-zA-Z][_a-zA-Z0-9]*\\'" lhs)
 	 ((string-match-p "\\`[a-zA-Z][_a-zA-Z0-9]*\\'" lhs)