Skip to content

Instantly share code, notes, and snippets.

@heikkil
Last active October 4, 2020 16:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heikkil/0e8e2342f0f3136ba0d1a4da174fc185 to your computer and use it in GitHub Desktop.
Save heikkil/0e8e2342f0f3136ba0d1a4da174fc185 to your computer and use it in GitHub Desktop.
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."
(interactive)
(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)
(org-reveal)
(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