浏览代码

Merge branch 'maint'

Nicolas Goaziou 9 年之前
父节点
当前提交
10cb9d7323
共有 2 个文件被更改,包括 46 次插入10 次删除
  1. 21 8
      lisp/org-footnote.el
  2. 25 2
      testing/lisp/test-org-footnote.el

+ 21 - 8
lisp/org-footnote.el

@@ -387,7 +387,7 @@ value if point was successfully moved."
       (user-error "Definition is outside narrowed part of buffer")))
     (org-mark-ring-push)
     (goto-char def-start)
-    (looking-at (format "\\[%s[]:]" label))
+    (looking-at (format "\\[%s[]:] ?" label))
     (goto-char (match-end 0))
     (org-show-context 'link-search)
     (when (derived-mode-p 'org-mode)
@@ -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)
@@ -655,6 +661,13 @@ offer additional commands in a menu."
   (let* ((context (and (not special) (org-element-context)))
 	 (type (org-element-type context)))
     (cond
+     ;; On white space after element, insert a new footnote.
+     ((> (point)
+	 (save-excursion
+	   (goto-char (org-element-property :end context))
+	   (skip-chars-backward " \t")
+	   (point)))
+      (org-footnote-new))
      ((eq type 'footnote-reference)
       (let ((label (org-element-property :label context)))
 	(cond

+ 25 - 2
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."
@@ -172,7 +195,7 @@
   ;; anonymous footnotes.
   (should
    (equal
-    " Definition."
+    "Definition."
     (org-test-with-temp-text "Some text\n[fn:1] Definition."
       (org-footnote-goto-definition "fn:1")
       (buffer-substring (point) (point-max)))))