about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--lisp/acdw-org.el36
1 files changed, 36 insertions, 0 deletions
diff --git a/lisp/acdw-org.el b/lisp/acdw-org.el index 47e8eb2..48760a2 100644 --- a/lisp/acdw-org.el +++ b/lisp/acdw-org.el
@@ -181,6 +181,42 @@ appropriate. In tables, insert a new row or end the table."
181 (let ((current-prefix-arg 4)) 181 (let ((current-prefix-arg 4))
182 (call-interactively #'unpackaged/org-fix-blank-lines)))) 182 (call-interactively #'unpackaged/org-fix-blank-lines))))
183 183
184
185;;; Generate custom IDs:
186;; https://amitp.blogspot.com/2021/04/automatically-generate-ids-for-emacs.html
187
188(defun acdw-org/generate-custom-ids ()
189 "Generate CUSTOM_ID for any headings that are missing one."
190 (let ((existing-ids (org-map-entries (lambda ()
191 (org-entry-get nil "CUSTOM_ID")))))
192 (org-map-entries
193 (lambda ()
194 (let* ((custom-id (org-entry-get nil "CUSTOM_ID"))
195 (heading (org-heading-components))
196 (level (nth 0 heading))
197 (todo (nth 2 heading))
198 (headline (nth 4 heading))
199 (slug (acdw-org/title-to-filename headline))
200 (duplicate-id (member slug existing-ids)))
201 (when (and (not custom-id)
202 (< level 4)
203 (not todo)
204 (not duplicate-id))
205 (message "Adding entry '%s' to '%s'" slug headline)
206 (org-entry-put nil "CUSTOM_ID" slug)))))))
207
208(defun acdw-org/title-to-filename (title)
209 "Convert TITLE to a reasonable filename."
210 ;; Based on the slug logic in `org-roam', but `org-roam' also uses a
211 ;; timestamp, and I only use the slug.
212 (setq title (s-downcase title))
213 (setq title (s-replace-regexp "[^a-zA-Z0-9]+" "-" title))
214 (setq title (s-replace-regexp "-+" "-" title))
215 (setq title (s-replace-regexp "^-" "" title))
216 (setq title (s-replace-regexp "-$" "" title))
217 title)
218
219
184;;; ADVICE 220;;; ADVICE
185 221
186;; Correct `org-delete-backward-char' to use `backward-delete-char-untabify' 222;; Correct `org-delete-backward-char' to use `backward-delete-char-untabify'