From ce74785920d6234072eb2ebef63bd140a25534c2 Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Thu, 11 Dec 2014 23:45:51 -0500 Subject: Add function to get citekeys in buffer --- bog-tests.el | 19 +++++++++++++++++++ bog.el | 18 ++++++++++++------ 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/bog-tests.el b/bog-tests.el index 201bc89..c454da7 100644 --- a/bog-tests.el +++ b/bog-tests.el @@ -250,6 +250,25 @@ some text and " ** second" (should-not (bog-citekey-from-surroundings)))) +(ert-deftest bog-citekeys-in-buffer () + (should (equal '("abc1900def" "ghi1950jkl" "mno2000pqr") + (bog-tests--with-temp-text + " +* abc1900def +ghi1950jkl +* mno2000pqr +* mno2000pqr" + (--sort (string-lessp it other) (bog-citekeys-in-buffer)))))) + +(ert-deftest bog-heading-citekeys-in-buffer () + (should (equal '("abc1900def" "mno2000pqr") + (bog-tests--with-temp-text + " +* abc1900def +ghi1950jkl +* mno2000pqr" + (bog-heading-citekeys-in-buffer))))) + ;; bog-{next,previous}-non-heading-citekey (ert-deftest bog-next-non-heading-citekey-default-arg () diff --git a/bog.el b/bog.el index 0d353c7..20d1f32 100644 --- a/bog.el +++ b/bog.el @@ -320,13 +320,19 @@ word constituents." (defun bog-citekeys-in-file (file) "Return all citekeys in FILE." - (let (refs - case-fold-search) - (with-temp-buffer - (insert-file-contents file) + (with-temp-buffer + (insert-file-contents file) + (bog-citekeys-in-buffer))) + +(defun bog-citekeys-in-buffer () + "Return all citekeys in current buffer." + (save-excursion + (let (refs + case-fold-search) + (goto-char (point-min)) (while (re-search-forward bog-citekey-format nil t) - (push (match-string-no-properties 0) refs))) - (-distinct refs))) + (push (match-string-no-properties 0) refs)) + (-distinct refs)))) (defun bog-heading-citekeys-in-file (file) "Return all citekeys in headings of FILE." -- cgit v1.2.3