summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2020-02-23 12:41:33 +0100
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2020-02-23 12:41:33 +0100
commitfe5962ce9b2474f5a85bcb609b8097ac62a73e64 (patch)
treec10d5c2697f434b88e09d434b130d27c9416cfe5
parent2ab655fb6e12d4df0a6148f24f2ad50720b4447c (diff)
downloadorg-mode-fe5962ce9b2474f5a85bcb609b8097ac62a73e64.tar.gz
Fix some time stamps regexps
* lisp/org.el (org-ts--internal-regexp): New variable. (org-ts-regexp): (org-ts-regexp-inactive): (org-ts-regexp-both): Use new variable. (org-maybe-keyword-time-regexp): Remove variable. (org-logbook-drawer-re): Simplify regexp. Also move "Timestamp" section higher in the library (topological order). This change should pacify "Relint" checks.
-rw-r--r--etc/ORG-NEWS3
-rw-r--r--lisp/org.el130
2 files changed, 65 insertions, 68 deletions
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 1111a92..7542d97 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -252,6 +252,9 @@ You can turn this on/off on a per-file basis with =#+startup: num= or
Functions in this hook are run after ~org-agenda-filter~ is called.
** Removed or renamed functions and variables
+*** Removed ~org-maybe-keyword-time-regexp~
+
+The variable was not used in the code base.
*** Renamed ~org-columns-set-tags-or-toggle~
diff --git a/lisp/org.el b/lisp/org.el
index 32fe741..8b88744 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -369,6 +369,65 @@ FULL is given."
(defconst org-dblock-end-re "^[ \t]*#\\+\\(?:END\\|end\\)\\([: \t\r\n]\\|$\\)"
"Matches the end of a dynamic block.")
+;;;; Timestamp
+
+(defconst org-ts--internal-regexp
+ (rx (seq
+ (= 4 digit) "-" (= 2 digit) "-" (= 2 digit)
+ (optional " " (*? nonl))))
+ "Regular expression matching the innards of a time stamp.")
+
+(defconst org-ts-regexp (format "<\\(%s\\)>" org-ts--internal-regexp)
+ "Regular expression for fast time stamp matching.")
+
+(defconst org-ts-regexp-inactive
+ (format "\\[\\(%s\\)\\]" org-ts--internal-regexp)
+ "Regular expression for fast inactive time stamp matching.")
+
+(defconst org-ts-regexp-both (format "[[<]\\(%s\\)[]>]" org-ts--internal-regexp)
+ "Regular expression for fast time stamp matching.")
+
+(defconst org-ts-regexp0
+ "\\(\\([0-9]\\{4\\}\\)-\\([0-9]\\{2\\}\\)-\\([0-9]\\{2\\}\\)\\( +[^]+0-9>\r\n -]+\\)?\\( +\\([0-9]\\{1,2\\}\\):\\([0-9]\\{2\\}\\)\\)?\\)"
+ "Regular expression matching time strings for analysis.
+This one does not require the space after the date, so it can be used
+on a string that terminates immediately after the date.")
+
+(defconst org-ts-regexp1 "\\(\\([0-9]\\{4\\}\\)-\\([0-9]\\{2\\}\\)-\\([0-9]\\{2\\}\\) *\\([^]+0-9>\r\n -]*\\)\\( \\([0-9]\\{1,2\\}\\):\\([0-9]\\{2\\}\\)\\)?\\)"
+ "Regular expression matching time strings for analysis.")
+
+(defconst org-ts-regexp2 (concat "<" org-ts-regexp1 "[^>\n]\\{0,16\\}>")
+ "Regular expression matching time stamps, with groups.")
+
+(defconst org-ts-regexp3 (concat "[[<]" org-ts-regexp1 "[^]>\n]\\{0,16\\}[]>]")
+ "Regular expression matching time stamps (also [..]), with groups.")
+
+(defconst org-tr-regexp (concat org-ts-regexp "--?-?" org-ts-regexp)
+ "Regular expression matching a time stamp range.")
+
+(defconst org-tr-regexp-both
+ (concat org-ts-regexp-both "--?-?" org-ts-regexp-both)
+ "Regular expression matching a time stamp range.")
+
+(defconst org-tsr-regexp (concat org-ts-regexp "\\(--?-?"
+ org-ts-regexp "\\)?")
+ "Regular expression matching a time stamp or time stamp range.")
+
+(defconst org-tsr-regexp-both
+ (concat org-ts-regexp-both "\\(--?-?"
+ org-ts-regexp-both "\\)?")
+ "Regular expression matching a time stamp or time stamp range.
+The time stamps may be either active or inactive.")
+
+(defconst org-repeat-re
+ "<[0-9]\\{4\\}-[0-9][0-9]-[0-9][0-9] [^>\n]*?\
+\\([.+]?\\+[0-9]+[hdwmy]\\(/[0-9]+[hdwmy]\\)?\\)"
+ "Regular expression for specifying repeated events.
+After a match, group 1 contains the repeat expression.")
+
+(defconst org-time-stamp-formats '("<%Y-%m-%d %a>" . "<%Y-%m-%d %a %H:%M>")
+ "Formats for `format-time-string' which are used for time stamps.")
+
;;;; Clock and Planning
(defconst org-clock-string "CLOCK:"
@@ -460,18 +519,6 @@ Matched keyword is in group 1.")
" *[[<]\\([^]>]+\\)[]>]")
"Matches any of the 3 keywords, together with the time stamp.")
-(defconst org-maybe-keyword-time-regexp
- (concat "\\(\\<"
- (regexp-opt
- (list org-scheduled-string org-deadline-string org-closed-string
- org-clock-string)
- t)
- "\\)?"
- " *\\([[<][0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} ?[^]\r\n>]*?[]>]"
- "\\|"
- "<%%([^\r\n>]*>\\)")
- "Matches a timestamp, possibly preceded by a keyword.")
-
(defconst org-all-time-keywords
(mapcar (lambda (w) (substring w 0 -1))
(list org-scheduled-string org-deadline-string
@@ -497,9 +544,9 @@ Group 1 contains drawer's name or \"END\".")
"Regular expression matching the last line of a clock drawer.")
(defconst org-logbook-drawer-re
- (concat "^[ \t]*:LOGBOOK:[ \t]*\n"
- "\\(?:[ \t]*.*\\(?: .*\\)?[ \t]*\n\\)*?"
- "[ \t]*:END:[ \t]*$")
+ (rx (seq bol (0+ (any "\t ")) ":LOGBOOK:" (0+ (any "\t ")) "\n"
+ (*? (0+ nonl) "\n")
+ (0+ (any "\t ")) ":END:" (0+ (any "\t ")) eol))
"Matches an entire LOGBOOK drawer.")
(defconst org-property-drawer-re
@@ -576,59 +623,6 @@ An entry can be toggled between COMMENT and normal with
Effort estimates given in this property need to be in the format
defined in org-duration.el.")
-;;;; Timestamp
-
-(defconst org-ts-regexp "<\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} ?[^\r\n>]*?\\)>"
- "Regular expression for fast time stamp matching.")
-
-(defconst org-ts-regexp-inactive
- "\\[\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} ?[^\r\n>]*?\\)\\]"
- "Regular expression for fast inactive time stamp matching.")
-
-(defconst org-ts-regexp-both "[[<]\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\} ?[^]\r\n>]*?\\)[]>]"
- "Regular expression for fast time stamp matching.")
-
-(defconst org-ts-regexp0
- "\\(\\([0-9]\\{4\\}\\)-\\([0-9]\\{2\\}\\)-\\([0-9]\\{2\\}\\)\\( +[^]+0-9>\r\n -]+\\)?\\( +\\([0-9]\\{1,2\\}\\):\\([0-9]\\{2\\}\\)\\)?\\)"
- "Regular expression matching time strings for analysis.
-This one does not require the space after the date, so it can be used
-on a string that terminates immediately after the date.")
-
-(defconst org-ts-regexp1 "\\(\\([0-9]\\{4\\}\\)-\\([0-9]\\{2\\}\\)-\\([0-9]\\{2\\}\\) *\\([^]+0-9>\r\n -]*\\)\\( \\([0-9]\\{1,2\\}\\):\\([0-9]\\{2\\}\\)\\)?\\)"
- "Regular expression matching time strings for analysis.")
-
-(defconst org-ts-regexp2 (concat "<" org-ts-regexp1 "[^>\n]\\{0,16\\}>")
- "Regular expression matching time stamps, with groups.")
-
-(defconst org-ts-regexp3 (concat "[[<]" org-ts-regexp1 "[^]>\n]\\{0,16\\}[]>]")
- "Regular expression matching time stamps (also [..]), with groups.")
-
-(defconst org-tr-regexp (concat org-ts-regexp "--?-?" org-ts-regexp)
- "Regular expression matching a time stamp range.")
-
-(defconst org-tr-regexp-both
- (concat org-ts-regexp-both "--?-?" org-ts-regexp-both)
- "Regular expression matching a time stamp range.")
-
-(defconst org-tsr-regexp (concat org-ts-regexp "\\(--?-?"
- org-ts-regexp "\\)?")
- "Regular expression matching a time stamp or time stamp range.")
-
-(defconst org-tsr-regexp-both
- (concat org-ts-regexp-both "\\(--?-?"
- org-ts-regexp-both "\\)?")
- "Regular expression matching a time stamp or time stamp range.
-The time stamps may be either active or inactive.")
-
-(defconst org-repeat-re
- "<[0-9]\\{4\\}-[0-9][0-9]-[0-9][0-9] [^>\n]*?\
-\\([.+]?\\+[0-9]+[hdwmy]\\(/[0-9]+[hdwmy]\\)?\\)"
- "Regular expression for specifying repeated events.
-After a match, group 1 contains the repeat expression.")
-
-(defconst org-time-stamp-formats '("<%Y-%m-%d %a>" . "<%Y-%m-%d %a %H:%M>")
- "Formats for `format-time-string' which are used for time stamps.")
-
;;; The custom variables