diff options
author | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2015-04-25 10:36:35 +0200 |
---|---|---|
committer | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2015-04-25 10:36:35 +0200 |
commit | 5954f6aa25b51a3a9a8f258fb0f15ef51be31366 (patch) | |
tree | 809329a79c8d64b6fb65409806cf1f6aca860252 | |
parent | 0d21d8d0eaec24adae9f0128392459b10d71b77e (diff) | |
download | org-mode-5954f6aa25b51a3a9a8f258fb0f15ef51be31366.tar.gz |
org-footnote: Do not move point if definition is unreachable
* lisp/org-footnote.el (org-footnote-goto-definition): Throw an error
when definition is outside narrowed part of buffer. Do not move
point either.
* testing/lisp/test-org-footnote.el (test-org-footnote/goto-definition):
New test.
Reported-by: Rasmus <rasmus@gmx.us>
<http://permalink.gmane.org/gmane.emacs.orgmode/97158>
-rw-r--r-- | lisp/org-footnote.el | 13 | ||||
-rw-r--r-- | testing/lisp/test-org-footnote.el | 27 |
2 files changed, 35 insertions, 5 deletions
diff --git a/lisp/org-footnote.el b/lisp/org-footnote.el index 2b04e00..f40f36f 100644 --- a/lisp/org-footnote.el +++ b/lisp/org-footnote.el @@ -360,17 +360,20 @@ If no footnote is found, return nil." "Move point to the definition of the footnote LABEL. Return a non-nil value when a definition has been found." (interactive "sLabel: ") - (org-mark-ring-push) (let ((def (org-footnote-get-definition label))) - (if (not def) - (error "Cannot find definition of footnote %s" label) + (cond + ((not def) (user-error "Cannot find definition of footnote %s" label)) + ((> (nth 1 def) (point-max)) + (user-error "Footnote definition outside of narrowed part of buffer")) + (t + (org-mark-ring-push) (goto-char (nth 1 def)) - (looking-at (format "\\[%s\\]\\|\\[%s:" label label)) + (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))) + t)))) (defun org-footnote-goto-previous-reference (label) "Find the first closest (to point) reference of footnote with label LABEL." diff --git a/testing/lisp/test-org-footnote.el b/testing/lisp/test-org-footnote.el index 1a10faa..b778c2e 100644 --- a/testing/lisp/test-org-footnote.el +++ b/testing/lisp/test-org-footnote.el @@ -152,6 +152,33 @@ (org-footnote-delete "1") (org-trim (buffer-string)))))) +(ert-deftest test-org-footnote/goto-definition () + "Test `org-footnote-goto-definition' specifications." + ;; Error on unknown definitions. + (should-error + (org-test-with-temp-text "No footnote definition" + (org-footnote-goto-definition "fn:1"))) + ;; Error when trying to reach a definition outside narrowed part of + ;; buffer. + (should-error + (org-test-with-temp-text "Some text<point>\n[fn:1] Definition." + (narrow-to-region (point-min) (point)) + (org-footnote-goto-definition "fn:1"))) + ;; Otherwise, move at the beginning of the definition, including + ;; anonymous footnotes. + (should + (equal + " Definition." + (org-test-with-temp-text "Some text\n[fn:1] Definition." + (org-footnote-goto-definition "fn:1") + (buffer-substring (point) (point-max))))) + (should + (equal + "definition]" + (org-test-with-temp-text "Some text[fn:label:definition]" + (org-footnote-goto-definition "fn:label") + (buffer-substring (point) (point-max)))))) + (ert-deftest test-org-footnote/normalize-in-org () "Test specifications for `org-footnote-normalize' in an Org buffer." ;; 1. With a non-nil `org-footnote-section'. |