summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <n.goaziou@gmail.com>2011-07-25 11:24:57 +0200
committerNicolas Goaziou <n.goaziou@gmail.com>2011-07-25 11:26:06 +0200
commit3b5132bf8f1785354ee5ea785dcd670fa4122557 (patch)
treec2193e740870e937b91cf5cd13cc510f6bc97ccd
parent642c6667666f1f86f8a461e7bbbc8a2e7510b4b9 (diff)
downloadorg-mode-3b5132bf8f1785354ee5ea785dcd670fa4122557.tar.gz
org-footnote: fix bug when inserting a footnote in a non-Org buffer
* lisp/org-footnote.el (org-footnote-create-definition): when skipping already written footnotes definition, the algorithme would assume each one was only one-line long.
-rw-r--r--lisp/org-footnote.el37
1 files changed, 23 insertions, 14 deletions
diff --git a/lisp/org-footnote.el b/lisp/org-footnote.el
index 5d1736c..7c49eae 100644
--- a/lisp/org-footnote.el
+++ b/lisp/org-footnote.el
@@ -479,21 +479,30 @@ or new, let the user edit the definition of the footnote."
(org-footnote-goto-local-insertion-point)
(org-show-context 'link-search))
(t
- (let ((re (concat "^" org-footnote-tag-for-non-org-mode-files "[ \t]*$")))
- (unless (re-search-forward re nil t)
- (let ((max (if (and (derived-mode-p 'message-mode)
- (re-search-forward message-signature-separator nil t))
- (progn (beginning-of-line) (point))
- (goto-char (point-max)))))
- (skip-chars-backward " \t\r\n")
- (delete-region (point) max)
- (insert "\n\n")
- (insert org-footnote-tag-for-non-org-mode-files "\n"))))
- ;; Skip existing footnotes
- (while (re-search-forward "^[[:space:]]*\\[[^]]+\\] " nil t)
- (forward-line))))
+ ;; In a non-Org file. Search for footnote tag, or create it if
+ ;; necessary (at the end of buffer, or before a signature if in
+ ;; Message mode). Set point after any definition already there.
+ (let ((tag (concat "^" org-footnote-tag-for-non-org-mode-files "[ \t]*$"))
+ (max (save-excursion
+ (if (and (derived-mode-p 'message-mode)
+ (re-search-forward
+ message-signature-separator nil t))
+ (copy-marker (point-at-bol) t)
+ (copy-marker (point-max) t)))))
+ (goto-char max)
+ (unless (re-search-backward tag nil t)
+ (skip-chars-backward " \t\r\n")
+ (delete-region (point) max)
+ (insert "\n\n" org-footnote-tag-for-non-org-mode-files "\n"))
+ ;; Skip existing footnotes.
+ (while (re-search-forward org-footnote-definition-re max t))
+ (let ((def (org-footnote-at-definition-p)))
+ (when def (goto-char (nth 2 def))))
+ (set-marker max nil))))
+ ;; Insert footnote label, position point and notify user.
+ (unless (bolp) (insert "\n"))
(insert "\n[" label "] \n")
- (goto-char (1- (point)))
+ (backward-char)
(message "Edit definition and go back with `C-c &' or, if unique, with `C-c C-c'.")))
;;;###autoload