summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <n.goaziou@gmail.com>2012-02-02 09:08:28 +0100
committerNicolas Goaziou <n.goaziou@gmail.com>2012-02-02 09:08:28 +0100
commit6c0da676af542fa4cfe3e6c917c1d8e4e80a9d08 (patch)
tree8f94d1199c5d76752d045677ad32e7146eefc6bb
parent04ecf18db0de904dd966318c9bfe89c94b058054 (diff)
downloadorg-mode-6c0da676af542fa4cfe3e6c917c1d8e4e80a9d08.tar.gz
org-footnote: Fix definition ending retrieval with no footnote section
* lisp/org-footnote.el (org-footnote-at-definition-p): Make sure to move point at the beginning of the separator before skiping white spaces. Refactor code.
-rw-r--r--lisp/org-footnote.el52
1 files changed, 29 insertions, 23 deletions
diff --git a/lisp/org-footnote.el b/lisp/org-footnote.el
index a812551..af5f744 100644
--- a/lisp/org-footnote.el
+++ b/lisp/org-footnote.el
@@ -242,40 +242,46 @@ positions, and the definition, when inlined."
(match-end 0) (1- end)))))))))
(defun org-footnote-at-definition-p ()
- "Is the cursor at a footnote definition?
+ "Is point within a footnote definition?
-This matches only pure definitions like [1] or [fn:name] at the beginning
-of a line. It does not match references like [fn:name:definition], where the
-footnote text is included and defined locally.
+This matches only pure definitions like [1] or [fn:name] at the
+beginning of a line. It does not match references like
+\[fn:name:definition], where the footnote text is included and
+defined locally.
-The return value will be nil if not at a footnote definition, and a list with
-label, start, end and definition of the footnote otherwise."
+The return value will be nil if not at a footnote definition, and
+a list with label, start, end and definition of the footnote
+otherwise."
(when (save-excursion (beginning-of-line) (org-footnote-in-valid-context-p))
(save-excursion
(end-of-line)
+ ;; Footnotes definitions are separated by new headlines or blank
+ ;; lines.
(let ((lim (save-excursion (re-search-backward
(concat org-outline-regexp-bol
"\\|^[ \t]*$") nil t))))
(when (re-search-backward org-footnote-definition-re lim t)
- (end-of-line)
- (list (org-match-string-no-properties 1)
- (match-beginning 0)
- (save-match-data
- ;; 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
+ (let ((label (org-match-string-no-properties 1))
+ (beg (match-beginning 0))
+ (beg-def (match-end 0))
+ ;; In message-mode, do not search after signature.
+ (end (let ((bound (and (derived-mode-p 'message-mode)
+ (save-excursion
+ (goto-char (point-max))
+ (re-search-backward
+ message-signature-separator nil t)))))
+ (if (progn
+ (end-of-line)
+ (re-search-forward
(concat org-outline-regexp-bol "\\|"
org-footnote-definition-re "\\|"
- "^[ \t]*$")
- bound 'move)
- (progn (skip-chars-forward " \t\n") (point-at-bol)))
- (point))))
- (org-trim (buffer-substring-no-properties
- (match-end 0) (point)))))))))
+ "^[ \t]*$") bound 'move))
+ (progn (goto-char (match-beginning 0))
+ (org-skip-whitespace)
+ (point-at-bol))
+ (point)))))
+ (list label beg end
+ (org-trim (buffer-substring-no-properties beg-def end)))))))))
(defun org-footnote-get-next-reference (&optional label backward limit)
"Return complete reference of the next footnote.