summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2014-02-15 15:04:49 -0500
committerKyle Meyer <kyle@kyleam.com>2014-02-15 15:04:49 -0500
commit9f58e9ba0d43f7bda3c07a493b1f5f4d146976e3 (patch)
tree6e29b6dc738eed284ce8af0a6fcc29c6129b2b38
parent46cc689116e384cf7eb6a780ce9026ce57cd5964 (diff)
downloadbog-9f58e9ba0d43f7bda3c07a493b1f5f4d146976e3.tar.gz
ENH: Remove bog-citekey-action
`bog-citekey-action' generalizes the common setup (citekey selection from notes or from user completion) of the citekey functions, but it doesn't allow much flexibility for functions to handle citekey selection differently. Replacing this with `bog-citekey-from-notes' shares the citekey selection from notes but doesn't couple this to the user selection.
-rw-r--r--bog-tests.el28
-rw-r--r--bog.el41
2 files changed, 23 insertions, 46 deletions
diff --git a/bog-tests.el b/bog-tests.el
index 6f64593..48da709 100644
--- a/bog-tests.el
+++ b/bog-tests.el
@@ -110,44 +110,32 @@
;; `bog-citekey-action'
-(ert-deftest bog-citekey-action-on-heading ()
- (let ((citekey "name2010word")
- (action '(lambda (ck) ck)))
+(ert-deftest bog-citekey-from-notes-on-heading ()
+ (let ((citekey "name2010word"))
(with-temp-buffer
(insert (format "\n* top level\n\n** %s\n\nsome text\n"
citekey))
(org-mode)
(show-all)
(re-search-backward bog-citekey-format)
- (should (equal (bog-citekey-action action nil nil) citekey)))))
+ (should (equal (bog-citekey-from-notes) citekey)))))
-(ert-deftest bog-citekey-action-on-in-text-citekey ()
- (let ((citekey "name2010word")
- (action '(lambda (ck) ck)))
+(ert-deftest bog-citekey-from-notes-on-in-text-citekey ()
+ (let ((citekey "name2010word"))
(with-temp-buffer
(insert (format "\n* top level\n\n** other2000key\n\nsome text and %s\n"
citekey))
(org-mode)
(show-all)
(re-search-backward bog-citekey-format)
- (should (equal (bog-citekey-action action nil nil) citekey)))))
+ (should (equal (bog-citekey-from-notes) citekey)))))
-(ert-deftest bog-citekey-action-no-citekey ()
+(ert-deftest bog-citekey-from-notes-no-citekey ()
(with-temp-buffer
(insert "\n* top level\n\n** second\n\n")
(org-mode)
(show-all)
- (should-error (bog-citekey-action nil nil nil))))
-
-(ert-deftest bog-citekey-action-askfunc ()
- (let* ((citekey "name2010word")
- (ask-func '(lambda () citekey))
- (action '(lambda (ck) ck)))
- (with-temp-buffer
- (insert "\n* top level\n\n** second\n\n")
- (org-mode)
- (show-all)
- (should (equal (bog-citekey-action action ask-func t) citekey)))))
+ (should-error (bog-citekey-from-notes))))
;;; BibTeX functions
diff --git a/bog.el b/bog.el
index 2efb801..aed8146 100644
--- a/bog.el
+++ b/bog.el
@@ -153,20 +153,6 @@ It should contain the placeholder \"%s\" for the query."
;;; General utilities
-(defun bog-citekey-action (action ask-func ask-citekey)
- "Perform ACTION on file associtated with a citekey.
-
-ASK-FUNC should be a function that queries the user for a citekey
-when ASK-CITEKEY is non-nil. Otherwise, the citekey will be taken
-from the text under point if it matches `bog-citekey-format' or
-using `bog-citekey-func'.
-
-ACTION will be called with the resulting citekey as an argument."
- (let ((citekey (or (and ask-citekey (funcall ask-func))
- (bog-citekey-at-point)
- (funcall bog-citekey-func))))
- (funcall action citekey)))
-
(defun bog-select-citekey (citekeys)
"Prompt for citekey from CITEKEYS"
(funcall bog-completing-read "Select citekey: " citekeys))
@@ -191,6 +177,11 @@ year, and the first meaningful word in the title)."
(bog-citekey-only-p maybe-citekey))
maybe-citekey)))
+(defun bog-citekey-from-notes ()
+ "Get the citekey from the context of the Org file."
+ (or (bog-citekey-at-point)
+ (funcall bog-citekey-func)))
+
(defun bog-citekey-from-heading-title ()
"Retrieve citekey from first parent heading that matches
`bog-citekey-format'."
@@ -241,9 +232,9 @@ available citekeys. Otherwise, the citekey will be taken from the
text under point if it matches `bog-citekey-format' or using
`bog-citekey-func'."
(interactive "P")
- (bog-citekey-action 'bog-open-citekey-pdf
- '(lambda () (bog-select-citekey (bog-pdf-citekeys)))
- arg))
+ (let ((citekey (or (and arg (bog-select-citekey (bog-pdf-citekeys)))
+ (bog-citekey-from-notes))))
+ (bog-open-citekey-pdf citekey)))
(defun bog-open-citekey-pdf (citekey)
(let ((pdf-file (bog-citekey-as-pdf citekey)))
@@ -257,9 +248,8 @@ text under point if it matches `bog-citekey-format' or using
The citekey will be taken from the text under point if it matches
`bog-citekey-format' or using `bog-citekey-func'."
(interactive)
- (bog-citekey-action 'bog-rename-staged-pdf
- nil
- nil))
+ (let ((citekey (bog-citekey-from-notes)))
+ (bog-rename-staged-pdf citekey)))
(defun bog-rename-staged-pdf (citekey)
(let* ((pdf-file (bog-citekey-as-pdf citekey))
@@ -302,9 +292,9 @@ available citekeys. Otherwise, the citekey will be taken from the
text under point if it matches `bog-citekey-format' or using
`bog-citekey-func'."
(interactive "P")
- (bog-citekey-action bog-find-citekey-bib-func
- '(lambda () (bog-select-citekey (bog-bib-citekeys)))
- arg))
+ (let ((citekey (or (and arg (bog-select-citekey (bog-pdf-citekeys)))
+ (bog-citekey-from-notes))))
+ (funcall bog-find-citekey-bib-func citekey)))
(defun bog-find-citekey-bib-file (citekey)
"Open BibTeX file of CITEKEY contained in `bog-bib-directory'."
@@ -401,9 +391,8 @@ The URL will be taken from `bog-web-search-url'.
The citekey is split by groups in `bog-citekey-format' and joined by
\"+\" to form the query string."
(interactive)
- (bog-citekey-action 'bog-open-citekey-on-web
- nil
- nil))
+ (let ((citekey (bog-citekey-from-notes)))
+ (bog-open-citekey-on-web citekey)))
(defun bog-open-citekey-on-web (citekey)
(let ((url (bog-citekey-as-search-url citekey)))