comparison lisp/packages/filladapt.el @ 120:cca96a509cfe r20-1b12

Import from CVS: tag r20-1b12
author cvs
date Mon, 13 Aug 2007 09:25:29 +0200
parents 360340f9fd5f
children 1856695b1fa9
comparison
equal deleted inserted replaced
119:d101af7320b8 120:cca96a509cfe
19 ;;; Send bug reports to kyle_jones@wonderworks.com 19 ;;; Send bug reports to kyle_jones@wonderworks.com
20 20
21 ;; LCD Archive Entry: 21 ;; LCD Archive Entry:
22 ;; filladapt|Kyle Jones|kyle_jones@wonderworks.com| 22 ;; filladapt|Kyle Jones|kyle_jones@wonderworks.com|
23 ;; Minor mode to adaptively set fill-prefix and overload filling functions| 23 ;; Minor mode to adaptively set fill-prefix and overload filling functions|
24 ;; 10-June-1996|2.09|~/packages/filladapt.el| 24 ;; 10-June-1996|2.10|~/packages/filladapt.el|
25 25
26 ;; These functions enhance the default behavior of Emacs' Auto Fill 26 ;; These functions enhance the default behavior of Emacs' Auto Fill
27 ;; mode and the commands fill-paragraph, lisp-fill-paragraph, 27 ;; mode and the commands fill-paragraph, lisp-fill-paragraph,
28 ;; fill-region-as-paragraph and fill-region. 28 ;; fill-region-as-paragraph and fill-region.
29 ;; 29 ;;
70 (and (featurep 'filladapt) 70 (and (featurep 'filladapt)
71 (error "filladapt cannot be loaded twice in the same Emacs session.")) 71 (error "filladapt cannot be loaded twice in the same Emacs session."))
72 72
73 (provide 'filladapt) 73 (provide 'filladapt)
74 74
75 (defvar filladapt-version "2.09" 75 ;; BLOB to make custom stuff work even without customize
76 (eval-and-compile
77 (condition-case ()
78 (require 'custom)
79 (error nil))
80 (if (and (featurep 'custom) (fboundp 'custom-declare-variable))
81 nil ;; We've got what we needed
82 ;; We have the old custom-library, hack around it!
83 (defmacro defgroup (&rest args)
84 nil)
85 (defmacro defcustom (var value doc &rest args)
86 (` (defvar (, var) (, value) (, doc))))))
87
88 (defgroup filladapt nil
89 "Enhanced filling"
90 :group 'editing)
91
92 (defvar filladapt-version "2.10"
76 "Version string for filladapt.") 93 "Version string for filladapt.")
77 94
78 (defvar filladapt-mode nil 95 (defcustom filladapt-mode nil
79 "*Non-nil means that Filladapt minor mode is enabled. 96 "*Non-nil means that Filladapt minor mode is enabled.
80 Use the filladapt-mode command to toggle the mode on/off.") 97 Use the filladapt-mode command to toggle the mode on/off."
98 :type 'boolean
99 :group 'filladapt)
81 (make-variable-buffer-local 'filladapt-mode) 100 (make-variable-buffer-local 'filladapt-mode)
82 101
83 (defvar filladapt-mode-line-string " Filladapt" 102 (defcustom filladapt-mode-line-string " Filladapt"
84 "*String to display in the modeline when Filladapt mode is active. 103 "*String to display in the modeline when Filladapt mode is active.
85 Set this to nil if you don't want a modeline indicator for Filladapt.") 104 Set this to nil if you don't want a modeline indicator for Filladapt."
86 105 :type 'string
87 (defvar filladapt-fill-column-tolerance nil 106 :group 'filladapt)
107
108 (defcustom filladapt-fill-column-tolerance nil
88 "*Tolerate filled paragraph lines ending this far from the fill column. 109 "*Tolerate filled paragraph lines ending this far from the fill column.
89 If any lines other than the last paragraph line end at a column 110 If any lines other than the last paragraph line end at a column
90 less than fill-column - filladapt-fill-column-tolerance, fill-column will 111 less than fill-column - filladapt-fill-column-tolerance, fill-column will
91 be adjusted using the filladapt-fill-column-*-fuzz variables and 112 be adjusted using the filladapt-fill-column-*-fuzz variables and
92 the paragraph will be re-filled until the tolerance is achieved 113 the paragraph will be re-filled until the tolerance is achieved
93 or filladapt runs out of fuzz values to try. 114 or filladapt runs out of fuzz values to try.
94 115
95 A nil value means behave normally, that is, don't try refilling 116 A nil value means behave normally, that is, don't try refilling
96 paragraphs to make filled line lengths fit within any particular 117 paragraphs to make filled line lengths fit within any particular
97 range.") 118 range."
98 119 :type '(choice (const nil)
99 (defvar filladapt-fill-column-forward-fuzz 5 120 integer)
121 :group 'filladapt)
122
123 (defcustom filladapt-fill-column-forward-fuzz 5
100 "*Try values from fill-column to fill-column plus this variable 124 "*Try values from fill-column to fill-column plus this variable
101 when trying to make filled paragraph lines fall with the tolerance 125 when trying to make filled paragraph lines fall with the tolerance
102 range specified by filladapt-fill-column-tolerance.") 126 range specified by filladapt-fill-column-tolerance."
103 127 :type 'integer
104 (defvar filladapt-fill-column-backward-fuzz 5 128 :group 'filladapt)
129
130 (defcustom filladapt-fill-column-backward-fuzz 5
105 "*Try values from fill-column to fill-column minus this variable 131 "*Try values from fill-column to fill-column minus this variable
106 when trying to make filled paragraph lines fall with the tolerance 132 when trying to make filled paragraph lines fall with the tolerance
107 range specified by filladapt-fill-column-tolerance.") 133 range specified by filladapt-fill-column-tolerance."
134 :type 'integer
135 :group 'filladapt)
108 136
109 ;; install on minor-mode-alist 137 ;; install on minor-mode-alist
110 (or (assq 'filladapt-mode minor-mode-alist) 138 (or (assq 'filladapt-mode minor-mode-alist)
111 (setq minor-mode-alist (cons (list 'filladapt-mode 139 (setq minor-mode-alist (cons (list 'filladapt-mode
112 'filladapt-mode-line-string) 140 'filladapt-mode-line-string)
113 minor-mode-alist))) 141 minor-mode-alist)))
114 142
115 (defvar filladapt-token-table 143 (defcustom filladapt-token-table
116 '( 144 '(
117 ;; this must be first 145 ;; this must be first
118 ("^" beginning-of-line) 146 ("^" beginning-of-line)
119 ;; Included text in news or mail replies 147 ;; Included text in news or mail replies
120 (">+" citation->) 148 (">+" citation->)
195 the beginning of the current line. Each REGEXP is matched 223 the beginning of the current line. Each REGEXP is matched
196 against the beginning of the line until a match is found. 224 against the beginning of the line until a match is found.
197 Matching is done case-sensitively. The corresponding SYM is 225 Matching is done case-sensitively. The corresponding SYM is
198 added to the list, point is moved to (match-end 0) and the 226 added to the list, point is moved to (match-end 0) and the
199 process is repeated. The process ends when there is no REGEXP in 227 process is repeated. The process ends when there is no REGEXP in
200 the table that matches what is at point.") 228 the table that matches what is at point."
201 229 :type '(repeat (list regexp symbol))
202 (defvar filladapt-not-token-table 230 :group 'filladapt)
231
232 (defcustom filladapt-not-token-table
203 '( 233 '(
204 "[Ee].g." 234 "[Ee].g."
205 "[Ii].e." 235 "[Ii].e."
206 ;; end-of-line isn't a token if whole line is empty 236 ;; end-of-line isn't a token if whole line is empty
207 "^$" 237 "^$"
210 Before trying the regular expressions in filladapt-token-table, 240 Before trying the regular expressions in filladapt-token-table,
211 the regexps in this list are tried. If any regexp in this list 241 the regexps in this list are tried. If any regexp in this list
212 matches what is at point then the token generator gives up and 242 matches what is at point then the token generator gives up and
213 doesn't try any of the regexps in filladapt-token-table. 243 doesn't try any of the regexps in filladapt-token-table.
214 244
215 Regexp matching is done case-sensitively.") 245 Regexp matching is done case-sensitively."
216 246 :type '(repeat regexp)
217 (defvar filladapt-token-match-table 247 :group 'filladapt)
248
249 (defcustom filladapt-token-match-table
218 '( 250 '(
219 (citation-> citation->) 251 (citation-> citation->)
220 (supercite-citation supercite-citation) 252 (supercite-citation supercite-citation)
221 (lisp-comment lisp-comment) 253 (lisp-comment lisp-comment)
222 (sh-comment sh-comment) 254 (sh-comment sh-comment)
237 Table format is 269 Table format is
238 270
239 (SYM [SYM1 [SYM2 ...]]) 271 (SYM [SYM1 [SYM2 ...]])
240 272
241 The first symbol SYM is the token, subsequent symbols are the 273 The first symbol SYM is the token, subsequent symbols are the
242 tokens that SYM will match.") 274 tokens that SYM will match."
243 275 :type '(repeat (repeat symbol))
244 (defvar filladapt-token-match-many-table 276 :group 'filladapt)
277
278 (defcustom filladapt-token-match-many-table
245 '( 279 '(
246 space 280 space
247 ) 281 )
248 "List of tokens that can match multiple tokens. 282 "List of tokens that can match multiple tokens.
249 If one of these tokens appears in a token list, it will eat all 283 If one of these tokens appears in a token list, it will eat all
250 matching tokens in a token list being matched against it until it 284 matching tokens in a token list being matched against it until it
251 encounters a token that doesn't match or a token that ends on 285 encounters a token that doesn't match or a token that ends on
252 a greater column number.") 286 a greater column number."
253 287 :type '(repeat symbol)
254 (defvar filladapt-token-paragraph-start-table 288 :group 'filladapt)
289
290 (defcustom filladapt-token-paragraph-start-table
255 '( 291 '(
256 bullet 292 bullet
257 ) 293 )
258 "List of tokens that indicate the start of a paragraph. 294 "List of tokens that indicate the start of a paragraph.
259 If parsing a line generates a token list containing one of 295 If parsing a line generates a token list containing one of
260 these tokens, then the line is considered to be the start of a 296 these tokens, then the line is considered to be the start of a
261 paragraph.") 297 paragraph."
262 298 :type '(repeat symbol)
263 (defvar filladapt-token-conversion-table 299 :group 'filladapt)
300
301 (defcustom filladapt-token-conversion-table
264 '( 302 '(
265 (citation-> . exact) 303 (citation-> . exact)
266 (supercite-citation . exact) 304 (supercite-citation . exact)
267 (lisp-comment . exact) 305 (lisp-comment . exact)
268 (sh-comment . exact) 306 (sh-comment . exact)
281 SYM is the symbol naming the token to be converted. 319 SYM is the symbol naming the token to be converted.
282 HOWTO specifies how to do the conversion. 320 HOWTO specifies how to do the conversion.
283 `exact' means copy the token's string directly into the fill prefix. 321 `exact' means copy the token's string directly into the fill prefix.
284 `spaces' means convert all characters in the token string that are 322 `spaces' means convert all characters in the token string that are
285 not a TAB or a space into spaces and copy the resulting string into 323 not a TAB or a space into spaces and copy the resulting string into
286 the fill prefix.") 324 the fill prefix."
325 :type '(repeat (cons symbol (choice (const exact)
326 (const spaces))))
327 :group 'filladapt)
287 328
288 (defvar filladapt-function-table 329 (defvar filladapt-function-table
289 (let ((assoc-list 330 (let ((assoc-list
290 (list (cons 'fill-paragraph (symbol-function 'fill-paragraph)) 331 (list (cons 'fill-paragraph (symbol-function 'fill-paragraph))
291 (cons 'fill-region (symbol-function 'fill-region)) 332 (cons 'fill-region (symbol-function 'fill-region))
298 (list (cons 'lisp-fill-paragraph 339 (list (cons 'lisp-fill-paragraph
299 (symbol-function 'lisp-fill-paragraph))))) 340 (symbol-function 'lisp-fill-paragraph)))))
300 assoc-list ) 341 assoc-list )
301 "Table containing the old function definitions that filladapt usurps.") 342 "Table containing the old function definitions that filladapt usurps.")
302 343
303 (defvar filladapt-fill-paragraph-post-hook nil 344 (defcustom filladapt-fill-paragraph-post-hook nil
304 "Hooks run after filladapt runs fill-paragraph.") 345 "Hooks run after filladapt runs fill-paragraph."
346 :type 'hook
347 :group 'filladapt)
305 348
306 (defvar filladapt-inside-filladapt nil 349 (defvar filladapt-inside-filladapt nil
307 "Non-nil if the filladapt version of a fill function executing. 350 "Non-nil if the filladapt version of a fill function executing.
308 Currently this is only checked by the filladapt version of 351 Currently this is only checked by the filladapt version of
309 fill-region-as-paragraph to avoid this infinite recursion: 352 fill-region-as-paragraph to avoid this infinite recursion:
310 353
311 fill-region-as-paragraph -> fill-paragraph -> fill-region-as-paragraph ...") 354 fill-region-as-paragraph -> fill-paragraph -> fill-region-as-paragraph ...")
312 355
313 (defvar filladapt-debug nil 356 (defcustom filladapt-debug nil
314 "Non-nil means filladapt debugging is enabled. 357 "Non-nil means filladapt debugging is enabled.
315 Use the filladapt-debug command to turn on debugging. 358 Use the filladapt-debug command to turn on debugging.
316 359
317 With debugging enabled, filladapt will 360 With debugging enabled, filladapt will
318 361
319 a. display the proposed indentation with the tokens highlighted 362 a. display the proposed indentation with the tokens highlighted
320 using filladapt-debug-indentation-face-1 and 363 using filladapt-debug-indentation-face-1 and
321 filladapt-debug-indentation-face-2. 364 filladapt-debug-indentation-face-2.
322 b. display the current paragraph using the face specified by 365 b. display the current paragraph using the face specified by
323 filladapt-debug-paragraph-face.") 366 filladapt-debug-paragraph-face."
367 :type 'boolean
368 :group 'filladapt)
324 369
325 (if filladapt-debug 370 (if filladapt-debug
326 (add-hook 'post-command-hook 'filladapt-display-debug-info-maybe)) 371 (add-hook 'post-command-hook 'filladapt-display-debug-info-maybe))
327 372
328 (defvar filladapt-debug-indentation-face-1 'highlight 373 (defvar filladapt-debug-indentation-face-1 'highlight