From f2fe3d4946f5d6e3beacc47f72250c96ac2d5905 Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Thu, 1 May 2014 21:55:48 -0400 Subject: Functions for collecting citekeys from notes For bigger Org files, these will probably be pretty slow, in which case I can look into caching the results. --- bog.el | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'bog.el') diff --git a/bog.el b/bog.el index b8ed18c..923d5e5 100644 --- a/bog.el +++ b/bog.el @@ -273,6 +273,50 @@ year, and the first meaningful word in the title)." (when (equal (length text) (match-end 0)) t)) +(defun bog-all-citekeys () + (apply 'append + (-map 'bog-citekeys-in-file + (bog-notes-files)))) + +(defun bog-all-heading-citekeys () + (-mapcat 'bog-heading-citekeys-in-file + (bog-notes-files))) + +(defun bog-citekeys-in-file (file) + (let ((was-open (org-find-base-buffer-visiting file)) + (buffer (find-file-noselect file)) + refs) + (with-current-buffer buffer + (save-excursion + (save-restriction + (widen) + (goto-char (point-min)) + (while (re-search-forward bog-citekey-format nil t) + (add-to-list 'refs (match-string-no-properties 0)))))) + (unless was-open + (kill-buffer buffer)) + refs)) + +(defun bog-heading-citekeys-in-file (file) + (let ((was-open (org-find-base-buffer-visiting file)) + (buffer (find-file-noselect file)) + citekeys) + (with-current-buffer buffer + (save-excursion + (setq citekeys (bog-heading-citekeys-in-buffer)))) + (unless was-open + (kill-buffer buffer)) + citekeys)) + +(defun bog-heading-citekeys-in-buffer () + (--keep it + (org-map-entries 'bog-get-heading-if-citekey nil 'file))) + +(defun bog-get-heading-if-citekey () + (let ((heading (org-no-properties (org-get-heading t t)))) + (when (bog-citekey-only-p heading) + heading))) + ;;; Citekey-associated files -- cgit v1.2.3