(vm-visit-folder): Declare as a function.
[bpt/emacs.git] / lisp / mail / footnote.el
CommitLineData
e8af40ee 1;;; footnote.el --- footnote support for message mode -*- coding: iso-latin-1;-*-
55492d86 2
f2e3589a 3;; Copyright (C) 1997, 2000, 2001, 2002, 2003, 2004,
d7a0267c 4;; 2005, 2006, 2007 Free Software Foundation, Inc.
55492d86
DL
5
6;; Author: Steven L Baur <steve@xemacs.org>
7;; Keywords: mail, news
8;; Version: 0.19
9
409f8a3f 10;; This file is part of GNU Emacs.
55492d86 11
409f8a3f 12;; GNU Emacs is free software; you can redistribute it and/or modify it
55492d86 13;; under the terms of the GNU General Public License as published by
ceaeecb0 14;; the Free Software Foundation; either version 3, or (at your option)
55492d86
DL
15;; any later version.
16
409f8a3f 17;; GNU Emacs is distributed in the hope that it will be useful, but
55492d86
DL
18;; WITHOUT ANY WARRANTY; without even the implied warranty of
19;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20;; General Public License for more details.
21
22;; You should have received a copy of the GNU General Public License
409f8a3f 23;; along with GNU Emacs; see the file COPYING. If not, write to the Free
3ef97fb6
LK
24;; Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
25;; MA 02110-1301, USA.
55492d86 26
55492d86
DL
27;;; Commentary:
28
29;; This file provides footnote[1] support for message-mode in emacsen.
30;; footnote-mode is implemented as a minor mode.
31
32;; [1] Footnotes look something like this. Along with some decorative
33;; stuff.
34
35;; TODO:
36;; Reasonable Undo support.
37;; more language styles.
38
55492d86
DL
39;;; Code:
40
409f8a3f
DL
41(eval-when-compile
42 (require 'cl)
43 (defvar filladapt-token-table))
44
55492d86
DL
45(defgroup footnote nil
46 "Support for footnotes in mail and news messages."
5404d9b0 47 :version "21.1"
55492d86
DL
48 :group 'message)
49
55492d86
DL
50(defcustom footnote-mode-line-string " FN"
51 "*String to display in modes section of the mode-line."
52 :group 'footnote)
53
54(defcustom footnote-mode-hook nil
55 "*Hook functions run when footnote-mode is activated."
56 :type 'hook
57 :group 'footnote)
58
59(defcustom footnote-narrow-to-footnotes-when-editing nil
60 "*If set, narrow to footnote text body while editing a footnote."
61 :type 'boolean
62 :group 'footnote)
63
64(defcustom footnote-prompt-before-deletion t
65 "*If set, prompt before deleting a footnote.
66There is currently no way to undo deletions."
67 :type 'boolean
68 :group 'footnote)
69
70(defcustom footnote-spaced-footnotes t
71 "If set true it will put a blank line between each footnote.
72If nil, no blank line will be inserted."
73 :type 'boolean
74 :group 'footnote)
75
55492d86
DL
76(defcustom footnote-use-message-mode t
77 "*If non-nil assume Footnoting will be done in message-mode."
78 :type 'boolean
79 :group 'footnote)
80
81(defcustom footnote-body-tag-spacing 2
82 "*Number of blanks separating a footnote body tag and its text."
83 :type 'integer
84 :group 'footnote)
85
55492d86
DL
86(defvar footnote-prefix [(control ?c) ?!]
87 "*When not using message mode, the prefix to bind in `mode-specific-map'")
88
89;;; Interface variables that probably shouldn't be changed
90
c4dc7971
RS
91(defcustom footnote-section-tag "Footnotes: "
92 "*Tag inserted at beginning of footnote section."
bf247b6e 93 :version "22.1"
c4dc7971
RS
94 :type 'string
95 :group 'footnote)
55492d86 96
5404d9b0
DL
97(defcustom footnote-section-tag-regexp "Footnotes\\(\\[.\\]\\)?: "
98 "*Regexp which indicates the start of a footnote section.
99See also `footnote-section-tag'."
100 :type 'regexp
101 :group 'footnote)
55492d86
DL
102
103;; The following three should be consumed by footnote styles.
5404d9b0
DL
104(defcustom footnote-start-tag "["
105 "*String used to denote start of numbered footnote."
106 :type 'string
107 :group 'footnote)
55492d86 108
5404d9b0
DL
109(defcustom footnote-end-tag "]"
110 "*String used to denote end of numbered footnote."
111 :type 'string
112 :group 'footnote)
55492d86
DL
113
114(defvar footnote-signature-separator (if (boundp 'message-signature-separator)
115 message-signature-separator
116 "^-- $")
117 "*String used to recognize .signatures.")
118
119;;; Private variables
120
121(defvar footnote-style-number nil
122 "Footnote style represented as an index into footnote-style-alist.")
123(make-variable-buffer-local 'footnote-style-number)
124
125(defvar footnote-text-marker-alist nil
126 "List of markers pointing to text of footnotes in message buffer.")
127(make-variable-buffer-local 'footnote-text-marker-alist)
128
129(defvar footnote-pointer-marker-alist nil
130 "List of markers pointing to footnote pointers in message buffer.")
131(make-variable-buffer-local 'footnote-pointer-marker-alist)
132
133(defvar footnote-mouse-highlight 'highlight
134 "Text property name to enable mouse over highlight.")
135
136(defvar footnote-mode nil
137 "Variable indicating whether footnote minor mode is active.")
138(make-variable-buffer-local 'footnote-mode)
139
140;;; Default styles
141;;; NUMERIC
2c28c519 142(defconst footnote-numeric-regexp "[0-9]+"
55492d86
DL
143 "Regexp for digits.")
144
145(defun Footnote-numeric (n)
146 "Numeric footnote style.
147Use Arabic numerals for footnoting."
148 (int-to-string n))
149
150;;; ENGLISH UPPER
151(defconst footnote-english-upper "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
152 "Upper case English alphabet.")
153
2c28c519 154(defconst footnote-english-upper-regexp "[A-Z]+"
55492d86
DL
155 "Regexp for upper case English alphabet.")
156
157(defun Footnote-english-upper (n)
158 "Upper case English footnoting.
159Wrapping around the alphabet implies successive repetitions of letters."
160 (let* ((ltr (mod (1- n) (length footnote-english-upper)))
161 (rep (/ (1- n) (length footnote-english-upper)))
162 (chr (char-to-string (aref footnote-english-upper ltr)))
163 rc)
164 (while (>= rep 0)
165 (setq rc (concat rc chr))
166 (setq rep (1- rep)))
167 rc))
a1506d29 168
55492d86
DL
169;;; ENGLISH LOWER
170(defconst footnote-english-lower "abcdefghijklmnopqrstuvwxyz"
171 "Lower case English alphabet.")
172
2c28c519 173(defconst footnote-english-lower-regexp "[a-z]+"
55492d86
DL
174 "Regexp of lower case English alphabet.")
175
176(defun Footnote-english-lower (n)
177 "Lower case English footnoting.
178Wrapping around the alphabet implies successive repetitions of letters."
179 (let* ((ltr (mod (1- n) (length footnote-english-lower)))
180 (rep (/ (1- n) (length footnote-english-lower)))
181 (chr (char-to-string (aref footnote-english-lower ltr)))
182 rc)
183 (while (>= rep 0)
184 (setq rc (concat rc chr))
185 (setq rep (1- rep)))
186 rc))
187
188;;; ROMAN LOWER
189(defconst footnote-roman-lower-list
190 '((1 . "i") (5 . "v") (10 . "x")
191 (50 . "l") (100 . "c") (500 . "d") (1000 . "m"))
192 "List of roman numerals with their values.")
193
2c28c519 194(defconst footnote-roman-lower-regexp "[ivxlcdm]+"
55492d86
DL
195 "Regexp of roman numerals.")
196
197(defun Footnote-roman-lower (n)
198 "Generic Roman number footnoting."
199 (Footnote-roman-common n footnote-roman-lower-list))
200
201;;; ROMAN UPPER
202(defconst footnote-roman-upper-list
203 '((1 . "I") (5 . "V") (10 . "X")
204 (50 . "L") (100 . "C") (500 . "D") (1000 . "M"))
205 "List of roman numerals with their values.")
206
2c28c519 207(defconst footnote-roman-upper-regexp "[IVXLCDM]+"
55492d86
DL
208 "Regexp of roman numerals. Not complete")
209
210(defun Footnote-roman-upper (n)
211 "Generic Roman number footnoting."
212 (Footnote-roman-common n footnote-roman-upper-list))
213
214(defun Footnote-roman-common (n footnote-roman-list)
215 "Lower case Roman footnoting."
216 (let* ((our-list footnote-roman-list)
217 (rom-lngth (length our-list))
218 (rom-high 0)
219 (rom-low 0)
220 (rom-div -1)
221 (count-high 0)
222 (count-low 0))
223 ;; find surrounding numbers
224 (while (and (<= count-high (1- rom-lngth))
225 (>= n (car (nth count-high our-list))))
226 ;; (message "Checking %d" (car (nth count-high our-list)))
227 (setq count-high (1+ count-high)))
228 (setq rom-high count-high)
229 (setq rom-low (1- count-high))
230 ;; find the appropriate divisor (if it exists)
231 (while (and (= rom-div -1)
232 (< count-low rom-high))
233 (when (or (> n (- (car (nth rom-high our-list))
234 (/ (car (nth count-low our-list))
235 2)))
236 (= n (- (car (nth rom-high our-list))
237 (car (nth count-low our-list)))))
238 (setq rom-div count-low))
239 ;; (message "Checking %d and %d in div loop" rom-high count-low)
240 (setq count-low (1+ count-low)))
241 ;;(message "We now have high: %d, low: %d, div: %d, n: %d"
242 ;; rom-high rom-low (if rom-div rom-div -1) n)
243 (let ((rom-low-pair (nth rom-low our-list))
244 (rom-high-pair (nth rom-high our-list))
245 (rom-div-pair (if (not (= rom-div -1)) (nth rom-div our-list) nil)))
246 ;; (message "pairs are: rom-low: %S, rom-high: %S, rom-div: %S"
247 ;; rom-low-pair rom-high-pair rom-div-pair)
248 (cond
249 ((< n 0) (error "Footnote-roman-common called with n < 0"))
250 ((= n 0) "")
251 ((= n (car rom-low-pair)) (cdr rom-low-pair))
252 ((= n (car rom-high-pair)) (cdr rom-high-pair))
253 ((= (car rom-low-pair) (car rom-high-pair))
254 (concat (cdr rom-low-pair)
255 (Footnote-roman-common
256 (- n (car rom-low-pair))
257 footnote-roman-list)))
258 ((>= rom-div 0) (concat (cdr rom-div-pair) (cdr rom-high-pair)
259 (Footnote-roman-common
260 (- n (- (car rom-high-pair)
261 (car rom-div-pair)))
262 footnote-roman-list)))
263 (t (concat (cdr rom-low-pair)
264 (Footnote-roman-common
265 (- n (car rom-low-pair))
266 footnote-roman-list)))))))
267
5404d9b0
DL
268;; Latin-1
269
dedecfd6
MR
270