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.
This commit is contained in:
Nicolas Goaziou 2011-07-25 11:24:57 +02:00
parent 642c666766
commit 3b5132bf8f
1 changed files with 23 additions and 14 deletions

View File

@ -479,21 +479,30 @@ or new, let the user edit the definition of the footnote."
(org-footnote-goto-local-insertion-point) (org-footnote-goto-local-insertion-point)
(org-show-context 'link-search)) (org-show-context 'link-search))
(t (t
(let ((re (concat "^" org-footnote-tag-for-non-org-mode-files "[ \t]*$"))) ;; In a non-Org file. Search for footnote tag, or create it if
(unless (re-search-forward re nil t) ;; necessary (at the end of buffer, or before a signature if in
(let ((max (if (and (derived-mode-p 'message-mode) ;; Message mode). Set point after any definition already there.
(re-search-forward message-signature-separator nil t)) (let ((tag (concat "^" org-footnote-tag-for-non-org-mode-files "[ \t]*$"))
(progn (beginning-of-line) (point)) (max (save-excursion
(goto-char (point-max))))) (if (and (derived-mode-p 'message-mode)
(skip-chars-backward " \t\r\n") (re-search-forward
(delete-region (point) max) message-signature-separator nil t))
(insert "\n\n") (copy-marker (point-at-bol) t)
(insert org-footnote-tag-for-non-org-mode-files "\n")))) (copy-marker (point-max) t)))))
;; Skip existing footnotes (goto-char max)
(while (re-search-forward "^[[:space:]]*\\[[^]]+\\] " nil t) (unless (re-search-backward tag nil t)
(forward-line)))) (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") (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'."))) (message "Edit definition and go back with `C-c &' or, if unique, with `C-c C-c'.")))
;;;###autoload ;;;###autoload