diff options
author | Kyle Meyer <kyle@kyleam.com> | 2014-05-01 21:55:48 -0400 |
---|---|---|
committer | Kyle Meyer <kyle@kyleam.com> | 2014-05-01 22:47:39 -0400 |
commit | f2fe3d4946f5d6e3beacc47f72250c96ac2d5905 (patch) | |
tree | 1b49a0aa05f0ae22e59cf0dded8403e8bbb0b5da /bog.el | |
parent | 3ad4c4332d82e0bf05d747067c9b2c7b9679d449 (diff) | |
download | bog-f2fe3d4946f5d6e3beacc47f72250c96ac2d5905.tar.gz |
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.
Diffstat (limited to 'bog.el')
-rw-r--r-- | bog.el | 44 |
1 files changed, 44 insertions, 0 deletions
@@ -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 |