--- /home/optimum/Downloads/footnote.el--downloaded_from_gnu.orig 2017-12-24 18:12:15.000000000 -0500 +++ /home/optimum/Downloads/footnote.el--downloaded_from_gnu 2017-12-24 18:35:34.199506628 -0500 @@ -747,6 +747,40 @@ footnote area, returns `point-max'." (setq i (1+ i))) rc))) +(defun Footnote--get-area-point-min (&optional arg) + "Return POINT of the beginning of the footnote area, being the +start of the first footnote. If there is no footnote area, +returns POINT-MAX. With optional arg, consider the +footnote-section-tag to be part of the footnote area." + (if (not footnote-text-marker-alist) + (point-max) + (if (not arg) + (cdr (first footnote-text-marker-alist)) + (when arg + (if (string-equal footnote-section-tag "") + (cdr (first footnote-text-marker-alist)) + (let ((p (point)) min) + (goto-char (cdr (first footnote-text-marker-alist))) + (if (re-search-backward (concat "^" footnote-section-tag-regexp) nil t) + (setq min (match-beginning 0)) + ; This `else' should never happen, and indicates an error, ie. footnotes + ; 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 "") + ; HOWEVER: The rest of footnote mode does not currently honor or account + ; for this. + ; + ; 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. + ; + ; TODO: integrate sanity checks at reasonable operational points. + (setq min (cdr (first footnote-text-marker-alist)))) + (goto-char p) + min)))))) + (defun Footnote-add-footnote (&optional arg) "Add a numbered footnote. The number the footnote receives is dependent upon the relative location @@ -755,6 +789,8 @@ If the variable `footnote-narrow-to-foot the buffer is narrowed to the footnote body. The restriction is removed by using `Footnote-back-to-message'." (interactive "*P") + (if (> (point) (Footnote--get-area-point-min "including section tag")) + (error "Add footnotes only while in text body.")) (let ((num (if footnote-text-marker-alist (if (< (point) (cl-cadar (last footnote-pointer-marker-alist)))