mirror of
https://git.savannah.gnu.org/git/emacs/org-mode.git
synced 2024-08-26 00:02:51 +00:00
org.el: improve org-property-re and use it throughout
* lisp/org.el (org-property-re): Improve definition so that this regex can be used in all situations. Extend docstring with explanation of matching groups. (org-at-property-p): Implement using `org-element-at-point'. (org-entry-properties, org-buffer-property-keys, org-indent-line): Use `org-property-re' and adjust match group numbers accordingly. * lisp/org-element.el (org-element-node-property-parser): Use `org-property-re' and adjust match group numbers accordingly. Move `looking-at' out of the let clause to not rely on the unspecified evaluation order inside the let.
This commit is contained in:
parent
c3711b14d6
commit
3c933adaf6
|
@ -2093,11 +2093,11 @@ Return a list whose CAR is `node-property' and CDR is a plist
|
||||||
containing `:key', `:value', `:begin', `:end' and `:post-blank'
|
containing `:key', `:value', `:begin', `:end' and `:post-blank'
|
||||||
keywords."
|
keywords."
|
||||||
(save-excursion
|
(save-excursion
|
||||||
|
(looking-at org-property-re)
|
||||||
(let ((case-fold-search t)
|
(let ((case-fold-search t)
|
||||||
(begin (point))
|
(begin (point))
|
||||||
(key (progn (looking-at "[ \t]*:\\(.*?\\):[ \t]+\\(.*?\\)[ \t]*$")
|
(key (org-match-string-no-properties 2))
|
||||||
(org-match-string-no-properties 1)))
|
(value (org-match-string-no-properties 3))
|
||||||
(value (org-match-string-no-properties 2))
|
|
||||||
(pos-before-blank (progn (forward-line) (point)))
|
(pos-before-blank (progn (forward-line) (point)))
|
||||||
(end (progn (skip-chars-forward " \r\t\n" limit)
|
(end (progn (skip-chars-forward " \r\t\n" limit)
|
||||||
(if (eobp) (point) (point-at-bol)))))
|
(if (eobp) (point) (point-at-bol)))))
|
||||||
|
|
40
lisp/org.el
40
lisp/org.el
|
@ -6127,8 +6127,15 @@ Use `org-reduced-level' to remove the effect of `org-odd-levels'."
|
||||||
|
|
||||||
(defvar org-font-lock-keywords nil)
|
(defvar org-font-lock-keywords nil)
|
||||||
|
|
||||||
(defconst org-property-re (org-re "^[ \t]*\\(:\\([-[:alnum:]_]+\\+?\\):\\)[ \t]*\\([^ \t\r\n].*\\)")
|
(defconst org-property-re
|
||||||
"Regular expression matching a property line.")
|
"^\\(?4:[ \t]*\\)\\(?1::\\(?2:.*?\\):\\)[ \t]+\\(?3:[^ \t\r\n].*?\\)\\(?5:[ \t]*\\)$"
|
||||||
|
"Regular expression matching a property line.
|
||||||
|
There are four matching groups:
|
||||||
|
1: :PROPKEY: including the leading and trailing colon,
|
||||||
|
2: PROPKEY without the leading and trailing colon,
|
||||||
|
3: PROPVAL without leading or trailing spaces,
|
||||||
|
4: the indentation of the current line,
|
||||||
|
5: trailing whitespace.")
|
||||||
|
|
||||||
(defvar org-font-lock-hook nil
|
(defvar org-font-lock-hook nil
|
||||||
"Functions to be called for special font lock stuff.")
|
"Functions to be called for special font lock stuff.")
|
||||||
|
@ -15110,13 +15117,9 @@ When INCREMENT is non-nil, set the property to the next allowed value."
|
||||||
(defun org-at-property-p ()
|
(defun org-at-property-p ()
|
||||||
"Is cursor inside a property drawer?"
|
"Is cursor inside a property drawer?"
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(beginning-of-line 1)
|
(when (equal 'node-property (car (org-element-at-point)))
|
||||||
(when (looking-at (org-re "^[ \t]*\\(:\\([[:alpha:]][[:alnum:]_-]*\\):\\)[ \t]*\\(.*\\)"))
|
(beginning-of-line 1)
|
||||||
(save-match-data ;; Used by calling procedures
|
(looking-at org-property-re))))
|
||||||
(let ((p (point))
|
|
||||||
(range (unless (org-before-first-heading-p)
|
|
||||||
(org-get-property-block))))
|
|
||||||
(and range (<= (car range) p) (< p (cdr range))))))))
|
|
||||||
|
|
||||||
(defun org-get-property-block (&optional beg end force)
|
(defun org-get-property-block (&optional beg end force)
|
||||||
"Return the (beg . end) range of the body of the property drawer.
|
"Return the (beg . end) range of the body of the property drawer.
|
||||||
|
@ -15241,11 +15244,10 @@ things up because then unnecessary parsing is avoided."
|
||||||
(setq range (org-get-property-block beg end))
|
(setq range (org-get-property-block beg end))
|
||||||
(when range
|
(when range
|
||||||
(goto-char (car range))
|
(goto-char (car range))
|
||||||
(while (re-search-forward
|
(while (re-search-forward org-property-re
|
||||||
(org-re "^[ \t]*:\\([[:alpha:]][[:alnum:]_-]*\\):[ \t]*\\(\\S-.*\\)?")
|
|
||||||
(cdr range) t)
|
(cdr range) t)
|
||||||
(setq key (org-match-string-no-properties 1)
|
(setq key (org-match-string-no-properties 2)
|
||||||
value (org-trim (or (org-match-string-no-properties 2) "")))
|
value (org-trim (or (org-match-string-no-properties 3) "")))
|
||||||
(unless (member key excluded)
|
(unless (member key excluded)
|
||||||
(push (cons key (or value "")) props)))))
|
(push (cons key (or value "")) props)))))
|
||||||
(if clocksum
|
(if clocksum
|
||||||
|
@ -15514,10 +15516,9 @@ formats in the current buffer."
|
||||||
(while (re-search-forward org-property-start-re nil t)
|
(while (re-search-forward org-property-start-re nil t)
|
||||||
(setq range (org-get-property-block))
|
(setq range (org-get-property-block))
|
||||||
(goto-char (car range))
|
(goto-char (car range))
|
||||||
(while (re-search-forward
|
(while (re-search-forward org-property-re
|
||||||
(org-re "^[ \t]*:\\([-[:alnum:]_]+\\):")
|
|
||||||
(cdr range) t)
|
(cdr range) t)
|
||||||
(add-to-list 'rtn (org-match-string-no-properties 1)))
|
(add-to-list 'rtn (org-match-string-no-properties 2)))
|
||||||
(outline-next-heading))))
|
(outline-next-heading))))
|
||||||
|
|
||||||
(when include-specials
|
(when include-specials
|
||||||
|
@ -22034,11 +22035,10 @@ hierarchy of headlines by UP levels before marking the subtree."
|
||||||
;; Special polishing for properties, see `org-property-format'
|
;; Special polishing for properties, see `org-property-format'
|
||||||
(setq column (current-column))
|
(setq column (current-column))
|
||||||
(beginning-of-line 1)
|
(beginning-of-line 1)
|
||||||
(if (looking-at
|
(if (looking-at org-property-re)
|
||||||
"\\([ \t]*\\)\\(:[-_0-9a-zA-Z]+:\\)[ \t]*\\(\\S-.*\\(\\S-\\|$\\)\\)")
|
(replace-match (concat (match-string 4)
|
||||||
(replace-match (concat (match-string 1)
|
|
||||||
(format org-property-format
|
(format org-property-format
|
||||||
(match-string 2) (match-string 3)))
|
(match-string 1) (match-string 3)))
|
||||||
t t))
|
t t))
|
||||||
(org-move-to-column column))))
|
(org-move-to-column column))))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue