annotate lisp/packages/filladapt.el @ 5:49b78a777eb4

Added tag r19-15b3 for changeset b82b59fe008d
author cvs
date Mon, 13 Aug 2007 08:46:57 +0200
parents 376386a54a3c
children ec9a17fef872
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; filladapt.el --- adaptive fill; replacement for fill commands
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; Keywords: wp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;;; Copyright (C) 1989, 1995, 1996 Kyle E. Jones
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;;; This program is free software; you can redistribute it and/or modify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;;; it under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;;; This program is distributed in the hope that it will be useful,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;;; GNU General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;;; A copy of the GNU General Public License can be obtained from this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;;; program's author (send electronic mail to kyle@uunet.uu.net) or from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;;; the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;;; 02139, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;;; Send bug reports to kyle@wonderworks.com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;;; Synched up with: Not in FSF.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;; LCD Archive Entry:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;; filladapt|Kyle Jones|kyle_jones@wonderworks.com|
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;; Minor mode to adaptively set fill-prefix and overload filling functions|
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;; 10-June-1996|2.08|~/packages/filladapt.el|
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;; These functions enhance the default behavior of Emacs' Auto Fill
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;; mode and the commands fill-paragraph, lisp-fill-paragraph and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;; fill-region-as-paragraph.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;; The chief improvement is that the beginning of a line to be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;; filled is examined and, based on information gathered, an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;; appropriate value for fill-prefix is constructed. Also the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;; boundaries of the current paragraph are located. This occurs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;; only if the fill prefix is not already non-nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;; The net result of this is that blurbs of text that are offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 ;; from left margin by asterisks, dashes, and/or spaces, numbered
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 ;; examples, included text from USENET news articles, etc. are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 ;; generally filled correctly with no fuss.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ;; Since this package replaces existing Emacs functions, it cannot
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ;; be autoloaded. Save this in a file named filladapt.el in a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 ;; Lisp directory that Emacs knows about, byte-compile it and put
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 ;; (require 'filladapt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 ;; in your .emacs file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 ;; Note that in this release Filladapt mode is a minor mode and it is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ;; _off_ by default. If you want it to be on by default, use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ;; (setq-default filladapt-mode t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 ;; M-x filladapt-mode toggles Filladapt mode on/off in the current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 ;; buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 ;; Use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 ;; (add-hook 'text-mode-hook 'turn-on-filladapt-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 ;; to have Filladapt always enabled in Text mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 ;; Use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 ;; (add-hook 'c-mode-hook 'turn-off-filladapt-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 ;; to have Filladapt always disabled in C mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 ;; In many cases, you can extend Filladapt by adding appropriate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 ;; entries to the following three `defvar's. See `postscript-comment'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 ;; or `texinfo-comment' as a sample of what needs to be done.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 ;; filladapt-token-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 ;; filladapt-token-match-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 ;; filladapt-token-conversion-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (provide 'filladapt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (defvar filladapt-version "2.08"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 "Version string for filladapt.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (defvar filladapt-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 "*Non-nil means that Filladapt minor mode is enabled.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 Use the filladapt-mode command to toggle the mode on/off.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (make-variable-buffer-local 'filladapt-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (defvar filladapt-mode-line-string " Filladapt"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 "*String to display in the modeline when Filladapt mode is active.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 Set this to nil if you don't want a modeline indicator for Filladapt.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 ;; install on minor-mode-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (or (assq 'filladapt-mode minor-mode-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (setq minor-mode-alist (cons (list 'filladapt-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 'filladapt-mode-line-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 minor-mode-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (defvar filladapt-token-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 '(
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 ;; Included text in news or mail replies
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (">+" . citation->)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 ;; Included text generated by SUPERCITE. We can't hope to match all
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 ;; the possible variations, your mileage may vary.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 ("[A-Za-z0-9][^'`\"< \t\n]*>[ \t]*" . supercite-citation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 ;; Lisp comments
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (";+" . lisp-comment)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 ;; UNIX shell comments
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 ("#+" . sh-comment)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 ;; Postscript comments
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 ("%+" . postscript-comment)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 ;; C++ comments
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 ("///*" . c++-comment)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 ;; Texinfo comments
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 ("@c[ \t]" . texinfo-comment)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 ("@comment[ \t]" . texinfo-comment)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 ;; Bullet types.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 ;; 1. xxxxx
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 ;; xxxxx
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 ("[0-9]+\\.[ \t]" . bullet)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 ;; 2.1.3 xxxxx xx x xx x
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 ;; xxx
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 ("[0-9]+\\(\\.[0-9]+\\)+[ \t]" . bullet)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 ;; a. xxxxxx xx
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 ;; xxx xxx
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 ("[A-Za-z]\\.[ \t]" . bullet)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 ;; 1) xxxx x xx x xx or (1) xx xx x x xx xx
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 ;; xx xx xxxx xxx xx x x xx x
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 ("(?[0-9]+)[ \t]" . bullet)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 ;; a) xxxx x xx x xx or (a) xx xx x x xx xx
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 ;; xx xx xxxx xxx xx x x xx x
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 ("(?[A-Za-z])[ \t]" . bullet)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 ;; 2a. xx x xxx x x xxx
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 ;; xxx xx x xx x
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 ("[0-9]+[A-Za-z]\\.[ \t]" . bullet)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 ;; 1a) xxxx x xx x xx or (1a) xx xx x x xx xx
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 ;; xx xx xxxx xxx xx x x xx x
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 ("(?[0-9]+[A-Za-z])[ \t]" . bullet)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 ;; - xx xxx xxxx or * xx xx x xxx xxx
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 ;; xxx xx xx x xxx x xx x x x
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 ("[-~*+]+[ \t]" . bullet)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 ;; o xx xxx xxxx xx x xx xxx x xxx xx x xxx
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 ;; xxx xx xx
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 ("o[ \t]" . bullet)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 ;; don't touch
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 ("[ \t]+" . space)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 ("$" . end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 "Table of tokens filladapt knows about.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 Format is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 ((REGEXP . SYM) ...)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 filladapt uses this table to build a tokenized representation of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 the beginning of the current line. Each REGEXP is matched
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 against the beginning of the line until a match is found.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 Matching is done case-sensitively. The corresponding SYM is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 added to the list, point is moved to (match-end 0) and the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 process is repeated. The process ends when there is no REGEXP in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 the table that matches what is at point.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (defvar filladapt-not-token-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 '(
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 "[Ee].g."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 "[Ii].e."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 ;; end-of-line isn't a token if whole line is empty
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 "^$"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 "List of regexps that can never be a token.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 Before trying the regular expressions in filladapt-token-table,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 the regexps in this list are tried. If any regexp in this list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 matches what is at point then the token generator gives up and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 doesn't try any of the regexps in filladapt-token-table.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 Regexp matching is done case-sensitively.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 (defvar filladapt-token-match-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 '(
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (citation-> citation->)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (supercite-citation supercite-citation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (lisp-comment lisp-comment)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (sh-comment sh-comment)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 (postscript-comment postscript-comment)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (c++-comment c++-comment)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (texinfo-comment texinfo-comment)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (bullet)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (space bullet space)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 "Table describing what tokens a certain token will match.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 To decide whether a line belongs in the current paragraph,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 filladapt creates a token list for the fill prefix of both lines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 Tokens and the columns where tokens end are compared. This table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 specifies what a certain token will match.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 Table format is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (SYM [SYM1 [SYM2 ...]])
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 The first symbol SYM is the token, subsequent symbols are the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 tokens that SYM will match.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (defvar filladapt-token-match-many-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 '(
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 space
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 "List of tokens that can match multiple tokens.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 If one of these tokens appears in a token list, it will eat all
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 matching tokens in a token list being matched against it until it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 encounters a token that doesn't match or a token that ends on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 a greater column number.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (defvar filladapt-token-paragraph-start-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 '(
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 bullet
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 "List of tokens that indicate the start of a paragraph.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 If parsing a line generates a token list containing one of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 these tokens, then the line is considered to be the start of a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 paragraph.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (defvar filladapt-token-conversion-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 '(
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (citation-> . exact)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (supercite-citation . exact)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (lisp-comment . exact)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (sh-comment . exact)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 (postscript-comment . exact)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (c++-comment . exact)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (texinfo-comment . exact)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 (bullet . spaces)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (space . exact)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (end-of-line . exact)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 "Table that specifies how to convert a token into a fill prefix.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 Table format is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 ((SYM . HOWTO) ...)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 SYM is the symbol naming the token to be converted.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 HOWTO specifies how to do the conversion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 `exact' means copy the token's string directly into the fill prefix.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 `spaces' means convert all characters in the token string that are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 not a TAB or a space into spaces and copy the resulting string into
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 the fill prefix.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (defvar filladapt-function-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (let ((assoc-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 (list (cons 'fill-paragraph (symbol-function 'fill-paragraph))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (cons 'fill-region-as-paragraph
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 (symbol-function 'fill-region-as-paragraph))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 (cons 'do-auto-fill (symbol-function 'do-auto-fill)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 ;; v18 Emacs doesn't have lisp-fill-paragraph
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (if (fboundp 'lisp-fill-paragraph)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 (nconc assoc-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (list (cons 'lisp-fill-paragraph
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 (symbol-function 'lisp-fill-paragraph)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 assoc-list )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 "Table containing the old function definitions that filladapt usurps.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 (defvar filladapt-fill-paragraph-post-hook nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 "Hooks run after filladapt runs fill-paragraph.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 (defvar filladapt-inside-filladapt nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 "Non-nil if the filladapt version of a fill function executing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 Currently this is only checked by the filladapt version of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 fill-region-as-paragraph to avoid this infinite recursion:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 fill-region-as-paragraph -> fill-paragraph -> fill-region-as-paragraph ...")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 (defvar filladapt-debug nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 "Non-nil means filladapt debugging is enabled.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 Use the filladapt-debug command to turn on debugging.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 With debugging enabled, filladapt will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 a. display the proposed indentation with the tokens highlighted
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 using filladapt-debug-indentation-face-1 and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 filladapt-debug-indentation-face-2.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 b. display the current paragraph using the face specified by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 filladapt-debug-paragraph-face.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 (if filladapt-debug
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 (add-hook 'post-command-hook 'filladapt-display-debug-info-maybe))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 (defvar filladapt-debug-indentation-face-1 'highlight
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 "Face used to display the indentation when debugging is enabled.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 (defvar filladapt-debug-indentation-face-2 'secondary-selection
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 "Another face used to display the indentation when debugging is enabled.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 (defvar filladapt-debug-paragraph-face 'bold
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 "Face used to display the current paragraph when debugging is enabled.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 (defvar filladapt-debug-indentation-extents nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 (make-variable-buffer-local 'filladapt-debug-indentation-extents)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 (defvar filladapt-debug-paragraph-extent nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 (make-variable-buffer-local 'filladapt-debug-paragraph-extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 ;; kludge city, see references in code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 (defvar filladapt-old-line-prefix)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 (defun do-auto-fill ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 (catch 'done
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 (if (and filladapt-mode (null fill-prefix))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 (let ((paragraph-ignore-fill-prefix nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 ;; if the user wanted this stuff, they probably
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 ;; wouldn't be using filladapt-mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 (adaptive-fill-mode nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 (adaptive-fill-regexp nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 ;; need this or Emacs 19 ignores fill-prefix when
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 ;; inside a comment.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 (comment-multi-line t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 (filladapt-inside-filladapt t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 fill-prefix retval)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 (if (filladapt-adapt nil nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 (setq retval (filladapt-funcall 'do-auto-fill))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 (throw 'done retval))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 (filladapt-funcall 'do-auto-fill)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 (defun filladapt-fill-paragraph (function arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 (catch 'done
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 (if (and filladapt-mode (null fill-prefix))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 (let ((paragraph-ignore-fill-prefix nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 ;; if the user wanted this stuff, they probably
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 ;; wouldn't be using filladapt-mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 (adaptive-fill-mode nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 (adaptive-fill-regexp nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 ;; need this or Emacs 19 ignores fill-prefix when
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 ;; inside a comment.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 (comment-multi-line t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 fill-prefix retval)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 (if (filladapt-adapt t nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 (setq retval (filladapt-funcall function arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 (run-hooks 'filladapt-fill-paragraph-post-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 (throw 'done retval))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 ;; filladapt-adapt failed, so do fill-paragraph normally.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 (filladapt-funcall function arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 (defun fill-paragraph (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 (interactive "*P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 (let ((filladapt-inside-filladapt t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 (filladapt-fill-paragraph 'fill-paragraph arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 (defun lisp-fill-paragraph (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 (interactive "*P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 (let ((filladapt-inside-filladapt t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 (filladapt-fill-paragraph 'lisp-fill-paragraph arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 (defun fill-region-as-paragraph (beg end &optional justify nosqueeze squeeze-after)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 (interactive "*r\nP")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 (if (and filladapt-mode (not filladapt-inside-filladapt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 (narrow-to-region beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 (let ((filladapt-inside-filladapt t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 line-start last-token)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 (goto-char beg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 (while (zerop (forward-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 (if (setq last-token
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 (car (filladapt-tail (filladapt-parse-prefixes))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 (setq line-start (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 (move-to-column (nth 1 last-token))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 (delete-region line-start (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 ;; Dance...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 ;; Do this instead of (delete-char -1) to keep
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 ;; markers on the correct side of the whitespace.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 (goto-char (1- (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 (insert " ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 (delete-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 (end-of-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 (goto-char beg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 (fill-paragraph justify))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 ;; In XEmacs 19.12 and Emacs 18.59 fill-region relies on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 ;; fill-region-as-paragraph to do this. If we don't do
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 ;; it, fill-region will spin in an endless loop.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 (goto-char (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 ;; five args for Emacs 19.31
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 (filladapt-funcall 'fill-region-as-paragraph beg end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 justify nosqueeze squeeze-after)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 (wrong-number-of-arguments
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 ;; four args for Emacs 19.29
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 (filladapt-funcall 'fill-region-as-paragraph beg end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 justify nosqueeze)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 ;; three args for the rest of the world.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 (wrong-number-of-arguments
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 (filladapt-funcall 'fill-region-as-paragraph beg end justify)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 (defvar zmacs-region-stays) ; for XEmacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 (defun filladapt-mode (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 "Toggle Filladapt minor mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 With arg, turn Filladapt mode on iff arg is positive. When
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 Filladapt mode is enabled, auto-fill-mode and the fill-paragraph
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 command are both smarter about guessing a proper fill-prefix and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 finding paragraph boundaries when bulleted and indented lines and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 paragraphs are used."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 ;; don't deactivate the region.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 (setq zmacs-region-stays t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 (setq filladapt-mode (or (and arg (> (prefix-numeric-value arg) 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 (and (null arg) (null filladapt-mode))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 (if (fboundp 'force-mode-line-update)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 (force-mode-line-update)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 (set-buffer-modified-p (buffer-modified-p))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 (defun turn-on-filladapt-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 "Unconditionally turn on Filladapt mode in the current buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 (filladapt-mode 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 (defun turn-off-filladapt-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 "Unconditionally turn off Filladapt mode in the current buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 (filladapt-mode -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 (defun filladapt-funcall (function &rest args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 "Call the old definition of a function that filladapt has usurped."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 (apply (cdr (assoc function filladapt-function-table)) args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 (defun filladapt-paragraph-start (list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 "Returns non-nil if LIST contains a paragraph starting token.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 LIST should be a token list as returned by filladapt-parse-prefixes."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 (catch 'done
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 (while list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 (if (memq (car (car list)) filladapt-token-paragraph-start-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 (throw 'done t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 (setq list (cdr list)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 (defun filladapt-parse-prefixes ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 "Parse all the tokens after point and return a list of them.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 The tokens regular expressions are specified in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 filladapt-token-table. The list returned is of this form
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 ((SYM COL STRING) ...)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 SYM is a token symbol as found in filladapt-token-table.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 COL is the column at which the token ended.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 STRING is the token's text."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 (let ((token-list nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 (done nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 (old-point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 (case-fold-search nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 token-table not-token-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 (catch 'done
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 (while (not done)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 (setq not-token-table filladapt-not-token-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 (while not-token-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 (if (looking-at (car not-token-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 (throw 'done t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 (setq not-token-table (cdr not-token-table)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 (setq token-table filladapt-token-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 done t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 (while token-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 (if (null (looking-at (car (car token-table))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 (setq token-table (cdr token-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 (goto-char (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 (setq token-list (cons (list (cdr (car token-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 (current-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 (buffer-substring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 (match-beginning 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 (match-end 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 token-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 token-table nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 done (eq (point) old-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 old-point (point))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 (nreverse token-list))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 (defun filladapt-tokens-match-p (list1 list2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 "Compare two token lists and return non-nil if they match, nil otherwise.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 The lists are walked through in lockstep, comparing tokens.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 When two tokens A and B are compared, they are considered to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 match if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 1. A appears in B's list of matching tokens or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 B appears in A's list of matching tokens
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 2. A and B both end at the same column
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 A can match multiple tokens and ends at a column > than B
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 B can match multiple tokens and ends at a column > than A
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 In the case where the end columns differ the list pointer for the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 token with the greater end column is not moved forward, which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 allows its current token to be matched against the next token in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 the other list in the next iteration of the matching loop.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 All tokens must be matched in order for the lists to be considered
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 matching."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 (let ((matched t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 (done nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 (while (and (not done) list1 list2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 (let* ((token1 (car (car list1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 (token1-matches-many-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 (memq token1 filladapt-token-match-many-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 (token1-matches (cdr (assq token1 filladapt-token-match-table)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 (token1-endcol (nth 1 (car list1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 (token2 (car (car list2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 (token2-matches-many-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 (memq token2 filladapt-token-match-many-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 (token2-matches (cdr (assq token2 filladapt-token-match-table)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 (token2-endcol (nth 1 (car list2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 (tokens-match (or (memq token1 token2-matches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 (memq token2 token1-matches))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 (cond ((not tokens-match)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 (setq matched nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 done t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 ((and token1-matches-many-p token2-matches-many-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 (cond ((= token1-endcol token2-endcol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 (setq list1 (cdr list1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 list2 (cdr list2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 ((< token1-endcol token2-endcol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 (setq list1 (cdr list1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 (setq list2 (cdr list2)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 (token1-matches-many-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 (cond ((= token1-endcol token2-endcol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 (setq list1 (cdr list1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 list2 (cdr list2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 ((< token1-endcol token2-endcol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 (setq matched nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 done t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 (setq list2 (cdr list2)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 (token2-matches-many-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 (cond ((= token1-endcol token2-endcol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 (setq list1 (cdr list1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 list2 (cdr list2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 ((< token2-endcol token1-endcol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 (setq matched nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 done t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 (setq list1 (cdr list1)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 ((= token1-endcol token2-endcol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 (setq list1 (cdr list1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 list2 (cdr list2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 (setq matched nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 done t)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 (and matched (null list1) (null list2)) ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 (defun filladapt-make-fill-prefix (list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 "Build a fill-prefix for a token LIST.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 filladapt-token-conversion-table specifies how this is done."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 (let ((prefix-list nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 (conversion-spec nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 (while list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 (setq conversion-spec (cdr (assq (car (car list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 filladapt-token-conversion-table)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 (cond ((eq conversion-spec 'spaces)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 (setq prefix-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 (cons
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 (filladapt-convert-to-spaces (nth 2 (car list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 prefix-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 ((eq conversion-spec 'exact)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 (setq prefix-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 (cons
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 (nth 2 (car list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 prefix-list))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 (setq list (cdr list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 (apply (function concat) (nreverse prefix-list)) ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 (defun filladapt-convert-to-spaces (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 "Return a copy of STRING, with all non-tabs and non-space changed to spaces."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 (let ((i 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 (space-list '(?\ ?\t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 (space ?\ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 (lim (length string)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 (setq string (copy-sequence string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 (while (< i lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 (if (not (memq (aref string i) space-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 (aset string i space))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 (setq i (1+ i)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 string ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 (defun filladapt-adapt (paragraph debugging)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 "Set fill-prefix based on the contents of the current line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 If the first arg PARAGRAPH is non-nil, also set a clipping region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 around the current paragraph.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 If the second arg DEBUGGING is non-nil, don't do the kludge that's
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 necessary to make certain paragraph fills work properly."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 (let ((token-list (filladapt-parse-prefixes))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 curr-list done)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 (if (null token-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 (setq fill-prefix (filladapt-make-fill-prefix token-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 (if paragraph
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 (let (beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 (if (filladapt-paragraph-start token-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 (setq beg (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 (setq done nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 (while (not done)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 (cond ((not (= 0 (forward-line -1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 (setq done t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 beg (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 ((not (filladapt-tokens-match-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 token-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 (setq curr-list (filladapt-parse-prefixes))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 (setq done t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 beg (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 ((filladapt-paragraph-start curr-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 (setq done t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 beg (point)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 (setq done nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 (while (not done)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 (cond ((not (= 0 (progn (end-of-line) (forward-line 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 (setq done t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 end (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 ((not (filladapt-tokens-match-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 token-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 (setq curr-list (filladapt-parse-prefixes))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 (setq done t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 end (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 ((filladapt-paragraph-start curr-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 (setq done t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 end (point))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 (narrow-to-region beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 ;; Multiple spaces after the bullet at the start of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 ;; a hanging list paragraph get squashed by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 ;; fill-paragraph. We kludge around this by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 ;; replacing the line prefix with the fill-prefix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 ;; used by the rest of the lines in the paragraph.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 ;; fill-paragraph will not alter the fill prefix so
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 ;; we win. The post hook restores the old line prefix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 ;; after fill-paragraph has been called.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 (if (and paragraph (not debugging))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 (let (col)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 (setq col (nth 1 (car (filladapt-tail token-list))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 (move-to-column col)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 (setq filladapt-old-line-prefix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 (buffer-substring (point-min) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 (delete-region (point-min) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 (insert fill-prefix)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 (add-hook 'filladapt-fill-paragraph-post-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 'filladapt-cleanup-kludge-at-point-min)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 t ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 (defun filladapt-cleanup-kludge-at-point-min ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 "Cleanup the paragraph fill kludge.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 See filladapt-adapt."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 (insert filladapt-old-line-prefix)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 (delete-char (length fill-prefix))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 (remove-hook 'filladapt-fill-paragraph-post-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 'filladapt-cleanup-kludge-at-point-min)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 (defun filladapt-tail (list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 "Returns the last cons in LIST."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 (if (null list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 (while (consp (cdr list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 (setq list (cdr list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 list ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 (defun filladapt-delete-extent (e)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 (if (fboundp 'delete-extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 (delete-extent e)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 (delete-overlay e)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 (defun filladapt-make-extent (beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 (if (fboundp 'make-extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 (make-extent beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 (make-overlay beg end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 (defun filladapt-set-extent-endpoints (e beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 (if (fboundp 'set-extent-endpoints)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 (set-extent-endpoints e beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 (move-overlay e beg end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 (defun filladapt-set-extent-property (e prop val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 (if (fboundp 'set-extent-property)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 (set-extent-property e prop val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 (overlay-put e prop val)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 (defun filladapt-debug ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 "Toggle filladapt debugging on/off in the current buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 ;; (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 (make-local-variable 'filladapt-debug)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 (setq filladapt-debug (not filladapt-debug))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 ;; make sure these faces exist at least
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 (make-face 'filladapt-debug-indentation-face-1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 (make-face 'filladapt-debug-indentation-face-2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 (make-face 'filladapt-debug-paragraph-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 (if (null filladapt-debug)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 (mapcar (function (lambda (e) (filladapt-set-extent-endpoints e 1 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 filladapt-debug-indentation-extents)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 (if filladapt-debug-paragraph-extent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 (filladapt-delete-extent filladapt-debug-paragraph-extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 (setq filladapt-debug-paragraph-extent nil)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 (add-hook 'post-command-hook 'filladapt-display-debug-info-maybe))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 (defun filladapt-display-debug-info-maybe ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 (cond ((null filladapt-debug) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 (fill-prefix nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 (if (null filladapt-debug-paragraph-extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 (let ((e (filladapt-make-extent 1 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 (filladapt-set-extent-property e 'detachable nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 (filladapt-set-extent-property e 'evaporate nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 (filladapt-set-extent-property e 'face
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 filladapt-debug-paragraph-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 (setq filladapt-debug-paragraph-extent e)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 (let ((ei-list filladapt-debug-indentation-extents)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 (ep filladapt-debug-paragraph-extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 (face filladapt-debug-indentation-face-1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 fill-prefix token-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 (if (null (filladapt-adapt t t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 (filladapt-set-extent-endpoints ep 1 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 (while ei-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 (filladapt-set-extent-endpoints (car ei-list) 1 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 (setq ei-list (cdr ei-list))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 (filladapt-set-extent-endpoints ep (point-min) (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 (setq token-list (filladapt-parse-prefixes))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 (message "(%s)" (mapconcat (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 (lambda (q) (symbol-name (car q))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 token-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756 " "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 (while token-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 (if ei-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 (setq e (car ei-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 ei-list (cdr ei-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 (setq e (filladapt-make-extent 1 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762 (filladapt-set-extent-property e 'detachable nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 (filladapt-set-extent-property e 'evaporate nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 (setq filladapt-debug-indentation-extents
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 (cons e filladapt-debug-indentation-extents)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766 (filladapt-set-extent-property e 'face face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 (filladapt-set-extent-endpoints e (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 (move-to-column
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 (nth 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 (car token-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 (if (eq face filladapt-debug-indentation-face-1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 (setq face filladapt-debug-indentation-face-2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 (setq face filladapt-debug-indentation-face-1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 (setq token-list (cdr token-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 (while ei-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 (filladapt-set-extent-endpoints (car ei-list) 1 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779 (setq ei-list (cdr ei-list))))))))))