Fix `org-refresh-category-properties'
* lisp/org.el (org-refresh-category-properties): Ignore false positives when setting category. Also, deprecate old CATEGORY keyword behaviour: new keywords override old ones.
This commit is contained in:
parent
c1a744659d
commit
80bccca4e2
49
lisp/org.el
49
lisp/org.el
|
@ -9541,33 +9541,40 @@ The refresh happens only for the current tree (not subtree)."
|
||||||
(defun org-refresh-category-properties ()
|
(defun org-refresh-category-properties ()
|
||||||
"Refresh category text properties in the buffer."
|
"Refresh category text properties in the buffer."
|
||||||
(let ((case-fold-search t)
|
(let ((case-fold-search t)
|
||||||
(inhibit-read-only t)
|
(inhibit-read-only t))
|
||||||
(def-cat (cond
|
(org-with-silent-modifications
|
||||||
((null org-category)
|
(org-with-wide-buffer
|
||||||
|
;; Set buffer-wide category. Search last #+CATEGORY keyword.
|
||||||
|
;; This is the default category for the buffer. If none is
|
||||||
|
;; found, fall-back to `org-category' or buffer file name.
|
||||||
|
(put-text-property
|
||||||
|
(point-min) (point-max)
|
||||||
|
'org-category
|
||||||
|
(catch 'buffer-category
|
||||||
|
(goto-char (point-max))
|
||||||
|
(while (re-search-backward "^[ \t]*#\\+CATEGORY:" (point-min) t)
|
||||||
|
(let ((element (org-element-at-point)))
|
||||||
|
(when (eq (org-element-type element) 'keyword)
|
||||||
|
(throw 'buffer-category
|
||||||
|
(org-element-property :value element)))))
|
||||||
|
(cond ((null org-category)
|
||||||
(if buffer-file-name
|
(if buffer-file-name
|
||||||
(file-name-sans-extension
|
(file-name-sans-extension
|
||||||
(file-name-nondirectory buffer-file-name))
|
(file-name-nondirectory buffer-file-name))
|
||||||
"???"))
|
"???"))
|
||||||
((symbolp org-category) (symbol-name org-category))
|
((symbolp org-category) (symbol-name org-category))
|
||||||
(t org-category)))
|
(t org-category))))
|
||||||
beg end cat pos optionp)
|
;; Set sub-tree specific categories.
|
||||||
(org-with-silent-modifications
|
|
||||||
(save-excursion
|
|
||||||
(save-restriction
|
|
||||||
(widen)
|
|
||||||
(goto-char (point-min))
|
(goto-char (point-min))
|
||||||
(put-text-property (point) (point-max) 'org-category def-cat)
|
(let ((regexp (org-re-property "CATEGORY")))
|
||||||
(while (re-search-forward
|
(while (re-search-forward regexp nil t)
|
||||||
"^[ \t]*\\(\\(?:#\\+\\|:\\)CATEGORY:\\)\\(.*\\)" nil t)
|
(let ((value (org-match-string-no-properties 3)))
|
||||||
(setq pos (match-end 0)
|
(when (org-at-property-p)
|
||||||
optionp (equal (char-after (match-beginning 0)) ?#)
|
(put-text-property
|
||||||
cat (org-trim (match-string 2)))
|
(save-excursion (org-back-to-heading t) (point))
|
||||||
(if optionp
|
(org-end-of-subtree t t)
|
||||||
(setq beg (point-at-bol) end (point-max))
|
'org-category
|
||||||
(org-back-to-heading t)
|
value)))))))))
|
||||||
(setq beg (point) end (org-end-of-subtree t t)))
|
|
||||||
(put-text-property beg end 'org-category cat)
|
|
||||||
(goto-char pos)))))))
|
|
||||||
|
|
||||||
(defun org-refresh-stats-properties ()
|
(defun org-refresh-stats-properties ()
|
||||||
"Refresh stats text properties in the buffer."
|
"Refresh stats text properties in the buffer."
|
||||||
|
|
Loading…
Reference in New Issue