mirrored from git://git.sv.gnu.org/emacs.git
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathwhitespace.el
2618 lines (2224 loc) · 98.2 KB
/
whitespace.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;; whitespace.el --- minor mode to visualize TAB, (HARD) SPACE, NEWLINE -*- lexical-binding: t -*-
;; Copyright (C) 2000-2025 Free Software Foundation, Inc.
;; Author: Vinicius Jose Latorre <viniciusjl.gnu@gmail.com>
;; Keywords: data, text
;; Version: 13.2.2
;; URL: https://www.emacswiki.org/cgi-bin/wiki/ViniciusJoseLatorre
;; This file is part of GNU Emacs.
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Introduction
;; ------------
;;
;; This package is a minor mode to visualize blanks (TAB, (HARD) SPACE
;; and NEWLINE).
;;
;; whitespace uses two ways to visualize blanks: faces and display
;; table.
;;
;; * Faces are used to highlight the background with a color.
;; whitespace uses font-lock to highlight blank characters.
;;
;; * Display table changes the way a character is displayed, that is,
;; it provides a visual mark for characters, for example, at the end
;; of line (?\xB6), at SPACEs (?\xB7) and at TABs (?\xBB).
;;
;; The `whitespace-style' variable selects which way blanks are
;; visualized.
;;
;; Note that when whitespace is turned on, whitespace saves the
;; font-lock state, that is, if font-lock is on or off. And
;; whitespace restores the font-lock state when it is turned off. So,
;; if whitespace is turned on and font-lock is off, whitespace also
;; turns on the font-lock to highlight blanks, but the font-lock will
;; be turned off when whitespace is turned off. Thus, turn on
;; font-lock before whitespace is on, if you want that font-lock
;; continues on after whitespace is turned off.
;;
;; When whitespace is on, it takes care of highlighting some special
;; characters over the default mechanism of `nobreak-char-display'
;; (which see) and `show-trailing-whitespace' (which see).
;;
;; The trailing spaces are not highlighted while point is at end of line.
;; Also the spaces at beginning of buffer are not highlighted while point is at
;; beginning of buffer; and the spaces at end of buffer are not highlighted
;; while point is at end of buffer.
;;
;; There are two ways of using whitespace: local and global.
;;
;; * Local whitespace affects only the current buffer.
;;
;; * Global whitespace affects all current and future buffers. That
;; is, if you turn on global whitespace and then create a new
;; buffer, the new buffer will also have whitespace on. The
;; `whitespace-global-modes' variable controls which major-mode will
;; be automagically turned on.
;;
;; You can mix the local and global usage without any conflict. But
;; local whitespace has priority over global whitespace. Whitespace
;; mode is active in a buffer if you have enabled it in that buffer or
;; if you have enabled it globally.
;;
;; When global and local whitespace are on:
;;
;; * if local whitespace is turned off, whitespace is turned off for
;; the current buffer only.
;;
;; * if global whitespace is turned off, whitespace continues on only
;; in the buffers in which local whitespace is on.
;;
;; whitespace was inspired by:
;;
;; whitespace.el Rajesh Vaidheeswarran <rv@gnu.org>
;; Warn about and clean bogus whitespaces in the file
;; (inspired the idea to warn and clean some blanks)
;; This was the original `whitespace.el' which was replaced by
;; `blank-mode.el'. And later `blank-mode.el' was renamed to
;; `whitespace.el'.
;;
;; show-whitespace-mode.el Aurelien Tisne <aurelien.tisne@free.fr>
;; Simple mode to highlight whitespaces
;; (inspired the idea to use font-lock)
;;
;; whitespace-mode.el Lawrence Mitchell <wence@gmx.li>
;; Major mode for editing Whitespace
;; (inspired the idea to use display table)
;;
;; visws.el Miles Bader <miles@gnu.org>
;; Make whitespace visible
;; (handle display table, his code was modified, but the main
;; idea was kept)
;;
;;
;; Using whitespace
;; ----------------
;;
;; There is no problem if you mix local and global minor mode usage.
;;
;; * LOCAL whitespace:
;; + To toggle whitespace options locally, type:
;;
;; M-x whitespace-toggle-options RET
;;
;; + To activate whitespace locally, type:
;;
;; C-u 1 M-x whitespace-mode RET
;;
;; + To deactivate whitespace locally, type:
;;
;; C-u 0 M-x whitespace-mode RET
;;
;; + To toggle whitespace locally, type:
;;
;; M-x whitespace-mode RET
;;
;; * GLOBAL whitespace:
;; + To toggle whitespace options globally, type:
;;
;; M-x global-whitespace-toggle-options RET
;;
;; + To activate whitespace globally, type:
;;
;; C-u 1 M-x global-whitespace-mode RET
;;
;; + To deactivate whitespace globally, type:
;;
;; C-u 0 M-x global-whitespace-mode RET
;;
;; + To toggle whitespace globally, type:
;;
;; M-x global-whitespace-mode RET
;;
;; There are also the following useful commands:
;;
;; `whitespace-newline-mode'
;; Toggle NEWLINE minor mode visualization ("nl" on mode line).
;;
;; `global-whitespace-newline-mode'
;; Toggle NEWLINE global minor mode visualization ("NL" on mode line).
;;
;; `whitespace-report'
;; Report some blank problems in buffer.
;;
;; `whitespace-report-region'
;; Report some blank problems in a region.
;;
;; `whitespace-cleanup'
;; Cleanup some blank problems in all buffer or at region.
;; See the function's docstring for more information.
;;
;; `whitespace-cleanup-region'
;; Cleanup some blank problems at region.
;;
;;
;; Options
;; -------
;;
;; Whitespace's behavior can be changed with `M-x customize-group
;; whitespace', which see for the full list of options.
;;
;;
;; Hooks
;; -----
;;
;; whitespace has the following hook variables:
;;
;; `whitespace-mode-hook'
;; It is evaluated always when whitespace is turned on locally.
;;
;; `global-whitespace-mode-hook'
;; It is evaluated always when whitespace is turned on globally.
;;
;; `whitespace-load-hook'
;; It is evaluated after whitespace package is loaded.
;;
;;
;; Acknowledgments
;; ---------------
;;
;; Thanks to felix (EmacsWiki) for keeping highlight when switching between
;; major modes on a file.
;;
;; Thanks to David Reitter <david.reitter@gmail.com> for suggesting a
;; `whitespace-newline' initialization with low contrast relative to
;; the background color.
;;
;; Thanks to Stephen Deasey <sdeasey@gmail.com> for the
;; `indent-tabs-mode' usage suggestion.
;;
;; Thanks to Eric Cooper <ecc@cmu.edu> for the suggestion to have hook
;; actions when buffer is written as the original whitespace package
;; had.
;;
;; Thanks to nschum (EmacsWiki) for the idea about highlight "long"
;; lines tail. See EightyColumnRule (EmacsWiki).
;;
;; Thanks to Juri Linkov <juri@jurta.org> for suggesting:
;; * `define-minor-mode'.
;; * `global-whitespace-*' name for global commands.
;;
;; Thanks to Robert J. Chassell <bob@gnu.org> for doc fix and testing.
;;
;; Thanks to Drew Adams <drew.adams@oracle.com> for toggle commands
;; suggestion.
;;
;; Thanks to Antti Kaihola <antti.kaihola@linux-aktivaattori.org> for
;; helping to fix `find-file-hooks' reference.
;;
;; Thanks to Andreas Roehler <andreas.roehler@easy-emacs.de> for
;; indicating defface byte-compilation warnings.
;;
;; Thanks to Tim O'Callaghan (EmacsWiki) for the idea about highlight
;; "long" lines. See EightyColumnRule (EmacsWiki).
;;
;; Thanks to Yanghui Bian <yanghuibian@gmail.com> for indicating a new
;; NEWLINE character mapping.
;;
;; Thanks to Pete Forman <pete.forman@westgeo.com> for indicating
;; whitespace-mode.el on XEmacs.
;;
;; Thanks to Miles Bader <miles@gnu.org> for handling display table via
;; visws.el (his code was modified, but the main idea was kept).
;;
;; Thanks to:
;; Rajesh Vaidheeswarran <rv@gnu.org> (original) whitespace.el
;; Aurelien Tisne <aurelien.tisne@free.fr> show-whitespace-mode.el
;; Lawrence Mitchell <wence@gmx.li> whitespace-mode.el
;; Miles Bader <miles@gnu.org> visws.el
;; And to all people who contributed with them.
;;
;;
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; User Variables:
;;; Interface to the command system
(defgroup whitespace nil
"Visualize blanks (TAB, (HARD) SPACE and NEWLINE)."
:link '(emacs-library-link :tag "Source Lisp File" "whitespace.el")
:version "23.1"
:group 'convenience)
(defcustom whitespace-style
'(face
tabs spaces trailing lines space-before-tab newline
indentation empty space-after-tab
space-mark tab-mark newline-mark
missing-newline-at-eof)
"Determine the kinds of whitespace are visualized.
The value is a list containing one or more of the following symbols:
face visualize by using faces (see below).
trailing visualize trailing blanks via faces.
This has effect only if `face' (see above)
is present in `whitespace-style'.
tabs visualize TABs via faces.
This has effect only if `face' (see above)
is present in `whitespace-style'.
spaces visualize SPACEs and HARD SPACEs via
faces.
This has effect only if `face' (see above)
is present in `whitespace-style'.
lines highlight lines which have columns beyond
`whitespace-line-column' via faces.
Whole line is highlighted.
This has precedence over `lines-tail' and
`lines-char' (see below).
This has effect only if `face' (see above)
is present in `whitespace-style'.
lines-tail highlighted lines which have columns beyond
`whitespace-line-column' via faces.
Only the part of line which goes beyond
`whitespace-line-column' column.
This has effect only if `lines' (see above)
is NOT present in `whitespace-style',
and if `face' (see above) IS present in
`whitespace-style'.
lines-char lines which have columns beyond
`whitespace-line-column' are highlighted via
putting a face on the first character that goes
beyond the `whitespace-line-column' column.
It has effect only if `lines' or
`lines-tail' (see above) is not present
in `whitespace-style' and if `face' (see
above) is present in `whitespace-style'.
newline visualize NEWLINEs via faces.
This has effect only if `face' (see above)
is present in `whitespace-style'.
missing-newline-at-eof visualize missing newline at the end of
the file via faces.
This has effect only if `face' (see above)
is present in `whitespace-style'.
empty visualize empty lines at beginning and/or
end of buffer via faces.
This has effect only if `face' (see above)
is present in `whitespace-style'.
indentation::tab visualize `tab-width' or more SPACEs at
beginning of line via faces.
This has effect only if `face' (see above)
is present in `whitespace-style'.
indentation::space visualize TABs at beginning of line via
faces.
This has effect only if `face' (see above)
is present in `whitespace-style'.
indentation visualize `tab-width' or more SPACEs at
beginning of line, if `indent-tabs-mode' (which
see) is non-nil; otherwise, visualize TABs
at beginning of line via faces.
This has effect only if `face' (see above)
is present in `whitespace-style'.
big-indent visualize big indentations via faces.
This has effect only if `face' (see above)
is present in `whitespace-style'.
space-after-tab::tab visualize `tab-width' or more SPACEs
after a TAB via faces.
This has effect only if `face' (see above)
is present in `whitespace-style'.
space-after-tab::space visualize TABs when `tab-width' or
more SPACEs occur after a TAB, via
faces.
This has effect only if `face' (see above)
is present in `whitespace-style'.
space-after-tab visualize `tab-width' or more SPACEs
after a TAB, if `indent-tabs-mode'
(which see) is non-nil; otherwise,
visualize the TABs via faces.
This has effect only if `face' (see above)
is present in `whitespace-style'.
space-before-tab::tab visualize SPACEs before TAB via faces.
This has effect only if `face' (see above)
is present in `whitespace-style'.
space-before-tab::space visualize TABs when SPACEs occur
before TAB, via faces.
This has effect only if `face' (see above)
is present in `whitespace-style'.
space-before-tab visualize SPACEs before TAB, if
`indent-tabs-mode' (which see) is
non-nil; otherwise, visualize TABs
via faces.
This has effect only if `face' (see above)
is present in `whitespace-style'.
space-mark visualize SPACEs and HARD SPACEs via
display table.
tab-mark visualize TABs via display table.
newline-mark visualize NEWLINEs via display table.
Any other value is ignored.
If nil, don't visualize TABs, (HARD) SPACEs and NEWLINEs via faces and
via display table.
There is an evaluation order for some values, if they are
included in `whitespace-style' list. For example, if
indentation, indentation::tab and/or indentation::space are
included in `whitespace-style' list, the evaluation order is:
* For indentation:
1. indentation
2. indentation::tab
3. indentation::space
* For SPACEs after TABs:
1. space-after-tab
2. space-after-tab::tab
3. space-after-tab::space
* For SPACEs before TABs:
1. space-before-tab
2. space-before-tab::tab
3. space-before-tab::space
For example, if `indentation' and `indentation::space' are
included in `whitespace-style', the `indentation' value is used
instead of the `indentation::space' value.
One reason to not use faces to visualize spaces (i.e., not
include `face' in `whitespace-style') is to use `whitespace-mode'
only for cleaning up a buffer. See `whitespace-cleanup' and
`whitespace-cleanup-region'.
See also `whitespace-display-mappings' for documentation."
:type '(set :tag "Kind of Blank"
(const :tag "(Face) Face visualization" face)
(const :tag "(Face) Trailing TABs, SPACEs and HARD SPACEs"
trailing)
(const :tag "(Face) TABs" tabs)
(const :tag "(Face) SPACEs and HARD SPACEs" spaces)
(const :tag "(Face) Lines" lines)
(const :tag "(Face) Lines, only overlong part" lines-tail)
(const :tag "(Face) Lines, only first character" lines-char)
(const :tag "(Face) NEWLINEs" newline)
(const :tag "(Face) Missing newlines at EOB"
missing-newline-at-eof)
(const :tag "(Face) Empty Lines At BOB And/Or EOB" empty)
(const :tag "(Face) Indentation SPACEs" indentation::tab)
(const :tag "(Face) Indentation TABs"
indentation::space)
(const :tag "(Face) Indentation TABs or SPACEs" indentation)
(const :tag "(Face) Too much line indentation" big-indent)
(const :tag "(Face) SPACEs after TAB: SPACEs"
space-after-tab::tab)
(const :tag "(Face) SPACEs after TAB: TABs"
space-after-tab::space)
(const :tag "(Face) SPACEs after TAB" space-after-tab)
(const :tag "(Face) SPACEs before TAB: SPACEs"
space-before-tab::tab)
(const :tag "(Face) SPACEs before TAB: TABs"
space-before-tab::space)
(const :tag "(Face) SPACEs before TAB" space-before-tab)
(const :tag "(Mark) SPACEs and HARD SPACEs" space-mark)
(const :tag "(Mark) TABs" tab-mark)
(const :tag "(Mark) NEWLINEs" newline-mark))
:group 'whitespace)
(defvar whitespace-space 'whitespace-space
"Symbol face used to visualize SPACE.
Used when `whitespace-style' includes the value `spaces'.")
(make-obsolete-variable 'whitespace-space "use the face instead." "24.4")
(defface whitespace-space
'((((class color) (background dark))
:background "grey20" :foreground "darkgray")
(((class color) (background light))
:background "LightYellow" :foreground "lightgray")
(t :inverse-video t))
"Face used to visualize SPACE.
See `whitespace-space-regexp'."
:group 'whitespace)
(defvar whitespace-hspace 'whitespace-hspace
"Symbol face used to visualize HARD SPACE.
Used when `whitespace-style' includes the value `spaces'.")
(make-obsolete-variable 'whitespace-hspace "use the face instead." "24.4")
(defface whitespace-hspace ; 'nobreak-space
'((((class color) (background dark))
:background "grey24" :foreground "darkgray")
(((class color) (background light))
:background "LemonChiffon3" :foreground "lightgray")
(t :inverse-video t))
"Face used to visualize HARD SPACE.
See `whitespace-hspace-regexp'."
:group 'whitespace)
(defvar whitespace-tab 'whitespace-tab
"Symbol face used to visualize TAB.
Used when `whitespace-style' includes the value `tabs'.")
(make-obsolete-variable 'whitespace-tab
"customize the face `whitespace-tab' instead." "24.4")
(defface whitespace-tab
'((((class color) (background dark))
:background "grey22" :foreground "darkgray")
(((class color) (background light))
:background "beige" :foreground "lightgray")
(t :inverse-video t))
"Face used to visualize TAB.
See `whitespace-tab-regexp'."
:group 'whitespace)
(defvar whitespace-newline 'whitespace-newline
"Symbol face used to visualize NEWLINE char mapping.
See `whitespace-display-mappings'.
Used when `whitespace-style' includes the values `newline-mark'
and `newline'.")
(make-obsolete-variable 'whitespace-newline "use the face instead." "24.4")
(defface whitespace-newline
'((default :weight normal)
(((class color) (background dark)) :foreground "darkgray")
(((class color) (min-colors 88) (background light)) :foreground "lightgray")
;; Displays with 16 colors use lightgray as background, so using a
;; lightgray foreground makes the newline mark invisible.
(((class color) (background light)) :foreground "brown")
(t :underline t))
"Face used to visualize NEWLINE char mapping.
See `whitespace-display-mappings'."
:group 'whitespace)
(defvar whitespace-trailing 'whitespace-trailing
"Symbol face used to visualize trailing blanks.
Used when `whitespace-style' includes the value `trailing'.")
(make-obsolete-variable 'whitespace-trailing "use the face instead." "24.4")
(defface whitespace-trailing ; 'trailing-whitespace
'((default :weight bold)
(((class mono)) :inverse-video t :underline t)
(t :background "red1" :foreground "yellow"))
"Face used to visualize trailing blanks.
See `whitespace-trailing-regexp'."
:group 'whitespace)
(defvar whitespace-line 'whitespace-line
"Symbol face used to visualize \"long\" lines.
See `whitespace-line-column'.
Used when `whitespace-style' includes the value `line'.")
(make-obsolete-variable 'whitespace-line "use the face instead." "24.4")
(defface whitespace-line
'((((class mono)) :inverse-video t :weight bold :underline t)
(t :background "gray20" :foreground "violet"))
"Face used to visualize \"long\" lines.
See `whitespace-line-column'."
:group 'whitespace)
(defvar whitespace-space-before-tab 'whitespace-space-before-tab
"Symbol face used to visualize SPACEs before TAB.
Used when `whitespace-style' includes the value `space-before-tab'.")
(make-obsolete-variable 'whitespace-space-before-tab
"use the face instead." "24.4")
(defface whitespace-space-before-tab
'((((class mono)) :inverse-video t :weight bold :underline t)
(t :background "DarkOrange" :foreground "firebrick"))
"Face used to visualize SPACEs before TAB.
See `whitespace-space-before-tab-regexp'."
:group 'whitespace)
(defvar whitespace-indentation 'whitespace-indentation
"Symbol face used to visualize `tab-width' or more SPACEs at beginning of line.
Used when `whitespace-style' includes the value `indentation'.")
(make-obsolete-variable 'whitespace-indentation "use the face instead." "24.4")
(defface whitespace-indentation
'((((class mono)) :inverse-video t :weight bold :underline t)
(t :background "yellow" :foreground "firebrick"))
"Face used to visualize `tab-width' or more SPACEs at beginning of line.
See `whitespace-indentation-regexp'."
:group 'whitespace)
(defface whitespace-big-indent
'((((class mono)) :inverse-video t :weight bold :underline t)
(t :background "red" :foreground "firebrick"))
"Face used to visualize big indentation.
See `whitespace-big-indent-regexp'."
:group 'whitespace)
(defface whitespace-missing-newline-at-eof
'((((class mono)) :inverse-video t :weight bold :underline t)
(t :background "#d0d040" :foreground "black"))
"Face used to visualize missing newline at the end of the file.")
(defvar whitespace-empty 'whitespace-empty
"Symbol face used to visualize empty lines at beginning and/or end of buffer.
Used when `whitespace-style' includes the value `empty'.")
(make-obsolete-variable 'whitespace-empty "use the face instead." "24.4")
(defface whitespace-empty
'((((class mono)) :inverse-video t :weight bold :underline t)
(t :background "yellow" :foreground "firebrick" :extend t))
"Face used to visualize empty lines at beginning and/or end of buffer.
See `whitespace-empty-at-bob-regexp' and `whitespace-empty-at-eob-regexp."
:group 'whitespace)
(defvar whitespace-space-after-tab 'whitespace-space-after-tab
"Symbol face used to visualize `tab-width' or more SPACEs after TAB.
Used when `whitespace-style' includes the value `space-after-tab'.")
(make-obsolete-variable 'whitespace-space-after-tab
"use the face instead." "24.4")
(defface whitespace-space-after-tab
'((((class mono)) :inverse-video t :weight bold :underline t)
(t :background "yellow" :foreground "firebrick"))
"Face used to visualize `tab-width' or more SPACEs after TAB.
See `whitespace-space-after-tab-regexp'."
:group 'whitespace)
(defcustom whitespace-hspace-regexp
"\\(\u00A0+\\)"
"Regexp to match HARD SPACE characters that should be visualized.
The HARD SPACE characters are highlighted using the `whitespace-hspace' face.
Here are some examples:
\"\\\\(^\\xA0+\\\\)\" \
visualize only leading HARD SPACEs.
\"\\\\(\\xA0+$\\\\)\" \
visualize only trailing HARD SPACEs.
\"\\\\(^\\xA0+\\\\|\\xA0+$\\\\)\" \
visualize leading and/or trailing HARD SPACEs.
\"\\t\\\\(\\xA0+\\\\)\\t\" \
visualize only HARD SPACEs between TABs.
NOTE: Always enclose the elements to highlight in \\\\(...\\\\).
Use exactly one pair of enclosing \\\\( and \\\\).
This variable is used when `whitespace-style' includes `spaces'."
:type '(regexp :tag "HARD SPACE Chars")
:group 'whitespace)
(defcustom whitespace-space-regexp "\\( +\\)"
"Regexp to match SPACE characters that should be visualized.
The SPACE characters are highlighted using the `whitespace-space' face.
By default only ASCII SPACE character is visualized, but if you
are typing in some non-Latin language, there may be other
characters besides \" \" that should be considered SPACE.
Here are some examples:
\"\\\\(^ +\\\\)\" visualize only leading SPACEs.
\"\\\\( +$\\\\)\" visualize only trailing SPACEs.
\"\\\\(^ +\\\\| +$\\\\)\" \
visualize leading and/or trailing SPACEs.
\"\\t\\\\( +\\\\)\\t\" visualize only SPACEs between TABs.
NOTE: Always enclose the elements to highlight in \\\\(...\\\\).
Use exactly one pair of enclosing \\\\( and \\\\).
This variable is used when `whitespace-style' includes `spaces'."
:type '(regexp :tag "SPACE Chars")
:group 'whitespace)
(defcustom whitespace-tab-regexp "\\(\t+\\)"
"Regexp to match TAB characters that should be visualized.
The TAB characters are highlighted using the `whitespace-tab' face.
By default only ASCII TAB character is visualized, but if you
are typing in some non-Latin language, there may be other
characters besides \" \" that should be considered a TAB.
Here are some examples:
\"\\\\(^\\t+\\\\)\" visualize only leading TABs.
\"\\\\(\\t+$\\\\)\" visualize only trailing TABs.
\"\\\\(^\\t+\\\\|\\t+$\\\\)\" \
visualize leading and/or trailing TABs.
\" \\\\(\\t+\\\\) \" visualize only TABs between SPACEs.
NOTE: Always enclose the elements to highlight in \\\\(...\\\\).
Use exactly one pair of enclosing \\\\( and \\\\).
This variable is used when `whitespace-style' includes `tabs'."
:type '(regexp :tag "TAB Chars")
:group 'whitespace)
(defcustom whitespace-trailing-regexp
"\\([\t \u00A0]+\\)$"
"Regexp to match trailing characters that should be visualized.
The trailing characters are highlighted using the `whitespace-trailing' face.
There may be other characters besides:
\" \" \"\\t\" \"\\u00A0\"
that should be considered blank.
NOTE: Always enclose the elements to highlight in \"\\\\(\"...\"\\\\)$\".
Use exactly one pair of enclosing elements above.
This variable is used when `whitespace-style' includes `trailing'."
:type '(regexp :tag "Trailing Chars")
:group 'whitespace)
(defcustom whitespace-space-before-tab-regexp "\\( +\\)\\(\t+\\)"
"Regexp to match SPACEs before TAB that should be visualized.
The SPACE characters are highlighted using the `whitespace-space-before-tab'
face.
This variable is used when `whitespace-style' includes
`space-before-tab', `space-before-tab::tab' or `space-before-tab::space'."
:type '(regexp :tag "SPACEs Before TAB")
:group 'whitespace)
(defcustom whitespace-indentation-regexp
'("^\t*\\(\\( \\{%d\\}\\)+\\)[^\n\t]"
. "^ *\\(\t+\\).")
"Regexps to match indentation whitespace that should be visualized.
The value should be a cons whose car specifies the regexp to match
visualization of SPACEs, and the cdr specifies the regexp to match
visualization of TABs.
The indentation characters are highlighted using the `whitespace-indentation'
face.
This variable is used when `whitespace-style' includes `indentation',
`indentation::tab' or `indentation::space'."
:type '(cons (string :tag "Indentation SPACEs")
(regexp :tag "Indentation TABs"))
:group 'whitespace)
(defcustom whitespace-empty-at-bob-regexp "\\`\\([ \t\n]*\\(?:\n\\|$\\)\\)"
"Regexp to match empty lines at beginning of buffer that should be visualized.
The empty lines are highlighted using the `whitespace-empty' face.
This variable is used when `whitespace-style' includes `empty'."
:type '(regexp :tag "Empty Lines At Beginning Of Buffer")
:group 'whitespace)
(defcustom whitespace-empty-at-eob-regexp "^\\([ \t\n]+\\)\\'"
"Regexp to match empty lines at end of buffer that should be visualized.
The empty lines are highlighted using the `whitespace-empty' face.
This variable is used when `whitespace-style' includes `empty'."
:type '(regexp :tag "Empty Lines At End Of Buffer")
:group 'whitespace)
(defcustom whitespace-space-after-tab-regexp
'("\t+\\(\\( \\{%d,\\}\\)+\\)"
. "\\(\t+\\) \\{%d,\\}")
"Regexps to match multiple SPACEs after TAB that should be visualized.
The SPACE and TAB characters will be visualized if there at least
as many SPACEs as `tab-width' after a TAB.
The value should be a cons whose car is used for SPACEs visualization
and whose cdr is used for TABs visualization.
The SPACE characters are highlighted using the `whitespace-space-after-tab'
face.
This variable is used when `whitespace-style' includes `space-after-tab',
`space-after-tab::tab' or `space-after-tab::space'."
:type '(cons (string :tag "SPACEs After TAB")
string)
:group 'whitespace)
(defcustom whitespace-big-indent-regexp
"^\\(\\(?:\t\\{4,\\}\\| \\{32,\\}\\)[\t ]*\\)"
"Regexp to match big indentation at BOL that should be visualized.
The indentation characters are highlighted using the `whitespace-big-indent'
face.
If you're using non-Latin languages, there may be other characters
besides \"\\t\" that should be considered a TAB.
NOTE: Always enclose the elements to highlight in \\\\(...\\\\).
Use exactly one pair of enclosing \\\\( and \\\\).
This variable is used when `whitespace-style' includes `big-indent'."
:version "25.1"
:type '(regexp :tag "Detect too much indentation at the beginning of a line")
:group 'whitespace)
(defcustom whitespace-line-column 80
"Column beyond which the line is highlighted.
The value must be an integer or nil. If nil, use the value
of the `fill-column' variable.
The characters beyond the column specified by this variable are
highlighted using the `whitespace-line' face.
This variable is used when `whitespace-style' includes `lines',
`lines-tail' or `lines-char'."
:type '(choice :tag "Line Length Limit"
(integer :tag "Line Length")
(const :tag "Use fill-column" nil))
:safe 'integerp
:group 'whitespace)
;; Hacked from `visible-whitespace-mappings' in visws.el
(defcustom whitespace-display-mappings
'(
(space-mark ?\ [?·] [?.]) ; space - middle dot
(space-mark ?\xA0 [?¤] [?_]) ; hard space - currency sign
;; NEWLINE is displayed using the face `whitespace-newline'
(newline-mark ?\n [?$ ?\n]) ; eol - dollar sign
;; (newline-mark ?\n [?↵ ?\n] [?$ ?\n]) ; eol - downwards arrow
;; (newline-mark ?\n [?¶ ?\n] [?$ ?\n]) ; eol - pilcrow
;; (newline-mark ?\n [?¯ ?\n] [?$ ?\n]) ; eol - overscore
;; (newline-mark ?\n [?¬ ?\n] [?$ ?\n]) ; eol - negation
;; (newline-mark ?\n [?° ?\n] [?$ ?\n]) ; eol - degrees
;;
;; WARNING: the mapping below has a problem.
;; When a TAB occupies exactly one column, it will display the
;; character ?\xBB at that column followed by a TAB which goes to
;; the next TAB column.
;; If this is a problem for you, please, comment the line below.
(tab-mark ?\t [?» ?\t] [?\\ ?\t]) ; tab - right guillemet
)
"Alist of mappings for displaying characters.
Each element has the following form:
(KIND CHAR VECTOR...)
Where:
KIND is the kind of character.
It can be one of the following symbols:
tab-mark for TAB character
space-mark for SPACE or HARD SPACE character
newline-mark for NEWLINE character
CHAR is the character to be mapped.
VECTOR is a vector of characters to be displayed in place of CHAR.
The first vector that can be displayed by the terminal is used;
if no display vector for a mapping can be displayed, then
that character is displayed unmodified.
The NEWLINE character is displayed using the face given by
`whitespace-newline' variable.
This variable is used when `whitespace-style' includes `tab-mark',
`space-mark' or `newline-mark'."
:type '(repeat
(list :tag "Character Mapping"
(choice :tag "Char Kind"
(const :tag "Tab" tab-mark)
(const :tag "Space" space-mark)
(const :tag "Newline" newline-mark))
(character :tag "Char")
(repeat :inline t :tag "Vector List"
(vector :tag ""
(repeat :inline t
:tag "Vector Characters"
(character :tag "Char"))))))
:group 'whitespace)
(defcustom whitespace-global-modes t
"Modes for which global `whitespace-mode' is automagically turned on.
Global `whitespace-mode' is controlled by the command
`global-whitespace-mode'.
If nil, no modes have `whitespace-mode' automatically turned on.
If t, all modes that support `whitespace-mode' have it
automatically turned on.
Else it should be a list of `major-mode' symbol names for which
`whitespace-mode' should be automatically turned on. The sense
of the list is negated if it begins with `not'. For example:
(c-mode c++-mode)
means that `whitespace-mode' is turned on for buffers in C and
C++ modes only."
:type '(choice :tag "Global Modes"
(const :tag "None" nil)
(const :tag "All" t)
(set :menu-tag "Mode Specific" :tag "Modes"
:value (not)
(const :tag "Except" not)
(repeat :inline t
(symbol :tag "Mode"))))
:group 'whitespace)
(defcustom whitespace-action nil
"Specify which action is taken when a buffer is visited or written.
The value is a list containing one or more of the following symbols:
nil no action is taken.
cleanup always cleanup any bogus whitespace when local
whitespace is turned on.
See `whitespace-cleanup' and
`whitespace-cleanup-region'.
report-on-bogus always report if there is any bogus whitespace
when local whitespace is turned on.
auto-cleanup cleanup any bogus whitespace when buffer is
written.
See `whitespace-cleanup' and
`whitespace-cleanup-region'.
abort-on-bogus signal an error when writing the buffer if there is
any bogus whitespace in the buffer.
warn-if-read-only give a warning if `cleanup' or `auto-cleanup'
is included in `whitespace-action' and the
buffer is read-only.
Any other value is treated as nil."
:type '(choice :tag "Actions"
(const :tag "None" nil)
(repeat :tag "Action List"
(choice :tag "Action"
(const :tag "Cleanup When On" cleanup)
(const :tag "Report On Bogus" report-on-bogus)
(const :tag "Auto Cleanup" auto-cleanup)
(const :tag "Abort On Bogus" abort-on-bogus)
(const :tag "Warn If Read-Only" warn-if-read-only))))
:group 'whitespace)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; User commands - Local mode
;;;###autoload
(define-minor-mode whitespace-mode
"Toggle whitespace visualization (Whitespace mode).
See also `whitespace-style', `whitespace-newline' and
`whitespace-display-mappings'.
This mode uses a number of faces to visualize the whitespace; see
the customization group `whitespace' for details."
:lighter " ws"
:init-value nil
:global nil
:group 'whitespace
(cond
(noninteractive ; running a batch job
(setq whitespace-mode nil))
(whitespace-mode ; whitespace-mode on
(whitespace-turn-on)
(whitespace-action-when-on))
(t ; whitespace-mode off
(whitespace-turn-off))))
;;;###autoload
(define-minor-mode whitespace-newline-mode
"Toggle newline visualization (Whitespace Newline mode).
Use `whitespace-newline-mode' only for NEWLINE visualization
exclusively. For other visualizations, including NEWLINE
visualization together with (HARD) SPACEs and/or TABs, please,
use `whitespace-mode'.
See also `whitespace-newline' and `whitespace-display-mappings'."