[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#29756: 25.2; Footnote-mode: recursive footnotes [UPDATED PATCH]

From: Boruch Baum
Subject: bug#29756: 25.2; Footnote-mode: recursive footnotes [UPDATED PATCH]
Date: Sun, 17 Dec 2017 16:21:31 -0500
User-agent: NeoMutt/20171208

The updated code below improves the prior patch by forbidding a user
from creating a footnote WITHIN the text of
the`footnote-section-tag-text', and covering a case of the user manuall
deleting that same footnote-section-tag-text after creating a footnote.

(defun Footnote--abort-when-in-fn-area (orig-function &optional arg)
  "Do not allow 'recursive footnotes'."
  (interactive "P")
  (let ((p (point))
        (q (if (not footnote-text-marker-alist) (point-max)
            (if (string-equal footnote-section-tag "")
              (cdr (first footnote-text-marker-alist))
             (goto-char (cdr (first footnote-text-marker-alist)))
             (if (re-search-backward
                   (concat "^" footnote-section-tag-regexp) nil t)
               (match-beginning 0)
              ; This `else' should never happen, and indicates an error, ie. 
              ; already exist and a footnote-section-tag is defined, but the 
section tag
              ; hasn't been found. We choose to assume that the user deleted it
              ; intentionally and wants us to behave in this buffer as if the 
section tag
              ; was set "", so we do that, now.
              (setq footnote-section-tag "")
              ; To illustrate the difference in behavior, create a few 
footnotes, delete
              ; the section tag, and create another footnote. Then undo, 
comment the
              ; above line (that sets the tag to ""), re-evaluate this 
function, and repeat.
              (cdr (first footnote-text-marker-alist))
   (goto-char p) ; undo `re-search-backward' side-effect
   (if (< p q)
      (apply orig-function arg)
    (message "Add footnotes only while in text body"))))
(advice-add 'Footnote-add-footnote :around #'Footnote--abort-when-in-fn-area)

CA45 09B5 5351 7C11 A9D1  7286 0036 9E45 1595 8BC0

reply via email to

[Prev in Thread] Current Thread [Next in Thread]