]> git.donarmstrong.com Git - lib.git/commitdiff
only add ids if there is not an option to remove them
authorDon Armstrong <don@donarmstrong.com>
Sat, 24 Dec 2022 21:55:40 +0000 (13:55 -0800)
committerDon Armstrong <don@donarmstrong.com>
Sat, 24 Dec 2022 21:55:56 +0000 (13:55 -0800)
emacs_el/configuration/don-configuration.org

index c1ee1c1f57150fac5fdc94e9d82bc5cbbbcb8ce3..87a740470097e13fbce577780aa929785674dc5b 100644 (file)
@@ -1,4 +1,5 @@
 #+PROPERTY: header-args:emacs-lisp :tangle don-configuration.el
+#+OPTIONS: auto-id:f
 * Load debugger
 
 # if for some reason, things get pear-shaped, we want to be able to
@@ -1836,22 +1837,27 @@ From http://julien.danjou.info/projects/emacs-packages#rainbow-mode, this colori
   (setq org-use-fast-todo-selection t)
   (setq org-treat-S-cursor-todo-selection-as-state-change nil)
 
-  ; create function to create headlines in file. This comes from
-  ; http://stackoverflow.com/questions/13340616/assign-ids-to-every-entry-in-org-mode
-  (defun my/org-add-ids-to-headlines-in-file ()
-    "Add ID properties to all headlines in the current file which
-  do not already have one."
-    (interactive)
-    (org-map-entries 'org-id-get-create))
-  (defun dla/org-update-ids-to-headlines-in-file ()
-    "Add or replace ID properties to all headlines in the current file 
-  (or narrowed region)."
-    (interactive)
-    (org-map-entries '(lambda () (org-id-get-create t))))
-  ; if we wanted to do this to every buffer, do the following:
-  (add-hook 'org-mode-hook
-            (lambda ()
-              (add-hook 'before-save-hook 'my/org-add-ids-to-headlines-in-file nil 'local)))
+; create function to create headlines in file. This comes from
+; http://stackoverflow.com/questions/13340616/assign-ids-to-every-entry-in-org-mode
+(defun my/org-add-ids-to-headlines-in-file ()
+  "Add ID properties to all headlines in the current file which
+do not already have one."
+  (interactive)
+  (save-excursion
+    (widen)
+    (goto-char (point-min))
+    (when (not (re-search-forward "^#\\+OPTIONS:.*auto-id:f" (point-max) t))
+      (org-map-entries 'org-id-get-create))))
+(defun dla/org-update-ids-to-headlines-in-file ()
+  "Add or replace ID properties to all headlines in the current file 
+(or narrowed region)."
+  (interactive)
+
+  (org-map-entries '(lambda () (org-id-get-create t))))
+; if we wanted to do this to every buffer, do the following:
+(add-hook 'org-mode-hook
+          (lambda ()
+            (add-hook 'before-save-hook 'my/org-add-ids-to-headlines-in-file nil 'local)))
 #+END_SRC
 ** Org ID locations
 #+BEGIN_SRC emacs-lisp