From efa6371a320de31b3e549d591cc50fc739286bff Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Thu, 5 Jun 2014 01:05:26 -0400 Subject: Remove bog-citekey-function Before, citekeys could be listed as either heading titles or properties, but these two styles could not be mixed. Now, they can, and the following method is used to find the citekey. 1. Take the citekey from title of the current heading. 2. Take the citekey from the property of the current heading. 3. If no citekey found, go to parent heading and repeat. The process stops as soon as a citekey is found or a top-level heading is reached. --- README | 6 ----- README.md | 6 ----- bog-tests.el | 16 +++++------- bog.el | 84 ++++++++++++++++++++---------------------------------------- 4 files changed, 35 insertions(+), 77 deletions(-) diff --git a/README b/README index 9e2efcc..6ee1c9e 100644 --- a/README +++ b/README @@ -123,12 +123,6 @@ The variables below are important for specifying how Bog behaves. A regular expression that defines the format used for citekeys -- =bog-citekey-function= - - A function to extract a citekey from the current subtree. Use this to - indicate whether the citekey should be taken from the heading or - property. - - =bog-find-citekey-bib-function= A function to find a citekey in a BibTeX file. This determines whether diff --git a/README.md b/README.md index 74ddb7b..246812d 100644 --- a/README.md +++ b/README.md @@ -110,12 +110,6 @@ The variables below are important for specifying how Bog behaves. A regular expression that defines the format used for citekeys -- `bog-citekey-function` - - A function to extract a citekey from the current subtree. Use this to - indicate whether the citekey should be taken from the heading or - property. - - `bog-find-citekey-bib-function` A function to find a citekey in a BibTeX file. This determines whether diff --git a/bog-tests.el b/bog-tests.el index 0ce46ad..34b4354 100644 --- a/bog-tests.el +++ b/bog-tests.el @@ -54,7 +54,7 @@ (goto-char (point-min)) (should (equal (bog-citekey-at-point) citekey))))) -;; `bog-citekey-from-heading-title' +;; `bog-citekey-from-tree' (ert-deftest bog-citekey-from-heading-title-current-level () (let ((citekey "name2010word")) @@ -63,7 +63,7 @@ citekey)) (org-mode) (show-all) - (should (equal (bog-citekey-from-heading-title) citekey))))) + (should (equal (bog-citekey-from-tree) citekey))))) (ert-deftest bog-citekey-from-heading-title-in-parent () (let ((citekey "name2010word")) @@ -72,7 +72,7 @@ citekey)) (org-mode) (show-all) - (should (equal (bog-citekey-from-heading-title) citekey))))) + (should (equal (bog-citekey-from-tree) citekey))))) (ert-deftest bog-citekey-from-heading-title-on-heading () (let ((citekey "name2010word")) @@ -82,9 +82,7 @@ (org-mode) (show-all) (re-search-backward bog-citekey-format) - (should (equal (bog-citekey-from-heading-title) citekey))))) - -;; `bog-citekey-from-property' + (should (equal (bog-citekey-from-tree) citekey))))) (ert-deftest bog-citekey-from-property-current-level () (let ((citekey "name2010word")) @@ -94,7 +92,7 @@ ":END:\nsome text\n") (org-mode) (show-all) - (should (equal (bog-citekey-from-property) citekey))))) + (should (equal (bog-citekey-from-tree) citekey))))) (ert-deftest bog-citekey-from-property-in-parent () (let ((citekey "name2010word")) @@ -105,7 +103,7 @@ "** subhead\n\n") (org-mode) (show-all) - (should (equal (bog-citekey-from-property) citekey))))) + (should (equal (bog-citekey-from-tree) citekey))))) (ert-deftest bog-citekey-from-property-on-heading () (let ((citekey "name2010word")) @@ -116,7 +114,7 @@ (org-mode) (show-all) (org-back-to-heading) - (should (equal (bog-citekey-from-property) citekey))))) + (should (equal (bog-citekey-from-tree) citekey))))) ;; `bog-citekey-from-notes' diff --git a/bog.el b/bog.el index 743d792..b30ca2c 100644 --- a/bog.el +++ b/bog.el @@ -73,24 +73,10 @@ settings: :group 'bog :type 'string) -(defcustom bog-citekey-func 'bog-citekey-from-heading-title - "Function used to get citekey from study notes. - -By default, this is `bog-citekey-from-heading-title', which -selects the citekey from the first parent heading whose title -matches `bog-citekey-format'. - -The other option is `bog-citekey-from-property', which selects -the citekey from the first parent that has the property -`bog-citekey-property'." - :group 'bog - :type 'function) - (defcustom bog-citekey-property "CUSTOM_ID" "Property name used to store citekey. -This is only used if `bog-citekey-func' is set to -`bog-citekey-from-property'. The default corresponds to the -default value of `org-bibtex-key-property'." +The default corresponds to the default value of +`org-bibtex-key-property'." :group 'bog :type 'string) @@ -249,43 +235,38 @@ year, and the first meaningful word in the title)." (defun bog-citekey-from-notes () "Get the citekey from the context of the Org file." (or (bog-citekey-at-point) - (funcall bog-citekey-func))) + (bog-citekey-from-tree))) -(defun bog-citekey-from-heading-title () - "Retrieve citekey from first parent heading that matches -`bog-citekey-format'." +(defun bog-citekey-from-tree () + "Retrieve citekey from first parent heading associated with citekey." (save-excursion (save-restriction (widen) - (let ((heading (org-no-properties (org-get-heading t t)))) - (while (and (not (bog-citekey-only-p heading)) - (org-up-heading-safe)) - (setq heading (org-no-properties (org-get-heading t t)))) - (when (bog-citekey-only-p heading) - heading))))) + (let (maybe-citekey) + (while (and (not (setq maybe-citekey (bog-citekey-from-heading))) + (org-up-heading-safe))) + maybe-citekey)))) -(defun bog-citekey-from-property () - "Retrieve citekey from first parent heading that has the - property `bog-citekey-property'." - (save-excursion - (save-restriction - (widen) - (let ((citekey (org-entry-get (point) bog-citekey-property))) - (while (and (not citekey) - (org-up-heading-safe)) - (setq citekey (org-entry-get (point) bog-citekey-property))) - citekey)))) +(defun bog-citekey-from-heading () + "Retrieve citekey from current heading title." + (or (bog-citekey-from-heading-title) + (bog-citekey-from-property))) -(defun bog-citekey-heading-p () - (let ((heading (org-no-properties (org-get-heading t t)))) - (or (bog-citekey-only-p heading) - (org-entry-get (point) bog-citekey-property)))) +(defun bog-citekey-from-heading-title () + (let ((title (org-no-properties (org-get-heading t t)))) + (when (bog-citekey-only-p title) + title))) (defun bog-citekey-p (text) "Indicate if TEXT matches `bog-citekey-format'." (when (string-match bog-citekey-format text) t)) +(defun bog-citekey-from-property () + (-when-let (prop (org-entry-get (point) bog-citekey-property)) + (when (bog-citekey-only-p prop) + prop))) + (defun bog-citekey-only-p (text) "Indicate if all of TEXT matches `bog-citekey-format'." (string-match bog-citekey-format text) @@ -329,12 +310,7 @@ year, and the first meaningful word in the title)." (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))) + (org-map-entries 'bog-citekey-from-heading nil 'file))) ;;; Citekey-associated files @@ -344,8 +320,7 @@ year, and the first meaningful word in the title)." "Open citekey-associated file. The citekey will be taken from the text under point if it matches -`bog-citekey-format' or from the current subtree using -`bog-citekey-func'. +`bog-citekey-format' or from the current tree. With prefix argument NO-CONTEXT, a prompt will open to select from citekeys for all associated files. This same prompt will be @@ -384,8 +359,7 @@ opened if locating a citekey from context fails." "Rename citekey file in `bog-stage-directory' with `bog-file-renaming-func'. The citekey will be taken from the text under point if it matches -`bog-citekey-format' or from the current subtree using -`bog-citekey-func'. +`bog-citekey-format' or from the current tree. With prefix argument NO-CONTEXT, a prompt will open to select from citekeys for all associated files. This same prompt will be @@ -467,8 +441,7 @@ used to control the default string used in the prompt." "Open BibTeX file for a citekey. The citekey will be taken from the text under point if it matches -`bog-citekey-format' or from the current subtree using -`bog-citekey-func'. +`bog-citekey-format' or from the current tree. With prefix argument NO-CONTEXT, a prompt will open to select from citekeys for all BibTeX files. This same prompt will be @@ -582,8 +555,7 @@ The citekey is split by groups in `bog-citekey-format' and joined by \"+\" to form the query string. The citekey will be taken from the text under point if it matches -`bog-citekey-format' or from the current subtree using -`bog-citekey-func'. +`bog-citekey-format' or from the current tree. With prefix argument NO-CONTEXT, a prompt will open to select from all citekeys present in notes. This same prompt will be @@ -733,7 +705,7 @@ Sorting is only done if the heading's level matches `bog-topic-heading-level' and it isn't a citekey heading." (let ((sorting-type (or sorting-type ?a))) (when (and (= (org-current-level) bog-topic-heading-level) - (not (bog-citekey-heading-p))) + (not (bog-citekey-from-heading))) (org-sort-entries nil sorting-type)))) -- cgit v1.2.3