Add org-unique-id-maybe as a wrapper to org-unique-id
This new function allows for a cleaner hook addition. It also moves the check for the presence of the auto-id option to this function. This allows the user to call org-unique-id on any org buffer, regardless of the presence of auto-id and its value.
This commit is contained in:
parent
c8c96c65d0
commit
975311184a
@ -118,9 +118,22 @@ somewhere. ie, #+OPTIONS: auto-id:t"
|
|||||||
(save-excursion
|
(save-excursion
|
||||||
(widen)
|
(widen)
|
||||||
(goto-char (point-min))
|
(goto-char (point-min))
|
||||||
(let ((case-fold-search t))
|
(org-map-entries (lambda () (org-unique-id-get (point) t)))))
|
||||||
(when (re-search-forward "^#\\+OPTIONS:.*auto-id:t" (point-max) t)
|
|
||||||
(org-map-entries (lambda () (org-unique-id-get (point) t)))))))
|
;;;###autoload
|
||||||
|
(defun org-unique-id-maybe ()
|
||||||
|
"Execute `org-unique-id' if in an org buffer and if enabled.
|
||||||
|
|
||||||
|
This function executes `org-unique-id' when the buffer’s major
|
||||||
|
mode is `org-mode', when the buffer is not read-only, and if
|
||||||
|
\\='auto-id:t\\' is found in an #+OPTIONS line."
|
||||||
|
(let ((case-fold-search t))
|
||||||
|
(when (and (eq major-mode 'org-mode)
|
||||||
|
(eq buffer-read-only nil)
|
||||||
|
(save-excursion
|
||||||
|
(let ((case-fold-search t))
|
||||||
|
(re-search-forward "^#\\+OPTIONS:.*auto-id:t" (point-max) t))))
|
||||||
|
(org-unique-id))))
|
||||||
|
|
||||||
(provide 'org-unique-id)
|
(provide 'org-unique-id)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user