Mercurial > hg > xemacs-beta
comparison lisp/packages/filladapt.el @ 108:360340f9fd5f r20-1b6
Import from CVS: tag r20-1b6
author | cvs |
---|---|
date | Mon, 13 Aug 2007 09:18:39 +0200 |
parents | 131b0175ea99 |
children | cca96a509cfe |
comparison
equal
deleted
inserted
replaced
107:523141596bda | 108:360340f9fd5f |
---|---|
1 ;;; filladapt.el --- adaptive fill; replacement for fill commands | 1 ;;; Adaptive fill |
2 | 2 ;;; Copyright (C) 1989, 1995, 1996, 1997 Kyle E. Jones |
3 ;; Keywords: wp | |
4 | |
5 ;;; Copyright (C) 1989, 1995, 1996 Kyle E. Jones | |
6 ;;; | 3 ;;; |
7 ;;; This program is free software; you can redistribute it and/or modify | 4 ;;; This program is free software; you can redistribute it and/or modify |
8 ;;; it under the terms of the GNU General Public License as published by | 5 ;;; it under the terms of the GNU General Public License as published by |
9 ;;; the Free Software Foundation; either version 2, or (at your option) | 6 ;;; the Free Software Foundation; either version 2, or (at your option) |
10 ;;; any later version. | 7 ;;; any later version. |
17 ;;; A copy of the GNU General Public License can be obtained from this | 14 ;;; A copy of the GNU General Public License can be obtained from this |
18 ;;; program's author (send electronic mail to kyle@uunet.uu.net) or from | 15 ;;; program's author (send electronic mail to kyle@uunet.uu.net) or from |
19 ;;; the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA | 16 ;;; the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA |
20 ;;; 02139, USA. | 17 ;;; 02139, USA. |
21 ;;; | 18 ;;; |
22 ;;; Send bug reports to kyle@wonderworks.com | 19 ;;; Send bug reports to kyle_jones@wonderworks.com |
23 | |
24 ;;; Synched up with: Not in FSF. | |
25 | 20 |
26 ;; LCD Archive Entry: | 21 ;; LCD Archive Entry: |
27 ;; filladapt|Kyle Jones|kyle_jones@wonderworks.com| | 22 ;; filladapt|Kyle Jones|kyle_jones@wonderworks.com| |
28 ;; Minor mode to adaptively set fill-prefix and overload filling functions| | 23 ;; Minor mode to adaptively set fill-prefix and overload filling functions| |
29 ;; 10-June-1996|2.08|~/packages/filladapt.el| | 24 ;; 10-June-1996|2.09|~/packages/filladapt.el| |
30 | 25 |
31 ;; These functions enhance the default behavior of Emacs' Auto Fill | 26 ;; These functions enhance the default behavior of Emacs' Auto Fill |
32 ;; mode and the commands fill-paragraph, lisp-fill-paragraph and | 27 ;; mode and the commands fill-paragraph, lisp-fill-paragraph, |
33 ;; fill-region-as-paragraph. | 28 ;; fill-region-as-paragraph and fill-region. |
34 ;; | 29 ;; |
35 ;; The chief improvement is that the beginning of a line to be | 30 ;; The chief improvement is that the beginning of a line to be |
36 ;; filled is examined and, based on information gathered, an | 31 ;; filled is examined and, based on information gathered, an |
37 ;; appropriate value for fill-prefix is constructed. Also the | 32 ;; appropriate value for fill-prefix is constructed. Also the |
38 ;; boundaries of the current paragraph are located. This occurs | 33 ;; boundaries of the current paragraph are located. This occurs |
70 ;; | 65 ;; |
71 ;; filladapt-token-table | 66 ;; filladapt-token-table |
72 ;; filladapt-token-match-table | 67 ;; filladapt-token-match-table |
73 ;; filladapt-token-conversion-table | 68 ;; filladapt-token-conversion-table |
74 | 69 |
70 (and (featurep 'filladapt) | |
71 (error "filladapt cannot be loaded twice in the same Emacs session.")) | |
72 | |
75 (provide 'filladapt) | 73 (provide 'filladapt) |
76 | 74 |
77 (defvar filladapt-version "2.08" | 75 (defvar filladapt-version "2.09" |
78 "Version string for filladapt.") | 76 "Version string for filladapt.") |
79 | 77 |
80 (defvar filladapt-mode nil | 78 (defvar filladapt-mode nil |
81 "*Non-nil means that Filladapt minor mode is enabled. | 79 "*Non-nil means that Filladapt minor mode is enabled. |
82 Use the filladapt-mode command to toggle the mode on/off.") | 80 Use the filladapt-mode command to toggle the mode on/off.") |
83 (make-variable-buffer-local 'filladapt-mode) | 81 (make-variable-buffer-local 'filladapt-mode) |
84 | 82 |
85 (defvar filladapt-mode-line-string " Filladapt" | 83 (defvar filladapt-mode-line-string " Filladapt" |
86 "*String to display in the modeline when Filladapt mode is active. | 84 "*String to display in the modeline when Filladapt mode is active. |
87 Set this to nil if you don't want a modeline indicator for Filladapt.") | 85 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.") | |
88 | 108 |
89 ;; install on minor-mode-alist | 109 ;; install on minor-mode-alist |
90 (or (assq 'filladapt-mode minor-mode-alist) | 110 (or (assq 'filladapt-mode minor-mode-alist) |
91 (setq minor-mode-alist (cons (list 'filladapt-mode | 111 (setq minor-mode-alist (cons (list 'filladapt-mode |
92 'filladapt-mode-line-string) | 112 'filladapt-mode-line-string) |
93 minor-mode-alist))) | 113 minor-mode-alist))) |
94 | 114 |
95 (defvar filladapt-token-table | 115 (defvar filladapt-token-table |
96 '( | 116 '( |
117 ;; this must be first | |
118 ("^" beginning-of-line) | |
97 ;; Included text in news or mail replies | 119 ;; Included text in news or mail replies |
98 (">+" . citation->) | 120 (">+" citation->) |
99 ;; Included text generated by SUPERCITE. We can't hope to match all | 121 ;; Included text generated by SUPERCITE. We can't hope to match all |
100 ;; the possible variations, your mileage may vary. | 122 ;; the possible variations, your mileage may vary. |
101 ("[A-Za-z0-9][^'`\"< \t\n]*>[ \t]*" . supercite-citation) | 123 ("[A-Za-z0-9][^'`\"< \t\n]*>[ \t]*" supercite-citation) |
102 ;; Lisp comments | 124 ;; Lisp comments |
103 (";+" . lisp-comment) | 125 (";+" lisp-comment) |
104 ;; UNIX shell comments | 126 ;; UNIX shell comments |
105 ("#+" . sh-comment) | 127 ("#+" sh-comment) |
106 ;; Postscript comments | 128 ;; Postscript comments |
107 ("%+" . postscript-comment) | 129 ("%+" postscript-comment) |
108 ;; C++ comments | 130 ;; C++ comments |
109 ("///*" . c++-comment) | 131 ("///*" c++-comment) |
110 ;; Texinfo comments | 132 ;; Texinfo comments |
111 ("@c[ \t]" . texinfo-comment) | 133 ("@c[ \t]" texinfo-comment) |
112 ("@comment[ \t]" . texinfo-comment) | 134 ("@comment[ \t]" texinfo-comment) |
113 ;; Bullet types. | 135 ;; Bullet types. |
136 ;; | |
137 ;; LaTex \item | |
138 ;; | |
139 ("\\\\item[ \t]" bullet) | |
114 ;; | 140 ;; |
115 ;; 1. xxxxx | 141 ;; 1. xxxxx |
116 ;; xxxxx | 142 ;; xxxxx |
117 ;; | 143 ;; |
118 ("[0-9]+\\.[ \t]" . bullet) | 144 ("[0-9]+\\.[ \t]" bullet) |
119 ;; | 145 ;; |
120 ;; 2.1.3 xxxxx xx x xx x | 146 ;; 2.1.3 xxxxx xx x xx x |
121 ;; xxx | 147 ;; xxx |
122 ;; | 148 ;; |
123 ("[0-9]+\\(\\.[0-9]+\\)+[ \t]" . bullet) | 149 ("[0-9]+\\(\\.[0-9]+\\)+[ \t]" bullet) |
124 ;; | 150 ;; |
125 ;; a. xxxxxx xx | 151 ;; a. xxxxxx xx |
126 ;; xxx xxx | 152 ;; xxx xxx |
127 ;; | 153 ;; |
128 ("[A-Za-z]\\.[ \t]" . bullet) | 154 ("[A-Za-z]\\.[ \t]" bullet) |
129 ;; | 155 ;; |
130 ;; 1) xxxx x xx x xx or (1) xx xx x x xx xx | 156 ;; 1) xxxx x xx x xx or (1) xx xx x x xx xx |
131 ;; xx xx xxxx xxx xx x x xx x | 157 ;; xx xx xxxx xxx xx x x xx x |
132 ;; | 158 ;; |
133 ("(?[0-9]+)[ \t]" . bullet) | 159 ("(?[0-9]+)[ \t]" bullet) |
134 ;; | 160 ;; |
135 ;; a) xxxx x xx x xx or (a) xx xx x x xx xx | 161 ;; a) xxxx x xx x xx or (a) xx xx x x xx xx |
136 ;; xx xx xxxx xxx xx x x xx x | 162 ;; xx xx xxxx xxx xx x x xx x |
137 ;; | 163 ;; |
138 ("(?[A-Za-z])[ \t]" . bullet) | 164 ("(?[A-Za-z])[ \t]" bullet) |
139 ;; | 165 ;; |
140 ;; 2a. xx x xxx x x xxx | 166 ;; 2a. xx x xxx x x xxx |
141 ;; xxx xx x xx x | 167 ;; xxx xx x xx x |
142 ;; | 168 ;; |
143 ("[0-9]+[A-Za-z]\\.[ \t]" . bullet) | 169 ("[0-9]+[A-Za-z]\\.[ \t]" bullet) |
144 ;; | 170 ;; |
145 ;; 1a) xxxx x xx x xx or (1a) xx xx x x xx xx | 171 ;; 1a) xxxx x xx x xx or (1a) xx xx x x xx xx |
146 ;; xx xx xxxx xxx xx x x xx x | 172 ;; xx xx xxxx xxx xx x x xx x |
147 ;; | 173 ;; |
148 ("(?[0-9]+[A-Za-z])[ \t]" . bullet) | 174 ("(?[0-9]+[A-Za-z])[ \t]" bullet) |
149 ;; | 175 ;; |
150 ;; - xx xxx xxxx or * xx xx x xxx xxx | 176 ;; - xx xxx xxxx or * xx xx x xxx xxx |
151 ;; xxx xx xx x xxx x xx x x x | 177 ;; xxx xx xx x xxx x xx x x x |
152 ;; | 178 ;; |
153 ("[-~*+]+[ \t]" . bullet) | 179 ("[-~*+]+[ \t]" bullet) |
154 ;; | 180 ;; |
155 ;; o xx xxx xxxx xx x xx xxx x xxx xx x xxx | 181 ;; o xx xxx xxxx xx x xx xxx x xxx xx x xxx |
156 ;; xxx xx xx | 182 ;; xxx xx xx |
157 ;; | 183 ;; |
158 ("o[ \t]" . bullet) | 184 ("o[ \t]" bullet) |
159 ;; don't touch | 185 ;; don't touch |
160 ("[ \t]+" . space) | 186 ("[ \t]+" space) |
161 ("$" . end-of-line) | 187 ("$" end-of-line) |
162 ) | 188 ) |
163 "Table of tokens filladapt knows about. | 189 "Table of tokens filladapt knows about. |
164 Format is | 190 Format is |
165 | 191 |
166 ((REGEXP . SYM) ...) | 192 ((REGEXP SYM) ...) |
167 | 193 |
168 filladapt uses this table to build a tokenized representation of | 194 filladapt uses this table to build a tokenized representation of |
169 the beginning of the current line. Each REGEXP is matched | 195 the beginning of the current line. Each REGEXP is matched |
170 against the beginning of the line until a match is found. | 196 against the beginning of the line until a match is found. |
171 Matching is done case-sensitively. The corresponding SYM is | 197 Matching is done case-sensitively. The corresponding SYM is |
197 (postscript-comment postscript-comment) | 223 (postscript-comment postscript-comment) |
198 (c++-comment c++-comment) | 224 (c++-comment c++-comment) |
199 (texinfo-comment texinfo-comment) | 225 (texinfo-comment texinfo-comment) |
200 (bullet) | 226 (bullet) |
201 (space bullet space) | 227 (space bullet space) |
228 (beginning-of-line beginning-of-line) | |
202 ) | 229 ) |
203 "Table describing what tokens a certain token will match. | 230 "Table describing what tokens a certain token will match. |
204 | 231 |
205 To decide whether a line belongs in the current paragraph, | 232 To decide whether a line belongs in the current paragraph, |
206 filladapt creates a token list for the fill prefix of both lines. | 233 filladapt creates a token list for the fill prefix of both lines. |
259 the fill prefix.") | 286 the fill prefix.") |
260 | 287 |
261 (defvar filladapt-function-table | 288 (defvar filladapt-function-table |
262 (let ((assoc-list | 289 (let ((assoc-list |
263 (list (cons 'fill-paragraph (symbol-function 'fill-paragraph)) | 290 (list (cons 'fill-paragraph (symbol-function 'fill-paragraph)) |
291 (cons 'fill-region (symbol-function 'fill-region)) | |
264 (cons 'fill-region-as-paragraph | 292 (cons 'fill-region-as-paragraph |
265 (symbol-function 'fill-region-as-paragraph)) | 293 (symbol-function 'fill-region-as-paragraph)) |
266 (cons 'do-auto-fill (symbol-function 'do-auto-fill))))) | 294 (cons 'do-auto-fill (symbol-function 'do-auto-fill))))) |
267 ;; v18 Emacs doesn't have lisp-fill-paragraph | 295 ;; v18 Emacs doesn't have lisp-fill-paragraph |
268 (if (fboundp 'lisp-fill-paragraph) | 296 (if (fboundp 'lisp-fill-paragraph) |
347 ;; inside a comment. | 375 ;; inside a comment. |
348 (comment-multi-line t) | 376 (comment-multi-line t) |
349 fill-prefix retval) | 377 fill-prefix retval) |
350 (if (filladapt-adapt t nil) | 378 (if (filladapt-adapt t nil) |
351 (progn | 379 (progn |
352 (setq retval (filladapt-funcall function arg)) | 380 (if filladapt-fill-column-tolerance |
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))) | |
353 (run-hooks 'filladapt-fill-paragraph-post-hook) | 413 (run-hooks 'filladapt-fill-paragraph-post-hook) |
354 (throw 'done retval)))))) | 414 (throw 'done retval)))))) |
355 ;; filladapt-adapt failed, so do fill-paragraph normally. | 415 ;; filladapt-adapt failed, so do fill-paragraph normally. |
356 (filladapt-funcall function arg))) | 416 (filladapt-funcall function arg))) |
357 | 417 |
358 (defun fill-paragraph (arg) | 418 (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." | |
359 (interactive "*P") | 428 (interactive "*P") |
360 (let ((filladapt-inside-filladapt t)) | 429 (let ((filladapt-inside-filladapt t)) |
361 (filladapt-fill-paragraph 'fill-paragraph arg))) | 430 (filladapt-fill-paragraph 'fill-paragraph arg))) |
362 | 431 |
363 (defun lisp-fill-paragraph (&optional arg) | 432 (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." | |
364 (interactive "*P") | 440 (interactive "*P") |
365 (let ((filladapt-inside-filladapt t)) | 441 (let ((filladapt-inside-filladapt t)) |
366 (filladapt-fill-paragraph 'lisp-fill-paragraph arg))) | 442 (filladapt-fill-paragraph 'lisp-fill-paragraph arg))) |
367 | 443 |
368 (defun fill-region-as-paragraph (beg end &optional justify nosqueeze squeeze-after) | 444 (defun fill-region-as-paragraph (beg end &optional justify |
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." | |
369 (interactive "*r\nP") | 465 (interactive "*r\nP") |
370 (if (and filladapt-mode (not filladapt-inside-filladapt)) | 466 (if (and filladapt-mode (not filladapt-inside-filladapt)) |
371 (save-restriction | 467 (save-restriction |
372 (narrow-to-region beg end) | 468 (narrow-to-region beg end) |
373 (let ((filladapt-inside-filladapt t) | 469 (let ((filladapt-inside-filladapt t) |
374 line-start last-token) | 470 line-start last-token) |
375 (goto-char beg) | 471 (goto-char beg) |
472 (while (equal (char-after (point)) ?\n) | |
473 (delete-char 1)) | |
376 (end-of-line) | 474 (end-of-line) |
377 (while (zerop (forward-line)) | 475 (while (zerop (forward-line)) |
378 (if (setq last-token | 476 (if (setq last-token |
379 (car (filladapt-tail (filladapt-parse-prefixes)))) | 477 (car (filladapt-tail (filladapt-parse-prefixes)))) |
380 (progn | 478 (progn |
403 (wrong-number-of-arguments | 501 (wrong-number-of-arguments |
404 (condition-case nil | 502 (condition-case nil |
405 ;; four args for Emacs 19.29 | 503 ;; four args for Emacs 19.29 |
406 (filladapt-funcall 'fill-region-as-paragraph beg end | 504 (filladapt-funcall 'fill-region-as-paragraph beg end |
407 justify nosqueeze) | 505 justify nosqueeze) |
408 ;; three args for the rest of the world. | 506 ;; 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) | |
409 (wrong-number-of-arguments | 554 (wrong-number-of-arguments |
410 (filladapt-funcall 'fill-region-as-paragraph beg end justify))))))) | 555 (condition-case nil |
556 (filladapt-funcall 'fill-region beg end justify nosqueeze) | |
557 (wrong-number-of-arguments | |
558 (filladapt-funcall 'fill-region beg end justify))))))) | |
411 | 559 |
412 (defvar zmacs-region-stays) ; for XEmacs | 560 (defvar zmacs-region-stays) ; for XEmacs |
413 | 561 |
414 (defun filladapt-mode (&optional arg) | 562 (defun filladapt-mode (&optional arg) |
415 "Toggle Filladapt minor mode. | 563 "Toggle Filladapt minor mode. |
461 (save-excursion | 609 (save-excursion |
462 (let ((token-list nil) | 610 (let ((token-list nil) |
463 (done nil) | 611 (done nil) |
464 (old-point (point)) | 612 (old-point (point)) |
465 (case-fold-search nil) | 613 (case-fold-search nil) |
466 token-table not-token-table) | 614 token-table not-token-table moved) |
467 (catch 'done | 615 (catch 'done |
468 (while (not done) | 616 (while (not done) |
469 (setq not-token-table filladapt-not-token-table) | 617 (setq not-token-table filladapt-not-token-table) |
470 (while not-token-table | 618 (while not-token-table |
471 (if (looking-at (car not-token-table)) | 619 (if (looking-at (car not-token-table)) |
475 done t) | 623 done t) |
476 (while token-table | 624 (while token-table |
477 (if (null (looking-at (car (car token-table)))) | 625 (if (null (looking-at (car (car token-table)))) |
478 (setq token-table (cdr token-table)) | 626 (setq token-table (cdr token-table)) |
479 (goto-char (match-end 0)) | 627 (goto-char (match-end 0)) |
480 (setq token-list (cons (list (cdr (car token-table)) | 628 (setq token-list (cons (list (nth 1 (car token-table)) |
481 (current-column) | 629 (current-column) |
482 (buffer-substring | 630 (buffer-substring |
483 (match-beginning 0) | 631 (match-beginning 0) |
484 (match-end 0))) | 632 (match-end 0))) |
485 token-list) | 633 token-list) |
486 token-table nil | 634 moved (not (eq (point) old-point)) |
487 done (eq (point) old-point) | 635 token-table (if moved nil (cdr token-table)) |
636 done (not moved) | |
488 old-point (point)))))) | 637 old-point (point)))))) |
489 (nreverse token-list)))) | 638 (nreverse token-list)))) |
490 | 639 |
491 (defun filladapt-tokens-match-p (list1 list2) | 640 (defun filladapt-tokens-match-p (list1 list2) |
492 "Compare two token lists and return non-nil if they match, nil otherwise. | 641 "Compare two token lists and return non-nil if they match, nil otherwise. |
581 (cons | 730 (cons |
582 (nth 2 (car list)) | 731 (nth 2 (car list)) |
583 prefix-list)))) | 732 prefix-list)))) |
584 (setq list (cdr list))) | 733 (setq list (cdr list))) |
585 (apply (function concat) (nreverse prefix-list)) )) | 734 (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 )))) | |
586 | 749 |
587 (defun filladapt-convert-to-spaces (string) | 750 (defun filladapt-convert-to-spaces (string) |
588 "Return a copy of STRING, with all non-tabs and non-space changed to spaces." | 751 "Return a copy of STRING, with all non-tabs and non-space changed to spaces." |
589 (let ((i 0) | 752 (let ((i 0) |
590 (space-list '(?\ ?\t)) | 753 (space-list '(?\ ?\t)) |
708 (defun filladapt-debug () | 871 (defun filladapt-debug () |
709 "Toggle filladapt debugging on/off in the current buffer." | 872 "Toggle filladapt debugging on/off in the current buffer." |
710 ;; (interactive) | 873 ;; (interactive) |
711 (make-local-variable 'filladapt-debug) | 874 (make-local-variable 'filladapt-debug) |
712 (setq filladapt-debug (not filladapt-debug)) | 875 (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) | |
717 (if (null filladapt-debug) | 876 (if (null filladapt-debug) |
718 (progn | 877 (progn |
719 (mapcar (function (lambda (e) (filladapt-set-extent-endpoints e 1 1))) | 878 (mapcar (function (lambda (e) (filladapt-set-extent-endpoints e 1 1))) |
720 filladapt-debug-indentation-extents) | 879 filladapt-debug-indentation-extents) |
721 (if filladapt-debug-paragraph-extent | 880 (if filladapt-debug-paragraph-extent |