summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2015-08-14 16:17:18 +0200
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2015-08-14 16:17:18 +0200
commit65ded0c7ed60db6e742a7f345fdb0b6355042536 (patch)
treee4b5e307081e2d00c5e025e8c8296de8bde3c77e
parent8500501984b6b0e283722d6e96c4e359f818f7cb (diff)
downloadorg-mode-65ded0c7ed60db6e742a7f345fdb0b6355042536.tar.gz
org-footnote: Fix f8c4102cc6e65d48e0b9502cc568843a86f92f1c
* lisp/org-footnote.el (org-footnote-new): Fix f8c4102cc6e65d48e0b9502cc568843a86f92f1c. * testing/lisp/test-org-footnote.el (test-org-footnote/new): Add test.
-rw-r--r--lisp/org-footnote.el20
-rw-r--r--testing/lisp/test-org-footnote.el25
2 files changed, 37 insertions, 8 deletions
diff --git a/lisp/org-footnote.el b/lisp/org-footnote.el
index cb882a4..fd48182 100644
--- a/lisp/org-footnote.el
+++ b/lisp/org-footnote.el
@@ -552,13 +552,19 @@ or new, let the user edit the definition of the footnote."
(org-footnote-auto-adjust-maybe))
(t
(insert "[" label "]")
- (org-footnote-create-definition label)
- (org-footnote-auto-adjust-maybe)
- (if (ignore-errors (org-footnote-goto-definition label))
- (forward-char)
- ;; Definition was created outside current scope: edit it
- ;; remotely.
- (org-edit-footnote-reference))))))
+ (let ((p (org-footnote-create-definition label)))
+ ;; `org-footnote-goto-definition' needs to be called
+ ;; after `org-footnote-auto-adjust-maybe'. Otherwise
+ ;; both label and location of the definition are lost.
+ ;; On the contrary, it needs to be called before
+ ;; `org-edit-footnote-reference' so that the remote
+ ;; editing buffer can display the correct label.
+ (if (ignore-errors (org-footnote-goto-definition label p))
+ (org-footnote-auto-adjust-maybe)
+ ;; Definition was created outside current scope: edit
+ ;; it remotely.
+ (org-footnote-auto-adjust-maybe)
+ (org-edit-footnote-reference)))))))
(defvar org-blank-before-new-entry) ; Silence byte-compiler.
(defun org-footnote-create-definition (label)
diff --git a/testing/lisp/test-org-footnote.el b/testing/lisp/test-org-footnote.el
index 9789853..4205d43 100644
--- a/testing/lisp/test-org-footnote.el
+++ b/testing/lisp/test-org-footnote.el
@@ -98,7 +98,30 @@
" \\*bold\\*\\[fn:1\\]"
(org-test-with-temp-text " *bold*<point>"
(let ((org-footnote-auto-label t)) (org-footnote-new))
- (buffer-string)))))
+ (buffer-string))))
+ ;; When creating a new footnote, move to its definition.
+ (should
+ (string=
+ "[fn:1] "
+ (org-test-with-temp-text "Text<point>"
+ (let ((org-footnote-auto-label t)
+ (org-footnote-auto-adjust nil))
+ (org-footnote-new))
+ (buffer-substring-no-properties (line-beginning-position) (point)))))
+ ;; Re-order and re-label footnotes properly when
+ ;; `org-footnote-auto-adjust' is non-nil.
+ (should
+ (string=
+ "[fn:1] 1\n\n[fn:2] \n\n[fn:3] 2\n"
+ (org-test-with-temp-text
+ "Text[fn:1]Text<point>Text[fn:2]\n\n[fn:1] 1\n\n[fn:2] 2"
+ (let ((org-footnote-auto-label t)
+ (org-footnote-auto-adjust t)
+ (org-footnote-section nil))
+ (org-footnote-new))
+ (buffer-substring-no-properties
+ (line-beginning-position -1)
+ (line-beginning-position 4))))))
(ert-deftest test-org-footnote/delete ()
"Test `org-footnote-delete' specifications."