summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <n.goaziou@gmail.com>2011-07-15 19:24:59 +0200
committerNicolas Goaziou <n.goaziou@gmail.com>2011-07-15 19:24:59 +0200
commitb824725df16a6692ee778e3bb2f0be0580e7de5b (patch)
tree8fd51fd4a2163bd60f4117c836a3ab35c15dacd5
parentdef5a2f567c30fcebc63c3b3abb10a1e78e93283 (diff)
downloadorg-mode-b824725df16a6692ee778e3bb2f0be0580e7de5b.tar.gz
org-footnote: fix problem with normalize in message-mode
* lisp/org-footnote.el (org-footnote-at-definition-p, org-footnote-normalize): do not grab signature in the definition of the last footnote.
-rw-r--r--lisp/org-footnote.el41
1 files changed, 29 insertions, 12 deletions
diff --git a/lisp/org-footnote.el b/lisp/org-footnote.el
index 43372d1..03e6369 100644
--- a/lisp/org-footnote.el
+++ b/lisp/org-footnote.el
@@ -235,11 +235,20 @@ label, start, end and definition of the footnote otherwise."
(list (match-string 2)
(match-beginning 0)
(save-match-data
- (or (and (re-search-forward
- (org-re "^[ \t]*$\\|^\\*+ \\|^\\[\\([0-9]+\\|fn:[-_[:word:]]+\\)\\]")
- nil t)
- (progn (skip-chars-forward " \t\n") (point-at-bol)))
- (point-max)))
+ ;; In a message, limit search to signature.
+ (let ((bound (and (derived-mode-p 'message-mode)
+ (save-excursion
+ (goto-char (point-max))
+ (re-search-backward
+ message-signature-separator nil t)))))
+ (or (and (re-search-forward
+ (org-re
+ (concat "^[ \t]*$" "\\|"
+ "^\\*+ " "\\|"
+ "^\\[\\([0-9]+\\|fn:[-_[:word:]]+\\)\\]"))
+ bound 'move)
+ (progn (skip-chars-forward " \t\n") (point-at-bol)))
+ (point))))
(org-trim (buffer-substring (match-end 0) (point))))))))
(defun org-footnote-get-next-reference (&optional label backward limit)
@@ -603,7 +612,7 @@ Additional note on `org-footnote-insert-pos-for-preprocessor':
;; Add label (REF), identifier (MARKER) and definition (DEF)
;; to REF-TABLE if data was unknown.
(unless a
- (let ((def (or (nth 3 ref) ; inline
+ (let ((def (or (nth 3 ref) ; inline
(and export-props
(cdr (assoc lbl org-export-footnotes-data)))
(nth 3 (org-footnote-get-definition lbl)))))
@@ -618,7 +627,7 @@ Additional note on `org-footnote-insert-pos-for-preprocessor':
export-props
'(:todo-keywords t :tags t :priority t))))
(org-export-preprocess-string def parameters))
- def)
+ def)
inlinep) ref-table)))
;; Remove definition of non-inlined footnotes.
(unless inlinep (org-footnote-delete-definitions lbl))))
@@ -653,9 +662,17 @@ Additional note on `org-footnote-insert-pos-for-preprocessor':
"[ \t]*$")
nil t)
(replace-match ""))
- (goto-char (point-max))
- (skip-chars-backward " \t\n\r")
- (delete-region (point) (point-max))
+ ;; In message-mode, ensure footnotes are inserted before the
+ ;; signature.
+ (let ((pt-max
+ (or (and (derived-mode-p 'message-mode)
+ (save-excursion
+ (goto-char (point-max))
+ (re-search-backward message-signature-separator nil t)))
+ (point-max))))
+ (goto-char pt-max)
+ (skip-chars-backward " \t\n\r")
+ (delete-region (point) pt-max))
(insert "\n\n" org-footnote-tag-for-non-org-mode-files "\n")
(setq ins-point (point))))
;; 3. Clean-up REF-TABLE.
@@ -693,8 +710,8 @@ Additional note on `org-footnote-insert-pos-for-preprocessor':
(nth (if sort-only 0 1) x) (nth 2 x)))
ref-table "\n\n")
"\n\n")
- ;; When exporting, add newly insert markers along with their
- ;; associated definition to `org-export-footnotes-seen'.
+ ;; When exporting, add newly inserted markers along with their
+ ;; associated definition to `org-export-footnotes-seen'.
(when export-props
(setq org-export-footnotes-seen ref-table)))
;; Else, insert each definition at the end of the section