forked from mirrors/org-mode
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.
This commit is contained in:
parent
8f394624b8
commit
f6492d953c
|
@ -364,26 +364,33 @@ If no footnote is found, return nil."
|
||||||
(org-element-property :contents-end datum))))))))))
|
(org-element-property :contents-end datum))))))))))
|
||||||
nil))))
|
nil))))
|
||||||
|
|
||||||
(defun org-footnote-goto-definition (label)
|
(defun org-footnote-goto-definition (label &optional location)
|
||||||
"Move point to the definition of the footnote LABEL.
|
"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: ")
|
(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
|
(cond
|
||||||
((not def-start)
|
((not def-start)
|
||||||
(user-error "Cannot find definition of footnote %s" label))
|
(user-error "Cannot find definition of footnote %s" label))
|
||||||
((or (> def-start (point-max))
|
((or (> def-start (point-max)) (< def-start (point-min)))
|
||||||
(< def-start (point-min)))
|
(user-error "Definition is outside narrowed part of buffer")))
|
||||||
(user-error "Footnote definition outside of narrowed part of buffer"))
|
(org-mark-ring-push)
|
||||||
(t
|
(goto-char def-start)
|
||||||
(org-mark-ring-push)
|
(looking-at (format "\\[%s[]:]" label))
|
||||||
(goto-char def-start)
|
(goto-char (match-end 0))
|
||||||
(looking-at (format "\\[%s[]:]" label))
|
(org-show-context 'link-search)
|
||||||
(goto-char (match-end 0))
|
(when (derived-mode-p 'org-mode)
|
||||||
(org-show-context 'link-search)
|
(message
|
||||||
(when (derived-mode-p 'org-mode)
|
(substitute-command-keys
|
||||||
(message "Edit definition and go back with `C-c &' or, if unique, with `C-c C-c'."))
|
"Edit definition and go back with `\\[org-mark-ring-goto]' or, if \
|
||||||
t))))
|
unique, with `\\[org-ctrl-c-ctrl-c]'.")))
|
||||||
|
t))
|
||||||
|
|
||||||
(defun org-footnote-goto-previous-reference (label)
|
(defun org-footnote-goto-previous-reference (label)
|
||||||
"Find the first closest (to point) reference of footnote with label LABEL."
|
"Find the first closest (to point) reference of footnote with label LABEL."
|
||||||
|
|
Loading…
Reference in a new issue