From fcd413951fbfae64ee03ee6043d675e01ca986f7 Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Fri, 30 Jan 2015 00:48:45 -0500 Subject: Add command bog-open-citekey-link This allows any link under a citekey heading to be opened, not just the first. --- NEWS | 11 ++++++----- README.org | 1 + bog.el | 26 ++++++++++++++++++++++---- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/NEWS b/NEWS index 6742e92..0a744ce 100644 --- a/NEWS +++ b/NEWS @@ -25,11 +25,12 @@ - New command =bog-insert-heading-citekey= prompts with all heading citekeys and inserts the selected one at point. -- New command =bog-open-first-citekey-link= opens the first link found - under the subtree of a citekey. This is particularly useful if you - place the main link for the study (usually a DOI link) as the first - link in the citekey's subtree. The citekey is either taken from at - point or selected from all heading citekeys. +- New commands =bog-open-citekey-link= and + =bog-open-first-citekey-link= open a link (or links) for a citekey. + =bog-open-first-citekey-link= is particularly useful if you place + the main link for the study (usually a DOI link) as the first link + in the citekey's subtree. The citekey is either taken from at point + or selected from all heading citekeys. - New commands =bog-next-non-heading-citekey= and =bog-previous-non-heading-citekey= diff --git a/README.org b/README.org index 2a97c34..72bbeb4 100644 --- a/README.org +++ b/README.org @@ -106,6 +106,7 @@ Other useful functions include - =bog-jump-to-topic-heading= - =bog-list-duplicate-heading-citekeys= - =bog-list-orphan-citekeys= +- =bog-open-citekey-link= - =bog-open-first-citekey-link= - =bog-refile= - =bog-search-notes= diff --git a/bog.el b/bog.el index 9b57c54..148d78c 100644 --- a/bog.el +++ b/bog.el @@ -948,8 +948,13 @@ current buffer." 'bog-all-heading-citekeys))) (insert (bog-select-citekey (funcall citekey-func))))) -(defun bog-open-first-citekey-link (&optional no-context) - "Open first link under citekey heading. +(defun bog-open-citekey-link (&optional no-context first) + "Open a link for a citekey heading. + +If FIRST is non-nil, open the first link under the heading. +Otherwise, if there is more than one link under the heading, +prompt with a list of links using the `org-open-at-point' +interface. The citekey is taken from the text under point if it matches `bog-citekey-format' or from the current tree. @@ -965,10 +970,22 @@ context fails." (org-with-wide-buffer (goto-char marker) (org-narrow-to-subtree) - (org-next-link) + (when first (org-next-link)) (org-open-at-point))) (message "Heading for %s not found in notes" citekey)))) +(defun bog-open-first-citekey-link (&optional no-context) + "Open first link for a citekey heading. + +The citekey is taken from the text under point if it matches +`bog-citekey-format' or from the current tree. + +With prefix argument NO-CONTEXT, prompt with citekeys that have a +heading in any note file. Do the same if locating a citekey from +context fails." + (interactive "P") + (bog-open-citekey-link no-context t)) + (defun bog-next-non-heading-citekey (&optional arg) "Move foward to next non-heading citekey. With argument ARG, do it ARG times." @@ -1110,7 +1127,8 @@ chosen." (define-key prefix-map "H" 'bog-goto-citekey-heading-in-notes) (define-key prefix-map "i" 'bog-citekey-tree-to-indirect-buffer) (define-key prefix-map "j" 'bog-jump-to-topic-heading) - (define-key prefix-map "l" 'bog-open-first-citekey-link) + (define-key prefix-map "l" 'bog-open-citekey-link) + (define-key prefix-map "L" 'bog-open-first-citekey-link) (define-key prefix-map "n" 'bog-next-non-heading-citekey) (define-key prefix-map "p" 'bog-previous-non-heading-citekey) (define-key prefix-map "r" 'bog-rename-staged-file-to-citekey) -- cgit v1.2.3