Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Report org headings with duplicate names in the *Messages* buffer. Reveal them and move to the last duplicate. Run after saving the buffer.
(require 'dash)
(defun org-duplicate-heading ()
"Move to duplicate heading in the current org buffer."
(let ((header-list '()))
(org-element-map (org-element-parse-buffer) 'headline
(lambda (x)
(let ((header (org-element-property :raw-value x))
(begin (org-element-property :begin x)))
(when (-contains? header-list header)
(message "Duplicate header: %s" header)
(goto-char begin)
(push header header-list))))))
(add-hook 'org-mode-hook
(lambda ()
(add-hook 'after-save-hook #'org-duplicate-heading)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment