forked from mirrors/org-mode
org-footnote: in Message mode, do not allow footnotes in headers
* lisp/org-footnote.el (org-footnote-in-valid-context-p): avoid cited lines and headers in message-mode. (org-footnote-at-reference-p): remove check for cited lines, this is now handled by the previous function. Refactor.
This commit is contained in:
parent
ce2a33104b
commit
ed685f8a7e
|
@ -168,14 +168,22 @@ extracted will be filled again."
|
||||||
|
|
||||||
(defun org-footnote-in-valid-context-p ()
|
(defun org-footnote-in-valid-context-p ()
|
||||||
"Is point in a context where footnotes are allowed?"
|
"Is point in a context where footnotes are allowed?"
|
||||||
|
(save-match-data
|
||||||
(not (or (org-in-commented-line)
|
(not (or (org-in-commented-line)
|
||||||
(org-in-indented-comment-line)
|
(org-in-indented-comment-line)
|
||||||
(org-in-verbatim-emphasis)
|
(org-in-verbatim-emphasis)
|
||||||
;; No footnote in literal example.
|
;; Avoid literal example.
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(beginning-of-line)
|
(beginning-of-line)
|
||||||
(looking-at "[ \t]*:[ \t]+"))
|
(looking-at "[ \t]*:[ \t]+"))
|
||||||
(org-in-block-p org-footnote-forbidden-blocks))))
|
;; Avoid cited text and headers in message-mode.
|
||||||
|
(and (derived-mode-p 'message-mode)
|
||||||
|
(or (save-excursion
|
||||||
|
(beginning-of-line)
|
||||||
|
(looking-at message-cite-prefix-regexp))
|
||||||
|
(message-point-in-header-p)))
|
||||||
|
;; Avoid forbidden blocks.
|
||||||
|
(org-in-block-p org-footnote-forbidden-blocks)))))
|
||||||
|
|
||||||
(defun org-footnote-at-reference-p ()
|
(defun org-footnote-at-reference-p ()
|
||||||
"Is the cursor at a footnote reference?
|
"Is the cursor at a footnote reference?
|
||||||
|
@ -200,19 +208,14 @@ positions, and the definition, when inlined."
|
||||||
(end (ignore-errors (scan-sexps beg 1))))
|
(end (ignore-errors (scan-sexps beg 1))))
|
||||||
;; Point is really at a reference if it's located before true
|
;; Point is really at a reference if it's located before true
|
||||||
;; ending of the footnote.
|
;; ending of the footnote.
|
||||||
(when (save-match-data
|
(when (and end (< (point) end)
|
||||||
(and end (< (point) end)
|
|
||||||
;; Verify match isn't a part of a link.
|
;; Verify match isn't a part of a link.
|
||||||
(not (save-excursion
|
(not (save-excursion
|
||||||
(goto-char beg)
|
(goto-char beg)
|
||||||
(let ((linkp (org-in-regexp org-bracket-link-regexp)))
|
(let ((linkp
|
||||||
|
(save-match-data
|
||||||
|
(org-in-regexp org-bracket-link-regexp))))
|
||||||
(and linkp (< (point) (cdr linkp))))))
|
(and linkp (< (point) (cdr linkp))))))
|
||||||
;; When in message-mode, verify match doesn't belong
|
|
||||||
;; to cited text.
|
|
||||||
(not (and (derived-mode-p 'message-mode)
|
|
||||||
(save-excursion
|
|
||||||
(beginning-of-line)
|
|
||||||
(looking-at message-cite-prefix-regexp))))
|
|
||||||
;; Verify point doesn't belong to a LaTeX macro.
|
;; Verify point doesn't belong to a LaTeX macro.
|
||||||
;; Beware though, when two footnotes are side by
|
;; Beware though, when two footnotes are side by
|
||||||
;; side, once the first one is changed into LaTeX,
|
;; side, once the first one is changed into LaTeX,
|
||||||
|
@ -221,7 +224,7 @@ positions, and the definition, when inlined."
|
||||||
;; the `org-protected' property of that command.
|
;; the `org-protected' property of that command.
|
||||||
(or (not (org-inside-latex-macro-p))
|
(or (not (org-inside-latex-macro-p))
|
||||||
(and (get-text-property (1- beg) 'org-protected)
|
(and (get-text-property (1- beg) 'org-protected)
|
||||||
(not (get-text-property beg 'org-protected))))))
|
(not (get-text-property beg 'org-protected)))))
|
||||||
(list label beg end
|
(list label beg end
|
||||||
;; Definition: ensure this is an inline footnote first.
|
;; Definition: ensure this is an inline footnote first.
|
||||||
(and (or (not label) (match-string 1))
|
(and (or (not label) (match-string 1))
|
||||||
|
|
Loading…
Reference in New Issue