2011-05-10 08:14:42 +00:00
|
|
|
;;; footnote.el --- footnote support for message mode -*- coding: utf-8;-*-
|
1999-12-09 23:31:50 +00:00
|
|
|
|
2015-01-01 22:26:41 +00:00
|
|
|
;; Copyright (C) 1997, 2000-2015 Free Software Foundation, Inc.
|
1999-12-09 23:31:50 +00:00
|
|
|
|
|
|
|
;; Author: Steven L Baur <steve@xemacs.org>
|
|
|
|
;; Keywords: mail, news
|
|
|
|
;; Version: 0.19
|
|
|
|
|
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
|
2008-05-06 07:25:26 +00:00
|
|
|
;; along with GNU Emacs. If not, see <http://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.
|
|
|
|
|
|
|
|
;; TODO:
|
|
|
|
;; Reasonable Undo support.
|
|
|
|
;; more language styles.
|
|
|
|
|
|
|
|
;;; 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 23:13:41 +00: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."
|
2013-12-28 08:21:33 +00:00
|
|
|
:type 'string
|
1999-12-09 23:31:50 +00:00
|
|
|
:group 'footnote)
|
|
|
|
|
|
|
|
(defcustom footnote-mode-hook nil
|
2008-10-06 06:29:05 +00:00
|
|
|
"Hook functions run when footnote-mode is activated."
|
1999-12-09 23:31:50 +00:00
|
|
|
:type 'hook
|
|
|
|
:group 'footnote)
|
|
|
|
|
|
|
|
(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."
|
1999-12-09 23:31:50 +00:00
|
|
|
:type 'boolean
|
|
|
|
:group 'footnote)
|
|
|
|
|
|
|
|
(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."
|
|
|
|
:type 'boolean
|
|
|
|
:group 'footnote)
|
|
|
|
|
|
|
|
(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."
|
1999-12-09 23:31:50 +00:00
|
|
|
:type 'boolean
|
|
|
|
:group 'footnote)
|
|
|
|
|
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'."
|
1999-12-09 23:31:50 +00:00
|
|
|
:type 'boolean
|
|
|
|
:group 'footnote)
|
|
|
|
|
|
|
|
(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."
|
1999-12-09 23:31:50 +00:00
|
|
|
:type 'integer
|
|
|
|
:group 'footnote)
|
|
|
|
|
2009-09-03 02:21:37 +00:00
|
|
|
(defcustom footnote-prefix [(control ?c) ?!]
|
|
|
|
"Prefix key to use for Footnote command in Footnote minor mode.
|
|
|
|
The value of this variable is checked as part of loading Footnote mode.
|
|
|
|
After that, changing the prefix key requires manipulating keymaps."
|
2013-12-28 08:21:33 +00:00
|
|
|
:type 'key-sequence
|
|
|
|
:group 'footnote)
|
1999-12-09 23:31:50 +00:00
|
|
|
|
|
|
|
;;; Interface variables that probably shouldn't be changed
|
|
|
|
|
2004-07-17 14:31:27 +00: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."
|
2004-07-17 14:31:27 +00:00
|
|
|
:type 'string
|
|
|
|
:group 'footnote)
|
1999-12-09 23:31:50 +00:00
|
|
|
|
2000-02-23 20:25:34 +00:00
|
|
|
(defcustom footnote-section-tag-regexp "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."
|
2000-02-23 20:25:34 +00:00
|
|
|
:type 'regexp
|
|
|
|
:group 'footnote)
|
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."
|
2000-02-23 20:25:34 +00:00
|
|
|
:type 'string
|
|
|
|
:group 'footnote)
|
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."
|
2000-02-23 20:25:34 +00:00
|
|
|
:type 'string
|
|
|
|
:group 'footnote)
|
1999-12-09 23:31:50 +00:00
|
|
|
|
2012-05-04 05:14:14 +00:00
|
|
|
(defcustom footnote-signature-separator (if (boundp 'message-signature-separator)
|
|
|
|
message-signature-separator
|
|
|
|
"^-- $")
|
|
|
|
"Regexp used by Footnote mode to recognize signatures."
|
|
|
|
:type 'regexp
|
|
|
|
:group 'footnote)
|
1999-12-09 23:31:50 +00:00
|
|
|
|
|
|
|
;;; Private variables
|
|
|
|
|
|
|
|
(defvar footnote-style-number nil
|
|
|
|
"Footnote style represented as an index into footnote-style-alist.")
|
|
|
|
(make-variable-buffer-local 'footnote-style-number)
|
|
|
|
|
|
|
|
(defvar footnote-text-marker-alist nil
|
|
|
|
"List of markers pointing to text of footnotes in message buffer.")
|
|
|
|
(make-variable-buffer-local 'footnote-text-marker-alist)
|
|
|
|
|
|
|
|
(defvar footnote-pointer-marker-alist nil
|
|
|
|
"List of markers pointing to footnote pointers in message buffer.")
|
|
|
|
(make-variable-buffer-local 'footnote-pointer-marker-alist)
|
|
|
|
|
|
|
|
(defvar footnote-mouse-highlight 'highlight
|
|
|
|
"Text property name to enable mouse over highlight.")
|
|
|
|
|
|
|
|
;;; 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.")
|
|
|
|
|
|
|
|
(defun Footnote-numeric (n)
|
|
|
|
"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.")
|
|
|
|
|
|
|
|
(defun Footnote-english-upper (n)
|
|
|
|
"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.")
|
|
|
|
|
|
|
|
(defun Footnote-english-lower (n)
|
|
|
|
"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.")
|
|
|
|
|
2007-11-01 03:40:30 +00:00
|
|
|
(defconst footnote-roman-lower-regexp "[ivxlcdm]+"
|
1999-12-09 23:31:50 +00:00
|
|
|
"Regexp of roman numerals.")
|
|
|
|
|
|
|
|
(defun Footnote-roman-lower (n)
|
|
|
|
"Generic Roman number footnoting."
|
|
|
|
(Footnote-roman-common n footnote-roman-lower-list))
|
|
|
|
|
|
|
|
;;; ROMAN UPPER
|
|
|
|
(defconst footnote-roman-upper-list
|
|
|
|
'((1 . "I") (5 . "V") (10 . "X")
|
|
|
|
(50 . "L") (100 . "C") (500 . "D") (1000 . "M"))
|
|
|
|
"List of roman numerals with their values.")
|
|
|
|
|
2007-11-01 03:40:30 +00:00
|
|
|
(defconst footnote-roman-upper-regexp "[IVXLCDM]+"
|
1999-12-09 23:31:50 +00:00
|
|
|
"Regexp of roman numerals. Not complete")
|
|
|
|
|
|
|
|
(defun Footnote-roman-upper (n)
|
|
|
|
"Generic Roman number footnoting."
|
|
|
|
(Footnote-roman-common n footnote-roman-upper-list))
|
|
|
|
|
|
|
|
(defun Footnote-roman-common (n footnote-roman-list)
|
|
|
|
"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
|
|
|
|
((< n 0) (error "Footnote-roman-common called with n < 0"))
|
|
|
|
((= 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)
|
|
|
|
(Footnote-roman-common
|
|
|
|
(- n (car rom-low-pair))
|
|
|
|
footnote-roman-list)))
|
|
|
|
((>= rom-div 0) (concat (cdr rom-div-pair) (cdr rom-high-pair)
|
|
|
|
(Footnote-roman-common
|
|
|
|
(- n (- (car rom-high-pair)
|
|
|
|
(car rom-div-pair)))
|
|
|
|
footnote-roman-list)))
|
|
|
|
(t (concat (cdr rom-low-pair)
|
|
|
|
(Footnote-roman-common
|
|
|
|
(- n (car rom-low-pair))
|
|
|
|
footnote-roman-list)))))))
|
|
|
|
|
2000-02-23 20:25:34 +00:00
|
|
|
;; Latin-1
|
|
|
|
|
2011-05-10 08:14:42 +00: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.")
|
|
|
|
|
|
|
|
(defun Footnote-latin (n)
|
|
|
|
"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 08:20:21 +00:00
|
|
|
;; Unicode
|
|
|
|
|
|
|
|
(defconst footnote-unicode-string "⁰¹²³⁴⁵⁶⁷⁸⁹"
|
2011-11-20 19:35:27 +00:00
|
|
|
"String of Unicode footnoting characters.")
|
2011-05-10 08:20:21 +00:00
|
|
|
|
|
|
|
(defconst footnote-unicode-regexp (concat "[" footnote-unicode-string "]+")
|
2011-11-20 19:35:27 +00:00
|
|
|
"Regexp for Unicode footnoting characters.")
|
2011-05-10 08:20:21 +00:00
|
|
|
|
|
|
|
(defun Footnote-unicode (n)
|
|
|
|
"Unicode footnote style.
|
2011-11-20 19:35:27 +00:00
|
|
|
Use Unicode characters for footnoting."
|
2011-05-10 08:20:21 +00: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)))
|
|
|
|
|
1999-12-09 23:31:50 +00:00
|
|
|
;;; list of all footnote styles
|
|
|
|
(defvar footnote-style-alist
|
|
|
|
`((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)
|
2000-02-23 20:25:34 +00:00
|
|
|
(roman-upper Footnote-roman-upper ,footnote-roman-upper-regexp)
|
2011-05-10 08:20:21 +00:00
|
|
|
(latin Footnote-latin ,footnote-latin-regexp)
|
|
|
|
(unicode Footnote-unicode ,footnote-unicode-regexp))
|
1999-12-09 23:31:50 +00:00
|
|
|
"Styles of footnote tags available.
|
|
|
|
By default only boring Arabic numbers, English letters and Roman Numerals
|
|
|
|
are available.
|
|
|
|
See footnote-han.el, footnote-greek.el and footnote-hebrew.el for more
|
|
|
|
exciting styles.")
|
|
|
|
|
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 08:14:42 +00:00
|
|
|
latin == ¹ ² ³ º ª § ¶
|
2011-05-10 08:20:21 +00:00
|
|
|
unicode == ¹, ², ³, ...
|
2007-04-15 17:28:00 +00:00
|
|
|
See also variables `footnote-start-tag' and `footnote-end-tag'.
|
|
|
|
|
2011-05-10 08:20:21 +00: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
|
|
|
|
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)))
|
|
|
|
footnote-style-alist))
|
|
|
|
:group 'footnote)
|
|
|
|
|
1999-12-09 23:31:50 +00:00
|
|
|
;;; Style utilities & functions
|
|
|
|
(defun Footnote-style-p (style)
|
2011-11-20 19:35:27 +00:00
|
|
|
"Return non-nil if style is a valid style known to `footnote-mode'."
|
1999-12-09 23:31:50 +00:00
|
|
|
(assq style footnote-style-alist))
|
|
|
|
|
|
|
|
(defun Footnote-index-to-string (index)
|
|
|
|
"Convert a binary index into a string to display as a footnote.
|
|
|
|
Conversion is done based upon the current selected style."
|
2007-04-15 17:25:36 +00:00
|
|
|
(let ((alist (if (Footnote-style-p footnote-style)
|
|
|
|
(assq footnote-style footnote-style-alist)
|
1999-12-09 23:31:50 +00:00
|
|
|
(nth 0 footnote-style-alist))))
|
|
|
|
(funcall (nth 1 alist) index)))
|
|
|
|
|
|
|
|
(defun Footnote-current-regexp ()
|
|
|
|
"Return the regexp of the index of the current style."
|
2007-04-15 17:25:36 +00:00
|
|
|
(concat (nth 2 (or (assq footnote-style footnote-style-alist)
|
2007-12-26 23:01:34 +00:00
|
|
|
(nth 0 footnote-style-alist)))
|
|
|
|
"*"))
|
1999-12-09 23:31:50 +00:00
|
|
|
|
|
|
|
(defun Footnote-refresh-footnotes (&optional index-regexp)
|
|
|
|
"Redraw all footnotes.
|
|
|
|
You must call this or arrange to have this called after changing footnote
|
|
|
|
styles."
|
|
|
|
(unless index-regexp
|
|
|
|
(setq index-regexp (Footnote-current-regexp)))
|
|
|
|
(save-excursion
|
|
|
|
;; Take care of the pointers first
|
|
|
|
(let ((i 0) locn alist)
|
|
|
|
(while (setq alist (nth i footnote-pointer-marker-alist))
|
|
|
|
(setq locn (cdr alist))
|
|
|
|
(while locn
|
|
|
|
(goto-char (car 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.
|
|
|
|
(when (looking-back (concat
|
|
|
|
(regexp-quote footnote-start-tag)
|
|
|
|
"\\(" index-regexp "+\\)"
|
|
|
|
(regexp-quote footnote-end-tag))
|
|
|
|
(line-beginning-position))
|
|
|
|
(replace-match
|
|
|
|
(propertize
|
|
|
|
(concat
|
|
|
|
footnote-start-tag
|
|
|
|
(Footnote-index-to-string (1+ i))
|
|
|
|
footnote-end-tag)
|
|
|
|
'footnote-number (1+ i) footnote-mouse-highlight t)
|
|
|
|
nil "\\1"))
|
1999-12-09 23:31:50 +00:00
|
|
|
(setq locn (cdr locn)))
|
|
|
|
(setq i (1+ i))))
|
|
|
|
|
|
|
|
;; Now take care of the text section
|
|
|
|
(let ((i 0) alist)
|
|
|
|
(while (setq alist (nth i footnote-text-marker-alist))
|
|
|
|
(goto-char (cdr alist))
|
|
|
|
(when (looking-at (concat
|
|
|
|
(regexp-quote footnote-start-tag)
|
2007-12-26 23:01:34 +00:00
|
|
|
"\\(" index-regexp "+\\)"
|
1999-12-09 23:31:50 +00:00
|
|
|
(regexp-quote footnote-end-tag)))
|
2008-10-06 06:29:05 +00:00
|
|
|
(replace-match
|
|
|
|
(propertize
|
|
|
|
(concat
|
|
|
|
footnote-start-tag
|
|
|
|
(Footnote-index-to-string (1+ i))
|
|
|
|
footnote-end-tag)
|
|
|
|
'footnote-number (1+ i))
|
|
|
|
nil "\\1"))
|
1999-12-09 23:31:50 +00:00
|
|
|
(setq i (1+ i))))))
|
|
|
|
|
|
|
|
(defun Footnote-assoc-index (key alist)
|
|
|
|
"Give index of key in alist."
|
|
|
|
(let ((i 0) (max (length alist)) rc)
|
|
|
|
(while (and (null rc)
|
|
|
|
(< i max))
|
|
|
|
(when (eq key (car (nth i alist)))
|
|
|
|
(setq rc i))
|
|
|
|
(setq i (1+ i)))
|
|
|
|
rc))
|
|
|
|
|
|
|
|
(defun Footnote-cycle-style ()
|
|
|
|
"Select next defined footnote style."
|
|
|
|
(interactive)
|
2007-04-15 17:25:36 +00:00
|
|
|
(let ((old (Footnote-assoc-index footnote-style footnote-style-alist))
|
1999-12-09 23:31:50 +00:00
|
|
|
(max (length footnote-style-alist))
|
|
|
|
idx)
|
|
|
|
(setq idx (1+ old))
|
|
|
|
(when (>= idx max)
|
|
|
|
(setq idx 0))
|
2007-04-15 17:25:36 +00:00
|
|
|
(setq footnote-style (car (nth idx footnote-style-alist)))
|
1999-12-09 23:31:50 +00:00
|
|
|
(Footnote-refresh-footnotes (nth 2 (nth old footnote-style-alist)))))
|
|
|
|
|
|
|
|
(defun Footnote-set-style (&optional style)
|
|
|
|
"Select a specific style."
|
|
|
|
(interactive
|
|
|
|
(list (intern (completing-read
|
|
|
|
"Footnote Style: "
|
|
|
|
obarray #'Footnote-style-p 'require-match))))
|
2008-10-06 06:29:05 +00:00
|
|
|
(let ((old (Footnote-assoc-index footnote-style footnote-style-alist)))
|
|
|
|
(setq footnote-style style)
|
|
|
|
(Footnote-refresh-footnotes (nth 2 (nth old footnote-style-alist)))))
|
1999-12-09 23:31:50 +00:00
|
|
|
|
|
|
|
;; Internal functions
|
|
|
|
(defun Footnote-insert-numbered-footnote (arg &optional mousable)
|
|
|
|
"Insert numbered footnote at (point)."
|
2008-10-06 06:29:05 +00:00
|
|
|
(let ((string (concat footnote-start-tag
|
|
|
|
(Footnote-index-to-string arg)
|
|
|
|
footnote-end-tag)))
|
|
|
|
(insert-before-markers
|
|
|
|
(if mousable
|
|
|
|
(propertize
|
|
|
|
string 'footnote-number arg footnote-mouse-highlight t)
|
|
|
|
(propertize string 'footnote-number arg)))))
|
1999-12-09 23:31:50 +00:00
|
|
|
|
|
|
|
(defun Footnote-renumber (from to pointer-alist text-alist)
|
|
|
|
"Renumber a single footnote."
|
|
|
|
(let* ((posn-list (cdr pointer-alist)))
|
|
|
|
(setcar pointer-alist to)
|
|
|
|
(setcar text-alist to)
|
|
|
|
(while posn-list
|
|
|
|
(goto-char (car posn-list))
|
2008-10-06 06:29:05 +00:00
|
|
|
(when (looking-back (concat (regexp-quote footnote-start-tag)
|
|
|
|
(Footnote-current-regexp)
|
|
|
|
(regexp-quote footnote-end-tag))
|
|
|
|
(line-beginning-position))
|
|
|
|
(replace-match
|
|
|
|
(propertize
|
|
|
|
(concat footnote-start-tag
|
|
|
|
(Footnote-index-to-string to)
|
|
|
|
footnote-end-tag)
|
|
|
|
'footnote-number to footnote-mouse-highlight t)))
|
1999-12-09 23:31:50 +00:00
|
|
|
(setq posn-list (cdr posn-list)))
|
|
|
|
(goto-char (cdr text-alist))
|
2008-10-06 06:29:05 +00:00
|
|
|
(when (looking-at (concat (regexp-quote footnote-start-tag)
|
1999-12-09 23:31:50 +00:00
|
|
|
(Footnote-current-regexp)
|
|
|
|
(regexp-quote footnote-end-tag)))
|
2008-10-06 06:29:05 +00:00
|
|
|
(replace-match
|
|
|
|
(propertize
|
|
|
|
(concat footnote-start-tag
|
|
|
|
(Footnote-index-to-string to)
|
|
|
|
footnote-end-tag)
|
|
|
|
'footnote-number to)))))
|
1999-12-09 23:31:50 +00:00
|
|
|
|
|
|
|
;; Not needed?
|
|
|
|
(defun Footnote-narrow-to-footnotes ()
|
|
|
|
"Restrict text in buffer to show only text of footnotes."
|
|
|
|
(interactive) ; testing
|
|
|
|
(goto-char (point-max))
|
|
|
|
(when (re-search-backward footnote-signature-separator nil t)
|
|
|
|
(let ((end (point)))
|
2008-10-06 06:29:05 +00:00
|
|
|
(cond
|
|
|
|
((and (not (string-equal footnote-section-tag ""))
|
|
|
|
(re-search-backward
|
|
|
|
(concat "^" footnote-section-tag-regexp) nil t))
|
|
|
|
(narrow-to-region (point) end))
|
|
|
|
(footnote-text-marker-alist
|
|
|
|
(narrow-to-region (cdar footnote-text-marker-alist) end))))))
|
1999-12-09 23:31:50 +00:00
|
|
|
|
|
|
|
(defun Footnote-goto-char-point-max ()
|
|
|
|
"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)))
|
|
|
|
|
|
|
|
(defun Footnote-insert-text-marker (arg locn)
|
2008-10-06 06:29:05 +00:00
|
|
|
"Insert a marker pointing to footnote ARG, at buffer location LOCN."
|
1999-12-09 23:31:50 +00:00
|
|
|
(let ((marker (make-marker)))
|
|
|
|
(unless (assq arg footnote-text-marker-alist)
|
|
|
|
(set-marker marker locn)
|
|
|
|
(setq footnote-text-marker-alist
|
1999-12-12 16:04:25 +00:00
|
|
|
(cons (cons arg marker) footnote-text-marker-alist))
|
1999-12-09 23:31:50 +00:00
|
|
|
(setq footnote-text-marker-alist
|
|
|
|
(Footnote-sort footnote-text-marker-alist)))))
|
|
|
|
|
|
|
|
(defun Footnote-insert-pointer-marker (arg locn)
|
2008-10-06 06:29:05 +00:00
|
|
|
"Insert a marker pointing to footnote ARG, at buffer location LOCN."
|
1999-12-09 23:31:50 +00:00
|
|
|
(let ((marker (make-marker))
|
|
|
|
alist)
|
|
|
|
(set-marker marker locn)
|
|
|
|
(if (setq alist (assq arg footnote-pointer-marker-alist))
|
|
|
|
(setf alist
|
|
|
|
(cons marker (cdr alist)))
|
|
|
|
(setq footnote-pointer-marker-alist
|
1999-12-12 16:04:25 +00:00
|
|
|
(cons (cons arg (list marker)) footnote-pointer-marker-alist))
|
1999-12-09 23:31:50 +00:00
|
|
|
(setq footnote-pointer-marker-alist
|
|
|
|
(Footnote-sort footnote-pointer-marker-alist)))))
|
|
|
|
|
|
|
|
(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)
|
|
|
|
(Footnote-insert-pointer-marker arg (point))
|
|
|
|
(Footnote-insert-numbered-footnote arg t)
|
|
|
|
(Footnote-goto-char-point-max)
|
2008-10-06 06:29:05 +00:00
|
|
|
(if (cond
|
|
|
|
((not (string-equal footnote-section-tag ""))
|
|
|
|
(re-search-backward (concat "^" footnote-section-tag-regexp) nil t))
|
|
|
|
(footnote-text-marker-alist
|
|
|
|
(goto-char (cdar footnote-text-marker-alist))))
|
1999-12-09 23:31:50 +00:00
|
|
|
(save-restriction
|
2003-02-04 13:24:35 +00:00
|
|
|
(when footnote-narrow-to-footnotes-when-editing
|
1999-12-09 23:31:50 +00:00
|
|
|
(Footnote-narrow-to-footnotes))
|
|
|
|
(Footnote-goto-footnote (1- arg)) ; evil, FIXME (less evil now)
|
|
|
|
;; (message "Inserting footnote %d" arg)
|
|
|
|
(unless
|
|
|
|
(or (eq arg 1)
|
|
|
|
(when (re-search-forward
|
|
|
|
(if footnote-spaced-footnotes
|
|
|
|
"\n\n"
|
|
|
|
(concat "\n"
|
|
|
|
(regexp-quote footnote-start-tag)
|
|
|
|
(Footnote-current-regexp)
|
|
|
|
(regexp-quote footnote-end-tag)))
|
|
|
|
nil t)
|
|
|
|
(unless (beginning-of-line) t))
|
2006-12-26 20:29:26 +00:00
|
|
|
(Footnote-goto-char-point-max)
|
2008-10-06 06:29:05 +00:00
|
|
|
(cond
|
|
|
|
((not (string-equal footnote-section-tag ""))
|
|
|
|
(re-search-backward
|
|
|
|
(concat "^" footnote-section-tag-regexp) nil t))
|
|
|
|
(footnote-text-marker-alist
|
|
|
|
(goto-char (cdar footnote-text-marker-alist)))))))
|
1999-12-09 23:31:50 +00:00
|
|
|
(unless (looking-at "^$")
|
|
|
|
(insert "\n"))
|
|
|
|
(when (eobp)
|
|
|
|
(insert "\n"))
|
2008-10-06 06:29:05 +00:00
|
|
|
(unless (string-equal footnote-section-tag "")
|
|
|
|
(insert footnote-section-tag "\n")))
|
1999-12-09 23:31:50 +00:00
|
|
|
(let ((old-point (point)))
|
|
|
|
(Footnote-insert-numbered-footnote arg nil)
|
|
|
|
(Footnote-insert-text-marker arg old-point)))
|
|
|
|
|
|
|
|
(defun Footnote-sort (list)
|
|
|
|
(sort list (lambda (e1 e2)
|
|
|
|
(< (car e1) (car e2)))))
|
|
|
|
|
|
|
|
(defun Footnote-text-under-cursor ()
|
|
|
|
"Return the number of 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."
|
|
|
|
(when (and (let ((old-point (point)))
|
|
|
|
(save-excursion
|
|
|
|
(save-restriction
|
|
|
|
(Footnote-narrow-to-footnotes)
|
|
|
|
(and (>= old-point (point-min))
|
|
|
|
(<= old-point (point-max))))))
|
2009-09-04 03:09:44 +00:00
|
|
|
footnote-text-marker-alist
|
|
|
|
(>= (point) (cdar footnote-text-marker-alist)))
|
1999-12-09 23:31:50 +00:00
|
|
|
(let ((i 1)
|
|
|
|
alist-txt rc)
|
|
|
|
(while (and (setq alist-txt (nth i footnote-text-marker-alist))
|
|
|
|
(null rc))
|
|
|
|
(when (< (point) (cdr alist-txt))
|
|
|
|
(setq rc (car (nth (1- i) footnote-text-marker-alist))))
|
|
|
|
(setq i (1+ i)))
|
|
|
|
(when (and (null rc)
|
|
|
|
(null alist-txt))
|
|
|
|
(setq rc (car (nth (1- i) footnote-text-marker-alist))))
|
|
|
|
rc)))
|
|
|
|
|
|
|
|
(defun Footnote-under-cursor ()
|
|
|
|
"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)
|
|
|
|
(Footnote-text-under-cursor)))
|
|
|
|
|
|
|
|
;;; User functions
|
|
|
|
|
|
|
|
(defun Footnote-make-hole ()
|
|
|
|
(save-excursion
|
|
|
|
(let ((i 0)
|
|
|
|
(notes (length footnote-pointer-marker-alist))
|
|
|
|
alist-ptr alist-txt rc)
|
|
|
|
(while (< i notes)
|
|
|
|
(setq alist-ptr (nth i footnote-pointer-marker-alist))
|
|
|
|
(setq alist-txt (nth i footnote-text-marker-alist))
|
|
|
|
(when (< (point) (- (cadr alist-ptr) 3))
|
|
|
|
(unless rc
|
|
|
|
(setq rc (car alist-ptr)))
|
|
|
|
(save-excursion
|
2003-02-04 13:24:35 +00:00
|
|
|
(message "Renumbering from %s to %s"
|
1999-12-09 23:31:50 +00:00
|
|
|
(Footnote-index-to-string (car alist-ptr))
|
2003-02-04 13:24:35 +00:00
|
|
|
(Footnote-index-to-string
|
1999-12-09 23:31:50 +00:00
|
|
|
(1+ (car alist-ptr))))
|
|
|
|
(Footnote-renumber (car alist-ptr)
|
|
|
|
(1+ (car alist-ptr))
|
|
|
|
alist-ptr
|
|
|
|
alist-txt)))
|
|
|
|
(setq i (1+ i)))
|
|
|
|
rc)))
|
|
|
|
|
|
|
|
(defun Footnote-add-footnote (&optional arg)
|
|
|
|
"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
|
|
|
|
by using `Footnote-back-to-message'."
|
|
|
|
(interactive "*P")
|
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 23:13:41 +00:00
|
|
|
(let ((num
|
|
|
|
(if footnote-text-marker-alist
|
2015-04-10 05:50:22 +00:00
|
|
|
(if (< (point) (cl-cadar (last footnote-pointer-marker-alist)))
|
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 23:13:41 +00:00
|
|
|
(Footnote-make-hole)
|
|
|
|
(1+ (caar (last footnote-text-marker-alist))))
|
|
|
|
1)))
|
1999-12-09 23:31:50 +00:00
|
|
|
(message "Adding footnote %d" num)
|
|
|
|
(Footnote-insert-footnote num)
|
|
|
|
(insert-before-markers (make-string footnote-body-tag-spacing ? ))
|
|
|
|
(let ((opoint (point)))
|
|
|
|
(save-excursion
|
|
|
|
(insert-before-markers
|
|
|
|
(if footnote-spaced-footnotes
|
|
|
|
"\n\n"
|
|
|
|
"\n"))
|
|
|
|
(when footnote-narrow-to-footnotes-when-editing
|
|
|
|
(Footnote-narrow-to-footnotes)))
|
|
|
|
;; Emacs/XEmacs bug? save-excursion doesn't restore point when using
|
|
|
|
;; insert-before-markers.
|
|
|
|
(goto-char opoint))))
|
|
|
|
|
|
|
|
(defun Footnote-delete-footnote (&optional arg)
|
|
|
|
"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
|
|
|
|
(setq arg (Footnote-under-cursor)))
|
|
|
|
(when (and arg
|
|
|
|
(or (not footnote-prompt-before-deletion)
|
|
|
|
(y-or-n-p (format "Really delete footnote %d?" arg))))
|
|
|
|
(let (alist-ptr alist-txt locn)
|
|
|
|
(setq alist-ptr (assq arg footnote-pointer-marker-alist))
|
|
|
|
(setq alist-txt (assq arg footnote-text-marker-alist))
|
|
|
|
(unless (and alist-ptr alist-txt)
|
|
|
|
(error "Can't delete footnote %d" arg))
|
|
|
|
(setq locn (cdr alist-ptr))
|
|
|
|
(while (car locn)
|
|
|
|
(save-excursion
|
|
|
|
(goto-char (car locn))
|
2008-10-06 06:29:05 +00:00
|
|
|
(when (looking-back (concat (regexp-quote footnote-start-tag)
|
|
|
|
(Footnote-current-regexp)
|
|
|
|
(regexp-quote footnote-end-tag))
|
|
|
|
(line-beginning-position))
|
|
|
|
(delete-region (match-beginning 0) (match-end 0))))
|
1999-12-09 23:31:50 +00:00
|
|
|
(setq locn (cdr locn)))
|
|
|
|
(save-excursion
|
|
|
|
(goto-char (cdr alist-txt))
|
2008-10-06 06:29:05 +00:00
|
|
|
(delete-region
|
|
|
|
(point)
|
|
|
|
(if footnote-spaced-footnotes
|
|
|
|
(search-forward "\n\n" nil t)
|
|
|
|
(save-restriction
|
|
|
|
(end-of-line)
|
|
|
|
(next-single-char-property-change
|
|
|
|
(point) 'footnote-number nil (Footnote-goto-char-point-max))))))
|
1999-12-09 23:31:50 +00:00
|
|
|
(setq footnote-pointer-marker-alist
|
|
|
|
(delq alist-ptr footnote-pointer-marker-alist))
|
|
|
|
(setq footnote-text-marker-alist
|
|
|
|
(delq alist-txt footnote-text-marker-alist))
|
|
|
|
(Footnote-renumber-footnotes)
|
|
|
|
(when (and (null footnote-text-marker-alist)
|
|
|
|
(null footnote-pointer-marker-alist))
|
|
|
|
(save-excursion
|
2008-10-06 06:29:05 +00:00
|
|
|
(if (not (string-equal footnote-section-tag ""))
|
|
|
|
(let* ((end (Footnote-goto-char-point-max))
|
|
|
|
(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))))
|
|
|
|
(Footnote-goto-char-point-max)
|
2015-04-21 01:55:00 +00: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
|
|
|
|
|
|
|
(defun Footnote-renumber-footnotes (&optional arg)
|
|
|
|
"Renumber footnotes, starting from 1."
|
|
|
|
(interactive "*P")
|
|
|
|
(save-excursion
|
|
|
|
(let ((i 0)
|
|
|
|
(notes (length footnote-pointer-marker-alist))
|
|
|
|
alist-ptr alist-txt)
|
|
|
|
(while (< i notes)
|
|
|
|
(setq alist-ptr (nth i footnote-pointer-marker-alist))
|
|
|
|
(setq alist-txt (nth i footnote-text-marker-alist))
|
2007-04-13 05:53:27 +00:00
|
|
|
(unless (= (1+ i) (car alist-ptr))
|
1999-12-09 23:31:50 +00:00
|
|
|
(Footnote-renumber (car alist-ptr) (1+ i) alist-ptr alist-txt))
|
|
|
|
(setq i (1+ i))))))
|
|
|
|
|
|
|
|
(defun Footnote-goto-footnote (&optional arg)
|
|
|
|
"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
|
|
|
|
(setq arg (Footnote-under-cursor)))
|
|
|
|
(let ((footnote (assq arg footnote-text-marker-alist)))
|
|
|
|
(cond
|
|
|
|
(footnote
|
|
|
|
(goto-char (cdr footnote)))
|
|
|
|
((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))
|
|
|
|
(footnote-text-marker-alist
|
|
|
|
(goto-char (cdar footnote-text-marker-alist)))))
|
|
|
|
(t
|
|
|
|
(error "I don't see a footnote here")))))
|
1999-12-09 23:31:50 +00:00
|
|
|
|
|
|
|
(defun Footnote-back-to-message (&optional arg)
|
|
|
|
"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."
|
|
|
|
(interactive "P")
|
|
|
|
(let ((note (Footnote-text-under-cursor)))
|
|
|
|
(when note
|
|
|
|
(when footnote-narrow-to-footnotes-when-editing
|
|
|
|
(widen))
|
|
|
|
(goto-char (cadr (assq note footnote-pointer-marker-alist))))))
|
|
|
|
|
2009-09-03 02:21:37 +00:00
|
|
|
(defvar footnote-mode-map
|
|
|
|
(let ((map (make-sparse-keymap)))
|
|
|
|
(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)
|
|
|
|
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.")
|
|
|
|
|
|
|
|
;;;###autoload
|
2009-09-03 02:21:37 +00:00
|
|
|
(define-minor-mode footnote-mode
|
2011-10-20 00:26:14 +00:00
|
|
|
"Toggle Footnote mode.
|
|
|
|
With a prefix argument ARG, enable Footnote mode if ARG is
|
|
|
|
positive, and disable it otherwise. If called from Lisp, enable
|
|
|
|
the mode if ARG is omitted or nil.
|
|
|
|
|
|
|
|
Footnode mode is a buffer-local minor mode. If enabled, it
|
|
|
|
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
|
1999-12-09 23:31:50 +00:00
|
|
|
;; (filladapt-mode t)
|
|
|
|
(when footnote-mode
|
|
|
|
;; (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)
|
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
|
2009-09-03 02:21:37 +00:00
|
|
|
(list (list bullet-regexp 'bullet)))))))))
|
1999-12-09 23:31:50 +00:00
|
|
|
|
|
|
|
(provide 'footnote)
|
|
|
|
|
|
|
|
;;; footnote.el ends here
|