another test
This commit is contained in:
parent
c9867715c1
commit
76ec29df1e
1 changed files with 46 additions and 47 deletions
|
@ -23,15 +23,14 @@
|
||||||
|
|
||||||
(require 'org)
|
(require 'org)
|
||||||
|
|
||||||
(with-eval-after-load 'org
|
(defvar org-auto-id--all-ids '()
|
||||||
(defvar org-auto-id--all-ids '()
|
|
||||||
"List as set of all ids of the current org-file")
|
"List as set of all ids of the current org-file")
|
||||||
|
|
||||||
(defun org-auto-id-format (title)
|
(defun org-auto-id-format (title)
|
||||||
"Generate a new org-id using TITLE."
|
"Generate a new org-id using TITLE."
|
||||||
(concat (downcase (replace-regexp-in-string "\\W" "-" title))))
|
(concat (downcase (replace-regexp-in-string "\\W" "-" title))))
|
||||||
|
|
||||||
(defun org-auto-id-add-id (id &optional new?)
|
(defun org-auto-id-add-id (id &optional new?)
|
||||||
"Add the id to the set of existing ids, warn if not a generation of new id."
|
"Add the id to the set of existing ids, warn if not a generation of new id."
|
||||||
(if (member id org-auto-id--all-ids)
|
(if (member id org-auto-id--all-ids)
|
||||||
(progn (unless new?
|
(progn (unless new?
|
||||||
|
@ -41,7 +40,7 @@
|
||||||
(add-to-list 'org-auto-id--all-ids id)
|
(add-to-list 'org-auto-id--all-ids id)
|
||||||
id)))
|
id)))
|
||||||
|
|
||||||
(defun org-auto-id-custom-id-get (&optional pom create)
|
(defun org-auto-id-custom-id-get (&optional pom create)
|
||||||
"Get the CUSTOM_ID property of the entry at point-or-marker POM.
|
"Get the CUSTOM_ID property of the entry at point-or-marker POM.
|
||||||
If POM is nil, refer to the entry at point.
|
If POM is nil, refer to the entry at point.
|
||||||
If the entry does not have an CUSTOM_ID, the function returns nil.
|
If the entry does not have an CUSTOM_ID, the function returns nil.
|
||||||
|
@ -61,7 +60,7 @@ In any case, the CUSTOM_ID of the entry is returned."
|
||||||
(org-entry-put pom "CUSTOM_ID" new-id)
|
(org-entry-put pom "CUSTOM_ID" new-id)
|
||||||
new-id)))))))
|
new-id)))))))
|
||||||
|
|
||||||
(defun org-auto-id-add-ids-to-headlines-in-file ()
|
(defun org-auto-id-add-ids-to-headlines-in-file ()
|
||||||
"Add CUSTOM_ID properties to all headlines.
|
"Add CUSTOM_ID properties to all headlines.
|
||||||
In the current file, all headlines which do not already have a CUSTOM_ID.
|
In the current file, all headlines which do not already have a CUSTOM_ID.
|
||||||
Only adds ids if the `auto-id' option is set to `t' in the file somewhere.
|
Only adds ids if the `auto-id' option is set to `t' in the file somewhere.
|
||||||
|
@ -75,13 +74,13 @@ ie, #+OPTIONS: auto-id:t"
|
||||||
(setq org-auto-id--all-ids '())
|
(setq org-auto-id--all-ids '())
|
||||||
(org-map-entries (lambda () (org-auto-id-custom-id-get (point) 'create)))))))
|
(org-map-entries (lambda () (org-auto-id-custom-id-get (point) 'create)))))))
|
||||||
|
|
||||||
(add-hook 'org-mode-hook
|
(add-hook 'org-mode-hook
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(add-hook 'before-save-hook
|
(add-hook 'before-save-hook
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(when (and (eq major-mode 'org-mode)
|
(when (and (eq major-mode 'org-mode)
|
||||||
(eq buffer-read-only nil))
|
(eq buffer-read-only nil))
|
||||||
(org-auto-id-add-ids-to-headlines-in-file)))))))
|
(org-auto-id-add-ids-to-headlines-in-file))))))
|
||||||
|
|
||||||
(provide 'org-auto-id)
|
(provide 'org-auto-id)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue