2017-12-25 23:32:24 -05:00
|
|
|
|
;;; footnote.el --- footnote support for message mode -*- lexical-binding:t -*-
|
1999-12-09 23:31:50 +00:00
|
|
|
|
|
2021-01-01 01:13:56 -08:00
|
|
|
|
;; Copyright (C) 1997, 2000-2021 Free Software Foundation, Inc.
|
1999-12-09 23:31:50 +00:00
|
|
|
|
|
2017-12-26 16:08:21 -05:00
|
|
|
|
;; Author: Steven L Baur <steve@xemacs.org> (1997-2011)
|
2017-12-25 23:27:26 -05:00
|
|
|
|
;; Boruch Baum <boruch_baum@gmx.com> (2017-)
|
1999-12-09 23:31:50 +00:00
|
|
|
|
;; Keywords: mail, news
|
2020-09-08 16:12:43 +02:00
|
|
|
|
;; Old-Version: 0.19
|
1999-12-09 23:31:50 +00:00
|
|
|
|
|
1999-12-12 16:04:25 +00:00
|
|
|
|
;; This file is part of GNU Emacs.
|
1999-12-09 23:31:50 +00:00
|
|
|
|
|
2008-05-06 07:25:26 +00:00
|
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
;; (at your option) any later version.
|
1999-12-09 23:31:50 +00:00
|
|
|
|
|
2008-05-06 07:25:26 +00:00
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
;; GNU General Public License for more details.
|
1999-12-09 23:31:50 +00:00
|
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
2017-09-13 15:52:52 -07:00
|
|
|
|
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
1999-12-09 23:31:50 +00:00
|
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
|
|
;; This file provides footnote[1] support for message-mode in emacsen.
|
|
|
|
|
;; footnote-mode is implemented as a minor mode.
|
|
|
|
|
|
|
|
|
|
;; [1] Footnotes look something like this. Along with some decorative
|
|
|
|
|
;; stuff.
|
|
|
|
|
|
2017-12-22 21:44:52 -05:00
|
|
|
|
;;;; TODO:
|
|
|
|
|
;; + Reasonable Undo support.
|
|
|
|
|
;; - could use an `apply' entry in the buffer-undo-list to be warned when
|
|
|
|
|
;; a footnote we inserted is removed via undo.
|
|
|
|
|
;; - should try to handle the more general problem of deleting/removing
|
|
|
|
|
;; footnotes via standard editing commands rather than via footnote
|
|
|
|
|
;; commands.
|
|
|
|
|
;; + more language styles.
|
|
|
|
|
;; + The key sequence 'C-c ! a C-y C-c ! b' should auto-fill the
|
|
|
|
|
;; footnote in adaptive fill mode. This does not seem to be a bug in
|
|
|
|
|
;; `adaptive-fill' because it behaves that way on all point movements
|
|
|
|
|
;; + Handle footmode mode elegantly in all modes, even if that means refuses to
|
|
|
|
|
;; accept the burden. For example, in a programming language mode, footnotes
|
|
|
|
|
;; should be commented.
|
|
|
|
|
;; + Manually autofilling the a first footnote should not cause it to
|
|
|
|
|
;; wrap into the footnote section tag
|
|
|
|
|
;; + Current solution adds a second newline after the section tag, so it is
|
|
|
|
|
;; clearly a separate paragraph. There may be stylistic objections to this.
|
|
|
|
|
;; + Footnotes with multiple paragraphs should not have their first
|
|
|
|
|
;; line out-dented.
|
|
|
|
|
;; + Upon leaving footnote area, perform an auto-fill on an entire
|
|
|
|
|
;; footnote (including multiple paragraphs), or on entire footnote area.
|
|
|
|
|
;; + fill-paragraph takes arg REGION, but seemingly only when called
|
|
|
|
|
;; interactively.
|
|
|
|
|
;; + At some point, it became necessary to change `footnote-section-tag-regexp'
|
|
|
|
|
;; to remove its trailing space. (Adaptive fill side-effect?)
|
|
|
|
|
;; + useful for lazy testing
|
|
|
|
|
;; (setq footnote-narrow-to-footnotes-when-editing t)
|
|
|
|
|
;; (setq footnote-section-tag "Footnotes: ")
|
|
|
|
|
;; (setq footnote-section-tag-regexp "Footnotes\\(\\[.\\]\\)?:")
|
1999-12-09 23:31:50 +00:00
|
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
|
(eval-when-compile (require 'cl-lib))
|
|
|
|
|
(defvar filladapt-token-table)
|
1999-12-12 16:04:25 +00:00
|
|
|
|
|
1999-12-09 23:31:50 +00:00
|
|
|
|
(defgroup footnote nil
|
|
|
|
|
"Support for footnotes in mail and news messages."
|
2000-02-23 20:25:34 +00:00
|
|
|
|
:version "21.1"
|
1999-12-09 23:31:50 +00:00
|
|
|
|
:group 'message)
|
|
|
|
|
|
|
|
|
|
(defcustom footnote-mode-line-string " FN"
|
2008-10-06 06:29:05 +00:00
|
|
|
|
"String to display in modes section of the mode-line."
|
2019-05-01 13:14:31 -04:00
|
|
|
|
:type 'string)
|
1999-12-09 23:31:50 +00:00
|
|
|
|
|
|
|
|
|
(defcustom footnote-narrow-to-footnotes-when-editing nil
|
2008-10-06 06:29:05 +00:00
|
|
|
|
"If non-nil, narrow to footnote text body while editing a footnote."
|
2019-05-01 13:14:31 -04:00
|
|
|
|
:type 'boolean)
|
1999-12-09 23:31:50 +00:00
|
|
|
|
|
|
|
|
|
(defcustom footnote-prompt-before-deletion t
|
2008-10-06 06:29:05 +00:00
|
|
|
|
"If non-nil, prompt before deleting a footnote.
|
1999-12-09 23:31:50 +00:00
|
|
|
|
There is currently no way to undo deletions."
|
2019-05-01 13:14:31 -04:00
|
|
|
|
:type 'boolean)
|
1999-12-09 23:31:50 +00:00
|
|
|
|
|
|
|
|
|
(defcustom footnote-spaced-footnotes t
|
2008-10-06 06:29:05 +00:00
|
|
|
|
"If non-nil, insert an empty line between footnotes.
|
|
|
|
|
Customizing this variable has no effect on buffers already
|
|
|
|
|
displaying footnotes."
|
2019-05-01 13:14:31 -04:00
|
|
|
|
:type 'boolean)
|
1999-12-09 23:31:50 +00:00
|
|
|
|
|
2008-10-06 06:29:05 +00:00
|
|
|
|
(defcustom footnote-use-message-mode t ; Nowhere used.
|
|
|
|
|
"If non-nil, assume Footnoting will be done in `message-mode'."
|
2019-05-01 13:14:31 -04:00
|
|
|
|
:type 'boolean)
|
1999-12-09 23:31:50 +00:00
|
|
|
|
|
|
|
|
|
(defcustom footnote-body-tag-spacing 2
|
2008-10-06 06:29:05 +00:00
|
|
|
|
"Number of spaces separating a footnote body tag and its text.
|
|
|
|
|
Customizing this variable has no effect on buffers already
|
|
|
|
|
displaying footnotes."
|
2019-05-01 13:14:31 -04:00
|
|
|
|
:type 'integer)
|
1999-12-09 23:31:50 +00:00
|
|
|
|
|
2009-09-03 02:21:37 +00:00
|
|
|
|
(defcustom footnote-prefix [(control ?c) ?!]
|
2019-05-15 13:00:51 -04:00
|
|
|
|
"Prefix key to use for Footnote commands in Footnote minor mode.
|
2009-09-03 02:21:37 +00:00
|
|
|
|
The value of this variable is checked as part of loading Footnote mode.
|
|
|
|
|
After that, changing the prefix key requires manipulating keymaps."
|
2019-05-01 13:14:31 -04:00
|
|
|
|
:type 'key-sequence)
|
1999-12-09 23:31:50 +00:00
|
|
|
|
|
|
|
|
|
;;; Interface variables that probably shouldn't be changed
|
|
|
|
|
|
2017-12-25 23:27:26 -05:00
|
|
|
|
(defcustom footnote-section-tag "Footnotes:"
|
2008-10-06 06:29:05 +00:00
|
|
|
|
"Tag inserted at beginning of footnote section.
|
|
|
|
|
If you set this to the empty string, no tag is inserted and the
|
|
|
|
|
value of `footnote-section-tag-regexp' is ignored. Customizing
|
|
|
|
|
this variable has no effect on buffers already displaying
|
|
|
|
|
footnotes."
|
2017-12-25 23:27:26 -05:00
|
|
|
|
:version "27.1"
|
2019-05-01 13:14:31 -04:00
|
|
|
|
:type 'string)
|
1999-12-09 23:31:50 +00:00
|
|
|
|
|
2017-12-22 21:44:52 -05:00
|
|
|
|
(defcustom footnote-section-tag-regexp
|
|
|
|
|
;; Even if `footnote-section-tag' has a trailing space, let's not require it
|
|
|
|
|
;; here, since it might be trimmed by various commands.
|
|
|
|
|
"Footnotes\\(\\[.\\]\\)?:"
|
2008-10-06 06:29:05 +00:00
|
|
|
|
"Regexp which indicates the start of a footnote section.
|
|
|
|
|
This variable is disregarded when `footnote-section-tag' is the
|
|
|
|
|
empty string. Customizing this variable has no effect on buffers
|
|
|
|
|
already displaying footnotes."
|
2017-12-22 21:44:52 -05:00
|
|
|
|
:version "27.1"
|
2019-05-01 13:14:31 -04:00
|
|
|
|
:type 'regexp)
|
1999-12-09 23:31:50 +00:00
|
|
|
|
|
|
|
|
|
;; The following three should be consumed by footnote styles.
|
2000-02-23 20:25:34 +00:00
|
|
|
|
(defcustom footnote-start-tag "["
|
2008-10-06 06:29:05 +00:00
|
|
|
|
"String used to denote start of numbered footnote.
|
|
|
|
|
Should not be set to the empty string. Customizing this variable
|
|
|
|
|
has no effect on buffers already displaying footnotes."
|
2019-05-01 13:14:31 -04:00
|
|
|
|
:type 'string)
|
1999-12-09 23:31:50 +00:00
|
|
|
|
|
2000-02-23 20:25:34 +00:00
|
|
|
|
(defcustom footnote-end-tag "]"
|
2008-10-06 06:29:05 +00:00
|
|
|
|
"String used to denote end of numbered footnote.
|
|
|
|
|
Should not be set to the empty string. Customizing this variable
|
|
|
|
|
has no effect on buffers already displaying footnotes."
|
2019-05-01 13:14:31 -04:00
|
|
|
|
:type 'string)
|
1999-12-09 23:31:50 +00:00
|
|
|
|
|
2017-12-22 23:06:22 -05:00
|
|
|
|
(defcustom footnote-signature-separator
|
|
|
|
|
(if (boundp 'message-signature-separator)
|
|
|
|
|
message-signature-separator
|
|
|
|
|
"^-- $")
|
2012-05-04 13:14:14 +08:00
|
|
|
|
"Regexp used by Footnote mode to recognize signatures."
|
2019-05-01 13:14:31 -04:00
|
|
|
|
:type 'regexp)
|
1999-12-09 23:31:50 +00:00
|
|
|
|
|
2017-12-22 23:06:22 -05:00
|
|
|
|
(defcustom footnote-align-to-fn-text t
|
2017-12-25 23:27:26 -05:00
|
|
|
|
"How to left-align footnote text.
|
|
|
|
|
If nil, footnote text is to be aligned flush left with left side
|
|
|
|
|
of the footnote number. If non-nil, footnote text is to be aligned
|
|
|
|
|
left with the first character of footnote text."
|
2017-12-22 23:06:22 -05:00
|
|
|
|
:type 'boolean)
|
|
|
|
|
|
1999-12-09 23:31:50 +00:00
|
|
|
|
;;; Private variables
|
|
|
|
|
|
2019-05-01 17:53:39 -04:00
|
|
|
|
(defvar-local footnote-style-number nil
|
|
|
|
|
"Footnote style represented as an index into `footnote-style-alist'.")
|
1999-12-09 23:31:50 +00:00
|
|
|
|
|
2019-05-01 17:53:39 -04:00
|
|
|
|
(defvar-local footnote--markers-alist nil
|
|
|
|
|
"List of (FN TEXT . POINTERS).
|
|
|
|
|
Where FN is the footnote number, TEXT is a marker pointing to
|
|
|
|
|
the footnote's text, and POINTERS is a list of markers pointing
|
2019-05-02 09:00:53 -04:00
|
|
|
|
to the places from which the footnote is referenced.
|
2019-05-02 10:27:42 -04:00
|
|
|
|
Both TEXT and POINTERS points right *before* the [...]")
|
1999-12-09 23:31:50 +00:00
|
|
|
|
|
|
|
|
|
(defvar footnote-mouse-highlight 'highlight
|
2019-05-01 13:14:31 -04:00
|
|
|
|
;; FIXME: This `highlight' property is not currently used.
|
|
|
|
|
;; We should use `mouse-face' and make mouse clicks work on them.
|
1999-12-09 23:31:50 +00:00
|
|
|
|
"Text property name to enable mouse over highlight.")
|
|
|
|
|
|
2017-12-22 23:06:22 -05:00
|
|
|
|
(defvar footnote-mode)
|
|
|
|
|
|
1999-12-09 23:31:50 +00:00
|
|
|
|
;;; Default styles
|
|
|
|
|
;;; NUMERIC
|
2007-11-01 03:40:30 +00:00
|
|
|
|
(defconst footnote-numeric-regexp "[0-9]+"
|
1999-12-09 23:31:50 +00:00
|
|
|
|
"Regexp for digits.")
|
|
|
|
|
|
2017-12-25 23:27:26 -05:00
|
|
|
|
(defun footnote--numeric (n)
|
1999-12-09 23:31:50 +00:00
|
|
|
|
"Numeric footnote style.
|
|
|
|
|
Use Arabic numerals for footnoting."
|
|
|
|
|
(int-to-string n))
|
|
|
|
|
|
|
|
|
|
;;; ENGLISH UPPER
|
|
|
|
|
(defconst footnote-english-upper "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
|
|
|
"Upper case English alphabet.")
|
|
|
|
|
|
2007-11-01 03:40:30 +00:00
|
|
|
|
(defconst footnote-english-upper-regexp "[A-Z]+"
|
1999-12-09 23:31:50 +00:00
|
|
|
|
"Regexp for upper case English alphabet.")
|
|
|
|
|
|
2017-12-25 23:27:26 -05:00
|
|
|
|
(defun footnote--english-upper (n)
|
1999-12-09 23:31:50 +00:00
|
|
|
|
"Upper case English footnoting.
|
|
|
|
|
Wrapping around the alphabet implies successive repetitions of letters."
|
|
|
|
|
(let* ((ltr (mod (1- n) (length footnote-english-upper)))
|
|
|
|
|
(rep (/ (1- n) (length footnote-english-upper)))
|
|
|
|
|
(chr (char-to-string (aref footnote-english-upper ltr)))
|
|
|
|
|
rc)
|
|
|
|
|
(while (>= rep 0)
|
|
|
|
|
(setq rc (concat rc chr))
|
|
|
|
|
(setq rep (1- rep)))
|
|
|
|
|
rc))
|
2003-02-04 13:24:35 +00:00
|
|
|
|
|
1999-12-09 23:31:50 +00:00
|
|
|
|
;;; ENGLISH LOWER
|
|
|
|
|
(defconst footnote-english-lower "abcdefghijklmnopqrstuvwxyz"
|
|
|
|
|
"Lower case English alphabet.")
|
|
|
|
|
|
2007-11-01 03:40:30 +00:00
|
|
|
|
(defconst footnote-english-lower-regexp "[a-z]+"
|
1999-12-09 23:31:50 +00:00
|
|
|
|
"Regexp of lower case English alphabet.")
|
|
|
|
|
|
2017-12-25 23:27:26 -05:00
|
|
|
|
(defun footnote--english-lower (n)
|
1999-12-09 23:31:50 +00:00
|
|
|
|
"Lower case English footnoting.
|
|
|
|
|
Wrapping around the alphabet implies successive repetitions of letters."
|
|
|
|
|
(let* ((ltr (mod (1- n) (length footnote-english-lower)))
|
|
|
|
|
(rep (/ (1- n) (length footnote-english-lower)))
|
|
|
|
|
(chr (char-to-string (aref footnote-english-lower ltr)))
|
|
|
|
|
rc)
|
|
|
|
|
(while (>= rep 0)
|
|
|
|
|
(setq rc (concat rc chr))
|
|
|
|
|
(setq rep (1- rep)))
|
|
|
|
|
rc))
|
|
|
|
|
|
|
|
|
|
;;; ROMAN LOWER
|
|
|
|
|
(defconst footnote-roman-lower-list
|
|
|
|
|
'((1 . "i") (5 . "v") (10 . "x")
|
|
|
|
|
(50 . "l") (100 . "c") (500 . "d") (1000 . "m"))
|
|
|
|
|
"List of roman numerals with their values.")
|
|
|
|
|
|
2017-12-26 00:08:48 -05:00
|
|
|
|
(defconst footnote-roman-lower-regexp
|
|
|
|
|
(concat "[" (mapconcat #'cdr footnote-roman-lower-list "") "]+")
|
1999-12-09 23:31:50 +00:00
|
|
|
|
"Regexp of roman numerals.")
|
|
|
|
|
|
2017-12-25 23:27:26 -05:00
|
|
|
|
(defun footnote--roman-lower (n)
|
1999-12-09 23:31:50 +00:00
|
|
|
|
"Generic Roman number footnoting."
|
2017-12-25 23:27:26 -05:00
|
|
|
|
(footnote--roman-common n footnote-roman-lower-list))
|
1999-12-09 23:31:50 +00:00
|
|
|
|
|
|
|
|
|
;;; ROMAN UPPER
|
|
|
|
|
(defconst footnote-roman-upper-list
|
2017-12-26 00:08:48 -05:00
|
|
|
|
(mapcar (lambda (x) (cons (car x) (upcase (cdr x))))
|
|
|
|
|
footnote-roman-lower-list)
|
1999-12-09 23:31:50 +00:00
|
|
|
|
"List of roman numerals with their values.")
|
|
|
|
|
|
2017-12-26 00:08:48 -05:00
|
|
|
|
(defconst footnote-roman-upper-regexp (upcase footnote-roman-lower-regexp)
|
1999-12-09 23:31:50 +00:00
|
|
|
|
"Regexp of roman numerals. Not complete")
|
|
|
|
|
|
2017-12-25 23:27:26 -05:00
|
|
|
|
(defun footnote--roman-upper (n)
|
1999-12-09 23:31:50 +00:00
|
|
|
|
"Generic Roman number footnoting."
|
2017-12-25 23:27:26 -05:00
|
|
|
|
(footnote--roman-common n footnote-roman-upper-list))
|
1999-12-09 23:31:50 +00:00
|
|
|
|
|
2017-12-25 23:27:26 -05:00
|
|
|
|
(defun footnote--roman-common (n footnote-roman-list)
|
1999-12-09 23:31:50 +00:00
|
|
|
|
"Lower case Roman footnoting."
|
|
|
|
|
(let* ((our-list footnote-roman-list)
|
|
|
|
|
(rom-lngth (length our-list))
|
|
|
|
|
(rom-high 0)
|
|
|
|
|
(rom-low 0)
|
|
|
|
|
(rom-div -1)
|
|
|
|
|
(count-high 0)
|
|
|
|
|
(count-low 0))
|
|
|
|
|
;; find surrounding numbers
|
|
|
|
|
(while (and (<= count-high (1- rom-lngth))
|
|
|
|
|
(>= n (car (nth count-high our-list))))
|
|
|
|
|
;; (message "Checking %d" (car (nth count-high our-list)))
|
|
|
|
|
(setq count-high (1+ count-high)))
|
|
|
|
|
(setq rom-high count-high)
|
|
|
|
|
(setq rom-low (1- count-high))
|
|
|
|
|
;; find the appropriate divisor (if it exists)
|
|
|
|
|
(while (and (= rom-div -1)
|
|
|
|
|
(< count-low rom-high))
|
|
|
|
|
(when (or (> n (- (car (nth rom-high our-list))
|
|
|
|
|
(/ (car (nth count-low our-list))
|
|
|
|
|
2)))
|
|
|
|
|
(= n (- (car (nth rom-high our-list))
|
|
|
|
|
(car (nth count-low our-list)))))
|
|
|
|
|
(setq rom-div count-low))
|
|
|
|
|
;; (message "Checking %d and %d in div loop" rom-high count-low)
|
|
|
|
|
(setq count-low (1+ count-low)))
|
|
|
|
|
;;(message "We now have high: %d, low: %d, div: %d, n: %d"
|
|
|
|
|
;; rom-high rom-low (if rom-div rom-div -1) n)
|
|
|
|
|
(let ((rom-low-pair (nth rom-low our-list))
|
|
|
|
|
(rom-high-pair (nth rom-high our-list))
|
|
|
|
|
(rom-div-pair (if (not (= rom-div -1)) (nth rom-div our-list) nil)))
|
|
|
|
|
;; (message "pairs are: rom-low: %S, rom-high: %S, rom-div: %S"
|
|
|
|
|
;; rom-low-pair rom-high-pair rom-div-pair)
|
|
|
|
|
(cond
|
2017-12-25 23:27:26 -05:00
|
|
|
|
((< n 0) (error "footnote--roman-common called with n < 0"))
|
1999-12-09 23:31:50 +00:00
|
|
|
|
((= n 0) "")
|
|
|
|
|
((= n (car rom-low-pair)) (cdr rom-low-pair))
|
|
|
|
|
((= n (car rom-high-pair)) (cdr rom-high-pair))
|
|
|
|
|
((= (car rom-low-pair) (car rom-high-pair))
|
|
|
|
|
(concat (cdr rom-low-pair)
|
2017-12-25 23:27:26 -05:00
|
|
|
|
(footnote--roman-common
|
1999-12-09 23:31:50 +00:00
|
|
|
|
(- n (car rom-low-pair))
|
|
|
|
|
footnote-roman-list)))
|
|
|
|
|
((>= rom-div 0) (concat (cdr rom-div-pair) (cdr rom-high-pair)
|
2017-12-25 23:27:26 -05:00
|
|
|
|
(footnote--roman-common
|
1999-12-09 23:31:50 +00:00
|
|
|
|
(- n (- (car rom-high-pair)
|
|
|
|
|
(car rom-div-pair)))
|
|
|
|
|
footnote-roman-list)))
|
|
|
|
|
(t (concat (cdr rom-low-pair)
|
2017-12-25 23:27:26 -05:00
|
|
|
|
(footnote--roman-common
|
1999-12-09 23:31:50 +00:00
|
|
|
|
(- n (car rom-low-pair))
|
|
|
|
|
footnote-roman-list)))))))
|
|
|
|
|
|
2000-02-23 20:25:34 +00:00
|
|
|
|
;; Latin-1
|
|
|
|
|
|
2011-05-10 16:14:42 +08:00
|
|
|
|
(defconst footnote-latin-string "¹²³ºª§¶"
|
2007-04-13 05:53:27 +00:00
|
|
|
|
"String of Latin-1 footnoting characters.")
|
|
|
|
|
|
2007-11-01 03:40:30 +00:00
|
|
|
|
;; Note not [...]+, because this style cycles.
|
2007-04-13 05:53:27 +00:00
|
|
|
|
(defconst footnote-latin-regexp (concat "[" footnote-latin-string "]")
|
2000-02-23 20:25:34 +00:00
|
|
|
|
"Regexp for Latin-1 footnoting characters.")
|
|
|
|
|
|
2017-12-25 23:27:26 -05:00
|
|
|
|
(defun footnote--latin (n)
|
2000-02-23 20:25:34 +00:00
|
|
|
|
"Latin-1 footnote style.
|
|
|
|
|
Use a range of Latin-1 non-ASCII characters for footnoting."
|
2007-04-13 05:53:27 +00:00
|
|
|
|
(string (aref footnote-latin-string
|
|
|
|
|
(mod (1- n) (length footnote-latin-string)))))
|
2000-02-23 20:25:34 +00:00
|
|
|
|
|
2011-05-10 16:20:21 +08:00
|
|
|
|
;; Unicode
|
|
|
|
|
|
|
|
|
|
(defconst footnote-unicode-string "⁰¹²³⁴⁵⁶⁷⁸⁹"
|
2011-11-20 20:35:27 +01:00
|
|
|
|
"String of Unicode footnoting characters.")
|
2011-05-10 16:20:21 +08:00
|
|
|
|
|
|
|
|
|
(defconst footnote-unicode-regexp (concat "[" footnote-unicode-string "]+")
|
2011-11-20 20:35:27 +01:00
|
|
|
|
"Regexp for Unicode footnoting characters.")
|
2011-05-10 16:20:21 +08:00
|
|
|
|
|
2017-12-25 23:27:26 -05:00
|
|
|
|
(defun footnote--unicode (n)
|
2011-05-10 16:20:21 +08:00
|
|
|
|
"Unicode footnote style.
|
2011-11-20 20:35:27 +01:00
|
|
|
|
Use Unicode characters for footnoting."
|
2011-05-10 16:20:21 +08:00
|
|
|
|
(let (modulus result done)
|
|
|
|
|
(while (not done)
|
|
|
|
|
(setq modulus (mod n 10)
|
|
|
|
|
n (truncate n 10))
|
|
|
|
|
(and (zerop n) (setq done t))
|
|
|
|
|
(push (aref footnote-unicode-string modulus) result))
|
|
|
|
|
(apply #'string result)))
|
|
|
|
|
|
2017-12-22 16:39:44 +02:00
|
|
|
|
;; Hebrew
|
|
|
|
|
|
|
|
|
|
(defconst footnote-hebrew-numeric
|
|
|
|
|
'(
|
|
|
|
|
("א" "ב" "ג" "ד" "ה" "ו" "ז" "ח" "ט")
|
|
|
|
|
("י" "כ" "ל" "מ" "נ" "ס" "ע" "פ" "צ")
|
2017-12-26 00:08:48 -05:00
|
|
|
|
("ק" "ר" "ש" "ת" "תק" "תר" "תש" "תת" "תתק")))
|
|
|
|
|
|
|
|
|
|
(defconst footnote-hebrew-numeric-regex
|
2019-03-27 11:36:13 -07:00
|
|
|
|
(let ((numchars (string-to-list
|
|
|
|
|
(apply #'concat (apply #'append footnote-hebrew-numeric)))))
|
2019-05-09 10:32:25 -04:00
|
|
|
|
(rx-to-string `(1+ (in ?' ,@numchars)))))
|
2017-12-26 00:08:48 -05:00
|
|
|
|
;; (defconst footnote-hebrew-numeric-regex "\\([אבגדהוזחט]'\\)?\\(ת\\)?\\(ת\\)?\\([קרשת]\\)?\\([טיכלמנסעפצ]\\)?\\([אבגדהוזחט]\\)?")
|
2017-12-22 16:39:44 +02:00
|
|
|
|
|
2017-12-25 23:27:26 -05:00
|
|
|
|
(defun footnote--hebrew-numeric (n)
|
2017-12-22 16:39:44 +02:00
|
|
|
|
"Supports 9999 footnotes, then rolls over."
|
|
|
|
|
(let* ((n (+ (mod n 10000) (/ n 10000)))
|
|
|
|
|
(thousands (/ n 1000))
|
|
|
|
|
(hundreds (/ (mod n 1000) 100))
|
|
|
|
|
(tens (/ (mod n 100) 10))
|
|
|
|
|
(units (mod n 10))
|
2017-12-26 00:08:48 -05:00
|
|
|
|
(special (cond
|
|
|
|
|
((not (= tens 1)) nil)
|
|
|
|
|
((= units 5) "טו")
|
|
|
|
|
((= units 6) "טז"))))
|
2017-12-22 16:39:44 +02:00
|
|
|
|
(concat
|
|
|
|
|
(when (/= 0 thousands)
|
|
|
|
|
(concat (nth (1- thousands) (nth 0 footnote-hebrew-numeric)) "'"))
|
|
|
|
|
(when (/= 0 hundreds)
|
|
|
|
|
(nth (1- hundreds) (nth 2 footnote-hebrew-numeric)))
|
2017-12-26 00:08:48 -05:00
|
|
|
|
(or special
|
|
|
|
|
(concat
|
|
|
|
|
(when (/= 0 tens) (nth (1- tens) (nth 1 footnote-hebrew-numeric)))
|
|
|
|
|
(when (/= 0 units) (nth (1- units) (nth 0 footnote-hebrew-numeric))))))))
|
2017-12-22 16:39:44 +02:00
|
|
|
|
|
|
|
|
|
(defconst footnote-hebrew-symbolic
|
|
|
|
|
'(
|
|
|
|
|
"א" "ב" "ג" "ד" "ה" "ו" "ז" "ח" "ט" "י" "כ" "ל" "מ" "נ" "ס" "ע" "פ" "צ" "ק" "ר" "ש" "ת"))
|
|
|
|
|
|
2017-12-26 00:08:48 -05:00
|
|
|
|
(defconst footnote-hebrew-symbolic-regex
|
|
|
|
|
(concat "[" (apply #'concat footnote-hebrew-symbolic) "]"))
|
|
|
|
|
|
2017-12-25 23:27:26 -05:00
|
|
|
|
(defun footnote--hebrew-symbolic (n)
|
2017-12-22 16:39:44 +02:00
|
|
|
|
"Only 22 elements, per the style of eg. 'פירוש שפתי חכמים על רש״י'.
|
|
|
|
|
Proceeds from `י' to `כ', from `צ' to `ק'. After `ת', rolls over to `א'."
|
|
|
|
|
(nth (mod (1- n) 22) footnote-hebrew-symbolic))
|
|
|
|
|
|
1999-12-09 23:31:50 +00:00
|
|
|
|
;;; list of all footnote styles
|
|
|
|
|
(defvar footnote-style-alist
|
2017-12-25 23:27:26 -05:00
|
|
|
|
`((numeric footnote--numeric ,footnote-numeric-regexp)
|
|
|
|
|
(english-lower footnote--english-lower ,footnote-english-lower-regexp)
|
|
|
|
|
(english-upper footnote--english-upper ,footnote-english-upper-regexp)
|
|
|
|
|
(roman-lower footnote--roman-lower ,footnote-roman-lower-regexp)
|
|
|
|
|
(roman-upper footnote--roman-upper ,footnote-roman-upper-regexp)
|
|
|
|
|
(latin footnote--latin ,footnote-latin-regexp)
|
|
|
|
|
(unicode footnote--unicode ,footnote-unicode-regexp)
|
|
|
|
|
(hebrew-numeric footnote--hebrew-numeric ,footnote-hebrew-numeric-regex)
|
|
|
|
|
(hebrew-symbolic footnote--hebrew-symbolic ,footnote-hebrew-symbolic-regex))
|
1999-12-09 23:31:50 +00:00
|
|
|
|
"Styles of footnote tags available.
|
2017-12-22 16:39:44 +02:00
|
|
|
|
By default, Arabic numbers, English letters, Roman Numerals,
|
|
|
|
|
Latin and Unicode superscript characters, and Hebrew numerals
|
2017-12-26 00:08:48 -05:00
|
|
|
|
are available.
|
|
|
|
|
Each element of the list should be of the form (NAME FUNCTION REGEXP)
|
|
|
|
|
where NAME is a symbol, FUNCTION takes a footnote number and
|
|
|
|
|
returns the corresponding representation in that style as a string,
|
|
|
|
|
and REGEXP should be a regexp that matches any output of FUNCTION.")
|
1999-12-09 23:31:50 +00:00
|
|
|
|
|
2000-02-23 20:25:34 +00:00
|
|
|
|
(defcustom footnote-style 'numeric
|
2008-10-06 06:29:05 +00:00
|
|
|
|
"Default style used for footnoting.
|
2000-02-23 20:25:34 +00:00
|
|
|
|
numeric == 1, 2, 3, ...
|
|
|
|
|
english-lower == a, b, c, ...
|
|
|
|
|
english-upper == A, B, C, ...
|
|
|
|
|
roman-lower == i, ii, iii, iv, v, ...
|
|
|
|
|
roman-upper == I, II, III, IV, V, ...
|
2011-05-10 16:14:42 +08:00
|
|
|
|
latin == ¹ ² ³ º ª § ¶
|
2011-05-10 16:20:21 +08:00
|
|
|
|
unicode == ¹, ², ³, ...
|
2017-12-22 16:39:44 +02:00
|
|
|
|
hebrew-numeric == א, ב, ..., יא, ..., תקא...
|
|
|
|
|
hebrew-symbolic == א, ב, ..., י, כ, ..., צ, ק, ..., ת, א
|
2007-04-15 17:28:00 +00:00
|
|
|
|
See also variables `footnote-start-tag' and `footnote-end-tag'.
|
|
|
|
|
|
2011-05-10 16:20:21 +08:00
|
|
|
|
Note: some characters in the unicode style may not show up
|
|
|
|
|
properly if the default font does not contain those characters.
|
|
|
|
|
|
2007-04-15 17:28:00 +00:00
|
|
|
|
Customizing this variable has no effect on buffers already
|
2008-10-06 06:29:05 +00:00
|
|
|
|
displaying footnotes. To change the style of footnotes in such a
|
2017-12-25 23:27:26 -05:00
|
|
|
|
buffer use the command `footnote-set-style'."
|
2000-02-23 20:25:34 +00:00
|
|
|
|
:type (cons 'choice (mapcar (lambda (x) (list 'const (car x)))
|
2019-05-01 13:14:31 -04:00
|
|
|
|
footnote-style-alist)))
|
2000-02-23 20:25:34 +00:00
|
|
|
|
|
1999-12-09 23:31:50 +00:00
|
|
|
|
;;; Style utilities & functions
|
|
|
|
|
|
2017-12-25 23:27:26 -05:00
|
|
|
|
(defun footnote--index-to-string (index)
|
1999-12-09 23:31:50 +00:00
|
|
|
|
"Convert a binary index into a string to display as a footnote.
|
|
|
|
|
Conversion is done based upon the current selected style."
|
2019-05-01 13:14:31 -04:00
|
|
|
|
(let ((alist (or (assq footnote-style footnote-style-alist)
|
|
|
|
|
(nth 0 footnote-style-alist))))
|
1999-12-09 23:31:50 +00:00
|
|
|
|
(funcall (nth 1 alist) index)))
|
|
|
|
|
|
2019-05-02 10:27:42 -04:00
|
|
|
|
(defun footnote--current-regexp (&optional index-regexp)
|
1999-12-09 23:31:50 +00:00
|
|
|
|
"Return the regexp of the index of the current style."
|
2019-05-02 10:27:42 -04:00
|
|
|
|
(let ((regexp (or index-regexp
|
|
|
|
|
(nth 2 (or (assq footnote-style footnote-style-alist)
|
|
|
|
|
(nth 0 footnote-style-alist))))))
|
2019-03-26 19:06:36 -07:00
|
|
|
|
(concat
|
2019-05-02 10:27:42 -04:00
|
|
|
|
(regexp-quote footnote-start-tag) "\\("
|
2019-03-26 19:06:36 -07:00
|
|
|
|
;; Hack to avoid repetition of repetition.
|
2019-03-27 11:36:13 -07:00
|
|
|
|
;; FIXME: I'm not sure the added * makes sense at all; there is
|
|
|
|
|
;; always a single number within the footnote-{start,end}-tag pairs.
|
2019-03-26 19:06:36 -07:00
|
|
|
|
(if (string-match "[^\\]\\\\\\{2\\}*[*+?]\\'" regexp)
|
|
|
|
|
(substring regexp 0 -1)
|
|
|
|
|
regexp)
|
2019-05-02 10:27:42 -04:00
|
|
|
|
"*\\)" (regexp-quote footnote-end-tag))))
|
1999-12-09 23:31:50 +00:00
|
|
|
|
|
2017-12-25 23:27:26 -05:00
|
|
|
|
(defun footnote--refresh-footnotes (&optional index-regexp)
|
1999-12-09 23:31:50 +00:00
|
|
|
|
"Redraw all footnotes.
|
2019-05-02 09:00:53 -04:00
|
|
|
|
You must call this or arrange to have this called after changing
|
|
|
|
|
footnote styles."
|
2019-05-02 10:27:42 -04:00
|
|
|
|
(let ((fn-regexp (footnote--current-regexp index-regexp)))
|
2019-05-02 09:00:53 -04:00
|
|
|
|
(save-excursion
|
|
|
|
|
(pcase-dolist (`(,fn ,text . ,pointers) footnote--markers-alist)
|
2019-05-02 11:00:20 -04:00
|
|
|
|
;; Take care of the pointers first.
|
2019-05-02 09:00:53 -04:00
|
|
|
|
(dolist (locn pointers)
|
|
|
|
|
(goto-char locn)
|
2008-10-06 06:29:05 +00:00
|
|
|
|
;; Try to handle the case where `footnote-start-tag' and
|
|
|
|
|
;; `footnote-end-tag' are the same string.
|
2019-05-02 10:27:42 -04:00
|
|
|
|
(when (looking-at fn-regexp)
|
2008-10-06 06:29:05 +00:00
|
|
|
|
(replace-match
|
|
|
|
|
(propertize
|
|
|
|
|
(concat
|
|
|
|
|
footnote-start-tag
|
2019-05-02 09:00:53 -04:00
|
|
|
|
(footnote--index-to-string fn)
|
2008-10-06 06:29:05 +00:00
|
|
|
|
footnote-end-tag)
|
2019-05-02 09:00:53 -04:00
|
|
|
|
'footnote-number fn footnote-mouse-highlight t)
|
|
|
|
|
t t)))
|
|
|
|
|
|
|
|
|
|
;; Now take care of the text section
|
|
|
|
|
(goto-char text)
|
|
|
|
|
(when (looking-at fn-regexp)
|
2008-10-06 06:29:05 +00:00
|
|
|
|
(replace-match
|
|
|
|
|
(propertize
|
|
|
|
|
(concat
|
|
|
|
|
footnote-start-tag
|
2019-05-02 09:00:53 -04:00
|
|
|
|
(footnote--index-to-string fn)
|
2008-10-06 06:29:05 +00:00
|
|
|
|
footnote-end-tag)
|
2019-05-02 09:00:53 -04:00
|
|
|
|
'footnote-number fn)
|
|
|
|
|
t t))))))
|
1999-12-09 23:31:50 +00:00
|
|
|
|
|
2017-12-25 23:27:26 -05:00
|
|
|
|
(defun footnote-cycle-style ()
|
1999-12-09 23:31:50 +00:00
|
|
|
|
"Select next defined footnote style."
|
|
|
|
|
(interactive)
|
2019-05-01 13:14:31 -04:00
|
|
|
|
(let ((old-desc (assq footnote-style footnote-style-alist)))
|
|
|
|
|
(setq footnote-style (caar (or (cdr (memq old-desc footnote-style-alist))
|
|
|
|
|
footnote-style-alist)))
|
2019-05-01 17:53:39 -04:00
|
|
|
|
(footnote--refresh-footnotes (nth 2 old-desc))
|
|
|
|
|
(message "Style set to %s" footnote-style)))
|
2019-05-01 13:14:31 -04:00
|
|
|
|
|
|
|
|
|
(defun footnote-set-style (style)
|
1999-12-09 23:31:50 +00:00
|
|
|
|
"Select a specific style."
|
|
|
|
|
(interactive
|
|
|
|
|
(list (intern (completing-read
|
|
|
|
|
"Footnote Style: "
|
2019-05-01 13:14:31 -04:00
|
|
|
|
footnote-style-alist nil 'require-match))))
|
|
|
|
|
(let ((old-desc (assq footnote-style footnote-style-alist)))
|
2008-10-06 06:29:05 +00:00
|
|
|
|
(setq footnote-style style)
|
2019-05-01 13:14:31 -04:00
|
|
|
|
(footnote--refresh-footnotes (nth 2 old-desc))))
|
1999-12-09 23:31:50 +00:00
|
|
|
|
|
|
|
|
|
;; Internal functions
|
2017-12-25 23:27:26 -05:00
|
|
|
|
(defun footnote--insert-numbered-footnote (arg &optional mousable)
|
2019-05-02 11:00:20 -04:00
|
|
|
|
"Insert numbered footnote at point.
|
|
|
|
|
Return a marker pointing to the beginning of the [...]."
|
2008-10-06 06:29:05 +00:00
|
|
|
|
(let ((string (concat footnote-start-tag
|
2017-12-25 23:27:26 -05:00
|
|
|
|
(footnote--index-to-string arg)
|
2019-05-02 11:00:20 -04:00
|
|
|
|
footnote-end-tag))
|
|
|
|
|
(pos (point)))
|
2019-05-02 10:27:42 -04:00
|
|
|
|
(insert
|
2008-10-06 06:29:05 +00:00
|
|
|
|
(if mousable
|
|
|
|
|
(propertize
|
|
|
|
|
string 'footnote-number arg footnote-mouse-highlight t)
|
2019-05-02 11:00:20 -04:00
|
|
|
|
(propertize string 'footnote-number arg)))
|
|
|
|
|
(copy-marker pos t)))
|
1999-12-09 23:31:50 +00:00
|
|
|
|
|
2019-05-01 17:53:39 -04:00
|
|
|
|
(defun footnote--renumber (to alist-elem)
|
1999-12-09 23:31:50 +00:00
|
|
|
|
"Renumber a single footnote."
|
2019-05-02 09:00:53 -04:00
|
|
|
|
(unless (equal to (car alist-elem)) ;Nothing to do.
|
2019-05-02 10:27:42 -04:00
|
|
|
|
(let* ((fn-regexp (footnote--current-regexp)))
|
2019-05-02 09:00:53 -04:00
|
|
|
|
(setcar alist-elem to)
|
|
|
|
|
(dolist (posn (cddr alist-elem))
|
|
|
|
|
(goto-char posn)
|
2019-05-02 10:27:42 -04:00
|
|
|
|
(when (looking-at fn-regexp)
|
2019-05-02 09:00:53 -04:00
|
|
|
|
(replace-match
|
|
|
|
|
(propertize
|
|
|
|
|
(concat footnote-start-tag
|
|
|
|
|
(footnote--index-to-string to)
|
|
|
|
|
footnote-end-tag)
|
|
|
|
|
'footnote-number to footnote-mouse-highlight t))))
|
|
|
|
|
(goto-char (cadr alist-elem))
|
|
|
|
|
(when (looking-at fn-regexp)
|
|
|
|
|
(replace-match
|
|
|
|
|
(propertize
|
2008-10-06 06:29:05 +00:00
|
|
|
|
(concat footnote-start-tag
|
2017-12-25 23:27:26 -05:00
|
|
|
|
(footnote--index-to-string to)
|
2008-10-06 06:29:05 +00:00
|
|
|
|
footnote-end-tag)
|
2019-05-02 09:00:53 -04:00
|
|
|
|
'footnote-number to))))))
|
1999-12-09 23:31:50 +00:00
|
|
|
|
|
2017-12-25 23:27:26 -05:00
|
|
|
|
(defun footnote--narrow-to-footnotes ()
|
1999-12-09 23:31:50 +00:00
|
|
|
|
"Restrict text in buffer to show only text of footnotes."
|
2017-12-22 21:44:52 -05:00
|
|
|
|
(interactive) ; testing
|
2017-12-25 23:27:26 -05:00
|
|
|
|
(narrow-to-region (footnote--get-area-point-min)
|
|
|
|
|
(footnote--get-area-point-max)))
|
1999-12-09 23:31:50 +00:00
|
|
|
|
|
2017-12-25 23:27:26 -05:00
|
|
|
|
(defun footnote--goto-char-point-max ()
|
1999-12-09 23:31:50 +00:00
|
|
|
|
"Move to end of buffer or prior to start of .signature."
|
|
|
|
|
(goto-char (point-max))
|
|
|
|
|
(or (re-search-backward footnote-signature-separator nil t)
|
|
|
|
|
(point)))
|
|
|
|
|
|
2019-05-02 11:00:20 -04:00
|
|
|
|
(defun footnote--insert-markers (arg text ptr)
|
|
|
|
|
"Insert the markers of new footnote ARG."
|
|
|
|
|
(cl-assert (and (numberp arg) (markerp text) (markerp ptr)))
|
|
|
|
|
(cl-assert (not (assq arg footnote--markers-alist)))
|
|
|
|
|
(push `(,arg ,text ,ptr) footnote--markers-alist)
|
|
|
|
|
(setq footnote--markers-alist
|
|
|
|
|
(footnote--sort footnote--markers-alist)))
|
2019-05-01 17:53:39 -04:00
|
|
|
|
|
|
|
|
|
(defun footnote--goto-first ()
|
|
|
|
|
"Go to beginning of footnote area and return non-nil if successful.
|
|
|
|
|
Presumes we're within the footnote area already."
|
|
|
|
|
(cond
|
|
|
|
|
((not (string-equal footnote-section-tag ""))
|
|
|
|
|
(re-search-backward
|
|
|
|
|
(concat "^" footnote-section-tag-regexp) nil t))
|
|
|
|
|
(footnote--markers-alist
|
2019-05-02 11:00:20 -04:00
|
|
|
|
(goto-char (cadr (car footnote--markers-alist))))))
|
1999-12-09 23:31:50 +00:00
|
|
|
|
|
2017-12-25 23:27:26 -05:00
|
|
|
|
(defun footnote--insert-footnote (arg)
|
2008-10-06 06:29:05 +00:00
|
|
|
|
"Insert a footnote numbered ARG, at (point)."
|
1999-12-09 23:31:50 +00:00
|
|
|
|
(push-mark)
|
2019-05-02 11:00:20 -04:00
|
|
|
|
(let ((ptr (footnote--insert-numbered-footnote arg t)))
|
|
|
|
|
(footnote--goto-char-point-max)
|
|
|
|
|
(if (footnote--goto-first)
|
|
|
|
|
(save-restriction
|
|
|
|
|
(when footnote-narrow-to-footnotes-when-editing
|
|
|
|
|
(footnote--narrow-to-footnotes))
|
|
|
|
|
(footnote-goto-footnote (1- arg)) ; evil, FIXME (less evil now)
|
|
|
|
|
;; (message "Inserting footnote %d" arg)
|
|
|
|
|
(or (eq arg 1)
|
|
|
|
|
(when (re-search-forward
|
|
|
|
|
(if footnote-spaced-footnotes
|
|
|
|
|
"\n\n"
|
|
|
|
|
(concat "\n" (footnote--current-regexp)))
|
|
|
|
|
nil t)
|
|
|
|
|
(beginning-of-line)
|
|
|
|
|
t)
|
|
|
|
|
(footnote--goto-char-point-max)
|
|
|
|
|
(footnote--goto-first)))
|
|
|
|
|
(unless (looking-at "^$")
|
|
|
|
|
(insert "\n"))
|
|
|
|
|
(when (eobp)
|
|
|
|
|
(insert "\n"))
|
|
|
|
|
(unless (string-equal footnote-section-tag "")
|
|
|
|
|
(insert footnote-section-tag "\n")))
|
|
|
|
|
(let ((text (footnote--insert-numbered-footnote arg nil)))
|
|
|
|
|
(footnote--insert-markers arg text ptr))))
|
1999-12-09 23:31:50 +00:00
|
|
|
|
|
2017-12-25 23:27:26 -05:00
|
|
|
|
(defun footnote--sort (list)
|
2019-05-01 13:14:31 -04:00
|
|
|
|
(sort list #'car-less-than-car))
|
1999-12-09 23:31:50 +00:00
|
|
|
|
|
2017-12-25 23:27:26 -05:00
|
|
|
|
(defun footnote--text-under-cursor ()
|
2017-12-22 21:44:52 -05:00
|
|
|
|
"Return the number of the current footnote if in footnote text.
|
2001-12-20 18:59:32 +00:00
|
|
|
|
Return nil if the cursor is not positioned over the text of
|
1999-12-09 23:31:50 +00:00
|
|
|
|
a footnote."
|
2019-05-02 09:00:53 -04:00
|
|
|
|
(when (<= (point) (footnote--get-area-point-max))
|
|
|
|
|
(let ((result nil))
|
|
|
|
|
(pcase-dolist (`(,fn ,text . ,_) footnote--markers-alist)
|
|
|
|
|
(if (<= text (point))
|
|
|
|
|
(setq result fn)))
|
2017-12-22 21:44:52 -05:00
|
|
|
|
result)))
|
1999-12-09 23:31:50 +00:00
|
|
|
|
|
2017-12-25 23:27:26 -05:00
|
|
|
|
(defun footnote--under-cursor ()
|
1999-12-09 23:31:50 +00:00
|
|
|
|
"Return the number of the footnote underneath the cursor.
|
2001-12-20 18:59:32 +00:00
|
|
|
|
Return nil if the cursor is not over a footnote."
|
1999-12-09 23:31:50 +00:00
|
|
|
|
(or (get-text-property (point) 'footnote-number)
|
2017-12-25 23:27:26 -05:00
|
|
|
|
(footnote--text-under-cursor)))
|
1999-12-09 23:31:50 +00:00
|
|
|
|
|
2017-12-25 23:27:26 -05:00
|
|
|
|
(defun footnote--calc-fn-alignment-column ()
|
2017-12-22 23:06:22 -05:00
|
|
|
|
"Calculate the left alignment for footnote text."
|
|
|
|
|
;; FIXME: Maybe it would be better to go to the footnote's beginning and
|
|
|
|
|
;; see at which column it starts.
|
|
|
|
|
(+ footnote-body-tag-spacing
|
|
|
|
|
(string-width
|
|
|
|
|
(concat footnote-start-tag footnote-end-tag
|
2017-12-25 23:27:26 -05:00
|
|
|
|
(footnote--index-to-string
|
2019-05-01 17:53:39 -04:00
|
|
|
|
(caar (last footnote--markers-alist)))))))
|
2017-12-22 23:06:22 -05:00
|
|
|
|
|
2017-12-25 23:27:26 -05:00
|
|
|
|
(defun footnote--fill-prefix-string ()
|
2017-12-22 23:06:22 -05:00
|
|
|
|
"Return the fill prefix to be used by footnote mode."
|
|
|
|
|
;; TODO: Prefix to this value other prefix strings, such as those
|
|
|
|
|
;; designating a comment line, a message response, or a boxquote.
|
2017-12-25 23:27:26 -05:00
|
|
|
|
(make-string (footnote--calc-fn-alignment-column) ?\s))
|
2017-12-22 23:06:22 -05:00
|
|
|
|
|
2017-12-25 23:27:26 -05:00
|
|
|
|
(defun footnote--point-in-body-p ()
|
2017-12-22 21:44:52 -05:00
|
|
|
|
"Return non-nil if point is in the buffer text area,
|
|
|
|
|
i.e. before the beginning of the footnote area."
|
2017-12-25 23:27:26 -05:00
|
|
|
|
(< (point) (footnote--get-area-point-min)))
|
2017-12-22 21:44:52 -05:00
|
|
|
|
|
2017-12-25 23:27:26 -05:00
|
|
|
|
(defun footnote--get-area-point-min (&optional before-tag)
|
2017-12-22 21:44:52 -05:00
|
|
|
|
"Return start of the first footnote.
|
|
|
|
|
If there is no footnote area, returns `point-max'.
|
|
|
|
|
With optional arg BEFORE-TAG, return position of the `footnote-section-tag'
|
|
|
|
|
instead, if applicable."
|
|
|
|
|
(cond
|
2017-12-25 23:27:26 -05:00
|
|
|
|
;; FIXME: Shouldn't we use `footnote--get-area-point-max' instead?
|
2019-05-02 11:00:20 -04:00
|
|
|
|
((not footnote--markers-alist) (point-max))
|
|
|
|
|
((not before-tag) (cadr (car footnote--markers-alist)))
|
|
|
|
|
((string-equal footnote-section-tag "") (cadr (car footnote--markers-alist)))
|
2017-12-22 21:44:52 -05:00
|
|
|
|
(t
|
|
|
|
|
(save-excursion
|
2019-05-02 11:00:20 -04:00
|
|
|
|
(goto-char (cadr (car footnote--markers-alist)))
|
2017-12-22 21:44:52 -05:00
|
|
|
|
(if (re-search-backward (concat "^" footnote-section-tag-regexp) nil t)
|
2019-05-02 11:00:20 -04:00
|
|
|
|
(point)
|
2017-12-22 21:44:52 -05:00
|
|
|
|
(message "Footnote section tag not found!")
|
|
|
|
|
;; 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.
|
2019-05-02 11:00:20 -04:00
|
|
|
|
(point))))))
|
2017-12-22 21:44:52 -05:00
|
|
|
|
|
2017-12-25 23:27:26 -05:00
|
|
|
|
(defun footnote--get-area-point-max ()
|
2017-12-22 21:44:52 -05:00
|
|
|
|
"Return the end of footnote area.
|
|
|
|
|
This is either `point-max' or the start of a `.signature' string, as
|
|
|
|
|
defined by variable `footnote-signature-separator'. If there is no
|
|
|
|
|
footnote area, returns `point-max'."
|
2017-12-25 23:27:26 -05:00
|
|
|
|
(save-excursion (footnote--goto-char-point-max)))
|
2017-12-22 21:44:52 -05:00
|
|
|
|
|
2017-12-25 23:27:26 -05:00
|
|
|
|
(defun footnote--adaptive-fill-function (orig-fun)
|
2017-12-22 23:06:22 -05:00
|
|
|
|
(or
|
|
|
|
|
(and
|
|
|
|
|
footnote-mode
|
|
|
|
|
footnote-align-to-fn-text
|
2017-12-25 23:27:26 -05:00
|
|
|
|
(footnote--text-under-cursor)
|
|
|
|
|
;; (not (footnote--point-in-body-p))
|
|
|
|
|
;; (< (point) (footnote--signature-area-start-point))
|
|
|
|
|
(footnote--fill-prefix-string))
|
2017-12-22 23:06:22 -05:00
|
|
|
|
;; If not within a footnote's text, fallback to the default.
|
|
|
|
|
(funcall orig-fun)))
|
|
|
|
|
|
2019-07-25 19:35:17 +02:00
|
|
|
|
(defun footnote--fill-paragraph (orig-fun justify)
|
|
|
|
|
(if (not (footnote--text-under-cursor))
|
|
|
|
|
(funcall orig-fun justify)
|
2019-07-21 16:43:07 +02:00
|
|
|
|
(let ((fill-paragraph-function nil)
|
|
|
|
|
(fill-prefix (if footnote-align-to-fn-text
|
|
|
|
|
(footnote--fill-prefix-string)
|
|
|
|
|
""))
|
|
|
|
|
(paragraph-start "\\["))
|
|
|
|
|
(fill-paragraph justify))))
|
|
|
|
|
|
1999-12-09 23:31:50 +00:00
|
|
|
|
;;; User functions
|
|
|
|
|
|
2017-12-25 23:27:26 -05:00
|
|
|
|
(defun footnote--make-hole ()
|
2019-05-02 10:27:42 -04:00
|
|
|
|
"Make room in the alist for a new footnote at point.
|
|
|
|
|
Return the footnote number to use."
|
1999-12-09 23:31:50 +00:00
|
|
|
|
(save-excursion
|
2019-05-02 09:00:53 -04:00
|
|
|
|
(let (rc)
|
|
|
|
|
(dolist (alist-elem footnote--markers-alist)
|
2019-05-02 10:27:42 -04:00
|
|
|
|
(when (<= (point) (cl-caddr alist-elem))
|
1999-12-09 23:31:50 +00:00
|
|
|
|
(unless rc
|
2019-05-01 17:53:39 -04:00
|
|
|
|
(setq rc (car alist-elem)))
|
1999-12-09 23:31:50 +00:00
|
|
|
|
(save-excursion
|
2003-02-04 13:24:35 +00:00
|
|
|
|
(message "Renumbering from %s to %s"
|
2019-05-01 17:53:39 -04:00
|
|
|
|
(footnote--index-to-string (car alist-elem))
|
2017-12-25 23:27:26 -05:00
|
|
|
|
(footnote--index-to-string
|
2019-05-01 17:53:39 -04:00
|
|
|
|
(1+ (car alist-elem))))
|
|
|
|
|
(footnote--renumber (1+ (car alist-elem))
|
2019-05-02 09:00:53 -04:00
|
|
|
|
alist-elem))))
|
2019-05-02 10:27:42 -04:00
|
|
|
|
(or rc
|
|
|
|
|
(1+ (or (caar (last footnote--markers-alist)) 0))))))
|
1999-12-09 23:31:50 +00:00
|
|
|
|
|
2017-12-25 23:32:24 -05:00
|
|
|
|
(defun footnote-add-footnote ()
|
1999-12-09 23:31:50 +00:00
|
|
|
|
"Add a numbered footnote.
|
|
|
|
|
The number the footnote receives is dependent upon the relative location
|
|
|
|
|
of any other previously existing footnotes.
|
|
|
|
|
If the variable `footnote-narrow-to-footnotes-when-editing' is set,
|
|
|
|
|
the buffer is narrowed to the footnote body. The restriction is removed
|
2017-12-25 23:27:26 -05:00
|
|
|
|
by using `footnote-back-to-message'."
|
2017-12-25 23:32:24 -05:00
|
|
|
|
(interactive "*")
|
2019-05-02 10:27:42 -04:00
|
|
|
|
(let ((num (footnote--make-hole)))
|
1999-12-09 23:31:50 +00:00
|
|
|
|
(message "Adding footnote %d" num)
|
2017-12-25 23:27:26 -05:00
|
|
|
|
(footnote--insert-footnote num)
|
2019-05-02 10:27:42 -04:00
|
|
|
|
(insert (make-string footnote-body-tag-spacing ? ))
|
|
|
|
|
(save-excursion
|
|
|
|
|
(insert
|
|
|
|
|
(if footnote-spaced-footnotes
|
|
|
|
|
"\n\n"
|
|
|
|
|
"\n"))
|
|
|
|
|
(when footnote-narrow-to-footnotes-when-editing
|
|
|
|
|
(footnote--narrow-to-footnotes)))))
|
1999-12-09 23:31:50 +00:00
|
|
|
|
|
2017-12-25 23:27:26 -05:00
|
|
|
|
(defun footnote-delete-footnote (&optional arg)
|
1999-12-09 23:31:50 +00:00
|
|
|
|
"Delete a numbered footnote.
|
2008-10-06 06:29:05 +00:00
|
|
|
|
With no parameter, delete the footnote under (point). With ARG specified,
|
1999-12-09 23:31:50 +00:00
|
|
|
|
delete the footnote with that number."
|
|
|
|
|
(interactive "*P")
|
|
|
|
|
(unless arg
|
2017-12-25 23:27:26 -05:00
|
|
|
|
(setq arg (footnote--under-cursor)))
|
1999-12-09 23:31:50 +00:00
|
|
|
|
(when (and arg
|
|
|
|
|
(or (not footnote-prompt-before-deletion)
|
|
|
|
|
(y-or-n-p (format "Really delete footnote %d?" arg))))
|
2019-05-02 09:00:53 -04:00
|
|
|
|
(let ((alist-elem (or (assq arg footnote--markers-alist)
|
|
|
|
|
(error "Can't delete footnote %d" arg)))
|
2019-05-02 10:27:42 -04:00
|
|
|
|
(fn-regexp (footnote--current-regexp)))
|
2019-05-02 09:00:53 -04:00
|
|
|
|
(dolist (locn (cddr alist-elem))
|
1999-12-09 23:31:50 +00:00
|
|
|
|
(save-excursion
|
2019-05-02 09:00:53 -04:00
|
|
|
|
(goto-char locn)
|
2019-05-02 10:27:42 -04:00
|
|
|
|
(when (looking-at fn-regexp)
|
2019-05-02 09:00:53 -04:00
|
|
|
|
(delete-region (match-beginning 0) (match-end 0)))))
|
1999-12-09 23:31:50 +00:00
|
|
|
|
(save-excursion
|
2019-05-01 17:53:39 -04:00
|
|
|
|
(goto-char (cadr alist-elem))
|
2008-10-06 06:29:05 +00:00
|
|
|
|
(delete-region
|
|
|
|
|
(point)
|
|
|
|
|
(if footnote-spaced-footnotes
|
|
|
|
|
(search-forward "\n\n" nil t)
|
2017-12-22 21:44:52 -05:00
|
|
|
|
(save-restriction ; <= 2017-12 Boruch: WHY?? I see no narrowing / widening here.
|
2008-10-06 06:29:05 +00:00
|
|
|
|
(end-of-line)
|
|
|
|
|
(next-single-char-property-change
|
2017-12-25 23:27:26 -05:00
|
|
|
|
(point) 'footnote-number nil (footnote--goto-char-point-max))))))
|
2019-05-01 17:53:39 -04:00
|
|
|
|
(setq footnote--markers-alist
|
|
|
|
|
(delq alist-elem footnote--markers-alist))
|
2019-05-02 09:00:53 -04:00
|
|
|
|
(if footnote--markers-alist
|
|
|
|
|
(footnote-renumber-footnotes)
|
1999-12-09 23:31:50 +00:00
|
|
|
|
(save-excursion
|
2008-10-06 06:29:05 +00:00
|
|
|
|
(if (not (string-equal footnote-section-tag ""))
|
2017-12-25 23:27:26 -05:00
|
|
|
|
(let* ((end (footnote--goto-char-point-max))
|
2008-10-06 06:29:05 +00:00
|
|
|
|
(start (1- (re-search-backward
|
|
|
|
|
(concat "^" footnote-section-tag-regexp)
|
|
|
|
|
nil t))))
|
|
|
|
|
(forward-line -1)
|
|
|
|
|
(when (looking-at "\n")
|
|
|
|
|
(kill-line))
|
|
|
|
|
(delete-region start (if (< end (point-max))
|
|
|
|
|
end
|
|
|
|
|
(point-max))))
|
2017-12-25 23:27:26 -05:00
|
|
|
|
(footnote--goto-char-point-max)
|
2015-04-20 21:55:00 -04:00
|
|
|
|
(when (looking-back "\n\n" (- (point) 2))
|
2008-10-06 06:29:05 +00:00
|
|
|
|
(kill-line -1))))))))
|
1999-12-09 23:31:50 +00:00
|
|
|
|
|
2017-12-25 23:32:24 -05:00
|
|
|
|
(defun footnote-renumber-footnotes ()
|
1999-12-09 23:31:50 +00:00
|
|
|
|
"Renumber footnotes, starting from 1."
|
2017-12-25 23:32:24 -05:00
|
|
|
|
(interactive "*")
|
1999-12-09 23:31:50 +00:00
|
|
|
|
(save-excursion
|
2019-05-02 09:00:53 -04:00
|
|
|
|
(let ((i 1))
|
|
|
|
|
(dolist (alist-elem footnote--markers-alist)
|
|
|
|
|
(footnote--renumber i alist-elem)
|
1999-12-09 23:31:50 +00:00
|
|
|
|
(setq i (1+ i))))))
|
|
|
|
|
|
2017-12-25 23:27:26 -05:00
|
|
|
|
(defun footnote-goto-footnote (&optional arg)
|
1999-12-09 23:31:50 +00:00
|
|
|
|
"Jump to the text of a footnote.
|
2008-10-06 06:29:05 +00:00
|
|
|
|
With no parameter, jump to the text of the footnote under (point). With ARG
|
1999-12-09 23:31:50 +00:00
|
|
|
|
specified, jump to the text of that footnote."
|
|
|
|
|
(interactive "P")
|
2008-10-06 06:29:05 +00:00
|
|
|
|
(unless arg
|
2017-12-25 23:27:26 -05:00
|
|
|
|
(setq arg (footnote--under-cursor)))
|
2019-05-01 17:53:39 -04:00
|
|
|
|
(let ((footnote (assq arg footnote--markers-alist)))
|
2008-10-06 06:29:05 +00:00
|
|
|
|
(cond
|
|
|
|
|
(footnote
|
2019-05-01 17:53:39 -04:00
|
|
|
|
(goto-char (cadr footnote)))
|
2008-10-06 06:29:05 +00:00
|
|
|
|
((eq arg 0)
|
|
|
|
|
(goto-char (point-max))
|
|
|
|
|
(cond
|
|
|
|
|
((not (string-equal footnote-section-tag ""))
|
|
|
|
|
(re-search-backward (concat "^" footnote-section-tag-regexp))
|
|
|
|
|
(forward-line 1))
|
2019-05-02 11:00:20 -04:00
|
|
|
|
(footnote--markers-alist
|
|
|
|
|
(goto-char (cadr (car footnote--markers-alist))))))
|
2008-10-06 06:29:05 +00:00
|
|
|
|
(t
|
|
|
|
|
(error "I don't see a footnote here")))))
|
1999-12-09 23:31:50 +00:00
|
|
|
|
|
2017-12-25 23:32:24 -05:00
|
|
|
|
(defun footnote-back-to-message ()
|
1999-12-09 23:31:50 +00:00
|
|
|
|
"Move cursor back to footnote referent.
|
|
|
|
|
If the cursor is not over the text of a footnote, point is not changed.
|
|
|
|
|
If the buffer was narrowed due to `footnote-narrow-to-footnotes-when-editing'
|
|
|
|
|
being set it is automatically widened."
|
2017-12-25 23:32:24 -05:00
|
|
|
|
(interactive)
|
2017-12-25 23:27:26 -05:00
|
|
|
|
(let ((note (footnote--text-under-cursor)))
|
1999-12-09 23:31:50 +00:00
|
|
|
|
(when note
|
|
|
|
|
(when footnote-narrow-to-footnotes-when-editing
|
|
|
|
|
(widen))
|
2019-05-02 10:27:42 -04:00
|
|
|
|
(goto-char (cl-caddr (assq note footnote--markers-alist)))
|
|
|
|
|
(when (looking-at (footnote--current-regexp))
|
|
|
|
|
(goto-char (match-end 0))))))
|
1999-12-09 23:31:50 +00:00
|
|
|
|
|
2009-09-03 02:21:37 +00:00
|
|
|
|
(defvar footnote-mode-map
|
|
|
|
|
(let ((map (make-sparse-keymap)))
|
2019-05-02 09:00:53 -04:00
|
|
|
|
(define-key map "a" #'footnote-add-footnote)
|
|
|
|
|
(define-key map "b" #'footnote-back-to-message)
|
|
|
|
|
(define-key map "c" #'footnote-cycle-style)
|
|
|
|
|
(define-key map "d" #'footnote-delete-footnote)
|
|
|
|
|
(define-key map "g" #'footnote-goto-footnote)
|
|
|
|
|
(define-key map "r" #'footnote-renumber-footnotes)
|
|
|
|
|
(define-key map "s" #'footnote-set-style)
|
2009-09-03 02:21:37 +00:00
|
|
|
|
map))
|
|
|
|
|
|
|
|
|
|
(defvar footnote-minor-mode-map
|
|
|
|
|
(let ((map (make-sparse-keymap)))
|
|
|
|
|
(define-key map footnote-prefix footnote-mode-map)
|
|
|
|
|
map)
|
1999-12-09 23:31:50 +00:00
|
|
|
|
"Keymap used for binding footnote minor mode.")
|
|
|
|
|
|
2019-07-25 19:35:17 +02:00
|
|
|
|
(defmacro footnote--local-advice (mode variable function)
|
|
|
|
|
"Add advice to a variable holding buffer-local functions.
|
|
|
|
|
Typical use would be to advice variables like
|
|
|
|
|
`fill-paragraph-function' from minor modes.
|
|
|
|
|
|
|
|
|
|
MODE is the minor mode symbol, VARIABLE is the variable to get
|
|
|
|
|
advice, and FUNCTION is what'll be added as an :around advice."
|
|
|
|
|
`(progn
|
|
|
|
|
(unless ,variable
|
|
|
|
|
;; nil and `ignore' have the same semantics for adaptive-fill-function,
|
|
|
|
|
;; but only `ignore' behaves correctly with add/remove-function.
|
2019-07-25 19:38:17 +02:00
|
|
|
|
(setq-local ,variable #'ignore))
|
2019-07-26 08:47:39 -04:00
|
|
|
|
(remove-function (local ',variable) #',function)
|
2019-07-25 19:35:17 +02:00
|
|
|
|
(when ,mode
|
|
|
|
|
(add-function :around (local ',variable)
|
|
|
|
|
#',function))))
|
|
|
|
|
|
1999-12-09 23:31:50 +00:00
|
|
|
|
;;;###autoload
|
2009-09-03 02:21:37 +00:00
|
|
|
|
(define-minor-mode footnote-mode
|
2011-10-19 20:26:14 -04:00
|
|
|
|
"Toggle Footnote mode.
|
|
|
|
|
|
2016-05-31 15:05:20 -04:00
|
|
|
|
Footnote mode is a buffer-local minor mode. If enabled, it
|
2011-10-19 20:26:14 -04:00
|
|
|
|
provides footnote support for `message-mode'. To get started,
|
|
|
|
|
play around with the following keys:
|
2009-09-03 02:21:37 +00:00
|
|
|
|
\\{footnote-minor-mode-map}"
|
|
|
|
|
:lighter footnote-mode-line-string
|
|
|
|
|
:keymap footnote-minor-mode-map
|
2019-07-25 19:35:17 +02:00
|
|
|
|
(footnote--local-advice footnote-mode adaptive-fill-function
|
|
|
|
|
footnote--adaptive-fill-function)
|
|
|
|
|
(footnote--local-advice footnote-mode fill-paragraph-function
|
|
|
|
|
footnote--fill-paragraph)
|
1999-12-09 23:31:50 +00:00
|
|
|
|
(when footnote-mode
|
2017-12-25 23:27:26 -05:00
|
|
|
|
;; (footnote-setup-keybindings)
|
2007-04-15 17:25:36 +00:00
|
|
|
|
(make-local-variable 'footnote-style)
|
2008-10-06 06:29:05 +00:00
|
|
|
|
(make-local-variable 'footnote-body-tag-spacing)
|
|
|
|
|
(make-local-variable 'footnote-spaced-footnotes)
|
|
|
|
|
(make-local-variable 'footnote-section-tag)
|
|
|
|
|
(make-local-variable 'footnote-section-tag-regexp)
|
|
|
|
|
(make-local-variable 'footnote-start-tag)
|
|
|
|
|
(make-local-variable 'footnote-end-tag)
|
2017-12-22 23:06:22 -05:00
|
|
|
|
(make-local-variable 'adaptive-fill-function)
|
1999-12-09 23:31:50 +00:00
|
|
|
|
|
2019-05-15 13:00:51 -04:00
|
|
|
|
;; Filladapt was an XEmacs package which is now in GNU ELPA.
|
1999-12-09 23:31:50 +00:00
|
|
|
|
(when (boundp 'filladapt-token-table)
|
|
|
|
|
;; add tokens to filladapt to match footnotes
|
|
|
|
|
;; 1] xxxxxxxxxxx x x x or [1] x x x x x x x
|
|
|
|
|
;; xxx x xx xxx xxxx x x x xxxxxxxxxx
|
|
|
|
|
(let ((bullet-regexp (concat (regexp-quote footnote-start-tag)
|
|
|
|
|
"?[0-9a-zA-Z]+"
|
|
|
|
|
(regexp-quote footnote-end-tag)
|
|
|
|
|
"[ \t]")))
|
|
|
|
|
(unless (assoc bullet-regexp filladapt-token-table)
|
|
|
|
|
(setq filladapt-token-table
|
|
|
|
|
(append filladapt-token-table
|
2021-01-20 19:42:21 +01:00
|
|
|
|
(list (list bullet-regexp 'bullet)))))))
|
|
|
|
|
(footnote--regenerate-alist)))
|
|
|
|
|
|
|
|
|
|
(defun footnote--regenerate-alist ()
|
|
|
|
|
(save-excursion
|
|
|
|
|
(goto-char (point-min))
|
2021-01-21 12:45:24 +01:00
|
|
|
|
(when (re-search-forward footnote-section-tag-regexp nil t)
|
2021-01-20 19:42:21 +01:00
|
|
|
|
(setq footnote--markers-alist
|
|
|
|
|
(cl-loop
|
|
|
|
|
with start-of-footnotes = (match-beginning 0)
|
|
|
|
|
with regexp = (footnote--current-regexp)
|
|
|
|
|
for (note text) in
|
|
|
|
|
(cl-loop for pos = (re-search-forward regexp nil t)
|
|
|
|
|
while pos
|
|
|
|
|
collect (list (match-string 1)
|
|
|
|
|
(copy-marker (match-beginning 0) t)))
|
|
|
|
|
do (goto-char (point-min))
|
|
|
|
|
collect (cl-list*
|
|
|
|
|
(string-to-number note)
|
|
|
|
|
text
|
|
|
|
|
(cl-loop
|
|
|
|
|
for pos = (re-search-forward regexp start-of-footnotes t)
|
|
|
|
|
while pos
|
|
|
|
|
when (equal note (match-string 1))
|
|
|
|
|
collect (copy-marker (match-beginning 0) t))))))))
|
1999-12-09 23:31:50 +00:00
|
|
|
|
|
|
|
|
|
(provide 'footnote)
|
|
|
|
|
|
|
|
|
|
;;; footnote.el ends here
|