aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVinicius Jose Latorre2008-04-16 03:41:17 +0000
committerVinicius Jose Latorre2008-04-16 03:41:17 +0000
commit55d1cfe8703c5829bacc8d129277f1f9b33950f6 (patch)
tree2c376d35571c86cc1201eb5af5e35ea1e629af33
parenta588d349153a86e892901e9c63352d35a064bb3d (diff)
downloademacs-55d1cfe8703c5829bacc8d129277f1f9b33950f6.tar.gz
emacs-55d1cfe8703c5829bacc8d129277f1f9b33950f6.zip
Honor the indent-tabs-mode and tab-width setting from user.
-rw-r--r--lisp/ChangeLog56
-rw-r--r--lisp/whitespace.el1239
2 files changed, 890 insertions, 405 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 32734c15c24..0205b66ec94 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -14,6 +14,62 @@
14 14
15 * vc.el: Rename vc-status to vc-dir and the vc-status var to vc-ewoc. 15 * vc.el: Rename vc-status to vc-dir and the vc-status var to vc-ewoc.
16 16
172008-04-15 Vinicius Jose Latorre <viniciusjl@ig.com.br>
18
19 * whitespace.el: Honor the `indent-tabs-mode' setting from user.
20 Suggested by Stephen Deasey <sdeasey@gmail.com>. Honor also the
21 `tab-width' setting from user. New version 10.0. Doc and docstring
22 fix.
23 (whitespace-style, whitespace-chars): Remove options.
24 (whitespace-style-mark): New option, replace whitespace-style deleted
25 option. Fix docstring.
26 (whitespace-style-color): New option, replace whitespace-chars deleted
27 option. Fix docstring.
28 (whitespace-space, whitespace-hspace, whitespace-tab)
29 (whitespace-newline, whitespace-trailing, whitespace-line)
30 (whitespace-space-before-tab, whitespace-indentation, whitespace-empty)
31 (whitespace-space-after-tab, whitespace-hspace-regexp)
32 (whitespace-space-regexp, whitespace-tab-regexp)
33 (whitespace-trailing-regexp, whitespace-empty-at-bob-regexp)
34 (whitespace-empty-at-eob-regexp, whitespace-line-column)
35 (whitespace-toggle-option-alist): Fix docstring.
36 (whitespace-space-before-tab-regexp, whitespace-indentation-regexp)
37 (whitespace-space-after-tab-regexp, whitespace-display-mappings): Fix
38 docstring and initialization.
39 (global-whitespace-mode): Autoloaded global minor mode.
40 (whitespace-chars-value-list, whitespace-style-value-list)
41 (whitespace-active-chars, whitespace-active-style)
42 (whitespace-toggle-chars, whitespace-toggle-style): Remove vars.
43 (whitespace-color-value-list): New var, replace
44 whitespace-chars-value-list removed var.
45 (whitespace-mark-value-list): New var, replace
46 whitespace-style-value-list removed var.
47 (whitespace-active-color): New var, replace whitespace-active-chars
48 removed var.
49 (whitespace-active-mark): New var, replace whitespace-active-style
50 removed var.
51 (whitespace-toggle-color): New var, replace whitespace-toggle-chars
52 removed var.
53 (whitespace-toggle-mark): New var, replace whitespace-toggle-style
54 removed var.
55 (whitespace-toggle-option-alist, whitespace-report-list)
56 (whitespace-report-text, whitespace-help-text): Fix initialization.
57 (whitespace-indent-tabs-mode, whitespace-tab-width): New vars.
58 (whitespace-toggle-options, global-whitespace-toggle-options)
59 (whitespace-cleanup-region, whitespace-report-region)
60 (whitespace-interactive-char): Fix docstring and code.
61 (whitespace-cleanup, whitespace-report): Fix docstring.
62 (whitespace-replace-spaces-by-tabs): Remove fun.
63 (whitespace-replace-action): New fun, replace
64 whitespace-replace-spaces-by-tabs removed fun.
65 (whitespace-regexp, whitespace-indentation-regexp)
66 (whitespace-space-after-tab-regexp, whitespace-insert-value)
67 (whitespace-kill-buffer): New funs.
68 (whitespace-insert-option-mark, whitespace-help-on)
69 (whitespace-help-off, whitespace-turn-on, whitespace-turn-off)
70 (whitespace-color-on, whitespace-color-off)
71 (whitespace-display-char-on): Fix code.
72
172008-04-15 Stefan Monnier <monnier@iro.umontreal.ca> 732008-04-15 Stefan Monnier <monnier@iro.umontreal.ca>
18 74
19 * mouse-drag.el (mouse-throw-magnifier-with-scroll-bar) 75 * mouse-drag.el (mouse-throw-magnifier-with-scroll-bar)
diff --git a/lisp/whitespace.el b/lisp/whitespace.el
index d156d47f12c..b94ed941370 100644
--- a/lisp/whitespace.el
+++ b/lisp/whitespace.el
@@ -6,7 +6,7 @@
6;; Author: Vinicius Jose Latorre <viniciusjl@ig.com.br> 6;; Author: Vinicius Jose Latorre <viniciusjl@ig.com.br>
7;; Maintainer: Vinicius Jose Latorre <viniciusjl@ig.com.br> 7;; Maintainer: Vinicius Jose Latorre <viniciusjl@ig.com.br>
8;; Keywords: data, wp 8;; Keywords: data, wp
9;; Version: 9.3 9;; Version: 10.0
10;; X-URL: http://www.emacswiki.org/cgi-bin/wiki/ViniciusJoseLatorre 10;; X-URL: http://www.emacswiki.org/cgi-bin/wiki/ViniciusJoseLatorre
11 11
12;; This file is part of GNU Emacs. 12;; This file is part of GNU Emacs.
@@ -46,8 +46,8 @@
46;; it provides a visual mark for characters, for example, at the end 46;; it provides a visual mark for characters, for example, at the end
47;; of line (?\xB6), at SPACEs (?\xB7) and at TABs (?\xBB). 47;; of line (?\xB6), at SPACEs (?\xB7) and at TABs (?\xBB).
48;; 48;;
49;; The `whitespace-style' and `whitespace-chars' variables are used to 49;; The `whitespace-style-mark' and `whitespace-style-color' variables
50;; select which way should be used to visualize blanks. 50;; are used to select which way should be used to visualize blanks.
51;; 51;;
52;; Note that when whitespace is turned on, whitespace saves the 52;; Note that when whitespace is turned on, whitespace saves the
53;; font-lock state, that is, if font-lock is on or off. And 53;; font-lock state, that is, if font-lock is on or off. And
@@ -178,24 +178,42 @@
178;; 178;;
179;; 1. empty lines at beginning of buffer. 179;; 1. empty lines at beginning of buffer.
180;; 2. empty lines at end of buffer. 180;; 2. empty lines at end of buffer.
181;; If `whitespace-chars' includes the value `empty', remove all 181;; If `whitespace-style-color' includes the value `empty', remove
182;; empty lines at beginning and/or end of buffer. 182;; all empty lines at beginning and/or end of buffer.
183;; 183;;
184;; 3. 8 or more SPACEs at beginning of line. 184;; 3. 8 or more SPACEs at beginning of line.
185;; If `whitespace-chars' includes the value `indentation', replace 185;; If `whitespace-style-color' includes the value `indentation':
186;; 8 or more SPACEs at beginning of line by TABs. 186;; replace 8 or more SPACEs at beginning of line by TABs, if
187;; `indent-tabs-mode' is non-nil; otherwise, replace TABs by
188;; SPACEs.
189;; If `whitespace-style-color' includes the value
190;; `indentation::tab', replace 8 or more SPACEs at beginning of line
191;; by TABs.
192;; If `whitespace-style-color' includes the value
193;; `indentation::space', replace TABs by SPACEs.
187;; 194;;
188;; 4. SPACEs before TAB. 195;; 4. SPACEs before TAB.
189;; If `whitespace-chars' includes the value `space-before-tab', 196;; If `whitespace-style-color' includes the value
190;; replace SPACEs by TABs. 197;; `space-before-tab': replace SPACEs by TABs, if
198;; `indent-tabs-mode' is non-nil; otherwise, replace TABs by
199;; SPACEs.
200;; If `whitespace-style-color' includes the value
201;; `space-before-tab::tab', replace SPACEs by TABs.
202;; If `whitespace-style-color' includes the value
203;; `space-before-tab::space', replace TABs by SPACEs.
191;; 204;;
192;; 5. SPACEs or TABs at end of line. 205;; 5. SPACEs or TABs at end of line.
193;; If `whitespace-chars' includes the value `trailing', remove all 206;; If `whitespace-style-color' includes the value `trailing',
194;; SPACEs or TABs at end of line. 207;; remove all SPACEs or TABs at end of line.
195;; 208;;
196;; 6. 8 or more SPACEs after TAB. 209;; 6. 8 or more SPACEs after TAB.
197;; If `whitespace-chars' includes the value `space-after-tab', 210;; If `whitespace-style-color' includes the value
198;; replace SPACEs by TABs. 211;; `space-after-tab': replace SPACEs by TABs, if `indent-tabs-mode'
212;; is non-nil; otherwise, replace TABs by SPACEs.
213;; If `whitespace-style-color' includes the value
214;; `space-after-tab::tab', replace SPACEs by TABs.
215;; If `whitespace-style-color' includes the value
216;; `space-after-tab::space', replace TABs by SPACEs.
199;; 217;;
200;; 218;;
201;; Hooks 219;; Hooks
@@ -219,10 +237,11 @@
219;; Below it's shown a brief description of whitespace options, please, 237;; Below it's shown a brief description of whitespace options, please,
220;; see the options declaration in the code for a long documentation. 238;; see the options declaration in the code for a long documentation.
221;; 239;;
222;; `whitespace-style' Specify the visualization style. 240;; `whitespace-style-mark' Specify which kind of blank is
241;; visualized via display table.
223;; 242;;
224;; `whitespace-chars' Specify which kind of blank is 243;; `whitespace-style-color' Specify which kind of blank is
225;; visualized. 244;; visualized via faces.
226;; 245;;
227;; `whitespace-space' Face used to visualize SPACE. 246;; `whitespace-space' Face used to visualize SPACE.
228;; 247;;
@@ -290,8 +309,12 @@
290;; Acknowledgements 309;; Acknowledgements
291;; ---------------- 310;; ----------------
292;; 311;;
293;; Thanks to Eric Cooper <ecc@cmu.edu> for the suggestion to have hook actions 312;; Thanks to Stephen Deasey <sdeasey@gmail.com> for the
294;; when buffer is written or killed as the original whitespace package had. 313;; `indent-tabs-mode' usage suggestion.
314;;
315;; Thanks to Eric Cooper <ecc@cmu.edu> for the suggestion to have hook
316;; actions when buffer is written or killed as the original whitespace
317;; package had.
295;; 318;;
296;; Thanks to nschum (EmacsWiki) for the idea about highlight "long" 319;; Thanks to nschum (EmacsWiki) for the idea about highlight "long"
297;; lines tail. See EightyColumnRule (EmacsWiki). 320;; lines tail. See EightyColumnRule (EmacsWiki).
@@ -351,31 +374,36 @@
351 :group 'data) 374 :group 'data)
352 375
353 376
354(defcustom whitespace-style '(mark color) 377(defcustom whitespace-style-mark '(space-mark tab-mark newline-mark)
355 "*Specify the visualization style. 378 "*Specify which kind of blank is visualized via display table.
356 379
357It's a list containing some or all of the following values: 380It's a list containing some or all of the following values:
358 381
359 mark display mappings are visualized. 382 space-mark SPACEs and HARD SPACEs are visualized.
383
384 tab-mark TABs are visualized.
360 385
361 color faces are visualized. 386 newline-mark NEWLINEs are visualized.
362 387
363Any other value is ignored. 388Any other value is ignored.
364 389
365If nil, don't visualize TABs, (HARD) SPACEs and NEWLINEs. 390If nil, don't visualize TABs, (HARD) SPACEs and NEWLINEs via display
391table.
366 392
367See also `whitespace-display-mappings' for documentation." 393See also `whitespace-display-mappings' for documentation."
368 :type '(repeat :tag "Style of Blank" 394 :type '(repeat :tag "Kind of Blank Mark"
369 (choice :tag "Style of Blank" 395 (choice :tag "Kind of Blank Mark"
370 (const :tag "Display Table" mark) 396 (const :tag "SPACEs and HARD SPACEs"
371 (const :tag "Faces" color))) 397 space-mark)
398 (const :tag "TABs" tab-mark)
399 (const :tag "NEWLINEs" newline-mark)))
372 :group 'whitespace) 400 :group 'whitespace)
373 401
374 402
375(defcustom whitespace-chars 403(defcustom whitespace-style-color
376 '(tabs spaces trailing lines space-before-tab newline 404 '(tabs spaces trailing lines space-before-tab newline
377 indentation empty space-after-tab) 405 indentation empty space-after-tab)
378 "*Specify which kind of blank is visualized. 406 "*Specify which kind of blank is visualized via faces.
379 407
380It's a list containing some or all of the following values: 408It's a list containing some or all of the following values:
381 409
@@ -396,29 +424,74 @@ It's a list containing some or all of the following values:
396 But only the part of line which goes 424 But only the part of line which goes
397 beyond `whitespace-line-column' column. 425 beyond `whitespace-line-column' column.
398 It has effect only if `lines' (see above) 426 It has effect only if `lines' (see above)
399 is not present in `whitespace-chars'. 427 is not present in `whitespace-style-color'.
400
401 space-before-tab SPACEs before TAB are visualized.
402 428
403 newline NEWLINEs are visualized. 429 newline NEWLINEs are visualized.
404 430
405 indentation 8 or more SPACEs at beginning of line are
406 visualized.
407
408 empty empty lines at beginning and/or end of buffer 431 empty empty lines at beginning and/or end of buffer
409 are visualized. 432 are visualized.
410 433
411 space-after-tab 8 or more SPACEs after a TAB are visualized. 434 indentation::tab 8 or more SPACEs at beginning of line are
435 visualized.
436
437 indentation::space TABs at beginning of line are visualized.
412 438
413Any other value is ignored. 439 indentation 8 or more SPACEs at beginning of line are
440 visualized, if `indent-tabs-mode' (which see)
441 is non-nil; otherwise, TABs at beginning of
442 line are visualized.
443
444 space-after-tab::tab 8 or more SPACEs after a TAB are
445 visualized.
446
447 space-after-tab::space TABs are visualized when occurs 8 or
448 more SPACEs after a TAB.
449
450 space-after-tab 8 or more SPACEs after a TAB are
451 visualized, if `indent-tabs-mode'
452 (which see) is non-nil; otherwise,
453 the TABs are visualized.
454
455 space-before-tab::tab SPACEs before TAB are visualized.
414 456
415If nil, don't visualize TABs, (HARD) SPACEs and NEWLINEs. 457 space-before-tab::space TABs are visualized when occurs SPACEs
458 before TAB.
416 459
417Used when `whitespace-style' includes the value `color'. 460 space-before-tab SPACEs before TAB are visualized, if
418Used also when `whitespace-chars' includes `newline', 461 `indent-tabs-mode' (which see) is
419and `whitespace-style' includes `mark'." 462 non-nil; otherwise, the TABs are
420 :type '(repeat :tag "Kind of Blank" 463 visualized.
421 (choice :tag "Kind of Blank" 464
465Any other value is ignored.
466
467If nil, don't visualize TABs, (HARD) SPACEs and NEWLINEs via faces.
468
469There is an evaluation order for some values, if some values are
470included in `whitespace-style-color' list. For example, if
471indentation, indentation::tab and/or indentation::space are
472included in `whitespace-style-color' list. The evaluation order
473for these values is:
474
475 * For indentation:
476 1. indentation
477 2. indentation::tab
478 3. indentation::space
479
480 * For SPACEs after TABs:
481 1. space-after-tab
482 2. space-after-tab::tab
483 3. space-after-tab::space
484
485 * For SPACEs before TABs:
486 1. space-before-tab
487 2. space-before-tab::tab
488 3. space-before-tab::space
489
490So, for example, if indentation and indentation::space are
491included in `whitespace-style-color' list, the indentation value
492is evaluated instead of indentation::space value."
493 :type '(repeat :tag "Kind of Blank Face"
494 (choice :tag "Kind of Blank Face"
422 (const :tag "Trailing TABs, SPACEs and HARD SPACEs" 495 (const :tag "Trailing TABs, SPACEs and HARD SPACEs"
423 trailing) 496 trailing)
424 (const :tag "SPACEs and HARD SPACEs" spaces) 497 (const :tag "SPACEs and HARD SPACEs" spaces)
@@ -438,7 +511,7 @@ and `whitespace-style' includes `mark'."
438(defcustom whitespace-space 'whitespace-space 511(defcustom whitespace-space 'whitespace-space
439 "*Symbol face used to visualize SPACE. 512 "*Symbol face used to visualize SPACE.
440 513
441Used when `whitespace-style' includes the value `color'." 514Used when `whitespace-style-color' includes the value `spaces'."
442 :type 'face 515 :type 'face
443 :group 'whitespace) 516 :group 'whitespace)
444 517
@@ -456,7 +529,7 @@ Used when `whitespace-style' includes the value `color'."
456(defcustom whitespace-hspace 'whitespace-hspace 529(defcustom whitespace-hspace 'whitespace-hspace
457 "*Symbol face used to visualize HARD SPACE. 530 "*Symbol face used to visualize HARD SPACE.
458 531
459Used when `whitespace-style' includes the value `color'." 532Used when `whitespace-style-color' includes the value `spaces'."
460 :type 'face 533 :type 'face
461 :group 'whitespace) 534 :group 'whitespace)
462 535
@@ -474,7 +547,7 @@ Used when `whitespace-style' includes the value `color'."
474(defcustom whitespace-tab 'whitespace-tab 547(defcustom whitespace-tab 'whitespace-tab
475 "*Symbol face used to visualize TAB. 548 "*Symbol face used to visualize TAB.
476 549
477Used when `whitespace-style' includes the value `color'." 550Used when `whitespace-style-color' includes the value `tabs'."
478 :type 'face 551 :type 'face
479 :group 'whitespace) 552 :group 'whitespace)
480 553
@@ -494,8 +567,8 @@ Used when `whitespace-style' includes the value `color'."
494 567
495See `whitespace-display-mappings'. 568See `whitespace-display-mappings'.
496 569
497Used when `whitespace-style' includes the values `mark' 570Used when `whitespace-style-mark' includes the values `newline-mark'
498and `color', and `whitespace-chars' includes `newline'." 571and `whitespace-style-color' includes `newline'."
499 :type 'face 572 :type 'face
500 :group 'whitespace) 573 :group 'whitespace)
501 574
@@ -515,7 +588,7 @@ See `whitespace-display-mappings'."
515(defcustom whitespace-trailing 'whitespace-trailing 588(defcustom whitespace-trailing 'whitespace-trailing
516 "*Symbol face used to visualize traling blanks. 589 "*Symbol face used to visualize traling blanks.
517 590
518Used when `whitespace-style' includes the value `color'." 591Used when `whitespace-style-color' includes the value `trailing'."
519 :type 'face 592 :type 'face
520 :group 'whitespace) 593 :group 'whitespace)
521 594
@@ -532,7 +605,7 @@ Used when `whitespace-style' includes the value `color'."
532 605
533See `whitespace-line-column'. 606See `whitespace-line-column'.
534 607
535Used when `whitespace-style' includes the value `color'." 608Used when `whitespace-style-color' includes the value `line'."
536 :type 'face 609 :type 'face
537 :group 'whitespace) 610 :group 'whitespace)
538 611
@@ -549,7 +622,7 @@ See `whitespace-line-column'."
549(defcustom whitespace-space-before-tab 'whitespace-space-before-tab 622(defcustom whitespace-space-before-tab 'whitespace-space-before-tab
550 "*Symbol face used to visualize SPACEs before TAB. 623 "*Symbol face used to visualize SPACEs before TAB.
551 624
552Used when `whitespace-style' includes the value `color'." 625Used when `whitespace-style-color' includes the value `space-before-tab'."
553 :type 'face 626 :type 'face
554 :group 'whitespace) 627 :group 'whitespace)
555 628
@@ -564,7 +637,7 @@ Used when `whitespace-style' includes the value `color'."
564(defcustom whitespace-indentation 'whitespace-indentation 637(defcustom whitespace-indentation 'whitespace-indentation
565 "*Symbol face used to visualize 8 or more SPACEs at beginning of line. 638 "*Symbol face used to visualize 8 or more SPACEs at beginning of line.
566 639
567Used when `whitespace-style' includes the value `color'." 640Used when `whitespace-style-color' includes the value `indentation'."
568 :type 'face 641 :type 'face
569 :group 'whitespace) 642 :group 'whitespace)
570 643
@@ -579,7 +652,7 @@ Used when `whitespace-style' includes the value `color'."
579(defcustom whitespace-empty 'whitespace-empty 652(defcustom whitespace-empty 'whitespace-empty
580 "*Symbol face used to visualize empty lines at beginning and/or end of buffer. 653 "*Symbol face used to visualize empty lines at beginning and/or end of buffer.
581 654
582Used when `whitespace-style' includes the value `color'." 655Used when `whitespace-style-color' includes the value `empty'."
583 :type 'face 656 :type 'face
584 :group 'whitespace) 657 :group 'whitespace)
585 658
@@ -594,7 +667,7 @@ Used when `whitespace-style' includes the value `color'."
594(defcustom whitespace-space-after-tab 'whitespace-space-after-tab 667(defcustom whitespace-space-after-tab 'whitespace-space-after-tab
595 "*Symbol face used to visualize 8 or more SPACEs after TAB. 668 "*Symbol face used to visualize 8 or more SPACEs after TAB.
596 669
597Used when `whitespace-style' includes the value `color'." 670Used when `whitespace-style-color' includes the value `space-after-tab'."
598 :type 'face 671 :type 'face
599 :group 'whitespace) 672 :group 'whitespace)
600 673
@@ -630,8 +703,7 @@ visualize only HARD SPACEs between TABs.
630NOTE: Enclose always by \\\\( and \\\\) the elements to highlight. 703NOTE: Enclose always by \\\\( and \\\\) the elements to highlight.
631 Use exactly one pair of enclosing \\\\( and \\\\). 704 Use exactly one pair of enclosing \\\\( and \\\\).
632 705
633Used when `whitespace-style' includes the value `color', 706Used when `whitespace-style-color' includes `spaces'."
634and `whitespace-chars' includes `spaces'."
635 :type '(regexp :tag "HARD SPACE Chars") 707 :type '(regexp :tag "HARD SPACE Chars")
636 :group 'whitespace) 708 :group 'whitespace)
637 709
@@ -653,8 +725,7 @@ visualize leading and/or trailing SPACEs.
653NOTE: Enclose always by \\\\( and \\\\) the elements to highlight. 725NOTE: Enclose always by \\\\( and \\\\) the elements to highlight.
654 Use exactly one pair of enclosing \\\\( and \\\\). 726 Use exactly one pair of enclosing \\\\( and \\\\).
655 727
656Used when `whitespace-style' includes the value `color', 728Used when `whitespace-style-color' includes `spaces'."
657and `whitespace-chars' includes `spaces'."
658 :type '(regexp :tag "SPACE Chars") 729 :type '(regexp :tag "SPACE Chars")
659 :group 'whitespace) 730 :group 'whitespace)
660 731
@@ -676,8 +747,7 @@ visualize leading and/or trailing TABs.
676NOTE: Enclose always by \\\\( and \\\\) the elements to highlight. 747NOTE: Enclose always by \\\\( and \\\\) the elements to highlight.
677 Use exactly one pair of enclosing \\\\( and \\\\). 748 Use exactly one pair of enclosing \\\\( and \\\\).
678 749
679Used when `whitespace-style' includes the value `color', 750Used when `whitespace-style-color' includes `tabs'."
680and `whitespace-chars' includes `tabs'."
681 :type '(regexp :tag "TAB Chars") 751 :type '(regexp :tag "TAB Chars")
682 :group 'whitespace) 752 :group 'whitespace)
683 753
@@ -697,13 +767,12 @@ NOTE: DO NOT enclose by \\\\( and \\\\) the elements to highlight.
697 `whitespace-mode' surrounds this regexp by \"\\\\(\\\\(\" and 767 `whitespace-mode' surrounds this regexp by \"\\\\(\\\\(\" and
698 \"\\\\)+\\\\)$\". 768 \"\\\\)+\\\\)$\".
699 769
700Used when `whitespace-style' includes the value `color', 770Used when `whitespace-style-color' includes `trailing'."
701and `whitespace-chars' includes `trailing'."
702 :type '(regexp :tag "Trailing Chars") 771 :type '(regexp :tag "Trailing Chars")
703 :group 'whitespace) 772 :group 'whitespace)
704 773
705 774
706(defcustom whitespace-space-before-tab-regexp "\\( +\\)\t" 775(defcustom whitespace-space-before-tab-regexp "\\( +\\)\\(\t+\\)"
707 "*Specify SPACEs before TAB regexp. 776 "*Specify SPACEs before TAB regexp.
708 777
709If you're using `mule' package, there may be other characters besides: 778If you're using `mule' package, there may be other characters besides:
@@ -713,16 +782,20 @@ If you're using `mule' package, there may be other characters besides:
713 782
714that should be considered blank. 783that should be considered blank.
715 784
716Used when `whitespace-style' includes the value `color', 785Used when `whitespace-style-color' includes `space-before-tab',
717and `whitespace-chars' includes `space-before-tab'." 786`space-before-tab::tab' or `space-before-tab::space'."
718 :type '(regexp :tag "SPACEs Before TAB") 787 :type '(regexp :tag "SPACEs Before TAB")
719 :group 'whitespace) 788 :group 'whitespace)
720 789
721 790
722(defcustom whitespace-indentation-regexp 791(defcustom whitespace-indentation-regexp
723 "^\t*\\(\\( \\{8\\}\\)+\\)[^\n\t]" 792 '("^\t*\\(\\( \\{%d\\}\\)+\\)[^\n\t]"
793 . "^ *\\(\t+\\)[^\n]")
724 "*Specify regexp for 8 or more SPACEs at beginning of line. 794 "*Specify regexp for 8 or more SPACEs at beginning of line.
725 795
796It is a cons where the cons car is used for SPACEs visualization
797and the cons cdr is used for TABs visualization.
798
726If you're using `mule' package, there may be other characters besides: 799If you're using `mule' package, there may be other characters besides:
727 800
728 \" \" \"\\t\" \"\\xA0\" \"\\x8A0\" \"\\x920\" \"\\xE20\" \ 801 \" \" \"\\t\" \"\\xA0\" \"\\x8A0\" \"\\x920\" \"\\xE20\" \
@@ -730,9 +803,10 @@ If you're using `mule' package, there may be other characters besides:
730 803
731that should be considered blank. 804that should be considered blank.
732 805
733Used when `whitespace-style' includes the value `color', 806Used when `whitespace-style-color' includes `indentation',
734and `whitespace-chars' includes `indentation'." 807`indentation::tab' or `indentation::space'."
735 :type '(regexp :tag "Indentation SPACEs") 808 :type '(cons (regexp :tag "Indentation SPACEs")
809 (regexp :tag "Indentation TABs"))
736 :group 'whitespace) 810 :group 'whitespace)
737 811
738 812
@@ -746,8 +820,7 @@ If you're using `mule' package, there may be other characters besides:
746 820
747that should be considered blank. 821that should be considered blank.
748 822
749Used when `whitespace-style' includes the value `color', 823Used when `whitespace-style-color' includes `empty'."
750and `whitespace-chars' includes `empty'."
751 :type '(regexp :tag "Empty Lines At Beginning Of Buffer") 824 :type '(regexp :tag "Empty Lines At Beginning Of Buffer")
752 :group 'whitespace) 825 :group 'whitespace)
753 826
@@ -762,15 +835,19 @@ If you're using `mule' package, there may be other characters besides:
762 835
763that should be considered blank. 836that should be considered blank.
764 837
765Used when `whitespace-style' includes the value `color', 838Used when `whitespace-style-color' includes `empty'."
766and `whitespace-chars' includes `empty'."
767 :type '(regexp :tag "Empty Lines At End Of Buffer") 839 :type '(regexp :tag "Empty Lines At End Of Buffer")
768 :group 'whitespace) 840 :group 'whitespace)
769 841
770 842
771(defcustom whitespace-space-after-tab-regexp "\t\\(\\( \\{8\\}\\)+\\)" 843(defcustom whitespace-space-after-tab-regexp
844 '("\t+\\(\\( \\{%d\\}\\)+\\)"
845 . "\\(\t+\\) +")
772 "*Specify regexp for 8 or more SPACEs after TAB. 846 "*Specify regexp for 8 or more SPACEs after TAB.
773 847
848It is a cons where the cons car is used for SPACEs visualization
849and the cons cdr is used for TABs visualization.
850
774If you're using `mule' package, there may be other characters besides: 851If you're using `mule' package, there may be other characters besides:
775 852
776 \" \" \"\\t\" \"\\xA0\" \"\\x8A0\" \"\\x920\" \"\\xE20\" \ 853 \" \" \"\\t\" \"\\xA0\" \"\\x8A0\" \"\\x920\" \"\\xE20\" \
@@ -778,8 +855,8 @@ If you're using `mule' package, there may be other characters besides:
778 855
779that should be considered blank. 856that should be considered blank.
780 857
781Used when `whitespace-style' includes the value `color', 858Used when `whitespace-style-color' includes `space-after-tab',
782and `whitespace-chars' includes `space-after-tab'." 859`space-after-tab::tab' or `space-after-tab::space'."
783 :type '(regexp :tag "SPACEs After TAB") 860 :type '(regexp :tag "SPACEs After TAB")
784 :group 'whitespace) 861 :group 'whitespace)
785 862
@@ -787,8 +864,7 @@ and `whitespace-chars' includes `space-after-tab'."
787(defcustom whitespace-line-column 80 864(defcustom whitespace-line-column 80
788 "*Specify column beyond which the line is highlighted. 865 "*Specify column beyond which the line is highlighted.
789 866
790Used when `whitespace-style' includes the value `color', 867Used when `whitespace-style-color' includes `lines' or `lines-tail'."
791and `whitespace-chars' includes `lines' or `lines-tail'."
792 :type '(integer :tag "Line Length") 868 :type '(integer :tag "Line Length")
793 :group 'whitespace) 869 :group 'whitespace)
794 870
@@ -796,35 +872,44 @@ and `whitespace-chars' includes `lines' or `lines-tail'."
796;; Hacked from `visible-whitespace-mappings' in visws.el 872;; Hacked from `visible-whitespace-mappings' in visws.el
797(defcustom whitespace-display-mappings 873(defcustom whitespace-display-mappings
798 '( 874 '(
799 (?\ [?\xB7] [?.]) ; space - centered dot 875 (space-mark ?\ [?\xB7] [?.]) ; space - centered dot
800 (?\xA0 [?\xA4] [?_]) ; hard space - currency 876 (space-mark ?\xA0 [?\xA4] [?_]) ; hard space - currency
801 (?\x8A0 [?\x8A4] [?_]) ; hard space - currency 877 (space-mark ?\x8A0 [?\x8A4] [?_]) ; hard space - currency
802 (?\x920 [?\x924] [?_]) ; hard space - currency 878 (space-mark ?\x920 [?\x924] [?_]) ; hard space - currency
803 (?\xE20 [?\xE24] [?_]) ; hard space - currency 879 (space-mark ?\xE20 [?\xE24] [?_]) ; hard space - currency
804 (?\xF20 [?\xF24] [?_]) ; hard space - currency 880 (space-mark ?\xF20 [?\xF24] [?_]) ; hard space - currency
805 ;; NEWLINE is displayed using the face `whitespace-newline' 881 ;; NEWLINE is displayed using the face `whitespace-newline'
806 (?\n [?\u21B5 ?\n] [?$ ?\n]) ; end-of-line - downwards arrow 882 (newline-mark ?\n [?$ ?\n]) ; eol - dollar sign
807 ;; (?\n [?$ ?\n]) ; end-of-line - dollar sign 883 ;; (newline-mark ?\n [?\u21B5 ?\n] [?$ ?\n]) ; eol - downwards arrow
808 ;; (?\n [?\xB6 ?\n] [?$ ?\n]) ; end-of-line - pilcrow 884 ;; (newline-mark ?\n [?\xB6 ?\n] [?$ ?\n]) ; eol - pilcrow
809 ;; (?\n [?\x8AF ?\n] [?$ ?\n]) ; end-of-line - overscore 885 ;; (newline-mark ?\n [?\x8AF ?\n] [?$ ?\n]) ; eol - overscore
810 ;; (?\n [?\x8AC ?\n] [?$ ?\n]) ; end-of-line - negation 886 ;; (newline-mark ?\n [?\x8AC ?\n] [?$ ?\n]) ; eol - negation
811 ;; (?\n [?\x8B0 ?\n] [?$ ?\n]) ; end-of-line - grade 887 ;; (newline-mark ?\n [?\x8B0 ?\n] [?$ ?\n]) ; eol - grade
812 ;; 888 ;;
813 ;; WARNING: the mapping below has a problem. 889 ;; WARNING: the mapping below has a problem.
814 ;; When a TAB occupies exactly one column, it will display the 890 ;; When a TAB occupies exactly one column, it will display the
815 ;; character ?\xBB at that column followed by a TAB which goes to 891 ;; character ?\xBB at that column followed by a TAB which goes to
816 ;; the next TAB column. 892 ;; the next TAB column.
817 ;; If this is a problem for you, please, comment the line below. 893 ;; If this is a problem for you, please, comment the line below.
818 (?\t [?\xBB ?\t] [?\\ ?\t]) ; tab - left quote mark 894 (tab-mark ?\t [?\xBB ?\t] [?\\ ?\t]) ; tab - left quote mark
819 ) 895 )
820 "*Specify an alist of mappings for displaying characters. 896 "*Specify an alist of mappings for displaying characters.
821 897
822Each element has the following form: 898Each element has the following form:
823 899
824 (CHAR VECTOR...) 900 (KIND CHAR VECTOR...)
825 901
826Where: 902Where:
827 903
904KIND is the kind of character.
905 It can be one of the following symbols:
906
907 tab-mark for TAB character
908
909 space-mark for SPACE or HARD SPACE character
910
911 newline-mark for NEWLINE character
912
828CHAR is the character to be mapped. 913CHAR is the character to be mapped.
829 914
830VECTOR is a vector of characters to be displayed in place of CHAR. 915VECTOR is a vector of characters to be displayed in place of CHAR.
@@ -833,13 +918,15 @@ VECTOR is a vector of characters to be displayed in place of CHAR.
833 that character is displayed unmodified. 918 that character is displayed unmodified.
834 919
835The NEWLINE character is displayed using the face given by 920The NEWLINE character is displayed using the face given by
836`whitespace-newline' variable. The characters in the vector to 921`whitespace-newline' variable.
837be displayed will not have this face applied if the character
838code is above #x1FFFF.
839 922
840Used when `whitespace-style' includes the value `mark'." 923Used when `whitespace-style-mark' is non-nil."
841 :type '(repeat 924 :type '(repeat
842 (list :tag "Character Mapping" 925 (list :tag "Character Mapping"
926 (choice :tag "Char Kind"
927 (const :tag "Tab" tab-mark)
928 (const :tag "Space" space-mark)
929 (const :tag "Newline" newline-mark))
843 (character :tag "Char") 930 (character :tag "Char")
844 (repeat :inline t :tag "Vector List" 931 (repeat :inline t :tag "Vector List"
845 (vector :tag "" 932 (vector :tag ""
@@ -945,6 +1032,7 @@ Only useful with a windowing system."
945;;;; User commands - Global mode 1032;;;; User commands - Global mode
946 1033
947 1034
1035;;;###autoload
948(define-minor-mode global-whitespace-mode 1036(define-minor-mode global-whitespace-mode
949 "Toggle whitespace global minor mode visualization (\"WS\" on modeline). 1037 "Toggle whitespace global minor mode visualization (\"WS\" on modeline).
950 1038
@@ -1002,43 +1090,60 @@ Only useful with a windowing system."
1002;;;; User commands - Toggle 1090;;;; User commands - Toggle
1003 1091
1004 1092
1005(defconst whitespace-chars-value-list 1093(defconst whitespace-color-value-list
1006 '(tabs 1094 '(tabs
1007 spaces 1095 spaces
1008 trailing 1096 trailing
1009 space-before-tab
1010 lines 1097 lines
1011 lines-tail 1098 lines-tail
1012 newline 1099 newline
1013 indentation
1014 empty 1100 empty
1101 indentation
1102 indentation::tab
1103 indentation::space
1015 space-after-tab 1104 space-after-tab
1105 space-after-tab::tab
1106 space-after-tab::space
1107 space-before-tab
1108 space-before-tab::tab
1109 space-before-tab::space
1016 ) 1110 )
1017 "List of valid `whitespace-chars' values.") 1111 "List of valid `whitespace-style-color' values.")
1018 1112
1019 1113
1020(defconst whitespace-style-value-list 1114(defconst whitespace-mark-value-list
1021 '(color 1115 '(tab-mark
1022 mark 1116 space-mark
1117 newline-mark
1023 ) 1118 )
1024 "List of valid `whitespace-style' values.") 1119 "List of valid `whitespace-style-mark' values.")
1025 1120
1026 1121
1027(defconst whitespace-toggle-option-alist 1122(defconst whitespace-toggle-option-alist
1028 '((?t . tabs) 1123 '( ;; `whitespace-color-value-list' values
1029 (?s . spaces) 1124 (?t . tabs)
1030 (?r . trailing) 1125 (?s . spaces)
1031 (?b . space-before-tab) 1126 (?r . trailing)
1032 (?l . lines) 1127 (?l . lines)
1033 (?L . lines-tail) 1128 (?L . lines-tail)
1034 (?n . newline) 1129 (?n . newline)
1035 (?i . indentation) 1130 (?e . empty)
1036 (?e . empty) 1131 (?\C-i . indentation)
1037 (?a . space-after-tab) 1132 (?I . indentation::tab)
1038 (?c . color) 1133 (?i . indentation::space)
1039 (?m . mark) 1134 (?\C-a . space-after-tab)
1040 (?x . whitespace-chars) 1135 (?A . space-after-tab::tab)
1041 (?z . whitespace-style) 1136 (?a . space-after-tab::space)
1137 (?\C-b . space-before-tab)
1138 (?B . space-before-tab::tab)
1139 (?b . space-before-tab::space)
1140 ;; `whitespace-mark-value-list' values
1141 (?T . tab-mark)
1142 (?S . space-mark)
1143 (?N . newline-mark)
1144 ;; restore values
1145 (?x . whitespace-style-color)
1146 (?z . whitespace-style-mark)
1042 ) 1147 )
1043 "Alist of toggle options. 1148 "Alist of toggle options.
1044 1149
@@ -1051,17 +1156,21 @@ Where:
1051CHAR is a char which the user will have to type. 1156CHAR is a char which the user will have to type.
1052 1157
1053SYMBOL is a valid symbol associated with CHAR. 1158SYMBOL is a valid symbol associated with CHAR.
1054 See `whitespace-chars-value-list' and 1159 See `whitespace-color-value-list' and
1055 `whitespace-style-value-list'.") 1160 `whitespace-mark-value-list'.")
1161
1056 1162
1163(defvar whitespace-active-color nil
1164 "Used to save locally `whitespace-style-color' value.")
1057 1165
1058(defvar whitespace-active-chars nil 1166(defvar whitespace-active-mark nil
1059 "Used to save locally `whitespace-chars' value.") 1167 "Used to save locally `whitespace-style-mark' value.")
1060(make-variable-buffer-local 'whitespace-active-chars)
1061 1168
1062(defvar whitespace-active-style nil 1169(defvar whitespace-indent-tabs-mode indent-tabs-mode
1063 "Used to save locally `whitespace-style' value.") 1170 "Used to save locally `indent-tabs-mode' value.")
1064(make-variable-buffer-local 'whitespace-active-style) 1171
1172(defvar whitespace-tab-width tab-width
1173 "Used to save locally `tab-width' value.")
1065 1174
1066 1175
1067;;;###autoload 1176;;;###autoload
@@ -1077,20 +1186,31 @@ and restart local whitespace-mode.
1077Interactively, it reads one of the following chars: 1186Interactively, it reads one of the following chars:
1078 1187
1079 CHAR MEANING 1188 CHAR MEANING
1189 (VIA FACES)
1080 t toggle TAB visualization 1190 t toggle TAB visualization
1081 s toggle SPACE and HARD SPACE visualization 1191 s toggle SPACE and HARD SPACE visualization
1082 r toggle trailing blanks visualization 1192 r toggle trailing blanks visualization
1083 b toggle SPACEs before TAB visualization
1084 l toggle \"long lines\" visualization 1193 l toggle \"long lines\" visualization
1085 L toggle \"long lines\" tail visualization 1194 L toggle \"long lines\" tail visualization
1086 n toggle NEWLINE visualization 1195 n toggle NEWLINE visualization
1087 i toggle indentation SPACEs visualization
1088 e toggle empty line at bob and/or eob visualization 1196 e toggle empty line at bob and/or eob visualization
1089 a toggle SPACEs after TAB visualization 1197 C-i toggle indentation SPACEs visualization (via `indent-tabs-mode')
1090 c toggle color faces 1198 I toggle indentation SPACEs visualization
1091 m toggle visual mark 1199 i toggle indentation TABs visualization
1092 x restore `whitespace-chars' value 1200 C-a toggle SPACEs after TAB visualization (via `indent-tabs-mode')
1093 z restore `whitespace-style' value 1201 A toggle SPACEs after TAB: SPACEs visualization
1202 a toggle SPACEs after TAB: TABs visualization
1203 C-b toggle SPACEs before TAB visualization (via `indent-tabs-mode')
1204 B toggle SPACEs before TAB: SPACEs visualization
1205 b toggle SPACEs before TAB: TABs visualization
1206
1207 (VIA DISPLAY TABLE)
1208 T toggle TAB visualization
1209 S toggle SPACEs before TAB visualization
1210 N toggle NEWLINE visualization
1211
1212 x restore `whitespace-style-color' value
1213 z restore `whitespace-style-mark' value
1094 ? display brief help 1214 ? display brief help
1095 1215
1096Non-interactively, ARG should be a symbol or a list of symbols. 1216Non-interactively, ARG should be a symbol or a list of symbols.
@@ -1099,36 +1219,48 @@ The valid symbols are:
1099 tabs toggle TAB visualization 1219 tabs toggle TAB visualization
1100 spaces toggle SPACE and HARD SPACE visualization 1220 spaces toggle SPACE and HARD SPACE visualization
1101 trailing toggle trailing blanks visualization 1221 trailing toggle trailing blanks visualization
1102 space-before-tab toggle SPACEs before TAB visualization
1103 lines toggle \"long lines\" visualization 1222 lines toggle \"long lines\" visualization
1104 lines-tail toggle \"long lines\" tail visualization 1223 lines-tail toggle \"long lines\" tail visualization
1105 newline toggle NEWLINE visualization 1224 newline toggle NEWLINE visualization
1106 indentation toggle indentation SPACEs visualization
1107 empty toggle empty line at bob and/or eob visualization 1225 empty toggle empty line at bob and/or eob visualization
1108 space-after-tab toggle SPACEs after TAB visualization 1226 indentation toggle indentation SPACEs visualization
1109 color toggle color faces 1227 indentation::tab toggle indentation SPACEs visualization
1110 mark toggle visual mark 1228 indentation::space toggle indentation TABs visualization
1111 whitespace-chars restore `whitespace-chars' value 1229 space-after-tab toggle SPACEs after TAB visualization
1112 whitespace-style restore `whitespace-style' value 1230 space-after-tab::tab toggle SPACEs after TAB: SPACEs visualization
1113 1231 space-after-tab::space toggle SPACEs after TAB: TABs visualization
1114Only useful with a windowing system." 1232 space-before-tab toggle SPACEs before TAB visualization
1233 space-before-tab::tab toggle SPACEs before TAB: SPACEs visualization
1234 space-before-tab::space toggle SPACEs before TAB: TABs visualization
1235
1236 tab-mark toggle TAB visualization
1237 space-mark toggle SPACEs before TAB visualization
1238 newline-mark toggle NEWLINE visualization
1239
1240 whitespace-style-color restore `whitespace-style-color' value
1241 whitespace-style-mark restore `whitespace-style-mark' value
1242
1243Only useful with a windowing system.
1244
1245See `whitespace-style-color', `whitespace-style-mark' and
1246`indent-tabs-mode' for documentation."
1115 (interactive (whitespace-interactive-char t)) 1247 (interactive (whitespace-interactive-char t))
1116 (let ((whitespace-chars 1248 (let ((whitespace-style-color
1117 (whitespace-toggle-list 1249 (whitespace-toggle-list
1118 t arg whitespace-active-chars whitespace-chars 1250 t arg whitespace-active-color whitespace-style-color
1119 'whitespace-chars whitespace-chars-value-list)) 1251 'whitespace-style-color whitespace-color-value-list))
1120 (whitespace-style 1252 (whitespace-style-mark
1121 (whitespace-toggle-list 1253 (whitespace-toggle-list
1122 t arg whitespace-active-style whitespace-style 1254 t arg whitespace-active-mark whitespace-style-mark
1123 'whitespace-style whitespace-style-value-list))) 1255 'whitespace-style-mark whitespace-mark-value-list)))
1124 (whitespace-mode 0) 1256 (whitespace-mode 0)
1125 (whitespace-mode 1))) 1257 (whitespace-mode 1)))
1126 1258
1127 1259
1128(defvar whitespace-toggle-chars nil 1260(defvar whitespace-toggle-color nil
1129 "Used to toggle the global `whitespace-chars' value.") 1261 "Used to toggle the global `whitespace-style-color' value.")
1130(defvar whitespace-toggle-style nil 1262(defvar whitespace-toggle-mark nil
1131 "Used to toggle the global `whitespace-style' value.") 1263 "Used to toggle the global `whitespace-style-mark' value.")
1132 1264
1133 1265
1134;;;###autoload 1266;;;###autoload
@@ -1144,20 +1276,31 @@ and restart global whitespace-mode.
1144Interactively, it accepts one of the following chars: 1276Interactively, it accepts one of the following chars:
1145 1277
1146 CHAR MEANING 1278 CHAR MEANING
1279 (VIA FACES)
1147 t toggle TAB visualization 1280 t toggle TAB visualization
1148 s toggle SPACE and HARD SPACE visualization 1281 s toggle SPACE and HARD SPACE visualization
1149 r toggle trailing blanks visualization 1282 r toggle trailing blanks visualization
1150 b toggle SPACEs before TAB visualization
1151 l toggle \"long lines\" visualization 1283 l toggle \"long lines\" visualization
1152 L toggle \"long lines\" tail visualization 1284 L toggle \"long lines\" tail visualization
1153 n toggle NEWLINE visualization 1285 n toggle NEWLINE visualization
1154 i toggle indentation SPACEs visualization
1155 e toggle empty line at bob and/or eob visualization 1286 e toggle empty line at bob and/or eob visualization
1156 a toggle SPACEs after TAB visualization 1287 C-i toggle indentation SPACEs visualization (via `indent-tabs-mode')
1157 c toggle color faces 1288 I toggle indentation SPACEs visualization
1158 m toggle visual mark 1289 i toggle indentation TABs visualization
1159 x restore `whitespace-chars' value 1290 C-a toggle SPACEs after TAB visualization (via `indent-tabs-mode')
1160 z restore `whitespace-style' value 1291 A toggle SPACEs after TAB: SPACEs visualization
1292 a toggle SPACEs after TAB: TABs visualization
1293 C-b toggle SPACEs before TAB visualization (via `indent-tabs-mode')
1294 B toggle SPACEs before TAB: SPACEs visualization
1295 b toggle SPACEs before TAB: TABs visualization
1296
1297 (VIA DISPLAY TABLE)
1298 T toggle TAB visualization
1299 S toggle SPACEs before TAB visualization
1300 N toggle NEWLINE visualization
1301
1302 x restore `whitespace-style-color' value
1303 z restore `whitespace-style-mark' value
1161 ? display brief help 1304 ? display brief help
1162 1305
1163Non-interactively, ARG should be a symbol or a list of symbols. 1306Non-interactively, ARG should be a symbol or a list of symbols.
@@ -1166,30 +1309,42 @@ The valid symbols are:
1166 tabs toggle TAB visualization 1309 tabs toggle TAB visualization
1167 spaces toggle SPACE and HARD SPACE visualization 1310 spaces toggle SPACE and HARD SPACE visualization
1168 trailing toggle trailing blanks visualization 1311 trailing toggle trailing blanks visualization
1169 space-before-tab toggle SPACEs before TAB visualization
1170 lines toggle \"long lines\" visualization 1312 lines toggle \"long lines\" visualization
1171 lines-tail toggle \"long lines\" tail visualization 1313 lines-tail toggle \"long lines\" tail visualization
1172 newline toggle NEWLINE visualization 1314 newline toggle NEWLINE visualization
1173 indentation toggle indentation SPACEs visualization
1174 empty toggle empty line at bob and/or eob visualization 1315 empty toggle empty line at bob and/or eob visualization
1175 space-after-tab toggle SPACEs after TAB visualization 1316 indentation toggle indentation SPACEs visualization
1176 color toggle color faces 1317 indentation::tab toggle indentation SPACEs visualization
1177 mark toggle visual mark 1318 indentation::space toggle indentation TABs visualization
1178 whitespace-chars restore `whitespace-chars' value 1319 space-after-tab toggle SPACEs after TAB visualization
1179 whitespace-style restore `whitespace-style' value 1320 space-after-tab::tab toggle SPACEs after TAB: SPACEs visualization
1180 1321 space-after-tab::space toggle SPACEs after TAB: TABs visualization
1181Only useful with a windowing system." 1322 space-before-tab toggle SPACEs before TAB visualization
1323 space-before-tab::tab toggle SPACEs before TAB: SPACEs visualization
1324 space-before-tab::space toggle SPACEs before TAB: TABs visualization
1325
1326 tab-mark toggle TAB visualization
1327 space-mark toggle SPACEs before TAB visualization
1328 newline-mark toggle NEWLINE visualization
1329
1330 whitespace-style-color restore `whitespace-style-color' value
1331 whitespace-style-mark restore `whitespace-style-mark' value
1332
1333Only useful with a windowing system.
1334
1335See `whitespace-style-color', `whitespace-style-mark' and
1336`indent-tabs-mode' for documentation."
1182 (interactive (whitespace-interactive-char nil)) 1337 (interactive (whitespace-interactive-char nil))
1183 (let ((whitespace-chars 1338 (let ((whitespace-style-color
1184 (whitespace-toggle-list 1339 (whitespace-toggle-list
1185 nil arg whitespace-toggle-chars whitespace-chars 1340 nil arg whitespace-toggle-color whitespace-style-color
1186 'whitespace-chars whitespace-chars-value-list)) 1341 'whitespace-style-color whitespace-color-value-list))
1187 (whitespace-style 1342 (whitespace-style-mark
1188 (whitespace-toggle-list 1343 (whitespace-toggle-list
1189 nil arg whitespace-toggle-style whitespace-style 1344 nil arg whitespace-toggle-mark whitespace-style-mark
1190 'whitespace-style whitespace-style-value-list))) 1345 'whitespace-style-mark whitespace-mark-value-list)))
1191 (setq whitespace-toggle-chars whitespace-chars 1346 (setq whitespace-toggle-color whitespace-style-color
1192 whitespace-toggle-style whitespace-style) 1347 whitespace-toggle-mark whitespace-style-mark)
1193 (global-whitespace-mode 0) 1348 (global-whitespace-mode 0)
1194 (global-whitespace-mode 1))) 1349 (global-whitespace-mode 1)))
1195 1350
@@ -1205,8 +1360,8 @@ Only useful with a windowing system."
1205It usually applies to the whole buffer, but in transient mark 1360It usually applies to the whole buffer, but in transient mark
1206mode when the mark is active, it applies to the region. It also 1361mode when the mark is active, it applies to the region. It also
1207applies to the region when it is not in transiente mark mode, the 1362applies to the region when it is not in transiente mark mode, the
1208mark is active and \\[universal-argument] was pressed just before calling 1363mark is active and \\[universal-argument] was pressed just before
1209`whitespace-cleanup' interactively. 1364calling `whitespace-cleanup' interactively.
1210 1365
1211See also `whitespace-cleanup-region'. 1366See also `whitespace-cleanup-region'.
1212 1367
@@ -1214,42 +1369,62 @@ The problems cleaned up are:
1214 1369
12151. empty lines at beginning of buffer. 13701. empty lines at beginning of buffer.
12162. empty lines at end of buffer. 13712. empty lines at end of buffer.
1217 If `whitespace-chars' includes the value `empty', remove all 1372 If `whitespace-style-color' includes the value `empty', remove all
1218 empty lines at beginning and/or end of buffer. 1373 empty lines at beginning and/or end of buffer.
1219 1374
12203. 8 or more SPACEs at beginning of line. 13753. 8 or more SPACEs at beginning of line.
1221 If `whitespace-chars' includes the value `indentation', replace 1376 If `whitespace-style-color' includes the value `indentation':
1222 8 or more SPACEs at beginning of line by TABs. 1377 replace 8 or more SPACEs at beginning of line by TABs, if
1378 `indent-tabs-mode' is non-nil; otherwise, replace TABs by
1379 SPACEs.
1380 If `whitespace-style-color' includes the value
1381 `indentation::tab', replace 8 or more SPACEs at beginning of
1382 line by TABs.
1383 If `whitespace-style-color' includes the value
1384 `indentation::space', replace TABs by SPACEs.
1223 1385
12244. SPACEs before TAB. 13864. SPACEs before TAB.
1225 If `whitespace-chars' includes the value `space-before-tab', 1387 If `whitespace-style-color' includes the value `space-before-tab':
1226 replace SPACEs by TABs. 1388 replace SPACEs by TABs, if `indent-tabs-mode' is non-nil;
1389 otherwise, replace TABs by SPACEs.
1390 If `whitespace-style-color' includes the value
1391 `space-before-tab::tab', replace SPACEs by TABs.
1392 If `whitespace-style-color' includes the value
1393 `space-before-tab::space', replace TABs by SPACEs.
1227 1394
12285. SPACEs or TABs at end of line. 13955. SPACEs or TABs at end of line.
1229 If `whitespace-chars' includes the value `trailing', remove all 1396 If `whitespace-style-color' includes the value `trailing', remove
1230 SPACEs or TABs at end of line. 1397 all SPACEs or TABs at end of line.
1231 1398
12326. 8 or more SPACEs after TAB. 13996. 8 or more SPACEs after TAB.
1233 If `whitespace-chars' includes the value `space-after-tab', 1400 If `whitespace-style-color' includes the value `space-after-tab':
1234 replace SPACEs by TABs." 1401 replace SPACEs by TABs, if `indent-tabs-mode' is non-nil;
1402 otherwise, replace TABs by SPACEs.
1403 If `whitespace-style-color' includes the value
1404 `space-after-tab::tab', replace SPACEs by TABs.
1405 If `whitespace-style-color' includes the value
1406 `space-after-tab::space', replace TABs by SPACEs.
1407
1408See `whitespace-style-color', `indent-tabs-mode' and `tab-width'
1409for documentation."
1235 (interactive "@*") 1410 (interactive "@*")
1236 (if (and (or transient-mark-mode 1411 (if (and (or transient-mark-mode
1237 current-prefix-arg) 1412 current-prefix-arg)
1238 mark-active) 1413 mark-active)
1239 ;; region active 1414 ;; region active
1240 ;; problems 1 and 2 are not handled in region 1415 ;; PROBLEMs 1 and 2 are not handled in region
1241 ;; problem 3: 8 or more SPACEs at bol 1416 ;; PROBLEM 3: 8 or more SPACEs at bol
1242 ;; problem 4: SPACEs before TAB 1417 ;; PROBLEM 4: SPACEs before TAB
1243 ;; problem 5: SPACEs or TABs at eol 1418 ;; PROBLEM 5: SPACEs or TABs at eol
1244 ;; problem 6: 8 or more SPACEs after TAB 1419 ;; PROBLEM 6: 8 or more SPACEs after TAB
1245 (whitespace-cleanup-region (region-beginning) (region-end)) 1420 (whitespace-cleanup-region (region-beginning) (region-end))
1246 ;; whole buffer 1421 ;; whole buffer
1247 (save-excursion 1422 (save-excursion
1248 (save-match-data 1423 (save-match-data
1249 ;; problem 1: empty lines at bob 1424 ;; PROBLEM 1: empty lines at bob
1250 ;; problem 2: empty lines at eob 1425 ;; PROBLEM 2: empty lines at eob
1251 ;; action: remove all empty lines at bob and/or eob 1426 ;; ACTION: remove all empty lines at bob and/or eob
1252 (when (memq 'empty whitespace-chars) 1427 (when (memq 'empty whitespace-style-color)
1253 (let (overwrite-mode) ; enforce no overwrite 1428 (let (overwrite-mode) ; enforce no overwrite
1254 (goto-char (point-min)) 1429 (goto-char (point-min))
1255 (when (re-search-forward 1430 (when (re-search-forward
@@ -1258,10 +1433,10 @@ The problems cleaned up are:
1258 (when (re-search-forward 1433 (when (re-search-forward
1259 whitespace-empty-at-eob-regexp nil t) 1434 whitespace-empty-at-eob-regexp nil t)
1260 (delete-region (match-beginning 1) (match-end 1))))))) 1435 (delete-region (match-beginning 1) (match-end 1)))))))
1261 ;; problem 3: 8 or more SPACEs at bol 1436 ;; PROBLEM 3: 8 or more SPACEs at bol
1262 ;; problem 4: SPACEs before TAB 1437 ;; PROBLEM 4: SPACEs before TAB
1263 ;; problem 5: SPACEs or TABs at eol 1438 ;; PROBLEM 5: SPACEs or TABs at eol
1264 ;; problem 6: 8 or more SPACEs after TAB 1439 ;; PROBLEM 6: 8 or more SPACEs after TAB
1265 (whitespace-cleanup-region (point-min) (point-max)))) 1440 (whitespace-cleanup-region (point-min) (point-max))))
1266 1441
1267 1442
@@ -1272,74 +1447,131 @@ The problems cleaned up are:
1272The problems cleaned up are: 1447The problems cleaned up are:
1273 1448
12741. 8 or more SPACEs at beginning of line. 14491. 8 or more SPACEs at beginning of line.
1275 If `whitespace-chars' includes the value `indentation', replace 1450 If `whitespace-style-color' includes the value `indentation':
1276 8 or more SPACEs at beginning of line by TABs. 1451 replace 8 or more SPACEs at beginning of line by TABs, if
1452 `indent-tabs-mode' is non-nil; otherwise, replace TABs by
1453 SPACEs.
1454 If `whitespace-style-color' includes the value
1455 `indentation::tab', replace 8 or more SPACEs at beginning of
1456 line by TABs.
1457 If `whitespace-style-color' includes the value
1458 `indentation::space', replace TABs by SPACEs.
1277 1459
12782. SPACEs before TAB. 14602. SPACEs before TAB.
1279 If `whitespace-chars' includes the value `space-before-tab', 1461 If `whitespace-style-color' includes the value `space-before-tab':
1280 replace SPACEs by TABs. 1462 replace SPACEs by TABs, if `indent-tabs-mode' is non-nil;
1463 otherwise, replace TABs by SPACEs.
1464 If `whitespace-style-color' includes the value
1465 `space-before-tab::tab', replace SPACEs by TABs.
1466 If `whitespace-style-color' includes the value
1467 `space-before-tab::space', replace TABs by SPACEs.
1281 1468
12823. SPACEs or TABs at end of line. 14693. SPACEs or TABs at end of line.
1283 If `whitespace-chars' includes the value `trailing', remove all 1470 If `whitespace-style-color' includes the value `trailing', remove
1284 SPACEs or TABs at end of line. 1471 all SPACEs or TABs at end of line.
1285 1472
12864. 8 or more SPACEs after TAB. 14734. 8 or more SPACEs after TAB.
1287 If `whitespace-chars' includes the value `space-after-tab', 1474 If `whitespace-style-color' includes the value `space-after-tab':
1288 replace SPACEs by TABs." 1475 replace SPACEs by TABs, if `indent-tabs-mode' is non-nil;
1476 otherwise, replace TABs by SPACEs.
1477 If `whitespace-style-color' includes the value
1478 `space-after-tab::tab', replace SPACEs by TABs.
1479 If `whitespace-style-color' includes the value
1480 `space-after-tab::space', replace TABs by SPACEs.
1481
1482See `whitespace-style-color', `indent-tabs-mode' and `tab-width'
1483for documentation."
1289 (interactive "@*r") 1484 (interactive "@*r")
1290 (let ((rstart (min start end)) 1485 (let ((rstart (min start end))
1291 (rend (copy-marker (max start end))) 1486 (rend (copy-marker (max start end)))
1292 (tab-width 8) ; assure TAB width 1487 (indent-tabs-mode whitespace-indent-tabs-mode)
1293 (indent-tabs-mode t) ; always insert TABs 1488 (tab-width whitespace-tab-width)
1294 overwrite-mode ; enforce no overwrite 1489 overwrite-mode ; enforce no overwrite
1295 tmp) 1490 tmp)
1296 (save-excursion 1491 (save-excursion
1297 (save-match-data 1492 (save-match-data
1298 ;; problem 1: 8 or more SPACEs at bol 1493 ;; PROBLEM 1: 8 or more SPACEs at bol
1299 ;; action: replace 8 or more SPACEs at bol by TABs 1494 (cond
1300 (when (memq 'indentation whitespace-chars) 1495 ;; ACTION: replace 8 or more SPACEs at bol by TABs, if
1301 (goto-char rstart) 1496 ;; `indent-tabs-mode' is non-nil; otherwise, replace TABs by
1302 (while (re-search-forward 1497 ;; SPACEs.
1303 whitespace-indentation-regexp rend t) 1498 ((memq 'indentation whitespace-style-color)
1304 (setq tmp (current-indentation)) 1499 (let ((regexp (whitespace-indentation-regexp)))
1305 (goto-char (match-beginning 0))
1306 (delete-horizontal-space)
1307 (unless (eolp)
1308 (indent-to tmp))))
1309 ;; problem 3: SPACEs or TABs at eol
1310 ;; action: remove all SPACEs or TABs at eol
1311 (when (memq 'trailing whitespace-chars)
1312 (let ((regexp (whitespace-trailing-regexp)))
1313 (goto-char rstart) 1500 (goto-char rstart)
1314 (while (re-search-forward regexp rend t) 1501 (while (re-search-forward regexp rend t)
1315 (delete-region (match-beginning 1) (match-end 1))))) 1502 (setq tmp (current-indentation))
1316 ;; problem 4: 8 or more SPACEs after TAB 1503 (goto-char (match-beginning 0))
1317 ;; action: replace 8 or more SPACEs by TABs 1504 (delete-horizontal-space)
1318 (when (memq 'space-after-tab whitespace-chars) 1505 (unless (eolp)
1319 (whitespace-replace-spaces-by-tabs 1506 (indent-to tmp)))))
1320 rstart rend whitespace-space-after-tab-regexp)) 1507 ;; ACTION: replace 8 or more SPACEs at bol by TABs.
1321 ;; problem 2: SPACEs before TAB 1508 ((memq 'indentation::tab whitespace-style-color)
1322 ;; action: replace SPACEs before TAB by TABs 1509 (whitespace-replace-action
1323 (when (memq 'space-before-tab whitespace-chars) 1510 'tabify rstart rend
1324 (whitespace-replace-spaces-by-tabs 1511 (whitespace-indentation-regexp 'tab) 0))
1325 rstart rend whitespace-space-before-tab-regexp)))) 1512 ;; ACTION: replace TABs by SPACEs.
1513 ((memq 'indentation::space whitespace-style-color)
1514 (whitespace-replace-action
1515 'untabify rstart rend
1516 (whitespace-indentation-regexp 'space) 0)))
1517 ;; PROBLEM 3: SPACEs or TABs at eol
1518 ;; ACTION: remove all SPACEs or TABs at eol
1519 (when (memq 'trailing whitespace-style-color)
1520 (whitespace-replace-action
1521 'delete-region rstart rend
1522 (whitespace-trailing-regexp) 1))
1523 ;; PROBLEM 4: 8 or more SPACEs after TAB
1524 (cond
1525 ;; ACTION: replace 8 or more SPACEs by TABs, if
1526 ;; `indent-tabs-mode' is non-nil; otherwise, replace TABs by
1527 ;; SPACEs.
1528 ((memq 'space-after-tab whitespace-style-color)
1529 (whitespace-replace-action
1530 (if whitespace-indent-tabs-mode 'tabify 'untabify)
1531 rstart rend (whitespace-space-after-tab-regexp) 1))
1532 ;; ACTION: replace 8 or more SPACEs by TABs.
1533 ((memq 'space-after-tab::tab whitespace-style-color)
1534 (whitespace-replace-action
1535 'tabify rstart rend
1536 (whitespace-space-after-tab-regexp 'tab) 1))
1537 ;; ACTION: replace TABs by SPACEs.
1538 ((memq 'space-after-tab::space whitespace-style-color)
1539 (whitespace-replace-action
1540 'untabify rstart rend
1541 (whitespace-space-after-tab-regexp 'space) 1)))
1542 ;; PROBLEM 2: SPACEs before TAB
1543 (cond
1544 ;; ACTION: replace SPACEs before TAB by TABs, if
1545 ;; `indent-tabs-mode' is non-nil; otherwise, replace TABs by
1546 ;; SPACEs.
1547 ((memq 'space-before-tab whitespace-style-color)
1548 (whitespace-replace-action
1549 (if whitespace-indent-tabs-mode 'tabify 'untabify)
1550 rstart rend whitespace-space-before-tab-regexp
1551 (if whitespace-indent-tabs-mode 1 2)))
1552 ;; ACTION: replace SPACEs before TAB by TABs.
1553 ((memq 'space-before-tab::tab whitespace-style-color)
1554 (whitespace-replace-action
1555 'tabify rstart rend
1556 whitespace-space-before-tab-regexp 1))
1557 ;; ACTION: replace TABs by SPACEs.
1558 ((memq 'space-before-tab::space whitespace-style-color)
1559 (whitespace-replace-action
1560 'untabify rstart rend
1561 whitespace-space-before-tab-regexp 2)))))
1326 (set-marker rend nil))) ; point marker to nowhere 1562 (set-marker rend nil))) ; point marker to nowhere
1327 1563
1328 1564
1329(defun whitespace-replace-spaces-by-tabs (rstart rend regexp) 1565(defun whitespace-replace-action (action rstart rend regexp index)
1330 "Replace all SPACEs by TABs matched by REGEXP between RSTART and REND." 1566 "Do ACTION in the string matched by REGEXP between RSTART and REND.
1567
1568INDEX is the level group matched by REGEXP and used by ACTION.
1569
1570See also `tab-width'."
1331 (goto-char rstart) 1571 (goto-char rstart)
1332 (while (re-search-forward regexp rend t) 1572 (while (re-search-forward regexp rend t)
1333 (goto-char (match-beginning 1)) 1573 (goto-char (match-end index))
1334 (let* ((scol (current-column)) 1574 (funcall action (match-beginning index) (match-end index))))
1335 (ecol (save-excursion
1336 (goto-char (match-end 1))
1337 (current-column))))
1338 (delete-region (match-beginning 1) (match-end 1))
1339 (insert-char ?\t
1340 (/ (- (- ecol (% ecol 8)) ; prev end col
1341 (- scol (% scol 8))) ; prev start col
1342 8)))))
1343 1575
1344 1576
1345;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1577;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -1351,31 +1583,93 @@ The problems cleaned up are:
1351 (concat "\\(\\(" whitespace-trailing-regexp "\\)+\\)$")) 1583 (concat "\\(\\(" whitespace-trailing-regexp "\\)+\\)$"))
1352 1584
1353 1585
1586(defun whitespace-regexp (regexp &optional kind)
1587 "Return REGEXP depending on `whitespace-indent-tabs-mode'."
1588 (cond
1589 ((or (eq kind 'tab)
1590 whitespace-indent-tabs-mode)
1591 (format (car regexp) whitespace-tab-width))
1592 ((or (eq kind 'space)
1593 (not whitespace-indent-tabs-mode))
1594 (cdr regexp))))
1595
1596
1597(defun whitespace-indentation-regexp (&optional kind)
1598 "Return the indentation regexp depending on `whitespace-indent-tabs-mode'."
1599 (whitespace-regexp whitespace-indentation-regexp kind))
1600
1601
1602(defun whitespace-space-after-tab-regexp (&optional kind)
1603 "Return the space-after-tab regexp depending on `whitespace-indent-tabs-mode'."
1604 (whitespace-regexp whitespace-space-after-tab-regexp kind))
1605
1606
1354(defconst whitespace-report-list 1607(defconst whitespace-report-list
1355 (list 1608 (list
1356 (cons 'empty whitespace-empty-at-bob-regexp) 1609 (cons 'empty whitespace-empty-at-bob-regexp)
1357 (cons 'empty whitespace-empty-at-eob-regexp) 1610 (cons 'empty whitespace-empty-at-eob-regexp)
1358 (cons 'indentation whitespace-indentation-regexp) 1611 (cons 'trailing (whitespace-trailing-regexp))
1359 (cons 'space-before-tab whitespace-space-before-tab-regexp) 1612 (cons 'indentation nil)
1360 (cons 'trailing (whitespace-trailing-regexp)) 1613 (cons 'indentation::tab nil)
1361 (cons 'space-after-tab whitespace-space-after-tab-regexp) 1614 (cons 'indentation::space nil)
1615 (cons 'space-before-tab whitespace-space-before-tab-regexp)
1616 (cons 'space-before-tab::tab whitespace-space-before-tab-regexp)
1617 (cons 'space-before-tab::space whitespace-space-before-tab-regexp)
1618 (cons 'space-after-tab nil)
1619 (cons 'space-after-tab::tab nil)
1620 (cons 'space-after-tab::space nil)
1362 ) 1621 )
1363 "List of whitespace bogus symbol and corresponding regexp.") 1622 "List of whitespace bogus symbol and corresponding regexp.")
1364 1623
1365 1624
1366(defconst whitespace-report-text 1625(defconst whitespace-report-text
1367 "\ 1626 '( ;; `indent-tabs-mode' has non-nil value
1368 Whitespace Report 1627 "\
1369 1628 Whitespace Report
1370 Current Setting Whitespace Problem 1629
1371 1630 Current Setting Whitespace Problem
1372 empty [] [] empty lines at beginning of buffer. 1631
1373 empty [] [] empty lines at end of buffer. 1632 empty [] [] empty lines at beginning of buffer
1374 indentation [] [] 8 or more SPACEs at beginning of line. 1633 empty [] [] empty lines at end of buffer
1375 space-before-tab [] [] SPACEs before TAB. 1634 trailing [] [] SPACEs or TABs at end of line
1376 trailing [] [] SPACEs or TABs at end of line. 1635 indentation [] [] 8 or more SPACEs at beginning of line
1377 space-after-tab [] [] 8 or more SPACEs after TAB.\n\n" 1636 indentation::tab [] [] 8 or more SPACEs at beginning of line
1378 "Text for whitespace bogus report.") 1637 indentation::space [] [] TABs at beginning of line
1638 space-before-tab [] [] SPACEs before TAB
1639 space-before-tab::tab [] [] SPACEs before TAB: SPACEs
1640 space-before-tab::space [] [] SPACEs before TAB: TABs
1641 space-after-tab [] [] 8 or more SPACEs after TAB
1642 space-after-tab::tab [] [] 8 or more SPACEs after TAB: SPACEs
1643 space-after-tab::space [] [] 8 or more SPACEs after TAB: TABs
1644
1645 indent-tabs-mode =
1646 tab-width = \n\n"
1647 . ;; `indent-tabs-mode' has nil value
1648 "\
1649 Whitespace Report
1650
1651 Current Setting Whitespace Problem
1652
1653 empty [] [] empty lines at beginning of buffer
1654 empty [] [] empty lines at end of buffer
1655 trailing [] [] SPACEs or TABs at end of line
1656 indentation [] [] TABs at beginning of line
1657 indentation::tab [] [] 8 or more SPACEs at beginning of line
1658 indentation::space [] [] TABs at beginning of line
1659 space-before-tab [] [] SPACEs before TAB
1660 space-before-tab::tab [] [] SPACEs before TAB: SPACEs
1661 space-before-tab::space [] [] SPACEs before TAB: TABs
1662 space-after-tab [] [] 8 or more SPACEs after TAB
1663 space-after-tab::tab [] [] 8 or more SPACEs after TAB: SPACEs
1664 space-after-tab::space [] [] 8 or more SPACEs after TAB: TABs
1665
1666 indent-tabs-mode =
1667 tab-width = \n\n")
1668 "Text for whitespace bogus report.
1669
1670It is a cons of strings, where the car part is used when
1671`indent-tabs-mode' is non-nil, and the cdr part is used when
1672`indent-tabs-mode' is nil.")
1379 1673
1380 1674
1381(defconst whitespace-report-buffer-name "*Whitespace Report*" 1675(defconst whitespace-report-buffer-name "*Whitespace Report*"
@@ -1389,14 +1683,14 @@ The problems cleaned up are:
1389Return nil if there is no whitespace problem; otherwise, return 1683Return nil if there is no whitespace problem; otherwise, return
1390non-nil. 1684non-nil.
1391 1685
1392If FORCE is non-nil or \\[universal-argument] was pressed just before calling 1686If FORCE is non-nil or \\[universal-argument] was pressed just
1393`whitespace-report' interactively, it forces `whitespace-chars' to 1687before calling `whitespace-report' interactively, it forces
1394have: 1688`whitespace-style-color' to have:
1395 1689
1396 empty 1690 empty
1691 trailing
1397 indentation 1692 indentation
1398 space-before-tab 1693 space-before-tab
1399 trailing
1400 space-after-tab 1694 space-after-tab
1401 1695
1402If REPORT-IF-BOGUS is non-nil, it reports only when there are any 1696If REPORT-IF-BOGUS is non-nil, it reports only when there are any
@@ -1404,14 +1698,24 @@ whitespace problems in buffer.
1404 1698
1405Report if some of the following whitespace problems exist: 1699Report if some of the following whitespace problems exist:
1406 1700
1701* If `indent-tabs-mode' is non-nil:
1407 empty 1. empty lines at beginning of buffer. 1702 empty 1. empty lines at beginning of buffer.
1408 empty 2. empty lines at end of buffer. 1703 empty 2. empty lines at end of buffer.
1409 indentation 3. 8 or more SPACEs at beginning of line. 1704 trailing 3. SPACEs or TABs at end of line.
1410 space-before-tab 4. SPACEs before TAB. 1705 indentation 4. 8 or more SPACEs at beginning of line.
1411 trailing 5. SPACEs or TABs at end of line. 1706 space-before-tab 5. SPACEs before TAB.
1412 space-after-tab 6. 8 or more SPACEs after TAB. 1707 space-after-tab 6. 8 or more SPACEs after TAB.
1413 1708
1414See `whitespace-chars' and `whitespace-style' for documentation. 1709* If `indent-tabs-mode' is nil:
1710 empty 1. empty lines at beginning of buffer.
1711 empty 2. empty lines at end of buffer.
1712 trailing 3. SPACEs or TABs at end of line.
1713 indentation 4. TABS at beginning of line.
1714 space-before-tab 5. SPACEs before TAB.
1715 space-after-tab 6. 8 or more SPACEs after TAB.
1716
1717See `whitespace-style-color' and `whitespace-style-mark' for
1718documentation.
1415See also `whitespace-cleanup' and `whitespace-cleanup-region' for 1719See also `whitespace-cleanup' and `whitespace-cleanup-region' for
1416cleaning up these problems." 1720cleaning up these problems."
1417 (interactive (list current-prefix-arg)) 1721 (interactive (list current-prefix-arg))
@@ -1426,9 +1730,9 @@ cleaning up these problems."
1426Return nil if there is no whitespace problem; otherwise, return 1730Return nil if there is no whitespace problem; otherwise, return
1427non-nil. 1731non-nil.
1428 1732
1429If FORCE is non-nil or \\[universal-argument] was pressed just before calling 1733If FORCE is non-nil or \\[universal-argument] was pressed just
1430`whitespace-report-region' interactively, it forces `whitespace-chars' 1734before calling `whitespace-report-region' interactively, it
1431to have: 1735forces `whitespace-style-color' to have:
1432 1736
1433 empty 1737 empty
1434 indentation 1738 indentation
@@ -1441,50 +1745,87 @@ whitespace problems in buffer.
1441 1745
1442Report if some of the following whitespace problems exist: 1746Report if some of the following whitespace problems exist:
1443 1747
1748* If `indent-tabs-mode' is non-nil:
1749 empty 1. empty lines at beginning of buffer.
1750 empty 2. empty lines at end of buffer.
1751 trailing 3. SPACEs or TABs at end of line.
1752 indentation 4. 8 or more SPACEs at beginning of line.
1753 space-before-tab 5. SPACEs before TAB.
1754 space-after-tab 6. 8 or more SPACEs after TAB.
1755
1756* If `indent-tabs-mode' is nil:
1444 empty 1. empty lines at beginning of buffer. 1757 empty 1. empty lines at beginning of buffer.
1445 empty 2. empty lines at end of buffer. 1758 empty 2. empty lines at end of buffer.
1446 indentation 3. 8 or more SPACEs at beginning of line. 1759 trailing 3. SPACEs or TABs at end of line.
1447 space-before-tab 4. SPACEs before TAB. 1760 indentation 4. TABS at beginning of line.
1448 trailing 5. SPACEs or TABs at end of line. 1761 space-before-tab 5. SPACEs before TAB.
1449 space-after-tab 6. 8 or more SPACEs after TAB. 1762 space-after-tab 6. 8 or more SPACEs after TAB.
1450 1763
1451See `whitespace-chars' and `whitespace-style' for documentation. 1764See `whitespace-style-color' and `whitespace-style-mark' for
1765documentation.
1452See also `whitespace-cleanup' and `whitespace-cleanup-region' for 1766See also `whitespace-cleanup' and `whitespace-cleanup-region' for
1453cleaning up these problems." 1767cleaning up these problems."
1454 (interactive "r") 1768 (interactive "r")
1455 (setq force (or current-prefix-arg force)) 1769 (setq force (or current-prefix-arg force))
1456 (save-excursion 1770 (save-excursion
1457 (save-match-data 1771 (save-match-data
1458 (let* (has-bogus 1772 (let* ((has-bogus nil)
1459 (rstart (min start end)) 1773 (rstart (min start end))
1460 (rend (max start end)) 1774 (rend (max start end))
1461 (bogus-list (mapcar 1775 (bogus-list
1462 #'(lambda (option) 1776 (mapcar
1463 (when force 1777 #'(lambda (option)
1464 (add-to-list 'whitespace-chars (car option))) 1778 (when force
1465 (goto-char rstart) 1779 (add-to-list 'whitespace-style-color
1466 (and (re-search-forward (cdr option) rend t) 1780 (car option)))
1467 (setq has-bogus t))) 1781 (goto-char rstart)
1468 whitespace-report-list))) 1782 (let ((regexp
1783 (cond
1784 ((eq (car option) 'indentation)
1785 (whitespace-indentation-regexp))
1786 ((eq (car option) 'indentation::tab)
1787 (whitespace-indentation-regexp 'tab))
1788 ((eq (car option) 'indentation::space)
1789 (whitespace-indentation-regexp 'space))
1790 ((eq (car option) 'space-after-tab)
1791 (whitespace-space-after-tab-regexp))
1792 ((eq (car option) 'space-after-tab::tab)
1793 (whitespace-space-after-tab-regexp 'tab))
1794 ((eq (car option) 'space-after-tab::space)
1795 (whitespace-space-after-tab-regexp 'space))
1796 (t
1797 (cdr option)))))
1798 (and (re-search-forward regexp rend t)
1799 (setq has-bogus t))))
1800 whitespace-report-list)))
1469 (when (if report-if-bogus has-bogus t) 1801 (when (if report-if-bogus has-bogus t)
1470 (with-current-buffer (get-buffer-create 1802 (whitespace-kill-buffer whitespace-report-buffer-name)
1471 whitespace-report-buffer-name) 1803 ;; `whitespace-indent-tabs-mode' is local to current buffer
1472 (erase-buffer) 1804 (let ((ws-indent-tabs-mode whitespace-indent-tabs-mode))
1473 (insert whitespace-report-text) 1805 (with-current-buffer (get-buffer-create
1474 (goto-char (point-min)) 1806 whitespace-report-buffer-name)
1475 (forward-line 3) 1807 (erase-buffer)
1476 (dolist (option whitespace-report-list) 1808 (insert (if ws-indent-tabs-mode
1809 (car whitespace-report-text)
1810 (cdr whitespace-report-text)))
1811 (goto-char (point-min))
1812 (forward-line 3)
1813 (dolist (option whitespace-report-list)
1814 (forward-line 1)
1815 (whitespace-mark-x
1816 27 (memq (car option) whitespace-style-color))
1817 (whitespace-mark-x 7 (car bogus-list))
1818 (setq bogus-list (cdr bogus-list)))
1477 (forward-line 1) 1819 (forward-line 1)
1478 (whitespace-mark-x 22 (memq (car option) whitespace-chars)) 1820 (whitespace-insert-value ws-indent-tabs-mode)
1479 (whitespace-mark-x 7 (car bogus-list)) 1821 (whitespace-insert-value whitespace-tab-width)
1480 (setq bogus-list (cdr bogus-list))) 1822 (when has-bogus
1481 (when has-bogus 1823 (goto-char (point-max))
1482 (goto-char (point-max)) 1824 (insert " Type `M-x whitespace-cleanup'"
1483 (insert " Type `M-x whitespace-cleanup'" 1825 " to cleanup the buffer.\n\n"
1484 " to cleanup the buffer.\n\n") 1826 " Type `M-x whitespace-cleanup-region'"
1485 (insert " Type `M-x whitespace-cleanup-region'" 1827 " to cleanup a region.\n\n"))
1486 " to cleanup a region.\n\n")) 1828 (whitespace-display-window (current-buffer)))))
1487 (whitespace-display-window (current-buffer))))
1488 has-bogus)))) 1829 has-bogus))))
1489 1830
1490 1831
@@ -1494,37 +1835,43 @@ cleaning up these problems."
1494 1835
1495(defvar whitespace-font-lock-mode nil 1836(defvar whitespace-font-lock-mode nil
1496 "Used to remember whether a buffer had font lock mode on or not.") 1837 "Used to remember whether a buffer had font lock mode on or not.")
1497(make-variable-buffer-local 'whitespace-font-lock-mode)
1498 1838
1499(defvar whitespace-font-lock nil 1839(defvar whitespace-font-lock nil
1500 "Used to remember whether a buffer initially had font lock on or not.") 1840 "Used to remember whether a buffer initially had font lock on or not.")
1501(make-variable-buffer-local 'whitespace-font-lock)
1502 1841
1503(defvar whitespace-font-lock-keywords nil 1842(defvar whitespace-font-lock-keywords nil
1504 "Used to save locally `font-lock-keywords' value.") 1843 "Used to save locally `font-lock-keywords' value.")
1505(make-variable-buffer-local 'whitespace-font-lock-keywords)
1506 1844
1507 1845
1508(defconst whitespace-help-text 1846(defconst whitespace-help-text
1509 "\ 1847 "\
1510 whitespace-mode toggle options: 1848 Whitespace Toggle Options
1511 1849
1512 [] t - toggle TAB visualization 1850 FACES
1513 [] s - toggle SPACE and HARD SPACE visualization 1851 [] t - toggle TAB visualization
1514 [] r - toggle trailing blanks visualization 1852 [] s - toggle SPACE and HARD SPACE visualization
1515 [] b - toggle SPACEs before TAB visualization 1853 [] r - toggle trailing blanks visualization
1516 [] l - toggle \"long lines\" visualization 1854 [] l - toggle \"long lines\" visualization
1517 [] L - toggle \"long lines\" tail visualization 1855 [] L - toggle \"long lines\" tail visualization
1518 [] n - toggle NEWLINE visualization 1856 [] n - toggle NEWLINE visualization
1519 [] i - toggle indentation SPACEs visualization 1857 [] e - toggle empty line at bob and/or eob visualization
1520 [] e - toggle empty line at bob and/or eob visualization 1858 [] C-i - toggle indentation SPACEs visualization (via `indent-tabs-mode')
1521 [] a - toggle SPACEs after TAB visualization 1859 [] I - toggle indentation SPACEs visualization
1522 1860 [] i - toggle indentation TABs visualization
1523 [] c - toggle color faces 1861 [] C-a - toggle SPACEs after TAB visualization (via `indent-tabs-mode')
1524 [] m - toggle visual mark 1862 [] A - toggle SPACEs after TAB: SPACEs visualization
1525 1863 [] a - toggle SPACEs after TAB: TABs visualization
1526 x - restore `whitespace-chars' value 1864 [] C-b - toggle SPACEs before TAB visualization (via `indent-tabs-mode')
1527 z - restore `whitespace-style' value 1865 [] B - toggle SPACEs before TAB: SPACEs visualization
1866 [] b - toggle SPACEs before TAB: TABs visualization
1867
1868 DISPLAY TABLE
1869 [] T - toggle TAB visualization
1870 [] S - toggle SPACE and HARD SPACE visualization
1871 [] N - toggle NEWLINE visualization
1872
1873 x - restore `whitespace-style-color' value
1874 z - restore `whitespace-style-mark' value
1528 1875
1529 ? - display this text\n\n" 1876 ? - display this text\n\n"
1530 "Text for whitespace toggle options.") 1877 "Text for whitespace toggle options.")
@@ -1534,6 +1881,13 @@ cleaning up these problems."
1534 "The buffer name for whitespace toggle options.") 1881 "The buffer name for whitespace toggle options.")
1535 1882
1536 1883
1884(defun whitespace-insert-value (value)
1885 "Insert VALUE at column 20 of next line."
1886 (forward-line 1)
1887 (move-to-column 20 t)
1888 (insert (format "%s" value)))
1889
1890
1537(defun whitespace-mark-x (nchars condition) 1891(defun whitespace-mark-x (nchars condition)
1538 "Insert the mark ('X' or ' ') after NCHARS depending on CONDITION." 1892 "Insert the mark ('X' or ' ') after NCHARS depending on CONDITION."
1539 (forward-char nchars) 1893 (forward-char nchars)
@@ -1542,7 +1896,7 @@ cleaning up these problems."
1542 1896
1543(defun whitespace-insert-option-mark (the-list the-value) 1897(defun whitespace-insert-option-mark (the-list the-value)
1544 "Insert the option mark ('X' or ' ') in toggle options buffer." 1898 "Insert the option mark ('X' or ' ') in toggle options buffer."
1545 (forward-line 1) 1899 (forward-line 2)
1546 (dolist (sym the-list) 1900 (dolist (sym the-list)
1547 (forward-line 1) 1901 (forward-line 1)
1548 (whitespace-mark-x 2 (memq sym the-value)))) 1902 (whitespace-mark-x 2 (memq sym the-value))))
@@ -1559,9 +1913,9 @@ cleaning up these problems."
1559 (insert whitespace-help-text) 1913 (insert whitespace-help-text)
1560 (goto-char (point-min)) 1914 (goto-char (point-min))
1561 (whitespace-insert-option-mark 1915 (whitespace-insert-option-mark
1562 whitespace-chars-value-list chars) 1916 whitespace-color-value-list chars)
1563 (whitespace-insert-option-mark 1917 (whitespace-insert-option-mark
1564 whitespace-style-value-list style) 1918 whitespace-mark-value-list style)
1565 (whitespace-display-window buffer))))) 1919 (whitespace-display-window buffer)))))
1566 1920
1567 1921
@@ -1580,14 +1934,19 @@ can't split window to display whitespace toggle options"))
1580 (set-window-buffer (split-window nil size) buffer))) 1934 (set-window-buffer (split-window nil size) buffer)))
1581 1935
1582 1936
1583(defun whitespace-help-off () 1937(defun whitespace-kill-buffer (buffer-name)
1584 "Remove the buffer and window of the whitespace toggle options." 1938 "Kill buffer BUFFER-NAME and windows related with it."
1585 (let ((buffer (get-buffer whitespace-help-buffer-name))) 1939 (let ((buffer (get-buffer buffer-name)))
1586 (when buffer 1940 (when buffer
1587 (delete-windows-on buffer) 1941 (delete-windows-on buffer)
1588 (kill-buffer buffer)))) 1942 (kill-buffer buffer))))
1589 1943
1590 1944
1945(defun whitespace-help-off ()
1946 "Remove the buffer and window of the whitespace toggle options."
1947 (whitespace-kill-buffer whitespace-help-buffer-name))
1948
1949
1591(defun whitespace-interactive-char (local-p) 1950(defun whitespace-interactive-char (local-p)
1592 "Interactive function to read a char and return a symbol. 1951 "Interactive function to read a char and return a symbol.
1593 1952
@@ -1597,32 +1956,43 @@ uses a global context.
1597It accepts one of the following chars: 1956It accepts one of the following chars:
1598 1957
1599 CHAR MEANING 1958 CHAR MEANING
1959 (VIA FACES)
1600 t toggle TAB visualization 1960 t toggle TAB visualization
1601 s toggle SPACE and HARD SPACE visualization 1961 s toggle SPACE and HARD SPACE visualization
1602 r toggle trailing blanks visualization 1962 r toggle trailing blanks visualization
1603 b toggle SPACEs before TAB visualization
1604 l toggle \"long lines\" visualization 1963 l toggle \"long lines\" visualization
1605 L toggle \"long lines\" tail visualization 1964 L toggle \"long lines\" tail visualization
1606 n toggle NEWLINE visualization 1965 n toggle NEWLINE visualization
1607 i toggle indentation SPACEs visualization
1608 e toggle empty line at bob and/or eob visualization 1966 e toggle empty line at bob and/or eob visualization
1609 a toggle SPACEs after TAB visualization 1967 C-i toggle indentation SPACEs visualization (via `indent-tabs-mode')
1610 c toggle color faces 1968 I toggle indentation SPACEs visualization
1611 m toggle visual mark 1969 i toggle indentation TABs visualization
1612 x restore `whitespace-chars' value 1970 C-a toggle SPACEs after TAB visualization (via `indent-tabs-mode')
1613 z restore `whitespace-style' value 1971 A toggle SPACEs after TAB: SPACEs visualization
1972 a toggle SPACEs after TAB: TABs visualization
1973 C-b toggle SPACEs before TAB visualization (via `indent-tabs-mode')
1974 B toggle SPACEs before TAB: SPACEs visualization
1975 b toggle SPACEs before TAB: TABs visualization
1976
1977 (VIA DISPLAY TABLE)
1978 T toggle TAB visualization
1979 S toggle SPACE and HARD SPACE visualization
1980 N toggle NEWLINE visualization
1981
1982 x restore `whitespace-style-color' value
1983 z restore `whitespace-style-mark' value
1614 ? display brief help 1984 ? display brief help
1615 1985
1616See also `whitespace-toggle-option-alist'." 1986See also `whitespace-toggle-option-alist'."
1617 (let* ((is-off (not (if local-p 1987 (let* ((is-off (not (if local-p
1618 whitespace-mode 1988 whitespace-mode
1619 global-whitespace-mode))) 1989 global-whitespace-mode)))
1620 (chars (cond (is-off whitespace-chars) ; use default value 1990 (chars (cond (is-off whitespace-style-color) ; use default value
1621 (local-p whitespace-active-chars) 1991 (local-p whitespace-active-color)
1622 (t whitespace-toggle-chars))) 1992 (t whitespace-toggle-color)))
1623 (style (cond (is-off whitespace-style) ; use default value 1993 (style (cond (is-off whitespace-style-mark) ; use default value
1624 (local-p whitespace-active-style) 1994 (local-p whitespace-active-mark)
1625 (t whitespace-toggle-style))) 1995 (t whitespace-toggle-mark)))
1626 (prompt 1996 (prompt
1627 (format "Whitespace Toggle %s (type ? for further options)-" 1997 (format "Whitespace Toggle %s (type ? for further options)-"
1628 (if local-p "Local" "Global"))) 1998 (if local-p "Local" "Global")))
@@ -1690,40 +2060,55 @@ options are valid."
1690 2060
1691(defun whitespace-turn-on () 2061(defun whitespace-turn-on ()
1692 "Turn on whitespace visualization." 2062 "Turn on whitespace visualization."
2063 ;; prepare local hooks
1693 (whitespace-add-local-hook) 2064 (whitespace-add-local-hook)
1694 (setq whitespace-active-style (if (listp whitespace-style) 2065 ;; create whitespace local buffer environment
1695 whitespace-style 2066 (set (make-local-variable 'whitespace-font-lock-mode) nil)
1696 (list whitespace-style))) 2067 (set (make-local-variable 'whitespace-font-lock) nil)
1697 (setq whitespace-active-chars (if (listp whitespace-chars) 2068 (set (make-local-variable 'whitespace-font-lock-keywords) nil)
1698 whitespace-chars 2069 (set (make-local-variable 'whitespace-display-table) nil)
1699 (list whitespace-chars))) 2070 (set (make-local-variable 'whitespace-display-table-was-local) nil)
1700 (when (memq 'color whitespace-active-style) 2071 (set (make-local-variable 'whitespace-active-mark)
2072 (if (listp whitespace-style-mark)
2073 whitespace-style-mark
2074 (list whitespace-style-mark)))
2075 (set (make-local-variable 'whitespace-active-color)
2076 (if (listp whitespace-style-color)
2077 whitespace-style-color
2078 (list whitespace-style-color)))
2079 (set (make-local-variable 'whitespace-indent-tabs-mode)
2080 indent-tabs-mode)
2081 (set (make-local-variable 'whitespace-tab-width)
2082 tab-width)
2083 ;; turn on whitespace
2084 (when whitespace-active-color
1701 (whitespace-color-on)) 2085 (whitespace-color-on))
1702 (when (memq 'mark whitespace-active-style) 2086 (when whitespace-active-mark
1703 (whitespace-display-char-on))) 2087 (whitespace-display-char-on)))
1704 2088
1705 2089
1706(defun whitespace-turn-off () 2090(defun whitespace-turn-off ()
1707 "Turn off whitespace visualization." 2091 "Turn off whitespace visualization."
1708 (whitespace-remove-local-hook) 2092 (whitespace-remove-local-hook)
1709 (when (memq 'color whitespace-active-style) 2093 (when whitespace-active-color
1710 (whitespace-color-off)) 2094 (whitespace-color-off))
1711 (when (memq 'mark whitespace-active-style) 2095 (when whitespace-active-mark
1712 (whitespace-display-char-off))) 2096 (whitespace-display-char-off)))
1713 2097
1714 2098
1715(defun whitespace-color-on () 2099(defun whitespace-color-on ()
1716 "Turn on color visualization." 2100 "Turn on color visualization."
1717 (when whitespace-active-chars 2101 (when whitespace-active-color
1718 (unless whitespace-font-lock 2102 (unless whitespace-font-lock
1719 (setq whitespace-font-lock t 2103 (setq whitespace-font-lock t
1720 whitespace-font-lock-keywords 2104 whitespace-font-lock-keywords
1721 (copy-sequence font-lock-keywords))) 2105 (copy-sequence font-lock-keywords)))
1722 ;; turn off font lock 2106 ;; turn off font lock
1723 (setq whitespace-font-lock-mode font-lock-mode) 2107 (set (make-local-variable 'whitespace-font-lock-mode)
2108 font-lock-mode)
1724 (font-lock-mode 0) 2109 (font-lock-mode 0)
1725 ;; add whitespace-mode color into font lock 2110 ;; add whitespace-mode color into font lock
1726 (when (memq 'spaces whitespace-active-chars) 2111 (when (memq 'spaces whitespace-active-color)
1727 (font-lock-add-keywords 2112 (font-lock-add-keywords
1728 nil 2113 nil
1729 (list 2114 (list
@@ -1732,22 +2117,22 @@ options are valid."
1732 ;; Show HARD SPACEs 2117 ;; Show HARD SPACEs
1733 (list whitespace-hspace-regexp 1 whitespace-hspace t)) 2118 (list whitespace-hspace-regexp 1 whitespace-hspace t))
1734 t)) 2119 t))
1735 (when (memq 'tabs whitespace-active-chars) 2120 (when (memq 'tabs whitespace-active-color)
1736 (font-lock-add-keywords 2121 (font-lock-add-keywords
1737 nil 2122 nil
1738 (list 2123 (list
1739 ;; Show TABs 2124 ;; Show TABs
1740 (list whitespace-tab-regexp 1 whitespace-tab t)) 2125 (list whitespace-tab-regexp 1 whitespace-tab t))
1741 t)) 2126 t))
1742 (when (memq 'trailing whitespace-active-chars) 2127 (when (memq 'trailing whitespace-active-color)
1743 (font-lock-add-keywords 2128 (font-lock-add-keywords
1744 nil 2129 nil
1745 (list 2130 (list
1746 ;; Show trailing blanks 2131 ;; Show trailing blanks
1747 (list (whitespace-trailing-regexp) 1 whitespace-trailing t)) 2132 (list (whitespace-trailing-regexp) 1 whitespace-trailing t))
1748 t)) 2133 t))
1749 (when (or (memq 'lines whitespace-active-chars) 2134 (when (or (memq 'lines whitespace-active-color)
1750 (memq 'lines-tail whitespace-active-chars)) 2135 (memq 'lines-tail whitespace-active-color))
1751 (font-lock-add-keywords 2136 (font-lock-add-keywords
1752 nil 2137 nil
1753 (list 2138 (list
@@ -1755,34 +2140,69 @@ options are valid."
1755 (list 2140 (list
1756 (format 2141 (format
1757 "^\\([^\t\n]\\{%s\\}\\|[^\t\n]\\{0,%s\\}\t\\)\\{%d\\}%s\\(.+\\)$" 2142 "^\\([^\t\n]\\{%s\\}\\|[^\t\n]\\{0,%s\\}\t\\)\\{%d\\}%s\\(.+\\)$"
1758 tab-width (1- tab-width) 2143 whitespace-tab-width (1- whitespace-tab-width)
1759 (/ whitespace-line-column tab-width) 2144 (/ whitespace-line-column tab-width)
1760 (let ((rem (% whitespace-line-column tab-width))) 2145 (let ((rem (% whitespace-line-column whitespace-tab-width)))
1761 (if (zerop rem) 2146 (if (zerop rem)
1762 "" 2147 ""
1763 (format ".\\{%d\\}" rem)))) 2148 (format ".\\{%d\\}" rem))))
1764 (if (memq 'lines whitespace-active-chars) 2149 (if (memq 'lines whitespace-active-color)
1765 0 ; whole line 2150 0 ; whole line
1766 2) ; line tail 2151 2) ; line tail
1767 whitespace-line t)) 2152 whitespace-line t))
1768 t)) 2153 t))
1769 (when (memq 'space-before-tab whitespace-active-chars) 2154 (cond
2155 ((memq 'space-before-tab whitespace-active-color)
2156 (font-lock-add-keywords
2157 nil
2158 (list
2159 ;; Show SPACEs before TAB (indent-tabs-mode)
2160 (list whitespace-space-before-tab-regexp
2161 (if whitespace-indent-tabs-mode 1 2)
2162 whitespace-space-before-tab t))
2163 t))
2164 ((memq 'space-before-tab::tab whitespace-active-color)
1770 (font-lock-add-keywords 2165 (font-lock-add-keywords
1771 nil 2166 nil
1772 (list 2167 (list
1773 ;; Show SPACEs before TAB 2168 ;; Show SPACEs before TAB (SPACEs)
1774 (list whitespace-space-before-tab-regexp 2169 (list whitespace-space-before-tab-regexp
1775 1 whitespace-space-before-tab t)) 2170 1 whitespace-space-before-tab t))
1776 t)) 2171 t))
1777 (when (memq 'indentation whitespace-active-chars) 2172 ((memq 'space-before-tab::space whitespace-active-color)
1778 (font-lock-add-keywords 2173 (font-lock-add-keywords
1779 nil 2174 nil
1780 (list 2175 (list
1781 ;; Show indentation SPACEs 2176 ;; Show SPACEs before TAB (TABs)
1782 (list whitespace-indentation-regexp 2177 (list whitespace-space-before-tab-regexp
2178 2 whitespace-space-before-tab t))
2179 t)))
2180 (cond
2181 ((memq 'indentation whitespace-active-color)
2182 (font-lock-add-keywords
2183 nil
2184 (list
2185 ;; Show indentation SPACEs (indent-tabs-mode)
2186 (list (whitespace-indentation-regexp)
1783 1 whitespace-indentation t)) 2187 1 whitespace-indentation t))
1784 t)) 2188 t))
1785 (when (memq 'empty whitespace-active-chars) 2189 ((memq 'indentation::tab whitespace-active-color)
2190 (font-lock-add-keywords
2191 nil
2192 (list
2193 ;; Show indentation SPACEs (SPACEs)
2194 (list (whitespace-indentation-regexp 'tab)
2195 1 whitespace-indentation t))
2196 t))
2197 ((memq 'indentation::space whitespace-active-color)
2198 (font-lock-add-keywords
2199 nil
2200 (list
2201 ;; Show indentation SPACEs (TABs)
2202 (list (whitespace-indentation-regexp 'space)
2203 1 whitespace-indentation t))
2204 t)))
2205 (when (memq 'empty whitespace-active-color)
1786 (font-lock-add-keywords 2206 (font-lock-add-keywords
1787 nil 2207 nil
1788 (list 2208 (list
@@ -1797,21 +2217,38 @@ options are valid."
1797 (list whitespace-empty-at-eob-regexp 2217 (list whitespace-empty-at-eob-regexp
1798 1 whitespace-empty t)) 2218 1 whitespace-empty t))
1799 t)) 2219 t))
1800 (when (memq 'space-after-tab whitespace-active-chars) 2220 (cond
2221 ((memq 'space-after-tab whitespace-active-color)
1801 (font-lock-add-keywords 2222 (font-lock-add-keywords
1802 nil 2223 nil
1803 (list 2224 (list
1804 ;; Show SPACEs after TAB 2225 ;; Show SPACEs after TAB (indent-tabs-mode)
1805 (list whitespace-space-after-tab-regexp 2226 (list (whitespace-space-after-tab-regexp)
1806 1 whitespace-space-after-tab t)) 2227 1 whitespace-space-after-tab t))
1807 t)) 2228 t))
2229 ((memq 'space-after-tab::tab whitespace-active-color)
2230 (font-lock-add-keywords
2231 nil
2232 (list
2233 ;; Show SPACEs after TAB (SPACEs)
2234 (list (whitespace-space-after-tab-regexp 'tab)
2235 1 whitespace-space-after-tab t))
2236 t))
2237 ((memq 'space-after-tab::space whitespace-active-color)
2238 (font-lock-add-keywords
2239 nil
2240 (list
2241 ;; Show SPACEs after TAB (TABs)
2242 (list (whitespace-space-after-tab-regexp 'space)
2243 1 whitespace-space-after-tab t))
2244 t)))
1808 ;; now turn on font lock and highlight blanks 2245 ;; now turn on font lock and highlight blanks
1809 (font-lock-mode 1))) 2246 (font-lock-mode 1)))
1810 2247
1811 2248
1812(defun whitespace-color-off () 2249(defun whitespace-color-off ()
1813 "Turn off color visualization." 2250 "Turn off color visualization."
1814 (when whitespace-active-chars 2251 (when whitespace-active-color
1815 ;; turn off font lock 2252 ;; turn off font lock
1816 (font-lock-mode 0) 2253 (font-lock-mode 0)
1817 (when whitespace-font-lock 2254 (when whitespace-font-lock
@@ -1827,11 +2264,9 @@ options are valid."
1827 2264
1828(defvar whitespace-display-table nil 2265(defvar whitespace-display-table nil
1829 "Used to save a local display table.") 2266 "Used to save a local display table.")
1830(make-variable-buffer-local 'whitespace-display-table)
1831 2267
1832(defvar whitespace-display-table-was-local nil 2268(defvar whitespace-display-table-was-local nil
1833 "Used to remember whether a buffer initially had a local display table.") 2269 "Used to remember whether a buffer initially had a local display table.")
1834(make-variable-buffer-local 'whitespace-display-table-was-local)
1835 2270
1836 2271
1837(defsubst whitespace-char-valid-p (char) 2272(defsubst whitespace-char-valid-p (char)
@@ -1861,35 +2296,29 @@ options are valid."
1861 (unless buffer-display-table 2296 (unless buffer-display-table
1862 (setq buffer-display-table (make-display-table))) 2297 (setq buffer-display-table (make-display-table)))
1863 (dolist (entry whitespace-display-mappings) 2298 (dolist (entry whitespace-display-mappings)
1864 (setq vecs (cdr entry)) 2299 ;; check if it is to display this mark
1865 ;; Get a displayable mapping. 2300 (when (memq (car entry) whitespace-style-mark)
1866 (while (and vecs 2301 ;; Get a displayable mapping.
1867 (not (whitespace-display-vector-p (car vecs)))) 2302 (setq vecs (cddr entry))
1868 (setq vecs (cdr vecs))) 2303 (while (and vecs
1869 ;; Display a valid mapping. 2304 (not (whitespace-display-vector-p (car vecs))))
1870 (when vecs 2305 (setq vecs (cdr vecs)))
1871 (setq vec (copy-sequence (car vecs))) 2306 ;; Display a valid mapping.
1872 (cond 2307 (when vecs
1873 ;; Any char except newline 2308 (setq vec (copy-sequence (car vecs)))
1874 ((not (eq (car entry) ?\n)) 2309 ;; NEWLINE char
1875 (aset buffer-display-table (car entry) vec)) 2310 (when (and (eq (cadr entry) ?\n)
1876 ;; Newline char - display it 2311 (memq 'newline whitespace-active-color))
1877 ((memq 'newline whitespace-active-chars) 2312 ;; Only insert face bits on NEWLINE char mapping to avoid
1878 ;; Only insert face bits on NEWLINE char mapping to avoid 2313 ;; obstruction of other faces like TABs and (HARD) SPACEs
1879 ;; obstruction of other faces like TABs and (HARD) SPACEs 2314 ;; faces, font-lock faces, etc.
1880 ;; faces, font-lock faces, etc.
1881 (when (memq 'color whitespace-active-style)
1882 (dotimes (i (length vec)) 2315 (dotimes (i (length vec))
1883 (or (eq (aref vec i) ?\n) 2316 (or (eq (aref vec i) ?\n)
1884 (aset vec i 2317 (aset vec i
1885 (make-glyph-code (aref vec i) 2318 (make-glyph-code (aref vec i)
1886 whitespace-newline))))) 2319 whitespace-newline)))))
1887 ;; Display mapping 2320 ;; Display mapping
1888 (aset buffer-display-table (car entry) vec)) 2321 (aset buffer-display-table (cadr entry) vec)))))))
1889 ;; Newline char - don't display it
1890 (t
1891 ;; Do nothing
1892 )))))))
1893 2322
1894 2323
1895(defun whitespace-display-char-off () 2324(defun whitespace-display-char-off ()
@@ -1937,7 +2366,7 @@ It should be added buffer-locally to `write-file-functions'."
1937 "Action to be taken when buffer is killed. 2366 "Action to be taken when buffer is killed.
1938It should be added buffer-locally to `kill-buffer-hook'." 2367It should be added buffer-locally to `kill-buffer-hook'."
1939 (whitespace-action) 2368 (whitespace-action)
1940 nil) ; continue hook processing 2369 nil) ; continue hook processing
1941 2370
1942 2371
1943(defun whitespace-action () 2372(defun whitespace-action ()