diff options
Diffstat (limited to 'lisp/org-footnote.el')
-rw-r--r-- | lisp/org-footnote.el | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/lisp/org-footnote.el b/lisp/org-footnote.el index 7396609..10e95ee 100644 --- a/lisp/org-footnote.el +++ b/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 "]") - (let ((l (copy-marker (org-footnote-create-definition label)))) - (org-footnote-auto-adjust-maybe) - (or (ignore-errors (org-footnote-goto-definition label l)) - ;; Since definition was created outside current - ;; scope, edit it remotely. - (progn (set-marker l nil) - (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,14 @@ 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. + ((and context + (> (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 |