summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2015-05-06 23:15:42 +0200
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2015-05-06 23:15:42 +0200
commitf6492d953c5a2995e15efc8975c494f8aaebe918 (patch)
treee2594bb75d3eb90285a3ab9061f7607070052beb
parent8f394624b8e160ccd6c1a5726c180ff9e8a0ff20 (diff)
downloadorg-mode-f6492d953c5a2995e15efc8975c494f8aaebe918.tar.gz
org-footnote: Add optional argument to `org-footnote-goto-definition'
* lisp/org-footnote.el (org-footnote-goto-definition): Add an optional argument in order to avoid duplicating calls to `org-footnote-get-definition'. Return non-nil when move was successful.
-rw-r--r--lisp/org-footnote.el37
1 files changed, 22 insertions, 15 deletions
diff --git a/lisp/org-footnote.el b/lisp/org-footnote.el
index d484de0..1ebced5 100644
--- a/lisp/org-footnote.el
+++ b/lisp/org-footnote.el
@@ -364,26 +364,33 @@ If no footnote is found, return nil."
(org-element-property :contents-end datum))))))))))
nil))))
-(defun org-footnote-goto-definition (label)
+(defun org-footnote-goto-definition (label &optional location)
"Move point to the definition of the footnote LABEL.
-Return a non-nil value when a definition has been found."
+
+LOCATION, when non-nil specifies the buffer position of the
+definition.
+
+Throw an error if there is no definition or if it cannot be
+reached from current narrowed part of buffer. Return a non-nil
+value if point was successfully moved."
(interactive "sLabel: ")
- (let ((def-start (nth 1 (org-footnote-get-definition label))))
+ (let ((def-start (or location (nth 1 (org-footnote-get-definition label)))))
(cond
((not def-start)
(user-error "Cannot find definition of footnote %s" label))
- ((or (> def-start (point-max))
- (< def-start (point-min)))
- (user-error "Footnote definition outside of narrowed part of buffer"))
- (t
- (org-mark-ring-push)
- (goto-char def-start)
- (looking-at (format "\\[%s[]:]" label))
- (goto-char (match-end 0))
- (org-show-context 'link-search)
- (when (derived-mode-p 'org-mode)
- (message "Edit definition and go back with `C-c &' or, if unique, with `C-c C-c'."))
- t))))
+ ((or (> def-start (point-max)) (< def-start (point-min)))
+ (user-error "Definition is outside narrowed part of buffer")))
+ (org-mark-ring-push)
+ (goto-char def-start)
+ (looking-at (format "\\[%s[]:]" label))
+ (goto-char (match-end 0))
+ (org-show-context 'link-search)
+ (when (derived-mode-p 'org-mode)
+ (message
+ (substitute-command-keys
+ "Edit definition and go back with `\\[org-mark-ring-goto]' or, if \
+unique, with `\\[org-ctrl-c-ctrl-c]'.")))
+ t))
(defun org-footnote-goto-previous-reference (label)
"Find the first closest (to point) reference of footnote with label LABEL."