summaryrefslogtreecommitdiff
path: root/bog.el
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2015-01-21 21:22:47 -0500
committerKyle Meyer <kyle@kyleam.com>2015-01-21 21:22:47 -0500
commitdf10f8bff96fc3941ae90adbd6663ea7b8520fbf (patch)
tree0b92d9906cacb5e372bcf121155d73a2b875ce27 /bog.el
parent8a80f8890545c9341b65a31327153d196aaafd38 (diff)
downloadbog-df10f8bff96fc3941ae90adbd6663ea7b8520fbf.tar.gz
Add command bog-list-duplicate-heading-citekeys
Diffstat (limited to 'bog.el')
-rw-r--r--bog.el31
1 files changed, 31 insertions, 0 deletions
diff --git a/bog.el b/bog.el
index 63f2fbe..1666243 100644
--- a/bog.el
+++ b/bog.el
@@ -392,6 +392,37 @@ With prefix FILE, include only orphan citekeys from that file."
(goto-char (point-min)))
(pop-to-buffer bufname)))
+(defun bog-list-duplicate-heading-citekeys (&optional clear-cache)
+ "List citekeys that have more than one heading.
+With prefix CLEAR-CACHE, reset cache of citekey headings (which
+is only active if `bog-use-citekey-cache' is non-nil)."
+ (interactive "P")
+ (when clear-cache
+ (setq bog--all-heading-citekeys nil))
+ (let ((bufname "*Bog duplicate heading citekeys*")
+ (dup-cks (-sort (lambda (x y) (string-lessp x y))
+ (bog--find-duplicates (bog-all-heading-citekeys)))))
+ (if (not dup-cks)
+ (message "No duplicate citekeys found")
+ (with-current-buffer (get-buffer-create bufname)
+ (erase-buffer)
+ (insert (mapconcat #'identity dup-cks "\n"))
+ (org-mode)
+ (bog-mode 1)
+ (goto-char (point-min)))
+ (pop-to-buffer bufname))))
+
+(defun bog--find-duplicates (list)
+ (let (dups uniqs)
+ (--each list
+ (cond
+ ((member it dups))
+ ((member it uniqs)
+ (push it dups))
+ (t
+ (push it uniqs))))
+ (nreverse dups)))
+
;;; Citekey-associated files