From 2e4a690f36d45be98799e58500eb30afc842b357 Mon Sep 17 00:00:00 2001 From: Don Armstrong Date: Sat, 24 Dec 2022 13:55:40 -0800 Subject: [PATCH] only add ids if there is not an option to remove them --- emacs_el/configuration/don-configuration.org | 38 +++++++++++--------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/emacs_el/configuration/don-configuration.org b/emacs_el/configuration/don-configuration.org index c1ee1c1..87a7404 100644 --- a/emacs_el/configuration/don-configuration.org +++ b/emacs_el/configuration/don-configuration.org @@ -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 -- 2.39.5