annotate lisp/mail/footnote.el @ 61901:787052160d87

(do_autoload): Record only autoloads in the autoload property of symbols.
author Lute Kamstra <lute@gnu.org>
date Thu, 28 Apr 2005 08:38:35 +0000
parents aac0a33f5772
children e055d02d8b97 3ebd9bdb4fe5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38436
b174db545cfd Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 27830
diff changeset
1 ;;; footnote.el --- footnote support for message mode -*- coding: iso-latin-1;-*-
26784
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
2
27830
99b1d31f039b (footnote): Add :version to defgroup.
Dave Love <fx@gnu.org>
parents: 26815
diff changeset
3 ;; Copyright (C) 1997, 2000 by Free Software Foundation, Inc.
26784
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
4
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
5 ;; Author: Steven L Baur <steve@xemacs.org>
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
6 ;; Keywords: mail, news
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
7 ;; Version: 0.19
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
8
26815
9fa9fd18d083 Require cl when compiling. Don't autoload kemap and minor-mode-alist
Dave Love <fx@gnu.org>
parents: 26784
diff changeset
9 ;; This file is part of GNU Emacs.
26784
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
10
26815
9fa9fd18d083 Require cl when compiling. Don't autoload kemap and minor-mode-alist
Dave Love <fx@gnu.org>
parents: 26784
diff changeset
11 ;; GNU Emacs is free software; you can redistribute it and/or modify it
26784
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
12 ;; under the terms of the GNU General Public License as published by
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
14 ;; any later version.
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
15
26815
9fa9fd18d083 Require cl when compiling. Don't autoload kemap and minor-mode-alist
Dave Love <fx@gnu.org>
parents: 26784
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful, but
26784
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
19 ;; General Public License for more details.
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
20
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
26815
9fa9fd18d083 Require cl when compiling. Don't autoload kemap and minor-mode-alist
Dave Love <fx@gnu.org>
parents: 26784
diff changeset
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the Free
26784
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
23 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
24 ;; 02111-1307, USA.
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
25
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
26 ;;; Commentary:
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
27
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
28 ;; This file provides footnote[1] support for message-mode in emacsen.
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
29 ;; footnote-mode is implemented as a minor mode.
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
30
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
31 ;; [1] Footnotes look something like this. Along with some decorative
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
32 ;; stuff.
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
33
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
34 ;; TODO:
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
35 ;; Reasonable Undo support.
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
36 ;; more language styles.
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
37
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
38 ;;; Code:
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
39
26815
9fa9fd18d083 Require cl when compiling. Don't autoload kemap and minor-mode-alist
Dave Love <fx@gnu.org>
parents: 26784
diff changeset
40 (eval-when-compile
9fa9fd18d083 Require cl when compiling. Don't autoload kemap and minor-mode-alist
Dave Love <fx@gnu.org>
parents: 26784
diff changeset
41 (require 'cl)
9fa9fd18d083 Require cl when compiling. Don't autoload kemap and minor-mode-alist
Dave Love <fx@gnu.org>
parents: 26784
diff changeset
42 (defvar filladapt-token-table))
9fa9fd18d083 Require cl when compiling. Don't autoload kemap and minor-mode-alist
Dave Love <fx@gnu.org>
parents: 26784
diff changeset
43
26784
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
44 (defgroup footnote nil
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
45 "Support for footnotes in mail and news messages."
27830
99b1d31f039b (footnote): Add :version to defgroup.
Dave Love <fx@gnu.org>
parents: 26815
diff changeset
46 :version "21.1"
26784
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
47 :group 'message)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
48
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
49 (defcustom footnote-mode-line-string " FN"
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
50 "*String to display in modes section of the mode-line."
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
51 :group 'footnote)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
52
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
53 (defcustom footnote-mode-hook nil
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
54 "*Hook functions run when footnote-mode is activated."
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
55 :type 'hook
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
56 :group 'footnote)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
57
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
58 (defcustom footnote-narrow-to-footnotes-when-editing nil
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
59 "*If set, narrow to footnote text body while editing a footnote."
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
60 :type 'boolean
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
61 :group 'footnote)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
62
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
63 (defcustom footnote-prompt-before-deletion t
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
64 "*If set, prompt before deleting a footnote.
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
65 There is currently no way to undo deletions."
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
66 :type 'boolean
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
67 :group 'footnote)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
68
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
69 (defcustom footnote-spaced-footnotes t
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
70 "If set true it will put a blank line between each footnote.
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
71 If nil, no blank line will be inserted."
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
72 :type 'boolean
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
73 :group 'footnote)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
74
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
75 (defcustom footnote-use-message-mode t
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
76 "*If non-nil assume Footnoting will be done in message-mode."
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
77 :type 'boolean
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
78 :group 'footnote)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
79
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
80 (defcustom footnote-body-tag-spacing 2
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
81 "*Number of blanks separating a footnote body tag and its text."
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
82 :type 'integer
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
83 :group 'footnote)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
84
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
85 (defvar footnote-prefix [(control ?c) ?!]
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
86 "*When not using message mode, the prefix to bind in `mode-specific-map'")
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
87
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
88 ;;; Interface variables that probably shouldn't be changed
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
89
56448
b56847dec7b7 (footnote-section-tag): Use defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
90 (defcustom footnote-section-tag "Footnotes: "
b56847dec7b7 (footnote-section-tag): Use defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
91 "*Tag inserted at beginning of footnote section."
59996
aac0a33f5772 Change release version from 21.4 to 22.1 throughout.
Kim F. Storm <storm@cua.dk>
parents: 56448
diff changeset
92 :version "22.1"
56448
b56847dec7b7 (footnote-section-tag): Use defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
93 :type 'string
b56847dec7b7 (footnote-section-tag): Use defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
94 :group 'footnote)
26784
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
95
27830
99b1d31f039b (footnote): Add :version to defgroup.
Dave Love <fx@gnu.org>
parents: 26815
diff changeset
96 (defcustom footnote-section-tag-regexp "Footnotes\\(\\[.\\]\\)?: "
99b1d31f039b (footnote): Add :version to defgroup.
Dave Love <fx@gnu.org>
parents: 26815
diff changeset
97 "*Regexp which indicates the start of a footnote section.
99b1d31f039b (footnote): Add :version to defgroup.
Dave Love <fx@gnu.org>
parents: 26815
diff changeset
98 See also `footnote-section-tag'."
99b1d31f039b (footnote): Add :version to defgroup.
Dave Love <fx@gnu.org>
parents: 26815
diff changeset
99 :type 'regexp
99b1d31f039b (footnote): Add :version to defgroup.
Dave Love <fx@gnu.org>
parents: 26815
diff changeset
100 :group 'footnote)
26784
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
101
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
102 ;; The following three should be consumed by footnote styles.
27830
99b1d31f039b (footnote): Add :version to defgroup.
Dave Love <fx@gnu.org>
parents: 26815
diff changeset
103 (defcustom footnote-start-tag "["
99b1d31f039b (footnote): Add :version to defgroup.
Dave Love <fx@gnu.org>
parents: 26815
diff changeset
104 "*String used to denote start of numbered footnote."
99b1d31f039b (footnote): Add :version to defgroup.
Dave Love <fx@gnu.org>
parents: 26815
diff changeset
105 :type 'string
99b1d31f039b (footnote): Add :version to defgroup.
Dave Love <fx@gnu.org>
parents: 26815
diff changeset
106 :group 'footnote)
26784
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
107
27830
99b1d31f039b (footnote): Add :version to defgroup.
Dave Love <fx@gnu.org>
parents: 26815
diff changeset
108 (defcustom footnote-end-tag "]"
99b1d31f039b (footnote): Add :version to defgroup.
Dave Love <fx@gnu.org>
parents: 26815
diff changeset
109 "*String used to denote end of numbered footnote."
99b1d31f039b (footnote): Add :version to defgroup.
Dave Love <fx@gnu.org>
parents: 26815
diff changeset
110 :type 'string
99b1d31f039b (footnote): Add :version to defgroup.
Dave Love <fx@gnu.org>
parents: 26815
diff changeset
111 :group 'footnote)
26784
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
112
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
113 (defvar footnote-signature-separator (if (boundp 'message-signature-separator)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
114 message-signature-separator
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
115 "^-- $")
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
116 "*String used to recognize .signatures.")
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
117
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
118 ;;; Private variables
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
119
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
120 (defvar footnote-style-number nil
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
121 "Footnote style represented as an index into footnote-style-alist.")
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
122 (make-variable-buffer-local 'footnote-style-number)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
123
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
124 (defvar footnote-text-marker-alist nil
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
125 "List of markers pointing to text of footnotes in message buffer.")
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
126 (make-variable-buffer-local 'footnote-text-marker-alist)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
127
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
128 (defvar footnote-pointer-marker-alist nil
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
129 "List of markers pointing to footnote pointers in message buffer.")
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
130 (make-variable-buffer-local 'footnote-pointer-marker-alist)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
131
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
132 (defvar footnote-mouse-highlight 'highlight
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
133 "Text property name to enable mouse over highlight.")
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
134
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
135 (defvar footnote-mode nil
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
136 "Variable indicating whether footnote minor mode is active.")
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
137 (make-variable-buffer-local 'footnote-mode)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
138
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
139 ;;; Default styles
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
140 ;;; NUMERIC
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
141 (defconst footnote-numeric-regexp "[0-9]"
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
142 "Regexp for digits.")
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
143
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
144 (defun Footnote-numeric (n)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
145 "Numeric footnote style.
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
146 Use Arabic numerals for footnoting."
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
147 (int-to-string n))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
148
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
149 ;;; ENGLISH UPPER
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
150 (defconst footnote-english-upper "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
151 "Upper case English alphabet.")
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
152
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
153 (defconst footnote-english-upper-regexp "[A-Z]"
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
154 "Regexp for upper case English alphabet.")
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
155
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
156 (defun Footnote-english-upper (n)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
157 "Upper case English footnoting.
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
158 Wrapping around the alphabet implies successive repetitions of letters."
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
159 (let* ((ltr (mod (1- n) (length footnote-english-upper)))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
160 (rep (/ (1- n) (length footnote-english-upper)))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
161 (chr (char-to-string (aref footnote-english-upper ltr)))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
162 rc)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
163 (while (>= rep 0)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
164 (setq rc (concat rc chr))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
165 (setq rep (1- rep)))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
166 rc))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 42205
diff changeset
167
26784
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
168 ;;; ENGLISH LOWER
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
169 (defconst footnote-english-lower "abcdefghijklmnopqrstuvwxyz"
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
170 "Lower case English alphabet.")
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
171
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
172 (defconst footnote-english-lower-regexp "[a-z]"
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
173 "Regexp of lower case English alphabet.")
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
174
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
175 (defun Footnote-english-lower (n)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
176 "Lower case English footnoting.
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
177 Wrapping around the alphabet implies successive repetitions of letters."
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
178 (let* ((ltr (mod (1- n) (length footnote-english-lower)))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
179 (rep (/ (1- n) (length footnote-english-lower)))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
180 (chr (char-to-string (aref footnote-english-lower ltr)))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
181 rc)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
182 (while (>= rep 0)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
183 (setq rc (concat rc chr))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
184 (setq rep (1- rep)))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
185 rc))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
186
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
187 ;;; ROMAN LOWER
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
188 (defconst footnote-roman-lower-list
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
189 '((1 . "i") (5 . "v") (10 . "x")
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
190 (50 . "l") (100 . "c") (500 . "d") (1000 . "m"))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
191 "List of roman numerals with their values.")
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
192
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
193 (defconst footnote-roman-lower-regexp "[ivxlcdm]"
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
194 "Regexp of roman numerals.")
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
195
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
196 (defun Footnote-roman-lower (n)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
197 "Generic Roman number footnoting."
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
198 (Footnote-roman-common n footnote-roman-lower-list))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
199
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
200 ;;; ROMAN UPPER
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
201 (defconst footnote-roman-upper-list
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
202 '((1 . "I") (5 . "V") (10 . "X")
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
203 (50 . "L") (100 . "C") (500 . "D") (1000 . "M"))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
204 "List of roman numerals with their values.")
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
205
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
206 (defconst footnote-roman-upper-regexp "[IVXLCDM]"
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
207 "Regexp of roman numerals. Not complete")
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
208
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
209 (defun Footnote-roman-upper (n)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
210 "Generic Roman number footnoting."
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
211 (Footnote-roman-common n footnote-roman-upper-list))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
212
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
213 (defun Footnote-roman-common (n footnote-roman-list)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
214 "Lower case Roman footnoting."
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
215 (let* ((our-list footnote-roman-list)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
216 (rom-lngth (length our-list))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
217 (rom-high 0)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
218 (rom-low 0)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
219 (rom-div -1)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
220 (count-high 0)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
221 (count-low 0))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
222 ;; find surrounding numbers
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
223 (while (and (<= count-high (1- rom-lngth))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
224 (>= n (car (nth count-high our-list))))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
225 ;; (message "Checking %d" (car (nth count-high our-list)))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
226 (setq count-high (1+ count-high)))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
227 (setq rom-high count-high)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
228 (setq rom-low (1- count-high))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
229 ;; find the appropriate divisor (if it exists)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
230 (while (and (= rom-div -1)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
231 (< count-low rom-high))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
232 (when (or (> n (- (car (nth rom-high our-list))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
233 (/ (car (nth count-low our-list))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
234 2)))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
235 (= n (- (car (nth rom-high our-list))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
236 (car (nth count-low our-list)))))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
237 (setq rom-div count-low))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
238 ;; (message "Checking %d and %d in div loop" rom-high count-low)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
239 (setq count-low (1+ count-low)))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
240 ;;(message "We now have high: %d, low: %d, div: %d, n: %d"
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
241 ;; rom-high rom-low (if rom-div rom-div -1) n)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
242 (let ((rom-low-pair (nth rom-low our-list))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
243 (rom-high-pair (nth rom-high our-list))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
244 (rom-div-pair (if (not (= rom-div -1)) (nth rom-div our-list) nil)))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
245 ;; (message "pairs are: rom-low: %S, rom-high: %S, rom-div: %S"
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
246 ;; rom-low-pair rom-high-pair rom-div-pair)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
247 (cond
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
248 ((< n 0) (error "Footnote-roman-common called with n < 0"))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
249 ((= n 0) "")
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
250 ((= n (car rom-low-pair)) (cdr rom-low-pair))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
251 ((= n (car rom-high-pair)) (cdr rom-high-pair))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
252 ((= (car rom-low-pair) (car rom-high-pair))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
253 (concat (cdr rom-low-pair)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
254 (Footnote-roman-common
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
255 (- n (car rom-low-pair))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
256 footnote-roman-list)))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
257 ((>= rom-div 0) (concat (cdr rom-div-pair) (cdr rom-high-pair)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
258 (Footnote-roman-common
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
259 (- n (- (car rom-high-pair)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
260 (car rom-div-pair)))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
261 footnote-roman-list)))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
262 (t (concat (cdr rom-low-pair)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
263 (Footnote-roman-common
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
264 (- n (car rom-low-pair))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
265 footnote-roman-list)))))))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
266
27830
99b1d31f039b (footnote): Add :version to defgroup.
Dave Love <fx@gnu.org>
parents: 26815
diff changeset
267 ;; Latin-1
99b1d31f039b (footnote): Add :version to defgroup.
Dave Love <fx@gnu.org>
parents: 26815
diff changeset
268
99b1d31f039b (footnote): Add :version to defgroup.
Dave Love <fx@gnu.org>
parents: 26815
diff changeset
269 (defconst footnote-latin-regexp "¹²³ºª§¶"
99b1d31f039b (footnote): Add :version to defgroup.
Dave Love <fx@gnu.org>
parents: 26815
diff changeset
270 "Regexp for Latin-1 footnoting characters.")
99b1d31f039b (footnote): Add :version to defgroup.
Dave Love <fx@gnu.org>
parents: 26815
diff changeset
271
99b1d31f039b (footnote): Add :version to defgroup.
Dave Love <fx@gnu.org>
parents: 26815
diff changeset
272 (defun Footnote-latin (n)
99b1d31f039b (footnote): Add :version to defgroup.
Dave Love <fx@gnu.org>
parents: 26815
diff changeset
273 "Latin-1 footnote style.
99b1d31f039b (footnote): Add :version to defgroup.
Dave Love <fx@gnu.org>
parents: 26815
diff changeset
274 Use a range of Latin-1 non-ASCII characters for footnoting."
99b1d31f039b (footnote): Add :version to defgroup.
Dave Love <fx@gnu.org>
parents: 26815
diff changeset
275 (string (aref footnote-latin-regexp
99b1d31f039b (footnote): Add :version to defgroup.
Dave Love <fx@gnu.org>
parents: 26815
diff changeset
276 (mod (1- n) (length footnote-latin-regexp)))))
99b1d31f039b (footnote): Add :version to defgroup.
Dave Love <fx@gnu.org>
parents: 26815
diff changeset
277
26784
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
278 ;;; list of all footnote styles
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
279 (defvar footnote-style-alist
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
280 `((numeric Footnote-numeric ,footnote-numeric-regexp)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
281 (english-lower Footnote-english-lower ,footnote-english-lower-regexp)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
282 (english-upper Footnote-english-upper ,footnote-english-upper-regexp)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
283 (roman-lower Footnote-roman-lower ,footnote-roman-lower-regexp)
27830
99b1d31f039b (footnote): Add :version to defgroup.
Dave Love <fx@gnu.org>
parents: 26815
diff changeset
284 (roman-upper Footnote-roman-upper ,footnote-roman-upper-regexp)
99b1d31f039b (footnote): Add :version to defgroup.
Dave Love <fx@gnu.org>
parents: 26815
diff changeset
285 (latin Footnote-latin ,footnote-latin-regexp))
26784
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
286 "Styles of footnote tags available.
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
287 By default only boring Arabic numbers, English letters and Roman Numerals
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
288 are available.
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
289 See footnote-han.el, footnote-greek.el and footnote-hebrew.el for more
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
290 exciting styles.")
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
291
27830
99b1d31f039b (footnote): Add :version to defgroup.
Dave Love <fx@gnu.org>
parents: 26815
diff changeset
292 (defcustom footnote-style 'numeric
99b1d31f039b (footnote): Add :version to defgroup.
Dave Love <fx@gnu.org>
parents: 26815
diff changeset
293 "*Style used for footnoting.
99b1d31f039b (footnote): Add :version to defgroup.
Dave Love <fx@gnu.org>
parents: 26815
diff changeset
294 numeric == 1, 2, 3, ...
99b1d31f039b (footnote): Add :version to defgroup.
Dave Love <fx@gnu.org>
parents: 26815
diff changeset
295 english-lower == a, b, c, ...
99b1d31f039b (footnote): Add :version to defgroup.
Dave Love <fx@gnu.org>
parents: 26815
diff changeset
296 english-upper == A, B, C, ...
99b1d31f039b (footnote): Add :version to defgroup.
Dave Love <fx@gnu.org>
parents: 26815
diff changeset
297 roman-lower == i, ii, iii, iv, v, ...
99b1d31f039b (footnote): Add :version to defgroup.
Dave Love <fx@gnu.org>
parents: 26815
diff changeset
298 roman-upper == I, II, III, IV, V, ...
99b1d31f039b (footnote): Add :version to defgroup.
Dave Love <fx@gnu.org>
parents: 26815
diff changeset
299 latin == ¹ ² ³ º ª § ¶
99b1d31f039b (footnote): Add :version to defgroup.
Dave Love <fx@gnu.org>
parents: 26815
diff changeset
300 See also variables `footnote-start-tag' and `footnote-end-tag'."
99b1d31f039b (footnote): Add :version to defgroup.
Dave Love <fx@gnu.org>
parents: 26815
diff changeset
301 :type (cons 'choice (mapcar (lambda (x) (list 'const (car x)))
99b1d31f039b (footnote): Add :version to defgroup.
Dave Love <fx@gnu.org>
parents: 26815
diff changeset
302 footnote-style-alist))
99b1d31f039b (footnote): Add :version to defgroup.
Dave Love <fx@gnu.org>
parents: 26815
diff changeset
303 :group 'footnote)
99b1d31f039b (footnote): Add :version to defgroup.
Dave Love <fx@gnu.org>
parents: 26815
diff changeset
304
26784
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
305 ;;; Style utilities & functions
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
306 (defun Footnote-style-p (style)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
307 "Return non-nil if style is a valid style known to footnote-mode."
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
308 (assq style footnote-style-alist))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
309
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
310 (defun Footnote-index-to-string (index)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
311 "Convert a binary index into a string to display as a footnote.
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
312 Conversion is done based upon the current selected style."
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
313 (let ((alist (if (Footnote-style-p footnote-style)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
314 (assq footnote-style footnote-style-alist)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
315 (nth 0 footnote-style-alist))))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
316 (funcall (nth 1 alist) index)))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
317
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
318 (defun Footnote-current-regexp ()
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
319 "Return the regexp of the index of the current style."
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
320 (concat (nth 2 (or (assq footnote-style footnote-style-alist)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
321 (nth 0 footnote-style-alist))) "*"))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
322
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
323 (defun Footnote-refresh-footnotes (&optional index-regexp)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
324 "Redraw all footnotes.
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
325 You must call this or arrange to have this called after changing footnote
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
326 styles."
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
327 (unless index-regexp
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
328 (setq index-regexp (Footnote-current-regexp)))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
329 (save-excursion
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
330 ;; Take care of the pointers first
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
331 (let ((i 0) locn alist)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
332 (while (setq alist (nth i footnote-pointer-marker-alist))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
333 (setq locn (cdr alist))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
334 (while locn
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
335 (goto-char (car locn))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
336 (search-backward footnote-start-tag nil t)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
337 (when (looking-at (concat
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
338 (regexp-quote footnote-start-tag)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
339 "\\(" index-regexp "\\)"
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
340 (regexp-quote footnote-end-tag)))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
341 (replace-match (concat
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
342 footnote-start-tag
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
343 (Footnote-index-to-string (1+ i))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
344 footnote-end-tag)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
345 nil "\\1"))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
346 (setq locn (cdr locn)))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
347 (setq i (1+ i))))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
348
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
349 ;; Now take care of the text section
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
350 (let ((i 0) alist)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
351 (while (setq alist (nth i footnote-text-marker-alist))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
352 (goto-char (cdr alist))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
353 (when (looking-at (concat
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
354 (regexp-quote footnote-start-tag)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
355 "\\(" index-regexp "\\)"
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
356 (regexp-quote footnote-end-tag)))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
357 (replace-match (concat
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
358 footnote-start-tag
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
359 (Footnote-index-to-string (1+ i))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
360 footnote-end-tag)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
361 nil "\\1"))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
362 (setq i (1+ i))))))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
363
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
364 (defun Footnote-assoc-index (key alist)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
365 "Give index of key in alist."
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
366 (let ((i 0) (max (length alist)) rc)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
367 (while (and (null rc)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
368 (< i max))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
369 (when (eq key (car (nth i alist)))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
370 (setq rc i))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
371 (setq i (1+ i)))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
372 rc))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
373
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
374 (defun Footnote-cycle-style ()
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
375 "Select next defined footnote style."
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
376 (interactive)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
377 (let ((old (Footnote-assoc-index footnote-style footnote-style-alist))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
378 (max (length footnote-style-alist))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
379 idx)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
380 (setq idx (1+ old))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
381 (when (>= idx max)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
382 (setq idx 0))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
383 (setq footnote-style (car (nth idx footnote-style-alist)))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
384 (Footnote-refresh-footnotes (nth 2 (nth old footnote-style-alist)))))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
385
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
386 (defun Footnote-set-style (&optional style)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
387 "Select a specific style."
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
388 (interactive
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
389 (list (intern (completing-read
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
390 "Footnote Style: "
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
391 obarray #'Footnote-style-p 'require-match))))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
392 (setq footnote-style style))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
393
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
394 ;; Internal functions
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
395 (defun Footnote-insert-numbered-footnote (arg &optional mousable)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
396 "Insert numbered footnote at (point)."
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
397 (let* ((start (point))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
398 (end (progn
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
399 (insert-before-markers (concat footnote-start-tag
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
400 (Footnote-index-to-string arg)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
401 footnote-end-tag))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
402 (point))))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
403
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
404 (add-text-properties start end
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
405 (list 'footnote-number arg))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
406 (when mousable
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
407 (add-text-properties start end
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
408 (list footnote-mouse-highlight t)))))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
409
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
410 (defun Footnote-renumber (from to pointer-alist text-alist)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
411 "Renumber a single footnote."
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
412 (let* ((posn-list (cdr pointer-alist)))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
413 (setcar pointer-alist to)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
414 (setcar text-alist to)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
415 (while posn-list
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
416 (goto-char (car posn-list))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
417 (search-backward footnote-start-tag nil t)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
418 (when (looking-at (format "%s%s%s"
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
419 (regexp-quote footnote-start-tag)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
420 (Footnote-current-regexp)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
421 (regexp-quote footnote-end-tag)))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
422 (add-text-properties (match-beginning 0) (match-end 0)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
423 (list 'footnote-number to))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
424 (replace-match (format "%s%s%s"
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
425 footnote-start-tag
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
426 (Footnote-index-to-string to)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
427 footnote-end-tag)))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
428 (setq posn-list (cdr posn-list)))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
429 (goto-char (cdr text-alist))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
430 (when (looking-at (format "%s%s%s"
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
431 (regexp-quote footnote-start-tag)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
432 (Footnote-current-regexp)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
433 (regexp-quote footnote-end-tag)))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
434 (add-text-properties (match-beginning 0) (match-end 0)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
435 (list 'footnote-number to))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
436 (replace-match (format "%s%s%s"
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
437 footnote-start-tag
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
438 (Footnote-index-to-string to)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
439 footnote-end-tag) nil t))))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
440
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
441 ;; Not needed?
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
442 (defun Footnote-narrow-to-footnotes ()
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
443 "Restrict text in buffer to show only text of footnotes."
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
444 (interactive) ; testing
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
445 (goto-char (point-max))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
446 (when (re-search-backward footnote-signature-separator nil t)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
447 (let ((end (point)))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
448 (when (re-search-backward (concat "^" footnote-section-tag-regexp) nil t)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
449 (narrow-to-region (point) end)))))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
450
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
451 (defun Footnote-goto-char-point-max ()
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
452 "Move to end of buffer or prior to start of .signature."
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
453 (goto-char (point-max))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
454 (or (re-search-backward footnote-signature-separator nil t)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
455 (point)))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
456
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
457 (defun Footnote-insert-text-marker (arg locn)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
458 "Insert a marker pointing to footnote arg, at buffer location locn."
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
459 (let ((marker (make-marker)))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
460 (unless (assq arg footnote-text-marker-alist)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
461 (set-marker marker locn)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
462 (setq footnote-text-marker-alist
26815
9fa9fd18d083 Require cl when compiling. Don't autoload kemap and minor-mode-alist
Dave Love <fx@gnu.org>
parents: 26784
diff changeset
463 (cons (cons arg marker) footnote-text-marker-alist))
26784
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
464 (setq footnote-text-marker-alist
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
465 (Footnote-sort footnote-text-marker-alist)))))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
466
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
467 (defun Footnote-insert-pointer-marker (arg locn)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
468 "Insert a marker pointing to footnote arg, at buffer location locn."
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
469 (let ((marker (make-marker))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
470 alist)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
471 (set-marker marker locn)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
472 (if (setq alist (assq arg footnote-pointer-marker-alist))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
473 (setf alist
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
474 (cons marker (cdr alist)))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
475 (setq footnote-pointer-marker-alist
26815
9fa9fd18d083 Require cl when compiling. Don't autoload kemap and minor-mode-alist
Dave Love <fx@gnu.org>
parents: 26784
diff changeset
476 (cons (cons arg (list marker)) footnote-pointer-marker-alist))
26784
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
477 (setq footnote-pointer-marker-alist
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
478 (Footnote-sort footnote-pointer-marker-alist)))))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
479
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
480 (defun Footnote-insert-footnote (arg)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
481 "Insert a footnote numbered arg, at (point)."
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
482 (push-mark)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
483 (Footnote-insert-pointer-marker arg (point))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
484 (Footnote-insert-numbered-footnote arg t)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
485 (Footnote-goto-char-point-max)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
486 (if (re-search-backward (concat "^" footnote-section-tag-regexp) nil t)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
487 (save-restriction
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 42205
diff changeset
488 (when footnote-narrow-to-footnotes-when-editing
26784
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
489 (Footnote-narrow-to-footnotes))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
490 (Footnote-goto-footnote (1- arg)) ; evil, FIXME (less evil now)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
491 ;; (message "Inserting footnote %d" arg)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
492 (unless
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
493 (or (eq arg 1)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
494 (when (re-search-forward
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
495 (if footnote-spaced-footnotes
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
496 "\n\n"
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
497 (concat "\n"
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
498 (regexp-quote footnote-start-tag)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
499 (Footnote-current-regexp)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
500 (regexp-quote footnote-end-tag)))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
501 nil t)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
502 (unless (beginning-of-line) t))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
503 (goto-char (point-max)))))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
504 (unless (looking-at "^$")
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
505 (insert "\n"))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
506 (when (eobp)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
507 (insert "\n"))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
508 (insert footnote-section-tag "\n"))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
509 (let ((old-point (point)))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
510 (Footnote-insert-numbered-footnote arg nil)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
511 (Footnote-insert-text-marker arg old-point)))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
512
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
513 (defun Footnote-sort (list)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
514 (sort list (lambda (e1 e2)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
515 (< (car e1) (car e2)))))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
516
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
517 (defun Footnote-text-under-cursor ()
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
518 "Return the number of footnote if in footnote text.
42205
7308bbc423d5 Doc fixes.
Pavel Janík <Pavel@Janik.cz>
parents: 38436
diff changeset
519 Return nil if the cursor is not positioned over the text of
26784
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
520 a footnote."
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
521 (when (and (let ((old-point (point)))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
522 (save-excursion
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
523 (save-restriction
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
524 (Footnote-narrow-to-footnotes)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
525 (and (>= old-point (point-min))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
526 (<= old-point (point-max))))))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
527 (>= (point) (cdar footnote-text-marker-alist)))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
528 (let ((i 1)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
529 alist-txt rc)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
530 (while (and (setq alist-txt (nth i footnote-text-marker-alist))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
531 (null rc))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
532 (when (< (point) (cdr alist-txt))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
533 (setq rc (car (nth (1- i) footnote-text-marker-alist))))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
534 (setq i (1+ i)))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
535 (when (and (null rc)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
536 (null alist-txt))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
537 (setq rc (car (nth (1- i) footnote-text-marker-alist))))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
538 rc)))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
539
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
540 (defun Footnote-under-cursor ()
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
541 "Return the number of the footnote underneath the cursor.
42205
7308bbc423d5 Doc fixes.
Pavel Janík <Pavel@Janik.cz>
parents: 38436
diff changeset
542 Return nil if the cursor is not over a footnote."
26784
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
543 (or (get-text-property (point) 'footnote-number)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
544 (Footnote-text-under-cursor)))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
545
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
546 ;;; User functions
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
547
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
548 (defun Footnote-make-hole ()
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
549 (save-excursion
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
550 (let ((i 0)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
551 (notes (length footnote-pointer-marker-alist))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
552 alist-ptr alist-txt rc)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
553 (while (< i notes)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
554 (setq alist-ptr (nth i footnote-pointer-marker-alist))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
555 (setq alist-txt (nth i footnote-text-marker-alist))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
556 (when (< (point) (- (cadr alist-ptr) 3))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
557 (unless rc
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
558 (setq rc (car alist-ptr)))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
559 (save-excursion
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 42205
diff changeset
560 (message "Renumbering from %s to %s"
26784
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
561 (Footnote-index-to-string (car alist-ptr))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 42205
diff changeset
562 (Footnote-index-to-string
26784
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
563 (1+ (car alist-ptr))))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
564 (Footnote-renumber (car alist-ptr)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
565 (1+ (car alist-ptr))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
566 alist-ptr
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
567 alist-txt)))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
568 (setq i (1+ i)))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
569 rc)))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
570
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
571 (defun Footnote-add-footnote (&optional arg)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
572 "Add a numbered footnote.
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
573 The number the footnote receives is dependent upon the relative location
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
574 of any other previously existing footnotes.
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
575 If the variable `footnote-narrow-to-footnotes-when-editing' is set,
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
576 the buffer is narrowed to the footnote body. The restriction is removed
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
577 by using `Footnote-back-to-message'."
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
578 (interactive "*P")
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
579 (let (num)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
580 (if footnote-text-marker-alist
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
581 (if (< (point) (cadar (last footnote-pointer-marker-alist)))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
582 (setq num (Footnote-make-hole))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
583 (setq num (1+ (caar (last footnote-text-marker-alist)))))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
584 (setq num 1))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
585 (message "Adding footnote %d" num)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
586 (Footnote-insert-footnote num)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
587 (insert-before-markers (make-string footnote-body-tag-spacing ? ))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
588 (let ((opoint (point)))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
589 (save-excursion
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
590 (insert-before-markers
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
591 (if footnote-spaced-footnotes
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
592 "\n\n"
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
593 "\n"))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
594 (when footnote-narrow-to-footnotes-when-editing
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
595 (Footnote-narrow-to-footnotes)))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
596 ;; Emacs/XEmacs bug? save-excursion doesn't restore point when using
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
597 ;; insert-before-markers.
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
598 (goto-char opoint))))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
599
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
600 (defun Footnote-delete-footnote (&optional arg)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
601 "Delete a numbered footnote.
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
602 With no parameter, delete the footnote under (point). With arg specified,
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
603 delete the footnote with that number."
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
604 (interactive "*P")
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
605 (unless arg
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
606 (setq arg (Footnote-under-cursor)))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
607 (when (and arg
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
608 (or (not footnote-prompt-before-deletion)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
609 (y-or-n-p (format "Really delete footnote %d?" arg))))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
610 (let (alist-ptr alist-txt locn)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
611 (setq alist-ptr (assq arg footnote-pointer-marker-alist))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
612 (setq alist-txt (assq arg footnote-text-marker-alist))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
613 (unless (and alist-ptr alist-txt)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
614 (error "Can't delete footnote %d" arg))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
615 (setq locn (cdr alist-ptr))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
616 (while (car locn)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
617 (save-excursion
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
618 (goto-char (car locn))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
619 (let* ((end (point))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
620 (start (search-backward footnote-start-tag nil t)))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
621 (kill-region start end)))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
622 (setq locn (cdr locn)))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
623 (save-excursion
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
624 (goto-char (cdr alist-txt))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
625 (kill-region (point) (search-forward "\n\n" nil t)))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
626 (setq footnote-pointer-marker-alist
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
627 (delq alist-ptr footnote-pointer-marker-alist))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
628 (setq footnote-text-marker-alist
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
629 (delq alist-txt footnote-text-marker-alist))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
630 (Footnote-renumber-footnotes)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
631 (when (and (null footnote-text-marker-alist)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
632 (null footnote-pointer-marker-alist))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
633 (save-excursion
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
634 (let* ((end (Footnote-goto-char-point-max))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
635 (start (1- (re-search-backward
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
636 (concat "^" footnote-section-tag-regexp)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
637 nil t))))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
638 (forward-line -1)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
639 (when (looking-at "\n")
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
640 (kill-line))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
641 (kill-region start (if (< end (point-max))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
642 end
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
643 (point-max)))))))))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
644
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
645 (defun Footnote-renumber-footnotes (&optional arg)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
646 "Renumber footnotes, starting from 1."
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
647 (interactive "*P")
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
648 (save-excursion
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
649 (let ((i 0)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
650 (notes (length footnote-pointer-marker-alist))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
651 alist-ptr alist-txt)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
652 (while (< i notes)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
653 (setq alist-ptr (nth i footnote-pointer-marker-alist))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
654 (setq alist-txt (nth i footnote-text-marker-alist))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
655 (unless (eq (1+ i) (car alist-ptr))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
656 (Footnote-renumber (car alist-ptr) (1+ i) alist-ptr alist-txt))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
657 (setq i (1+ i))))))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
658
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
659 (defun Footnote-goto-footnote (&optional arg)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
660 "Jump to the text of a footnote.
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
661 With no parameter, jump to the text of the footnote under (point). With arg
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
662 specified, jump to the text of that footnote."
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
663 (interactive "P")
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
664 (let (footnote)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
665 (if arg
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
666 (setq footnote (assq arg footnote-text-marker-alist))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
667 (when (setq arg (Footnote-under-cursor))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
668 (setq footnote (assq arg footnote-text-marker-alist))))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
669 (if footnote
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
670 (goto-char (cdr footnote))
27830
99b1d31f039b (footnote): Add :version to defgroup.
Dave Love <fx@gnu.org>
parents: 26815
diff changeset
671 (if (eq arg 0)
26784
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
672 (progn
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
673 (goto-char (point-max))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
674 (re-search-backward (concat "^" footnote-section-tag-regexp))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
675 (forward-line 1))
38436
b174db545cfd Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 27830
diff changeset
676 (error "I don't see a footnote here")))))
26784
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
677
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
678 (defun Footnote-back-to-message (&optional arg)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
679 "Move cursor back to footnote referent.
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
680 If the cursor is not over the text of a footnote, point is not changed.
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
681 If the buffer was narrowed due to `footnote-narrow-to-footnotes-when-editing'
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
682 being set it is automatically widened."
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
683 (interactive "P")
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
684 (let ((note (Footnote-text-under-cursor)))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
685 (when note
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
686 (when footnote-narrow-to-footnotes-when-editing
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
687 (widen))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
688 (goto-char (cadr (assq note footnote-pointer-marker-alist))))))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
689
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
690 (defvar footnote-mode-map nil
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
691 "Keymap used for footnote minor mode.")
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
692
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
693 ;; Set up our keys
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
694 (unless footnote-mode-map
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
695 (setq footnote-mode-map (make-sparse-keymap))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
696 (define-key footnote-mode-map "a" 'Footnote-add-footnote)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
697 (define-key footnote-mode-map "b" 'Footnote-back-to-message)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
698 (define-key footnote-mode-map "c" 'Footnote-cycle-style)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
699 (define-key footnote-mode-map "d" 'Footnote-delete-footnote)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
700 (define-key footnote-mode-map "g" 'Footnote-goto-footnote)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
701 (define-key footnote-mode-map "r" 'Footnote-renumber-footnotes)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
702 (define-key footnote-mode-map "s" 'Footnote-set-style))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
703
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
704 (defvar footnote-minor-mode-map nil
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
705 "Keymap used for binding footnote minor mode.")
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
706
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
707 (unless footnote-minor-mode-map
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
708 (define-key global-map footnote-prefix footnote-mode-map))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
709
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
710 ;;;###autoload
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
711 (defun footnote-mode (&optional arg)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
712 "Toggle footnote minor mode.
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
713 \\<message-mode-map>
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
714 key binding
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
715 --- -------
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
716
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
717 \\[Footnote-renumber-footnotes] Footnote-renumber-footnotes
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
718 \\[Footnote-goto-footnote] Footnote-goto-footnote
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
719 \\[Footnote-delete-footnote] Footnote-delete-footnote
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
720 \\[Footnote-cycle-style] Footnote-cycle-style
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
721 \\[Footnote-back-to-message] Footnote-back-to-message
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
722 \\[Footnote-add-footnote] Footnote-add-footnote
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
723 "
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
724 (interactive "*P")
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
725 ;; (filladapt-mode t)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
726 (setq footnote-mode
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
727 (if (null arg) (not footnote-mode)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
728 (> (prefix-numeric-value arg) 0)))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
729 (when footnote-mode
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
730 ;; (Footnote-setup-keybindings)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
731 (make-local-variable 'footnote-style)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
732 (if (fboundp 'force-mode-line-update)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
733 (force-mode-line-update)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
734 (set-buffer-modified-p (buffer-modified-p)))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
735
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
736 (when (boundp 'filladapt-token-table)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
737 ;; add tokens to filladapt to match footnotes
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
738 ;; 1] xxxxxxxxxxx x x x or [1] x x x x x x x
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
739 ;; xxx x xx xxx xxxx x x x xxxxxxxxxx
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
740 (let ((bullet-regexp (concat (regexp-quote footnote-start-tag)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
741 "?[0-9a-zA-Z]+"
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
742 (regexp-quote footnote-end-tag)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
743 "[ \t]")))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
744 (unless (assoc bullet-regexp filladapt-token-table)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
745 (setq filladapt-token-table
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
746 (append filladapt-token-table
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
747 (list (list bullet-regexp 'bullet)))))))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
748
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
749 (run-hooks 'footnote-mode-hook)))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
750
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
751 (unless (assq 'footnote-mode minor-mode-alist)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
752 (setq minor-mode-alist
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
753 (cons '(footnote-mode footnote-mode-line-string)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
754 minor-mode-alist)))
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
755
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
756 (provide 'footnote)
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
757
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 49598
diff changeset
758 ;;; arch-tag: 9bcfb6d7-2161-4caf-8793-700f62400398
26784
4d1698b6a3bb Current XEmacs version.
Dave Love <fx@gnu.org>
parents:
diff changeset
759 ;;; footnote.el ends here