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