diff --git a/init.org b/init.org index 792ea7b..5ed3de6 100644 --- a/init.org +++ b/init.org @@ -3949,6 +3949,25 @@ preceded by another heading) and after headings." :hook (org-mode . org-superstar-mode)) #+END_SRC +*** Automatically add CUSTOM_ID property +Probably best run in =before-save-hook=. Considerations - +1. making human-readable CUSTOM_IDs by reusing heading titles +2. maintaining CUSTOM_ID uniqueness + +#+BEGIN_SRC emacs-lisp +(defun my-org-set-custom-id () + (let (headings) + (org-map-region + (lambda () + (let ((heading (org-element-at-point))) + (unless (org-element-property "CUSTOM_ID" heading) + (cl-pushnew (org-element-property :title heading) headings)))) + (point-min) + (point-max)) + (reverse headings))) +(add-hook 'org-insert-heading-hook #'my-org-set-custom-id) +#+END_SRC + ** markdown-mode :editing: #+BEGIN_SRC emacs-lisp (use-package markdown-mode