Mercurial > hg > xemacs-beta
comparison lisp/packages/filladapt.el @ 70:131b0175ea99 r20-0b30
Import from CVS: tag r20-0b30
author | cvs |
---|---|
date | Mon, 13 Aug 2007 09:02:59 +0200 |
parents | ec9a17fef872 |
children | 360340f9fd5f |
comparison
equal
deleted
inserted
replaced
69:804d1389bcd6 | 70:131b0175ea99 |
---|---|
1 ;;; Adaptive fill | 1 ;;; filladapt.el --- adaptive fill; replacement for fill commands |
2 ;;; Copyright (C) 1989, 1995, 1996, 1997 Kyle E. Jones | 2 |
3 ;; Keywords: wp | |
4 | |
5 ;;; Copyright (C) 1989, 1995, 1996 Kyle E. Jones | |
3 ;;; | 6 ;;; |
4 ;;; This program is free software; you can redistribute it and/or modify | 7 ;;; This program is free software; you can redistribute it and/or modify |
5 ;;; it under the terms of the GNU General Public License as published by | 8 ;;; it under the terms of the GNU General Public License as published by |
6 ;;; the Free Software Foundation; either version 2, or (at your option) | 9 ;;; the Free Software Foundation; either version 2, or (at your option) |
7 ;;; any later version. | 10 ;;; any later version. |
14 ;;; A copy of the GNU General Public License can be obtained from this | 17 ;;; A copy of the GNU General Public License can be obtained from this |
15 ;;; program's author (send electronic mail to kyle@uunet.uu.net) or from | 18 ;;; program's author (send electronic mail to kyle@uunet.uu.net) or from |
16 ;;; the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA | 19 ;;; the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA |
17 ;;; 02139, USA. | 20 ;;; 02139, USA. |
18 ;;; | 21 ;;; |
19 ;;; Send bug reports to kyle_jones@wonderworks.com | 22 ;;; Send bug reports to kyle@wonderworks.com |
23 | |
24 ;;; Synched up with: Not in FSF. | |
20 | 25 |
21 ;; LCD Archive Entry: | 26 ;; LCD Archive Entry: |
22 ;; filladapt|Kyle Jones|kyle_jones@wonderworks.com| | 27 ;; filladapt|Kyle Jones|kyle_jones@wonderworks.com| |
23 ;; Minor mode to adaptively set fill-prefix and overload filling functions| | 28 ;; Minor mode to adaptively set fill-prefix and overload filling functions| |
24 ;; 10-June-1996|2.09|~/packages/filladapt.el| | 29 ;; 10-June-1996|2.08|~/packages/filladapt.el| |
25 | 30 |
26 ;; These functions enhance the default behavior of Emacs' Auto Fill | 31 ;; These functions enhance the default behavior of Emacs' Auto Fill |
27 ;; mode and the commands fill-paragraph, lisp-fill-paragraph, | 32 ;; mode and the commands fill-paragraph, lisp-fill-paragraph and |
28 ;; fill-region-as-paragraph and fill-region. | 33 ;; fill-region-as-paragraph. |
29 ;; | 34 ;; |
30 ;; The chief improvement is that the beginning of a line to be | 35 ;; The chief improvement is that the beginning of a line to be |
31 ;; filled is examined and, based on information gathered, an | 36 ;; filled is examined and, based on information gathered, an |
32 ;; appropriate value for fill-prefix is constructed. Also the | 37 ;; appropriate value for fill-prefix is constructed. Also the |
33 ;; boundaries of the current paragraph are located. This occurs | 38 ;; boundaries of the current paragraph are located. This occurs |
65 ;; | 70 ;; |
66 ;; filladapt-token-table | 71 ;; filladapt-token-table |
67 ;; filladapt-token-match-table | 72 ;; filladapt-token-match-table |
68 ;; filladapt-token-conversion-table | 73 ;; filladapt-token-conversion-table |
69 | 74 |
70 (and (featurep 'filladapt) | |
71 (error "filladapt cannot be loaded twice in the same Emacs session.")) | |
72 | |
73 (provide 'filladapt) | 75 (provide 'filladapt) |
74 | 76 |
75 (defvar filladapt-version "2.09" | 77 (defvar filladapt-version "2.08" |
76 "Version string for filladapt.") | 78 "Version string for filladapt.") |
77 | 79 |
78 (defvar filladapt-mode nil | 80 (defvar filladapt-mode nil |
79 "*Non-nil means that Filladapt minor mode is enabled. | 81 "*Non-nil means that Filladapt minor mode is enabled. |
80 Use the filladapt-mode command to toggle the mode on/off.") | 82 Use the filladapt-mode command to toggle the mode on/off.") |
81 (make-variable-buffer-local 'filladapt-mode) | 83 (make-variable-buffer-local 'filladapt-mode) |
82 | 84 |
83 (defvar filladapt-mode-line-string " Filladapt" | 85 (defvar filladapt-mode-line-string " Filladapt" |
84 "*String to display in the modeline when Filladapt mode is active. | 86 "*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.") | 87 Set this to nil if you don't want a modeline indicator for Filladapt.") |
86 | |
87 (defvar filladapt-fill-column-tolerance nil | |
88 "*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 | |
90 less than fill-column - filladapt-fill-column-tolerance, fill-column will | |
91 be adjusted using the filladapt-fill-column-*-fuzz variables and | |
92 the paragraph will be re-filled until the tolerance is achieved | |
93 or filladapt runs out of fuzz values to try. | |
94 | |
95 A nil value means behave normally, that is, don't try refilling | |
96 paragraphs to make filled line lengths fit within any particular | |
97 range.") | |
98 | |
99 (defvar filladapt-fill-column-forward-fuzz 5 | |
100 "*Try values from fill-column to fill-column plus this variable | |
101 when trying to make filled paragraph lines fall with the tolerance | |
102 range specified by filladapt-fill-column-tolerance.") | |
103 | |
104 (defvar filladapt-fill-column-backward-fuzz 5 | |
105 "*Try values from fill-column to fill-column minus this variable | |
106 when trying to make filled paragraph lines fall with the tolerance | |
107 range specified by filladapt-fill-column-tolerance.") | |
108 | 88 |
109 ;; install on minor-mode-alist | 89 ;; install on minor-mode-alist |
110 (or (assq 'filladapt-mode minor-mode-alist) | 90 (or (assq 'filladapt-mode minor-mode-alist) |
111 (setq minor-mode-alist (cons (list 'filladapt-mode | 91 (setq minor-mode-alist (cons (list 'filladapt-mode |
112 'filladapt-mode-line-string) | 92 'filladapt-mode-line-string) |
113 minor-mode-alist))) | 93 minor-mode-alist))) |
114 | 94 |
115 (defvar filladapt-token-table | 95 (defvar filladapt-token-table |
116 '( | 96 '( |
117 ;; this must be first | |
118 ("^" beginning-of-line) | |
119 ;; Included text in news or mail replies | 97 ;; Included text in news or mail replies |
120 (">+" citation->) | 98 (">+" . citation->) |
121 ;; Included text generated by SUPERCITE. We can't hope to match all | 99 ;; Included text generated by SUPERCITE. We can't hope to match all |
122 ;; the possible variations, your mileage may vary. | 100 ;; the possible variations, your mileage may vary. |
123 ("[A-Za-z0-9][^'`\"< \t\n]*>[ \t]*" supercite-citation) | 101 ("[A-Za-z0-9][^'`\"< \t\n]*>[ \t]*" . supercite-citation) |
124 ;; Lisp comments | 102 ;; Lisp comments |
125 (";+" lisp-comment) | 103 (";+" . lisp-comment) |
126 ;; UNIX shell comments | 104 ;; UNIX shell comments |
127 ("#+" sh-comment) | 105 ("#+" . sh-comment) |
128 ;; Postscript comments | 106 ;; Postscript comments |
129 ("%+" postscript-comment) | 107 ("%+" . postscript-comment) |
130 ;; C++ comments | 108 ;; C++ comments |
131 ("///*" c++-comment) | 109 ("///*" . c++-comment) |
132 ;; Texinfo comments | 110 ;; Texinfo comments |
133 ("@c[ \t]" texinfo-comment) | 111 ("@c[ \t]" . texinfo-comment) |
134 ("@comment[ \t]" texinfo-comment) | 112 ("@comment[ \t]" . texinfo-comment) |
135 ;; Bullet types. | 113 ;; Bullet types. |
136 ;; | |
137 ;; LaTex \item | |
138 ;; | |
139 ("\\\\item[ \t]" bullet) | |
140 ;; | 114 ;; |
141 ;; 1. xxxxx | 115 ;; 1. xxxxx |
142 ;; xxxxx | 116 ;; xxxxx |
143 ;; | 117 ;; |
144 ("[0-9]+\\.[ \t]" bullet) | 118 ("[0-9]+\\.[ \t]" . bullet) |
145 ;; | 119 ;; |
146 ;; 2.1.3 xxxxx xx x xx x | 120 ;; 2.1.3 xxxxx xx x xx x |
147 ;; xxx | 121 ;; xxx |
148 ;; | 122 ;; |
149 ("[0-9]+\\(\\.[0-9]+\\)+[ \t]" bullet) | 123 ("[0-9]+\\(\\.[0-9]+\\)+[ \t]" . bullet) |
150 ;; | 124 ;; |
151 ;; a. xxxxxx xx | 125 ;; a. xxxxxx xx |
152 ;; xxx xxx | 126 ;; xxx xxx |
153 ;; | 127 ;; |
154 ("[A-Za-z]\\.[ \t]" bullet) | 128 ("[A-Za-z]\\.[ \t]" . bullet) |
155 ;; | 129 ;; |
156 ;; 1) xxxx x xx x xx or (1) xx xx x x xx xx | 130 ;; 1) xxxx x xx x xx or (1) xx xx x x xx xx |
157 ;; xx xx xxxx xxx xx x x xx x | 131 ;; xx xx xxxx xxx xx x x xx x |
158 ;; | 132 ;; |
159 ("(?[0-9]+)[ \t]" bullet) | 133 ("(?[0-9]+)[ \t]" . bullet) |
160 ;; | 134 ;; |
161 ;; a) xxxx x xx x xx or (a) xx xx x x xx xx | 135 ;; a) xxxx x xx x xx or (a) xx xx x x xx xx |
162 ;; xx xx xxxx xxx xx x x xx x | 136 ;; xx xx xxxx xxx xx x x xx x |
163 ;; | 137 ;; |
164 ("(?[A-Za-z])[ \t]" bullet) | 138 ("(?[A-Za-z])[ \t]" . bullet) |
165 ;; | 139 ;; |
166 ;; 2a. xx x xxx x x xxx | 140 ;; 2a. xx x xxx x x xxx |
167 ;; xxx xx x xx x | 141 ;; xxx xx x xx x |
168 ;; | 142 ;; |
169 ("[0-9]+[A-Za-z]\\.[ \t]" bullet) | 143 ("[0-9]+[A-Za-z]\\.[ \t]" . bullet) |
170 ;; | 144 ;; |
171 ;; 1a) xxxx x xx x xx or (1a) xx xx x x xx xx | 145 ;; 1a) xxxx x xx x xx or (1a) xx xx x x xx xx |
172 ;; xx xx xxxx xxx xx x x xx x | 146 ;; xx xx xxxx xxx xx x x xx x |
173 ;; | 147 ;; |
174 ("(?[0-9]+[A-Za-z])[ \t]" bullet) | 148 ("(?[0-9]+[A-Za-z])[ \t]" . bullet) |
175 ;; | 149 ;; |
176 ;; - xx xxx xxxx or * xx xx x xxx xxx | 150 ;; - xx xxx xxxx or * xx xx x xxx xxx |
177 ;; xxx xx xx x xxx x xx x x x | 151 ;; xxx xx xx x xxx x xx x x x |
178 ;; | 152 ;; |
179 ("[-~*+]+[ \t]" bullet) | 153 ("[-~*+]+[ \t]" . bullet) |
180 ;; | 154 ;; |
181 ;; o xx xxx xxxx xx x xx xxx x xxx xx x xxx | 155 ;; o xx xxx xxxx xx x xx xxx x xxx xx x xxx |
182 ;; xxx xx xx | 156 ;; xxx xx xx |
183 ;; | 157 ;; |
184 ("o[ \t]" bullet) | 158 ("o[ \t]" . bullet) |
185 ;; don't touch | 159 ;; don't touch |
186 ("[ \t]+" space) | 160 ("[ \t]+" . space) |
187 ("$" end-of-line) | 161 ("$" . end-of-line) |
188 ) | 162 ) |
189 "Table of tokens filladapt knows about. | 163 "Table of tokens filladapt knows about. |
190 Format is | 164 Format is |
191 | 165 |
192 ((REGEXP SYM) ...) | 166 ((REGEXP . SYM) ...) |
193 | 167 |
194 filladapt uses this table to build a tokenized representation of | 168 filladapt uses this table to build a tokenized representation of |
195 the beginning of the current line. Each REGEXP is matched | 169 the beginning of the current line. Each REGEXP is matched |
196 against the beginning of the line until a match is found. | 170 against the beginning of the line until a match is found. |
197 Matching is done case-sensitively. The corresponding SYM is | 171 Matching is done case-sensitively. The corresponding SYM is |
223 (postscript-comment postscript-comment) | 197 (postscript-comment postscript-comment) |
224 (c++-comment c++-comment) | 198 (c++-comment c++-comment) |
225 (texinfo-comment texinfo-comment) | 199 (texinfo-comment texinfo-comment) |
226 (bullet) | 200 (bullet) |
227 (space bullet space) | 201 (space bullet space) |
228 (beginning-of-line beginning-of-line) | |
229 ) | 202 ) |
230 "Table describing what tokens a certain token will match. | 203 "Table describing what tokens a certain token will match. |
231 | 204 |
232 To decide whether a line belongs in the current paragraph, | 205 To decide whether a line belongs in the current paragraph, |
233 filladapt creates a token list for the fill prefix of both lines. | 206 filladapt creates a token list for the fill prefix of both lines. |
286 the fill prefix.") | 259 the fill prefix.") |
287 | 260 |
288 (defvar filladapt-function-table | 261 (defvar filladapt-function-table |
289 (let ((assoc-list | 262 (let ((assoc-list |
290 (list (cons 'fill-paragraph (symbol-function 'fill-paragraph)) | 263 (list (cons 'fill-paragraph (symbol-function 'fill-paragraph)) |
291 (cons 'fill-region (symbol-function 'fill-region)) | |
292 (cons 'fill-region-as-paragraph | 264 (cons 'fill-region-as-paragraph |
293 (symbol-function 'fill-region-as-paragraph)) | 265 (symbol-function 'fill-region-as-paragraph)) |
294 (cons 'do-auto-fill (symbol-function 'do-auto-fill))))) | 266 (cons 'do-auto-fill (symbol-function 'do-auto-fill))))) |
295 ;; v18 Emacs doesn't have lisp-fill-paragraph | 267 ;; v18 Emacs doesn't have lisp-fill-paragraph |
296 (if (fboundp 'lisp-fill-paragraph) | 268 (if (fboundp 'lisp-fill-paragraph) |
375 ;; inside a comment. | 347 ;; inside a comment. |
376 (comment-multi-line t) | 348 (comment-multi-line t) |
377 fill-prefix retval) | 349 fill-prefix retval) |
378 (if (filladapt-adapt t nil) | 350 (if (filladapt-adapt t nil) |
379 (progn | 351 (progn |
380 (if filladapt-fill-column-tolerance | 352 (setq retval (filladapt-funcall function arg)) |
381 (let* ((low (- fill-column | |
382 filladapt-fill-column-backward-fuzz)) | |
383 (high (+ fill-column | |
384 filladapt-fill-column-forward-fuzz)) | |
385 (old-fill-column fill-column) | |
386 (fill-column fill-column) | |
387 (lim (- high low)) | |
388 (done nil) | |
389 (sign 1) | |
390 (delta 0)) | |
391 (while (not done) | |
392 (setq retval (filladapt-funcall function arg)) | |
393 (if (filladapt-paragraph-within-fill-tolerance) | |
394 (setq done 'success) | |
395 (setq delta (1+ delta) | |
396 sign (* sign -1) | |
397 fill-column (+ fill-column (* delta sign))) | |
398 (while (and (<= delta lim) | |
399 (or (< fill-column low) | |
400 (> fill-column high))) | |
401 (setq delta (1+ delta) | |
402 sign (* sign -1) | |
403 fill-column (+ fill-column | |
404 (* delta sign)))) | |
405 (setq done (> delta lim)))) | |
406 ;; if the paragraph lines never fell | |
407 ;; within the tolerances, refill using | |
408 ;; the old fill-column. | |
409 (if (not (eq done 'success)) | |
410 (let ((fill-column old-fill-column)) | |
411 (setq retval (filladapt-funcall function arg))))) | |
412 (setq retval (filladapt-funcall function arg))) | |
413 (run-hooks 'filladapt-fill-paragraph-post-hook) | 353 (run-hooks 'filladapt-fill-paragraph-post-hook) |
414 (throw 'done retval)))))) | 354 (throw 'done retval)))))) |
415 ;; filladapt-adapt failed, so do fill-paragraph normally. | 355 ;; filladapt-adapt failed, so do fill-paragraph normally. |
416 (filladapt-funcall function arg))) | 356 (filladapt-funcall function arg))) |
417 | 357 |
418 (defun fill-paragraph (arg) | 358 (defun fill-paragraph (arg) |
419 "Fill paragraph at or after point. Prefix arg means justify as well. | |
420 | |
421 (This function has been overloaded with the `filladapt' version.) | |
422 | |
423 If `sentence-end-double-space' is non-nil, then period followed by one | |
424 space does not end a sentence, so don't break a line there. | |
425 | |
426 If `fill-paragraph-function' is non-nil, we call it (passing our | |
427 argument to it), and if it returns non-nil, we simply return its value." | |
428 (interactive "*P") | 359 (interactive "*P") |
429 (let ((filladapt-inside-filladapt t)) | 360 (let ((filladapt-inside-filladapt t)) |
430 (filladapt-fill-paragraph 'fill-paragraph arg))) | 361 (filladapt-fill-paragraph 'fill-paragraph arg))) |
431 | 362 |
432 (defun lisp-fill-paragraph (&optional arg) | 363 (defun lisp-fill-paragraph (&optional arg) |
433 "Like \\[fill-paragraph], but handle Emacs Lisp comments. | |
434 | |
435 (This function has been overloaded with the `filladapt' version.) | |
436 | |
437 If any of the current line is a comment, fill the comment or the | |
438 paragraph of it that point is in, preserving the comment's indentation | |
439 and initial semicolons." | |
440 (interactive "*P") | 364 (interactive "*P") |
441 (let ((filladapt-inside-filladapt t)) | 365 (let ((filladapt-inside-filladapt t)) |
442 (filladapt-fill-paragraph 'lisp-fill-paragraph arg))) | 366 (filladapt-fill-paragraph 'lisp-fill-paragraph arg))) |
443 | 367 |
444 (defun fill-region-as-paragraph (beg end &optional justify | 368 (defun fill-region-as-paragraph (beg end &optional justify nosqueeze squeeze-after) |
445 nosqueeze squeeze-after) | |
446 "Fill the region as one paragraph. | |
447 | |
448 (This function has been overloaded with the `filladapt' version.) | |
449 | |
450 It removes any paragraph breaks in the region and extra newlines at the end, | |
451 indents and fills lines between the margins given by the | |
452 `current-left-margin' and `current-fill-column' functions. | |
453 It leaves point at the beginning of the line following the paragraph. | |
454 | |
455 Normally performs justification according to the `current-justification' | |
456 function, but with a prefix arg, does full justification instead. | |
457 | |
458 From a program, optional third arg JUSTIFY can specify any type of | |
459 justification. Fourth arg NOSQUEEZE non-nil means not to make spaces | |
460 between words canonical before filling. Fifth arg SQUEEZE-AFTER, if non-nil, | |
461 means don't canonicalize spaces before that position. | |
462 | |
463 If `sentence-end-double-space' is non-nil, then period followed by one | |
464 space does not end a sentence, so don't break a line there." | |
465 (interactive "*r\nP") | 369 (interactive "*r\nP") |
466 (if (and filladapt-mode (not filladapt-inside-filladapt)) | 370 (if (and filladapt-mode (not filladapt-inside-filladapt)) |
467 (save-restriction | 371 (save-restriction |
468 (narrow-to-region beg end) | 372 (narrow-to-region beg end) |
469 (let ((filladapt-inside-filladapt t) | 373 (let ((filladapt-inside-filladapt t) |
470 line-start last-token) | 374 line-start last-token) |
471 (goto-char beg) | 375 (goto-char beg) |
472 (while (equal (char-after (point)) ?\n) | |
473 (delete-char 1)) | |
474 (end-of-line) | 376 (end-of-line) |
475 (while (zerop (forward-line)) | 377 (while (zerop (forward-line)) |
476 (if (setq last-token | 378 (if (setq last-token |
477 (car (filladapt-tail (filladapt-parse-prefixes)))) | 379 (car (filladapt-tail (filladapt-parse-prefixes)))) |
478 (progn | 380 (progn |
501 (wrong-number-of-arguments | 403 (wrong-number-of-arguments |
502 (condition-case nil | 404 (condition-case nil |
503 ;; four args for Emacs 19.29 | 405 ;; four args for Emacs 19.29 |
504 (filladapt-funcall 'fill-region-as-paragraph beg end | 406 (filladapt-funcall 'fill-region-as-paragraph beg end |
505 justify nosqueeze) | 407 justify nosqueeze) |
506 ;; three args for the rest of the world. | 408 ;; three args for the rest of the world. |
507 (wrong-number-of-arguments | |
508 (filladapt-funcall 'fill-region-as-paragraph beg end justify))))))) | |
509 | |
510 (defun fill-region (beg end &optional justify nosqueeze to-eop) | |
511 "Fill each of the paragraphs in the region. | |
512 | |
513 (This function has been overloaded with the `filladapt' version.) | |
514 | |
515 Prefix arg (non-nil third arg, if called from program) means justify as well. | |
516 | |
517 Noninteractively, fourth arg NOSQUEEZE non-nil means to leave | |
518 whitespace other than line breaks untouched, and fifth arg TO-EOP | |
519 non-nil means to keep filling to the end of the paragraph (or next | |
520 hard newline, if `use-hard-newlines' is on). | |
521 | |
522 If `sentence-end-double-space' is non-nil, then period followed by one | |
523 space does not end a sentence, so don't break a line there." | |
524 (interactive "*r\nP") | |
525 (if (and filladapt-mode (not filladapt-inside-filladapt)) | |
526 (save-restriction | |
527 (narrow-to-region beg end) | |
528 (let ((filladapt-inside-filladapt t) | |
529 start) | |
530 (goto-char beg) | |
531 (while (not (eobp)) | |
532 (setq start (point)) | |
533 (while (and (not (eobp)) (not (filladapt-parse-prefixes))) | |
534 (forward-line 1)) | |
535 (if (not (equal start (point))) | |
536 (progn | |
537 (save-restriction | |
538 (narrow-to-region start (point)) | |
539 (fill-region start (point) justify nosqueeze to-eop) | |
540 (goto-char (point-max))) | |
541 (if (and (not (bolp)) (not (eobp))) | |
542 (forward-line 1)))) | |
543 (if (filladapt-parse-prefixes) | |
544 (progn | |
545 (save-restriction | |
546 ;; for the clipping region | |
547 (filladapt-adapt t t) | |
548 (fill-paragraph justify) | |
549 (goto-char (point-max))) | |
550 (if (and (not (bolp)) (not (eobp))) | |
551 (forward-line 1))))))) | |
552 (condition-case nil | |
553 (filladapt-funcall 'fill-region beg end justify nosqueeze to-eop) | |
554 (wrong-number-of-arguments | 409 (wrong-number-of-arguments |
555 (condition-case nil | 410 (filladapt-funcall 'fill-region-as-paragraph beg end justify))))))) |
556 (filladapt-funcall 'fill-region beg end justify nosqueeze) | |
557 (wrong-number-of-arguments | |
558 (filladapt-funcall 'fill-region beg end justify))))))) | |
559 | 411 |
560 (defvar zmacs-region-stays) ; for XEmacs | 412 (defvar zmacs-region-stays) ; for XEmacs |
561 | 413 |
562 (defun filladapt-mode (&optional arg) | 414 (defun filladapt-mode (&optional arg) |
563 "Toggle Filladapt minor mode. | 415 "Toggle Filladapt minor mode. |
609 (save-excursion | 461 (save-excursion |
610 (let ((token-list nil) | 462 (let ((token-list nil) |
611 (done nil) | 463 (done nil) |
612 (old-point (point)) | 464 (old-point (point)) |
613 (case-fold-search nil) | 465 (case-fold-search nil) |
614 token-table not-token-table moved) | 466 token-table not-token-table) |
615 (catch 'done | 467 (catch 'done |
616 (while (not done) | 468 (while (not done) |
617 (setq not-token-table filladapt-not-token-table) | 469 (setq not-token-table filladapt-not-token-table) |
618 (while not-token-table | 470 (while not-token-table |
619 (if (looking-at (car not-token-table)) | 471 (if (looking-at (car not-token-table)) |
623 done t) | 475 done t) |
624 (while token-table | 476 (while token-table |
625 (if (null (looking-at (car (car token-table)))) | 477 (if (null (looking-at (car (car token-table)))) |
626 (setq token-table (cdr token-table)) | 478 (setq token-table (cdr token-table)) |
627 (goto-char (match-end 0)) | 479 (goto-char (match-end 0)) |
628 (setq token-list (cons (list (nth 1 (car token-table)) | 480 (setq token-list (cons (list (cdr (car token-table)) |
629 (current-column) | 481 (current-column) |
630 (buffer-substring | 482 (buffer-substring |
631 (match-beginning 0) | 483 (match-beginning 0) |
632 (match-end 0))) | 484 (match-end 0))) |
633 token-list) | 485 token-list) |
634 moved (not (eq (point) old-point)) | 486 token-table nil |
635 token-table (if moved nil (cdr token-table)) | 487 done (eq (point) old-point) |
636 done (not moved) | |
637 old-point (point)))))) | 488 old-point (point)))))) |
638 (nreverse token-list)))) | 489 (nreverse token-list)))) |
639 | 490 |
640 (defun filladapt-tokens-match-p (list1 list2) | 491 (defun filladapt-tokens-match-p (list1 list2) |
641 "Compare two token lists and return non-nil if they match, nil otherwise. | 492 "Compare two token lists and return non-nil if they match, nil otherwise. |
730 (cons | 581 (cons |
731 (nth 2 (car list)) | 582 (nth 2 (car list)) |
732 prefix-list)))) | 583 prefix-list)))) |
733 (setq list (cdr list))) | 584 (setq list (cdr list))) |
734 (apply (function concat) (nreverse prefix-list)) )) | 585 (apply (function concat) (nreverse prefix-list)) )) |
735 | |
736 (defun filladapt-paragraph-within-fill-tolerance () | |
737 (catch 'done | |
738 (save-excursion | |
739 (let ((low (- fill-column filladapt-fill-column-tolerance)) | |
740 (shortline nil)) | |
741 (goto-char (point-min)) | |
742 (while (not (eobp)) | |
743 (if shortline | |
744 (throw 'done nil) | |
745 (end-of-line) | |
746 (setq shortline (< (current-column) low)) | |
747 (forward-line 1))) | |
748 t )))) | |
749 | 586 |
750 (defun filladapt-convert-to-spaces (string) | 587 (defun filladapt-convert-to-spaces (string) |
751 "Return a copy of STRING, with all non-tabs and non-space changed to spaces." | 588 "Return a copy of STRING, with all non-tabs and non-space changed to spaces." |
752 (let ((i 0) | 589 (let ((i 0) |
753 (space-list '(?\ ?\t)) | 590 (space-list '(?\ ?\t)) |
871 (defun filladapt-debug () | 708 (defun filladapt-debug () |
872 "Toggle filladapt debugging on/off in the current buffer." | 709 "Toggle filladapt debugging on/off in the current buffer." |
873 ;; (interactive) | 710 ;; (interactive) |
874 (make-local-variable 'filladapt-debug) | 711 (make-local-variable 'filladapt-debug) |
875 (setq filladapt-debug (not filladapt-debug)) | 712 (setq filladapt-debug (not filladapt-debug)) |
713 ;; make sure these faces exist at least | |
714 (make-face 'filladapt-debug-indentation-face-1) | |
715 (make-face 'filladapt-debug-indentation-face-2) | |
716 (make-face 'filladapt-debug-paragraph-face) | |
876 (if (null filladapt-debug) | 717 (if (null filladapt-debug) |
877 (progn | 718 (progn |
878 (mapcar (function (lambda (e) (filladapt-set-extent-endpoints e 1 1))) | 719 (mapcar (function (lambda (e) (filladapt-set-extent-endpoints e 1 1))) |
879 filladapt-debug-indentation-extents) | 720 filladapt-debug-indentation-extents) |
880 (if filladapt-debug-paragraph-extent | 721 (if filladapt-debug-paragraph-extent |