annotate lisp/whitespace.el @ 86018:2c176c668b7a

(query-replace-show-replacement): New defcustom. (perform-replace): Use `match-substitute-replacement' if `query-replace-show-replacement' is non-nil.
author Juri Linkov <juri@jurta.org>
date Sat, 10 Nov 2007 21:48:46 +0000
parents d3e87ee5aa0e
children f358a2fd5895 880960b70474
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38436
b174db545cfd Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 36945
diff changeset
1 ;;; whitespace.el --- warn about and clean bogus whitespaces in the file
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
2
74442
b2e5081b9320 Update copyright years.
Glenn Morris <rgm@gnu.org>
parents: 74396
diff changeset
3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
75347
e3694f1cb928 Add 2007 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 74442
diff changeset
4 ;; 2005, 2006, 2007 Free Software Foundation, Inc.
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
5
29333
189f70e66cab Update whitespace.el with a more tolerable timer scan time.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 27583
diff changeset
6 ;; Author: Rajesh Vaidheeswarran <rv@gnu.org>
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
7 ;; Keywords: convenience
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
8
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
10
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
78236
9355f9b7bbff Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents: 76692
diff changeset
13 ;; the Free Software Foundation; either version 3, or (at your option)
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
14 ;; any later version.
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
15
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
19 ;; GNU General Public License for more details.
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
20
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
64091
6fb026ad601f Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 63200
diff changeset
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
6fb026ad601f Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 63200
diff changeset
24 ;; Boston, MA 02110-1301, USA.
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
25
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
26 ;;; Commentary:
51542
ad8c09d9513c Update whitespace.el
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 50964
diff changeset
27 ;;
ad8c09d9513c Update whitespace.el
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 50964
diff changeset
28 ;; URL: http://www.dsmit.com/lisp/
ad8c09d9513c Update whitespace.el
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 50964
diff changeset
29 ;;
47420
b7a8fec8113c (whitespace-global-mode): Use define-minor-mode. Use the new file hook names.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42013
diff changeset
30 ;; The whitespace library is intended to find and help fix five different types
b7a8fec8113c (whitespace-global-mode): Use define-minor-mode. Use the new file hook names.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42013
diff changeset
31 ;; of whitespace problems that commonly exist in source code.
51542
ad8c09d9513c Update whitespace.el
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 50964
diff changeset
32 ;;
47420
b7a8fec8113c (whitespace-global-mode): Use define-minor-mode. Use the new file hook names.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42013
diff changeset
33 ;; 1. Leading space (empty lines at the top of a file).
b7a8fec8113c (whitespace-global-mode): Use define-minor-mode. Use the new file hook names.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42013
diff changeset
34 ;; 2. Trailing space (empty lines at the end of a file).
b7a8fec8113c (whitespace-global-mode): Use define-minor-mode. Use the new file hook names.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42013
diff changeset
35 ;; 3. Indentation space (8 or more spaces at beginning of line, that should be
52672
d4d213cfb340 whitespace.el now takes user customizable variable to display cleanliness of
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 52401
diff changeset
36 ;; replaced with TABS).
47420
b7a8fec8113c (whitespace-global-mode): Use define-minor-mode. Use the new file hook names.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42013
diff changeset
37 ;; 4. Spaces followed by a TAB. (Almost always, we never want that).
b7a8fec8113c (whitespace-global-mode): Use define-minor-mode. Use the new file hook names.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42013
diff changeset
38 ;; 5. Spaces or TABS at the end of a line.
51542
ad8c09d9513c Update whitespace.el
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 50964
diff changeset
39 ;;
47420
b7a8fec8113c (whitespace-global-mode): Use define-minor-mode. Use the new file hook names.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42013
diff changeset
40 ;; Whitespace errors are reported in a buffer, and on the modeline.
51542
ad8c09d9513c Update whitespace.el
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 50964
diff changeset
41 ;;
47420
b7a8fec8113c (whitespace-global-mode): Use define-minor-mode. Use the new file hook names.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42013
diff changeset
42 ;; Modeline will show a W:<x>!<y> to denote a particular type of whitespace,
b7a8fec8113c (whitespace-global-mode): Use define-minor-mode. Use the new file hook names.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42013
diff changeset
43 ;; where `x' and `y' can be one (or more) of:
51542
ad8c09d9513c Update whitespace.el
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 50964
diff changeset
44 ;;
47420
b7a8fec8113c (whitespace-global-mode): Use define-minor-mode. Use the new file hook names.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42013
diff changeset
45 ;; e - End-of-Line whitespace.
b7a8fec8113c (whitespace-global-mode): Use define-minor-mode. Use the new file hook names.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42013
diff changeset
46 ;; i - Indentation whitespace.
b7a8fec8113c (whitespace-global-mode): Use define-minor-mode. Use the new file hook names.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42013
diff changeset
47 ;; l - Leading whitespace.
b7a8fec8113c (whitespace-global-mode): Use define-minor-mode. Use the new file hook names.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42013
diff changeset
48 ;; s - Space followed by Tab.
b7a8fec8113c (whitespace-global-mode): Use define-minor-mode. Use the new file hook names.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42013
diff changeset
49 ;; t - Trailing whitespace.
51542
ad8c09d9513c Update whitespace.el
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 50964
diff changeset
50 ;;
47420
b7a8fec8113c (whitespace-global-mode): Use define-minor-mode. Use the new file hook names.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42013
diff changeset
51 ;; If any of the whitespace checks is turned off, the modeline will display a
b7a8fec8113c (whitespace-global-mode): Use define-minor-mode. Use the new file hook names.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42013
diff changeset
52 ;; !<y>.
51542
ad8c09d9513c Update whitespace.el
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 50964
diff changeset
53 ;;
47420
b7a8fec8113c (whitespace-global-mode): Use define-minor-mode. Use the new file hook names.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42013
diff changeset
54 ;; (since (3) is the most controversial one, here is the rationale: Most
b7a8fec8113c (whitespace-global-mode): Use define-minor-mode. Use the new file hook names.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42013
diff changeset
55 ;; terminal drivers and printer drivers have TAB configured or even
b7a8fec8113c (whitespace-global-mode): Use define-minor-mode. Use the new file hook names.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42013
diff changeset
56 ;; hardcoded to be 8 spaces. (Some of them allow configuration, but almost
b7a8fec8113c (whitespace-global-mode): Use define-minor-mode. Use the new file hook names.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42013
diff changeset
57 ;; always they default to 8.)
51542
ad8c09d9513c Update whitespace.el
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 50964
diff changeset
58 ;;
47420
b7a8fec8113c (whitespace-global-mode): Use define-minor-mode. Use the new file hook names.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42013
diff changeset
59 ;; Changing `tab-width' to other than 8 and editing will cause your code to
b7a8fec8113c (whitespace-global-mode): Use define-minor-mode. Use the new file hook names.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42013
diff changeset
60 ;; look different from within Emacs, and say, if you cat it or more it, or
b7a8fec8113c (whitespace-global-mode): Use define-minor-mode. Use the new file hook names.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42013
diff changeset
61 ;; even print it.
51542
ad8c09d9513c Update whitespace.el
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 50964
diff changeset
62 ;;
47420
b7a8fec8113c (whitespace-global-mode): Use define-minor-mode. Use the new file hook names.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42013
diff changeset
63 ;; Almost all the popular programming modes let you define an offset (like
b7a8fec8113c (whitespace-global-mode): Use define-minor-mode. Use the new file hook names.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42013
diff changeset
64 ;; c-basic-offset or perl-indent-level) to configure the offset, so you
b7a8fec8113c (whitespace-global-mode): Use define-minor-mode. Use the new file hook names.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42013
diff changeset
65 ;; should never have to set your `tab-width' to be other than 8 in all
b7a8fec8113c (whitespace-global-mode): Use define-minor-mode. Use the new file hook names.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42013
diff changeset
66 ;; these modes. In fact, with an indent level of say, 4, 2 TABS will cause
b7a8fec8113c (whitespace-global-mode): Use define-minor-mode. Use the new file hook names.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42013
diff changeset
67 ;; Emacs to replace your 8 spaces with one \t (try it). If vi users in
b7a8fec8113c (whitespace-global-mode): Use define-minor-mode. Use the new file hook names.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42013
diff changeset
68 ;; your office complain, tell them to use vim, which distinguishes between
b7a8fec8113c (whitespace-global-mode): Use define-minor-mode. Use the new file hook names.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42013
diff changeset
69 ;; tabstop and shiftwidth (vi equivalent of our offsets), and also ask them
b7a8fec8113c (whitespace-global-mode): Use define-minor-mode. Use the new file hook names.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42013
diff changeset
70 ;; to set smarttab.)
51542
ad8c09d9513c Update whitespace.el
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 50964
diff changeset
71 ;;
47420
b7a8fec8113c (whitespace-global-mode): Use define-minor-mode. Use the new file hook names.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42013
diff changeset
72 ;; All the above have caused (and will cause) unwanted codeline integration and
b7a8fec8113c (whitespace-global-mode): Use define-minor-mode. Use the new file hook names.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42013
diff changeset
73 ;; merge problems.
51542
ad8c09d9513c Update whitespace.el
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 50964
diff changeset
74 ;;
47420
b7a8fec8113c (whitespace-global-mode): Use define-minor-mode. Use the new file hook names.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42013
diff changeset
75 ;; whitespace.el will complain if it detects whitespaces on opening a file, and
b7a8fec8113c (whitespace-global-mode): Use define-minor-mode. Use the new file hook names.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42013
diff changeset
76 ;; warn you on closing a file also (in case you had inserted any
b7a8fec8113c (whitespace-global-mode): Use define-minor-mode. Use the new file hook names.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42013
diff changeset
77 ;; whitespaces during the process of your editing).
51542
ad8c09d9513c Update whitespace.el
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 50964
diff changeset
78 ;;
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
79 ;; Exported functions:
51542
ad8c09d9513c Update whitespace.el
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 50964
diff changeset
80 ;;
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
81 ;; `whitespace-buffer' - To check the current buffer for whitespace problems.
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
82 ;; `whitespace-cleanup' - To cleanup all whitespaces in the current buffer.
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
83 ;; `whitespace-region' - To check between point and mark for whitespace
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
84 ;; problems.
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
85 ;; `whitespace-cleanup-region' - To cleanup all whitespaces between point
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
86 ;; and mark in the current buffer.
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
87
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
88 ;;; Code:
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
89
61488
230af31ce843 whitespace.el - fix higlighting test and bump rev
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 61471
diff changeset
90 (defvar whitespace-version "3.5" "Version of the whitespace library.")
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
91
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
92 (defvar whitespace-all-buffer-files nil
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
93 "An associated list of buffers and files checked for whitespace cleanliness.
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
94
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
95 This is to enable periodic checking of whitespace cleanliness in the files
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
96 visited by the buffers.")
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
97
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
98 (defvar whitespace-rescan-timer nil
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
99 "Timer object used to rescan the files in buffers that have been modified.")
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
100
26245
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
101 ;; Tell Emacs about this new kind of minor mode
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
102 (defvar whitespace-mode nil
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
103 "Non-nil when Whitespace mode (a minor mode) is enabled.")
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
104 (make-variable-buffer-local 'whitespace-mode)
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
105
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
106 (defvar whitespace-mode-line nil
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
107 "String to display in the mode line for Whitespace mode.")
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
108 (make-variable-buffer-local 'whitespace-mode-line)
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
109
36944
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
110 (defvar whitespace-check-buffer-leading nil
64286
f44bd79f483b (whitespace-check-buffer-leading, whitespace-check-buffer-trailing,
Juanma Barranquero <lekktu@gmail.com>
parents: 64178
diff changeset
111 "Test leading whitespace for file in current buffer if t.")
36944
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
112 (make-variable-buffer-local 'whitespace-check-buffer-leading)
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
113
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
114 (defvar whitespace-check-buffer-trailing nil
64286
f44bd79f483b (whitespace-check-buffer-leading, whitespace-check-buffer-trailing,
Juanma Barranquero <lekktu@gmail.com>
parents: 64178
diff changeset
115 "Test trailing whitespace for file in current buffer if t.")
36944
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
116 (make-variable-buffer-local 'whitespace-check-buffer-trailing)
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
117
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
118 (defvar whitespace-check-buffer-indent nil
64286
f44bd79f483b (whitespace-check-buffer-leading, whitespace-check-buffer-trailing,
Juanma Barranquero <lekktu@gmail.com>
parents: 64178
diff changeset
119 "Test indentation whitespace for file in current buffer if t.")
36944
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
120 (make-variable-buffer-local 'whitespace-check-buffer-indent)
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
121
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
122 (defvar whitespace-check-buffer-spacetab nil
64286
f44bd79f483b (whitespace-check-buffer-leading, whitespace-check-buffer-trailing,
Juanma Barranquero <lekktu@gmail.com>
parents: 64178
diff changeset
123 "Test Space-followed-by-TABS whitespace for file in current buffer if t.")
36944
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
124 (make-variable-buffer-local 'whitespace-check-buffer-spacetab)
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
125
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
126 (defvar whitespace-check-buffer-ateol nil
64286
f44bd79f483b (whitespace-check-buffer-leading, whitespace-check-buffer-trailing,
Juanma Barranquero <lekktu@gmail.com>
parents: 64178
diff changeset
127 "Test end-of-line whitespace for file in current buffer if t.")
36944
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
128 (make-variable-buffer-local 'whitespace-check-buffer-ateol)
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
129
42013
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
130 (defvar whitespace-highlighted-space nil
64286
f44bd79f483b (whitespace-check-buffer-leading, whitespace-check-buffer-trailing,
Juanma Barranquero <lekktu@gmail.com>
parents: 64178
diff changeset
131 "The variable to store the extent to highlight.")
42013
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
132 (make-variable-buffer-local 'whitespace-highlighted-space)
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
133
26253
3bb622df1c52 (whitespace-version): Update to 2.8
Gerd Moellmann <gerd@gnu.org>
parents: 26245
diff changeset
134 ;; For flavors of Emacs which don't define `defgroup' and `defcustom'.
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
135 (eval-when-compile
26253
3bb622df1c52 (whitespace-version): Update to 2.8
Gerd Moellmann <gerd@gnu.org>
parents: 26245
diff changeset
136 (if (not (fboundp 'defgroup))
3bb622df1c52 (whitespace-version): Update to 2.8
Gerd Moellmann <gerd@gnu.org>
parents: 26245
diff changeset
137 (defmacro defgroup (sym memb doc &rest args)
64286
f44bd79f483b (whitespace-check-buffer-leading, whitespace-check-buffer-trailing,
Juanma Barranquero <lekktu@gmail.com>
parents: 64178
diff changeset
138 "Null macro for `defgroup' in all versions of Emacs that don't define it."
26253
3bb622df1c52 (whitespace-version): Update to 2.8
Gerd Moellmann <gerd@gnu.org>
parents: 26245
diff changeset
139 t))
3bb622df1c52 (whitespace-version): Update to 2.8
Gerd Moellmann <gerd@gnu.org>
parents: 26245
diff changeset
140 (if (not (fboundp 'defcustom))
3bb622df1c52 (whitespace-version): Update to 2.8
Gerd Moellmann <gerd@gnu.org>
parents: 26245
diff changeset
141 (defmacro defcustom (sym val doc &rest args)
64286
f44bd79f483b (whitespace-check-buffer-leading, whitespace-check-buffer-trailing,
Juanma Barranquero <lekktu@gmail.com>
parents: 64178
diff changeset
142 "Macro to alias `defcustom' to `defvar' in all versions of Emacs that
f44bd79f483b (whitespace-check-buffer-leading, whitespace-check-buffer-trailing,
Juanma Barranquero <lekktu@gmail.com>
parents: 64178
diff changeset
143 don't define it."
26253
3bb622df1c52 (whitespace-version): Update to 2.8
Gerd Moellmann <gerd@gnu.org>
parents: 26245
diff changeset
144 `(defvar ,sym ,val ,doc))))
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
145
64378
89982901a9ad (whitespace-make-overlay)
Richard M. Stallman <rms@gnu.org>
parents: 64286
diff changeset
146 (defalias 'whitespace-make-overlay
89982901a9ad (whitespace-make-overlay)
Richard M. Stallman <rms@gnu.org>
parents: 64286
diff changeset
147 (if (featurep 'xemacs) 'make-extent 'make-overlay))
89982901a9ad (whitespace-make-overlay)
Richard M. Stallman <rms@gnu.org>
parents: 64286
diff changeset
148 (defalias 'whitespace-overlay-put
89982901a9ad (whitespace-make-overlay)
Richard M. Stallman <rms@gnu.org>
parents: 64286
diff changeset
149 (if (featurep 'xemacs) 'set-extent-property 'overlay-put))
89982901a9ad (whitespace-make-overlay)
Richard M. Stallman <rms@gnu.org>
parents: 64286
diff changeset
150 (defalias 'whitespace-delete-overlay
89982901a9ad (whitespace-make-overlay)
Richard M. Stallman <rms@gnu.org>
parents: 64286
diff changeset
151 (if (featurep 'xemacs) 'delete-extent 'delete-overlay))
89982901a9ad (whitespace-make-overlay)
Richard M. Stallman <rms@gnu.org>
parents: 64286
diff changeset
152 (defalias 'whitespace-overlay-start
89982901a9ad (whitespace-make-overlay)
Richard M. Stallman <rms@gnu.org>
parents: 64286
diff changeset
153 (if (featurep 'xemacs) 'extent-start 'overlay-start))
89982901a9ad (whitespace-make-overlay)
Richard M. Stallman <rms@gnu.org>
parents: 64286
diff changeset
154 (defalias 'whitespace-overlay-end
89982901a9ad (whitespace-make-overlay)
Richard M. Stallman <rms@gnu.org>
parents: 64286
diff changeset
155 (if (featurep 'xemacs) 'extent-end 'overlay-end))
89982901a9ad (whitespace-make-overlay)
Richard M. Stallman <rms@gnu.org>
parents: 64286
diff changeset
156 (defalias 'whitespace-mode-line-update
89982901a9ad (whitespace-make-overlay)
Richard M. Stallman <rms@gnu.org>
parents: 64286
diff changeset
157 (if (featurep 'xemacs) 'redraw-modeline 'force-mode-line-update))
42013
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
158
32501
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
159 (defgroup whitespace nil
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
160 "Check for and fix five different types of whitespaces in source code."
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
161 :version "21.1"
51542
ad8c09d9513c Update whitespace.el
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 50964
diff changeset
162 :link '(emacs-commentary-link "whitespace.el")
64378
89982901a9ad (whitespace-make-overlay)
Richard M. Stallman <rms@gnu.org>
parents: 64286
diff changeset
163 ;; Since XEmacs doesn't have a 'convenience group, use the next best group
89982901a9ad (whitespace-make-overlay)
Richard M. Stallman <rms@gnu.org>
parents: 64286
diff changeset
164 ;; which is 'editing?
89982901a9ad (whitespace-make-overlay)
Richard M. Stallman <rms@gnu.org>
parents: 64286
diff changeset
165 :group (if (featurep 'xemacs) 'editing 'convenience))
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
166
25724
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
167 (defcustom whitespace-check-leading-whitespace t
64286
f44bd79f483b (whitespace-check-buffer-leading, whitespace-check-buffer-trailing,
Juanma Barranquero <lekktu@gmail.com>
parents: 64178
diff changeset
168 "Flag to check leading whitespace. This is the global for the system.
36944
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
169 It can be overriden by setting a buffer local variable
64286
f44bd79f483b (whitespace-check-buffer-leading, whitespace-check-buffer-trailing,
Juanma Barranquero <lekktu@gmail.com>
parents: 64178
diff changeset
170 `whitespace-check-buffer-leading'."
25724
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
171 :type 'boolean
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
172 :group 'whitespace)
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
173
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
174 (defcustom whitespace-check-trailing-whitespace t
64286
f44bd79f483b (whitespace-check-buffer-leading, whitespace-check-buffer-trailing,
Juanma Barranquero <lekktu@gmail.com>
parents: 64178
diff changeset
175 "Flag to check trailing whitespace. This is the global for the system.
36944
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
176 It can be overriden by setting a buffer local variable
64286
f44bd79f483b (whitespace-check-buffer-leading, whitespace-check-buffer-trailing,
Juanma Barranquero <lekktu@gmail.com>
parents: 64178
diff changeset
177 `whitespace-check-buffer-trailing'."
25724
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
178 :type 'boolean
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
179 :group 'whitespace)
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
180
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
181 (defcustom whitespace-check-spacetab-whitespace t
64286
f44bd79f483b (whitespace-check-buffer-leading, whitespace-check-buffer-trailing,
Juanma Barranquero <lekktu@gmail.com>
parents: 64178
diff changeset
182 "Flag to check space followed by a TAB. This is the global for the system.
36944
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
183 It can be overriden by setting a buffer local variable
64286
f44bd79f483b (whitespace-check-buffer-leading, whitespace-check-buffer-trailing,
Juanma Barranquero <lekktu@gmail.com>
parents: 64178
diff changeset
184 `whitespace-check-buffer-spacetab'."
25724
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
185 :type 'boolean
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
186 :group 'whitespace)
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
187
42013
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
188 (defcustom whitespace-spacetab-regexp "[ ]+\t"
73666
b0f398ac4cbd (whitespace-indent-regexp): Make this match any multiples of eight spaces near
Eli Zaretskii <eliz@gnu.org>
parents: 72472
diff changeset
189 "Regexp to match one or more spaces followed by a TAB."
32501
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
190 :type 'regexp
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
191 :group 'whitespace)
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
192
38882
ceec599316a4 whitespace 3.1
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38874
diff changeset
193 (defcustom whitespace-check-indent-whitespace indent-tabs-mode
64286
f44bd79f483b (whitespace-check-buffer-leading, whitespace-check-buffer-trailing,
Juanma Barranquero <lekktu@gmail.com>
parents: 64178
diff changeset
194 "Flag to check indentation whitespace. This is the global for the system.
36944
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
195 It can be overriden by setting a buffer local variable
64286
f44bd79f483b (whitespace-check-buffer-leading, whitespace-check-buffer-trailing,
Juanma Barranquero <lekktu@gmail.com>
parents: 64178
diff changeset
196 `whitespace-check-buffer-indent'."
25724
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
197 :type 'boolean
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
198 :group 'whitespace)
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
199
73666
b0f398ac4cbd (whitespace-indent-regexp): Make this match any multiples of eight spaces near
Eli Zaretskii <eliz@gnu.org>
parents: 72472
diff changeset
200 (defcustom whitespace-indent-regexp "^\t*\\( \\)+"
b0f398ac4cbd (whitespace-indent-regexp): Make this match any multiples of eight spaces near
Eli Zaretskii <eliz@gnu.org>
parents: 72472
diff changeset
201 "Regexp to match multiples of eight spaces near line beginnings.
b0f398ac4cbd (whitespace-indent-regexp): Make this match any multiples of eight spaces near
Eli Zaretskii <eliz@gnu.org>
parents: 72472
diff changeset
202 The default value ignores leading TABs."
32501
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
203 :type 'regexp
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
204 :group 'whitespace)
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
205
25724
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
206 (defcustom whitespace-check-ateol-whitespace t
64286
f44bd79f483b (whitespace-check-buffer-leading, whitespace-check-buffer-trailing,
Juanma Barranquero <lekktu@gmail.com>
parents: 64178
diff changeset
207 "Flag to check end-of-line whitespace. This is the global for the system.
36944
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
208 It can be overriden by setting a buffer local variable
64286
f44bd79f483b (whitespace-check-buffer-leading, whitespace-check-buffer-trailing,
Juanma Barranquero <lekktu@gmail.com>
parents: 64178
diff changeset
209 `whitespace-check-buffer-ateol'."
25724
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
210 :type 'boolean
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
211 :group 'whitespace)
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
212
42013
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
213 (defcustom whitespace-ateol-regexp "[ \t]+$"
73666
b0f398ac4cbd (whitespace-indent-regexp): Make this match any multiples of eight spaces near
Eli Zaretskii <eliz@gnu.org>
parents: 72472
diff changeset
214 "Regexp to match one or more TABs or spaces at line ends."
32501
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
215 :type 'regexp
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
216 :group 'whitespace)
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
217
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
218 (defcustom whitespace-errbuf "*Whitespace Errors*"
32501
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
219 "The name of the buffer where whitespace related messages will be logged."
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
220 :type 'string
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
221 :group 'whitespace)
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
222
52672
d4d213cfb340 whitespace.el now takes user customizable variable to display cleanliness of
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 52401
diff changeset
223 (defcustom whitespace-clean-msg "clean."
d4d213cfb340 whitespace.el now takes user customizable variable to display cleanliness of
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 52401
diff changeset
224 "If non-nil, this message will be displayed after a whitespace check
d4d213cfb340 whitespace.el now takes user customizable variable to display cleanliness of
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 52401
diff changeset
225 determines a file to be clean."
d4d213cfb340 whitespace.el now takes user customizable variable to display cleanliness of
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 52401
diff changeset
226 :type 'string
d4d213cfb340 whitespace.el now takes user customizable variable to display cleanliness of
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 52401
diff changeset
227 :group 'whitespace)
d4d213cfb340 whitespace.el now takes user customizable variable to display cleanliness of
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 52401
diff changeset
228
38882
ceec599316a4 whitespace 3.1
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38874
diff changeset
229 (defcustom whitespace-abort-on-error nil
64286
f44bd79f483b (whitespace-check-buffer-leading, whitespace-check-buffer-trailing,
Juanma Barranquero <lekktu@gmail.com>
parents: 64178
diff changeset
230 "While writing a file, abort if the file is unclean.
f44bd79f483b (whitespace-check-buffer-leading, whitespace-check-buffer-trailing,
Juanma Barranquero <lekktu@gmail.com>
parents: 64178
diff changeset
231 If `whitespace-auto-cleanup' is set, that takes precedence over
f44bd79f483b (whitespace-check-buffer-leading, whitespace-check-buffer-trailing,
Juanma Barranquero <lekktu@gmail.com>
parents: 64178
diff changeset
232 this variable."
38882
ceec599316a4 whitespace 3.1
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38874
diff changeset
233 :type 'boolean
ceec599316a4 whitespace 3.1
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38874
diff changeset
234 :group 'whitespace)
ceec599316a4 whitespace 3.1
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38874
diff changeset
235
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
236 (defcustom whitespace-auto-cleanup nil
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
237 "Cleanup a buffer automatically on finding it whitespace unclean."
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
238 :type 'boolean
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
239 :group 'whitespace)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
240
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
241 (defcustom whitespace-silent nil
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
242 "All whitespace errors will be shown only in the modeline when t.
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
243
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
244 Note that setting this may cause all whitespaces introduced in a file to go
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
245 unnoticed when the buffer is killed, unless the user visits the `*Whitespace
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
246 Errors*' buffer before opening (or closing) another file."
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
247 :type 'boolean
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
248 :group 'whitespace)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
249
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
250 (defcustom whitespace-modes '(ada-mode asm-mode autoconf-mode awk-mode
25724
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
251 c-mode c++-mode cc-mode
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
252 change-log-mode cperl-mode
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
253 electric-nroff-mode emacs-lisp-mode
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
254 f90-mode fortran-mode html-mode
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
255 html3-mode java-mode jde-mode
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
256 ksh-mode latex-mode LaTeX-mode
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
257 lisp-mode m4-mode makefile-mode
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
258 modula-2-mode nroff-mode objc-mode
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
259 pascal-mode perl-mode prolog-mode
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
260 python-mode scheme-mode sgml-mode
25724
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
261 sh-mode shell-script-mode simula-mode
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
262 tcl-mode tex-mode texinfo-mode
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
263 vrml-mode xml-mode)
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
264
64286
f44bd79f483b (whitespace-check-buffer-leading, whitespace-check-buffer-trailing,
Juanma Barranquero <lekktu@gmail.com>
parents: 64178
diff changeset
265 "Major modes in which we turn on whitespace checking.
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
266
32501
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
267 These are mostly programming and documentation modes. But you may add other
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
268 modes that you want whitespaces checked in by adding something like the
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
269 following to your `.emacs':
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
270
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
271 \(setq whitespace-modes (cons 'my-mode (cons 'my-other-mode
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
272 whitespace-modes))\)
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
273
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
274 Or, alternately, you can use the Emacs `customize' command to set this."
32501
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
275 :type '(repeat symbol)
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
276 :group 'whitespace)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
277
29333
189f70e66cab Update whitespace.el with a more tolerable timer scan time.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 27583
diff changeset
278 (defcustom whitespace-rescan-timer-time 600
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
279 "Period in seconds to rescan modified buffers for whitespace creep.
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
280
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
281 This is the period after which the timer will fire causing
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
282 `whitespace-rescan-files-in-buffers' to check for whitespace creep in
25724
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
283 modified buffers.
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
284
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
285 To disable timer scans, set this to zero."
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
286 :type 'integer
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
287 :group 'whitespace)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
288
26245
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
289 (defcustom whitespace-display-in-modeline t
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
290 "Display whitespace errors on the modeline."
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
291 :type 'boolean
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
292 :group 'whitespace)
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
293
42013
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
294 (defcustom whitespace-display-spaces-in-color t
63200
eef21c221eff Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-371
Miles Bader <miles@gnu.org>
parents: 61492
diff changeset
295 "Display the bogus whitespaces by coloring them with the face
eef21c221eff Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-371
Miles Bader <miles@gnu.org>
parents: 61492
diff changeset
296 `whitespace-highlight'."
42013
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
297 :type 'boolean
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
298 :group 'whitespace)
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
299
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
300 (defgroup whitespace-faces nil
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
301 "Faces used in whitespace."
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
302 :prefix "whitespace-"
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
303 :group 'whitespace
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
304 :group 'faces)
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
305
63200
eef21c221eff Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-371
Miles Bader <miles@gnu.org>
parents: 61492
diff changeset
306 (defface whitespace-highlight '((((class color) (background light))
eef21c221eff Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-371
Miles Bader <miles@gnu.org>
parents: 61492
diff changeset
307 (:background "green1"))
eef21c221eff Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-371
Miles Bader <miles@gnu.org>
parents: 61492
diff changeset
308 (((class color) (background dark))
eef21c221eff Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-371
Miles Bader <miles@gnu.org>
parents: 61492
diff changeset
309 (:background "sea green"))
eef21c221eff Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-371
Miles Bader <miles@gnu.org>
parents: 61492
diff changeset
310 (((class grayscale mono)
eef21c221eff Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-371
Miles Bader <miles@gnu.org>
parents: 61492
diff changeset
311 (background light))
eef21c221eff Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-371
Miles Bader <miles@gnu.org>
parents: 61492
diff changeset
312 (:background "black"))
eef21c221eff Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-371
Miles Bader <miles@gnu.org>
parents: 61492
diff changeset
313 (((class grayscale mono)
eef21c221eff Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-371
Miles Bader <miles@gnu.org>
parents: 61492
diff changeset
314 (background dark))
eef21c221eff Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-371
Miles Bader <miles@gnu.org>
parents: 61492
diff changeset
315 (:background "white")))
42013
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
316 "Face used for highlighting the bogus whitespaces that exist in the buffer."
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
317 :group 'whitespace-faces)
63200
eef21c221eff Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-371
Miles Bader <miles@gnu.org>
parents: 61492
diff changeset
318 ;; backward-compatibility alias
eef21c221eff Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-371
Miles Bader <miles@gnu.org>
parents: 61492
diff changeset
319 (put 'whitespace-highlight-face 'face-alias 'whitespace-highlight)
42013
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
320
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
321 (if (not (assoc 'whitespace-mode minor-mode-alist))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
322 (setq minor-mode-alist (cons '(whitespace-mode whitespace-mode-line)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
323 minor-mode-alist)))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
324
36944
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
325 (set-default 'whitespace-check-buffer-leading
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
326 whitespace-check-leading-whitespace)
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
327 (set-default 'whitespace-check-buffer-trailing
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
328 whitespace-check-trailing-whitespace)
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
329 (set-default 'whitespace-check-buffer-indent
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
330 whitespace-check-indent-whitespace)
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
331 (set-default 'whitespace-check-buffer-spacetab
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
332 whitespace-check-spacetab-whitespace)
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
333 (set-default 'whitespace-check-buffer-ateol
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
334 whitespace-check-ateol-whitespace)
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
335
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
336 (defun whitespace-check-whitespace-mode (&optional arg)
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
337 "Test and set the whitespace-mode in qualifying buffers."
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
338 (if (null whitespace-mode)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
339 (setq whitespace-mode
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
340 (if (or arg (member major-mode whitespace-modes))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
341 t
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
342 nil))))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
343
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
344 ;;;###autoload
36944
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
345 (defun whitespace-toggle-leading-check ()
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
346 "Toggle the check for leading space in the local buffer."
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
347 (interactive)
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
348 (let ((current-val whitespace-check-buffer-leading))
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
349 (setq whitespace-check-buffer-leading (not current-val))
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
350 (message "Will%s check for leading space in buffer."
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
351 (if whitespace-check-buffer-leading "" " not"))
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
352 (if whitespace-check-buffer-leading (whitespace-buffer-leading))))
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
353
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
354 ;;;###autoload
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
355 (defun whitespace-toggle-trailing-check ()
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
356 "Toggle the check for trailing space in the local buffer."
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
357 (interactive)
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
358 (let ((current-val whitespace-check-buffer-trailing))
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
359 (setq whitespace-check-buffer-trailing (not current-val))
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
360 (message "Will%s check for trailing space in buffer."
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
361 (if whitespace-check-buffer-trailing "" " not"))
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
362 (if whitespace-check-buffer-trailing (whitespace-buffer-trailing))))
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
363
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
364 ;;;###autoload
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
365 (defun whitespace-toggle-indent-check ()
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
366 "Toggle the check for indentation space in the local buffer."
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
367 (interactive)
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
368 (let ((current-val whitespace-check-buffer-indent))
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
369 (setq whitespace-check-buffer-indent (not current-val))
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
370 (message "Will%s check for indentation space in buffer."
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
371 (if whitespace-check-buffer-indent "" " not"))
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
372 (if whitespace-check-buffer-indent
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
373 (whitespace-buffer-search whitespace-indent-regexp))))
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
374
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
375 ;;;###autoload
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
376 (defun whitespace-toggle-spacetab-check ()
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
377 "Toggle the check for space-followed-by-TABs in the local buffer."
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
378 (interactive)
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
379 (let ((current-val whitespace-check-buffer-spacetab))
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
380 (setq whitespace-check-buffer-spacetab (not current-val))
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
381 (message "Will%s check for space-followed-by-TABs in buffer."
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
382 (if whitespace-check-buffer-spacetab "" " not"))
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
383 (if whitespace-check-buffer-spacetab
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
384 (whitespace-buffer-search whitespace-spacetab-regexp))))
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
385
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
386
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
387 ;;;###autoload
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
388 (defun whitespace-toggle-ateol-check ()
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
389 "Toggle the check for end-of-line space in the local buffer."
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
390 (interactive)
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
391 (let ((current-val whitespace-check-buffer-ateol))
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
392 (setq whitespace-check-buffer-ateol (not current-val))
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
393 (message "Will%s check for end-of-line space in buffer."
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
394 (if whitespace-check-buffer-ateol "" " not"))
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
395 (if whitespace-check-buffer-ateol
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
396 (whitespace-buffer-search whitespace-ateol-regexp))))
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
397
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
398
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
399 ;;;###autoload
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
400 (defun whitespace-buffer (&optional quiet)
32501
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
401 "Find five different types of white spaces in buffer.
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
402 These are:
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
403 1. Leading space \(empty lines at the top of a file\).
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
404 2. Trailing space \(empty lines at the end of a file\).
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
405 3. Indentation space \(8 or more spaces, that should be replaced with TABS\).
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
406 4. Spaces followed by a TAB. \(Almost always, we never want that\).
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
407 5. Spaces or TABS at the end of a line.
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
408
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
409 Check for whitespace only if this buffer really contains a non-empty file
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
410 and:
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
411 1. the major mode is one of the whitespace-modes, or
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
412 2. `whitespace-buffer' was explicitly called with a prefix argument."
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
413 (interactive)
26245
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
414 (let ((whitespace-error nil))
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
415 (whitespace-check-whitespace-mode current-prefix-arg)
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
416 (if (and buffer-file-name (> (buffer-size) 0) whitespace-mode)
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
417 (progn
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
418 (whitespace-check-buffer-list (buffer-name) buffer-file-name)
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
419 (whitespace-tickle-timer)
73812
75af8d959739 (whitespace-buffer): Call remove-overlays after overlay-recenter for
Chong Yidong <cyd@stupidchicken.com>
parents: 73666
diff changeset
420 (overlay-recenter (point-max))
73666
b0f398ac4cbd (whitespace-indent-regexp): Make this match any multiples of eight spaces near
Eli Zaretskii <eliz@gnu.org>
parents: 72472
diff changeset
421 (remove-overlays nil nil 'face 'whitespace-highlight)
26245
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
422 (if whitespace-auto-cleanup
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
423 (if buffer-read-only
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
424 (if (not quiet)
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
425 (message "Can't cleanup: %s is read-only" (buffer-name)))
70927
1d492927a08d whitespace.el - make whitesspace-cleanup use the current active regoin, if there is one.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 68651
diff changeset
426 (whitespace-cleanup-internal))
36944
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
427 (let ((whitespace-leading (if whitespace-check-buffer-leading
26245
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
428 (whitespace-buffer-leading)
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
429 nil))
36944
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
430 (whitespace-trailing (if whitespace-check-buffer-trailing
26245
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
431 (whitespace-buffer-trailing)
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
432 nil))
36944
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
433 (whitespace-indent (if whitespace-check-buffer-indent
26245
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
434 (whitespace-buffer-search
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
435 whitespace-indent-regexp)
25724
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
436 nil))
36944
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
437 (whitespace-spacetab (if whitespace-check-buffer-spacetab
26245
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
438 (whitespace-buffer-search
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
439 whitespace-spacetab-regexp)
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
440 nil))
36944
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
441 (whitespace-ateol (if whitespace-check-buffer-ateol
26245
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
442 (whitespace-buffer-search
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
443 whitespace-ateol-regexp)
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
444 nil))
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
445 (whitespace-errmsg nil)
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
446 (whitespace-filename buffer-file-name)
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
447 (whitespace-this-modeline ""))
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
448
26245
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
449 ;; Now let's complain if we found any of the above.
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
450 (setq whitespace-error (or whitespace-leading whitespace-indent
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
451 whitespace-spacetab whitespace-ateol
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
452 whitespace-trailing))
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
453
26245
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
454 (if whitespace-error
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
455 (progn
26245
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
456 (setq whitespace-errmsg
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
457 (concat whitespace-filename " contains:\n"
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
458 (if whitespace-leading
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
459 "Leading whitespace\n")
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
460 (if whitespace-indent
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
461 (concat "Indentation whitespace"
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
462 whitespace-indent "\n"))
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
463 (if whitespace-spacetab
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
464 (concat "Space followed by Tab"
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
465 whitespace-spacetab "\n"))
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
466 (if whitespace-ateol
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
467 (concat "End-of-line whitespace"
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
468 whitespace-ateol "\n"))
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
469 (if whitespace-trailing
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
470 "Trailing whitespace\n")
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
471 "\ntype `M-x whitespace-cleanup' to "
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
472 "cleanup the file."))
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
473 (setq whitespace-this-modeline
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
474 (concat (if whitespace-ateol "e")
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
475 (if whitespace-indent "i")
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
476 (if whitespace-leading "l")
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
477 (if whitespace-spacetab "s")
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
478 (if whitespace-trailing "t")))))
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
479 (whitespace-update-modeline whitespace-this-modeline)
61395
21f8452c722e (whitespace-highlight-the-space): Put the same overlay
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 61394
diff changeset
480 (if (get-buffer whitespace-errbuf)
21f8452c722e (whitespace-highlight-the-space): Put the same overlay
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 61394
diff changeset
481 (kill-buffer whitespace-errbuf))
21f8452c722e (whitespace-highlight-the-space): Put the same overlay
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 61394
diff changeset
482 (with-current-buffer (get-buffer-create whitespace-errbuf)
26245
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
483 (if whitespace-errmsg
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
484 (progn
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
485 (insert whitespace-errmsg)
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
486 (if (not (or quiet whitespace-silent))
61395
21f8452c722e (whitespace-highlight-the-space): Put the same overlay
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 61394
diff changeset
487 (display-buffer (current-buffer) t))
26245
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
488 (if (not quiet)
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
489 (message "Whitespaces: [%s%s] in %s"
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
490 whitespace-this-modeline
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
491 (let ((whitespace-unchecked
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
492 (whitespace-unchecked-whitespaces)))
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
493 (if whitespace-unchecked
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
494 (concat "!" whitespace-unchecked)
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
495 ""))
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
496 whitespace-filename)))
52672
d4d213cfb340 whitespace.el now takes user customizable variable to display cleanliness of
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 52401
diff changeset
497 (if (and (not quiet) (not (equal whitespace-clean-msg "")))
d4d213cfb340 whitespace.el now takes user customizable variable to display cleanliness of
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 52401
diff changeset
498 (message "%s %s" whitespace-filename
d4d213cfb340 whitespace.el now takes user customizable variable to display cleanliness of
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 52401
diff changeset
499 whitespace-clean-msg))))))))
61395
21f8452c722e (whitespace-highlight-the-space): Put the same overlay
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 61394
diff changeset
500 whitespace-error))
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
501
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
502 ;;;###autoload
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
503 (defun whitespace-region (s e)
32501
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
504 "Check the region for whitespace errors."
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
505 (interactive "r")
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
506 (save-excursion
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
507 (save-restriction
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
508 (narrow-to-region s e)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
509 (whitespace-buffer))))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
510
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
511 ;;;###autoload
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
512 (defun whitespace-cleanup ()
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
513 "Cleanup the five different kinds of whitespace problems.
72472
1f82c3397a43 (whitespace-cleanup): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 72442
diff changeset
514 It normally applies to the whole buffer, but in Transient Mark mode
1f82c3397a43 (whitespace-cleanup): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 72442
diff changeset
515 when the mark is active it applies to the region.
66327
63c0efccff42 (whitespace-cleanup): Doc fix.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 64762
diff changeset
516 See `whitespace-buffer' docstring for a summary of the problems."
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
517 (interactive)
70927
1d492927a08d whitespace.el - make whitesspace-cleanup use the current active regoin, if there is one.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 68651
diff changeset
518 (if (and transient-mark-mode mark-active)
1d492927a08d whitespace.el - make whitesspace-cleanup use the current active regoin, if there is one.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 68651
diff changeset
519 (whitespace-cleanup-region (region-beginning) (region-end))
1d492927a08d whitespace.el - make whitesspace-cleanup use the current active regoin, if there is one.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 68651
diff changeset
520 (whitespace-cleanup-internal)))
1d492927a08d whitespace.el - make whitesspace-cleanup use the current active regoin, if there is one.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 68651
diff changeset
521
72442
384cd9b2e977 (whitespace-cleanup-internal): New optional arg REGION-ONLY. If it's non-nil,
Eli Zaretskii <eliz@gnu.org>
parents: 70927
diff changeset
522 (defun whitespace-cleanup-internal (&optional region-only)
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
523 ;; If this buffer really contains a file, then run, else quit.
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
524 (whitespace-check-whitespace-mode current-prefix-arg)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
525 (if (and buffer-file-name whitespace-mode)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
526 (let ((whitespace-any nil)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
527 (whitespace-tabwith 8)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
528 (whitespace-tabwith-saved tab-width))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
529
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
530 ;; since all printable TABS should be 8, irrespective of how
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
531 ;; they are displayed.
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
532 (setq tab-width whitespace-tabwith)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
533
36944
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
534 (if (and whitespace-check-buffer-leading
25724
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
535 (whitespace-buffer-leading))
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
536 (progn
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
537 (whitespace-buffer-leading-cleanup)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
538 (setq whitespace-any t)))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
539
36944
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
540 (if (and whitespace-check-buffer-trailing
25724
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
541 (whitespace-buffer-trailing))
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
542 (progn
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
543 (whitespace-buffer-trailing-cleanup)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
544 (setq whitespace-any t)))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
545
36944
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
546 (if (and whitespace-check-buffer-indent
25724
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
547 (whitespace-buffer-search whitespace-indent-regexp))
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
548 (progn
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
549 (whitespace-indent-cleanup)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
550 (setq whitespace-any t)))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
551
36944
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
552 (if (and whitespace-check-buffer-spacetab
25724
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
553 (whitespace-buffer-search whitespace-spacetab-regexp))
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
554 (progn
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
555 (whitespace-buffer-cleanup whitespace-spacetab-regexp "\t")
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
556 (setq whitespace-any t)))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
557
36944
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
558 (if (and whitespace-check-buffer-ateol
25724
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
559 (whitespace-buffer-search whitespace-ateol-regexp))
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
560 (progn
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
561 (whitespace-buffer-cleanup whitespace-ateol-regexp "")
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
562 (setq whitespace-any t)))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
563
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
564 ;; Call this recursively till everything is taken care of
25724
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
565 (if whitespace-any
74396
ee60f0fe10d6 (whitespace-cleanup-internal): Use current
Dan Nicolaescu <dann@ics.uci.edu>
parents: 73812
diff changeset
566 (whitespace-cleanup-internal region-only)
72442
384cd9b2e977 (whitespace-cleanup-internal): New optional arg REGION-ONLY. If it's non-nil,
Eli Zaretskii <eliz@gnu.org>
parents: 70927
diff changeset
567 ;; if we are done, talk to the user
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
568 (progn
72442
384cd9b2e977 (whitespace-cleanup-internal): New optional arg REGION-ONLY. If it's non-nil,
Eli Zaretskii <eliz@gnu.org>
parents: 70927
diff changeset
569 (unless whitespace-silent
384cd9b2e977 (whitespace-cleanup-internal): New optional arg REGION-ONLY. If it's non-nil,
Eli Zaretskii <eliz@gnu.org>
parents: 70927
diff changeset
570 (if region-only
384cd9b2e977 (whitespace-cleanup-internal): New optional arg REGION-ONLY. If it's non-nil,
Eli Zaretskii <eliz@gnu.org>
parents: 70927
diff changeset
571 (message "The region is now clean")
384cd9b2e977 (whitespace-cleanup-internal): New optional arg REGION-ONLY. If it's non-nil,
Eli Zaretskii <eliz@gnu.org>
parents: 70927
diff changeset
572 (message "%s is now clean" buffer-file-name)))
26245
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
573 (whitespace-update-modeline)))
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
574 (setq tab-width whitespace-tabwith-saved))))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
575
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
576 ;;;###autoload
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
577 (defun whitespace-cleanup-region (s e)
32501
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
578 "Whitespace cleanup on the region."
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
579 (interactive "r")
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
580 (save-excursion
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
581 (save-restriction
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
582 (narrow-to-region s e)
72442
384cd9b2e977 (whitespace-cleanup-internal): New optional arg REGION-ONLY. If it's non-nil,
Eli Zaretskii <eliz@gnu.org>
parents: 70927
diff changeset
583 (whitespace-cleanup-internal t))
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
584 (whitespace-buffer t)))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
585
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
586 (defun whitespace-buffer-leading ()
73666
b0f398ac4cbd (whitespace-indent-regexp): Make this match any multiples of eight spaces near
Eli Zaretskii <eliz@gnu.org>
parents: 72472
diff changeset
587 "Return t if the current buffer has leading newline characters.
b0f398ac4cbd (whitespace-indent-regexp): Make this match any multiples of eight spaces near
Eli Zaretskii <eliz@gnu.org>
parents: 72472
diff changeset
588 If highlighting is enabled, highlight these characters."
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
589 (save-excursion
73666
b0f398ac4cbd (whitespace-indent-regexp): Make this match any multiples of eight spaces near
Eli Zaretskii <eliz@gnu.org>
parents: 72472
diff changeset
590 (goto-char (point-min))
b0f398ac4cbd (whitespace-indent-regexp): Make this match any multiples of eight spaces near
Eli Zaretskii <eliz@gnu.org>
parents: 72472
diff changeset
591 (skip-chars-forward "\n")
b0f398ac4cbd (whitespace-indent-regexp): Make this match any multiples of eight spaces near
Eli Zaretskii <eliz@gnu.org>
parents: 72472
diff changeset
592 (unless (bobp)
b0f398ac4cbd (whitespace-indent-regexp): Make this match any multiples of eight spaces near
Eli Zaretskii <eliz@gnu.org>
parents: 72472
diff changeset
593 (whitespace-highlight-the-space (point-min) (point))
b0f398ac4cbd (whitespace-indent-regexp): Make this match any multiples of eight spaces near
Eli Zaretskii <eliz@gnu.org>
parents: 72472
diff changeset
594 t)))
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
595
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
596 (defun whitespace-buffer-leading-cleanup ()
73666
b0f398ac4cbd (whitespace-indent-regexp): Make this match any multiples of eight spaces near
Eli Zaretskii <eliz@gnu.org>
parents: 72472
diff changeset
597 "Remove any leading newline characters from current buffer."
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
598 (save-excursion
64178
0b1f11faf0b2 (whitespace-buffer-leading-cleanup): Simplify w/ skip-chars-forward.
Richard M. Stallman <rms@gnu.org>
parents: 64091
diff changeset
599 (goto-char (point-min))
0b1f11faf0b2 (whitespace-buffer-leading-cleanup): Simplify w/ skip-chars-forward.
Richard M. Stallman <rms@gnu.org>
parents: 64091
diff changeset
600 (skip-chars-forward "\n")
0b1f11faf0b2 (whitespace-buffer-leading-cleanup): Simplify w/ skip-chars-forward.
Richard M. Stallman <rms@gnu.org>
parents: 64091
diff changeset
601 (delete-region (point-min) (point))))
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
602
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
603 (defun whitespace-buffer-trailing ()
73666
b0f398ac4cbd (whitespace-indent-regexp): Make this match any multiples of eight spaces near
Eli Zaretskii <eliz@gnu.org>
parents: 72472
diff changeset
604 "Return t if the current buffer has extra trailing newline characters.
b0f398ac4cbd (whitespace-indent-regexp): Make this match any multiples of eight spaces near
Eli Zaretskii <eliz@gnu.org>
parents: 72472
diff changeset
605 If highlighting is enabled, highlight these characters."
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
606 (save-excursion
73666
b0f398ac4cbd (whitespace-indent-regexp): Make this match any multiples of eight spaces near
Eli Zaretskii <eliz@gnu.org>
parents: 72472
diff changeset
607 (goto-char (point-max))
b0f398ac4cbd (whitespace-indent-regexp): Make this match any multiples of eight spaces near
Eli Zaretskii <eliz@gnu.org>
parents: 72472
diff changeset
608 (skip-chars-backward "\n")
b0f398ac4cbd (whitespace-indent-regexp): Make this match any multiples of eight spaces near
Eli Zaretskii <eliz@gnu.org>
parents: 72472
diff changeset
609 (forward-line)
b0f398ac4cbd (whitespace-indent-regexp): Make this match any multiples of eight spaces near
Eli Zaretskii <eliz@gnu.org>
parents: 72472
diff changeset
610 (unless (eobp)
b0f398ac4cbd (whitespace-indent-regexp): Make this match any multiples of eight spaces near
Eli Zaretskii <eliz@gnu.org>
parents: 72472
diff changeset
611 (whitespace-highlight-the-space (point) (point-max))
b0f398ac4cbd (whitespace-indent-regexp): Make this match any multiples of eight spaces near
Eli Zaretskii <eliz@gnu.org>
parents: 72472
diff changeset
612 t)))
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
613
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
614 (defun whitespace-buffer-trailing-cleanup ()
73666
b0f398ac4cbd (whitespace-indent-regexp): Make this match any multiples of eight spaces near
Eli Zaretskii <eliz@gnu.org>
parents: 72472
diff changeset
615 "Remove extra trailing newline characters from current buffer."
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
616 (save-excursion
64178
0b1f11faf0b2 (whitespace-buffer-leading-cleanup): Simplify w/ skip-chars-forward.
Richard M. Stallman <rms@gnu.org>
parents: 64091
diff changeset
617 (goto-char (point-max))
0b1f11faf0b2 (whitespace-buffer-leading-cleanup): Simplify w/ skip-chars-forward.
Richard M. Stallman <rms@gnu.org>
parents: 64091
diff changeset
618 (skip-chars-backward "\n")
73666
b0f398ac4cbd (whitespace-indent-regexp): Make this match any multiples of eight spaces near
Eli Zaretskii <eliz@gnu.org>
parents: 72472
diff changeset
619 (unless (eobp)
b0f398ac4cbd (whitespace-indent-regexp): Make this match any multiples of eight spaces near
Eli Zaretskii <eliz@gnu.org>
parents: 72472
diff changeset
620 (forward-line)
b0f398ac4cbd (whitespace-indent-regexp): Make this match any multiples of eight spaces near
Eli Zaretskii <eliz@gnu.org>
parents: 72472
diff changeset
621 (delete-region (point) (point-max)))))
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
622
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
623 (defun whitespace-buffer-search (regexp)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
624 "Search for any given whitespace REGEXP."
73666
b0f398ac4cbd (whitespace-indent-regexp): Make this match any multiples of eight spaces near
Eli Zaretskii <eliz@gnu.org>
parents: 72472
diff changeset
625 (with-local-quit
b0f398ac4cbd (whitespace-indent-regexp): Make this match any multiples of eight spaces near
Eli Zaretskii <eliz@gnu.org>
parents: 72472
diff changeset
626 (let (whitespace-retval)
b0f398ac4cbd (whitespace-indent-regexp): Make this match any multiples of eight spaces near
Eli Zaretskii <eliz@gnu.org>
parents: 72472
diff changeset
627 (save-excursion
b0f398ac4cbd (whitespace-indent-regexp): Make this match any multiples of eight spaces near
Eli Zaretskii <eliz@gnu.org>
parents: 72472
diff changeset
628 (goto-char (point-min))
b0f398ac4cbd (whitespace-indent-regexp): Make this match any multiples of eight spaces near
Eli Zaretskii <eliz@gnu.org>
parents: 72472
diff changeset
629 (while (re-search-forward regexp nil t)
b0f398ac4cbd (whitespace-indent-regexp): Make this match any multiples of eight spaces near
Eli Zaretskii <eliz@gnu.org>
parents: 72472
diff changeset
630 (whitespace-highlight-the-space (match-beginning 0) (match-end 0))
b0f398ac4cbd (whitespace-indent-regexp): Make this match any multiples of eight spaces near
Eli Zaretskii <eliz@gnu.org>
parents: 72472
diff changeset
631 (push (match-beginning 0) whitespace-retval)))
b0f398ac4cbd (whitespace-indent-regexp): Make this match any multiples of eight spaces near
Eli Zaretskii <eliz@gnu.org>
parents: 72472
diff changeset
632 (when whitespace-retval
b0f398ac4cbd (whitespace-indent-regexp): Make this match any multiples of eight spaces near
Eli Zaretskii <eliz@gnu.org>
parents: 72472
diff changeset
633 (format " %s" (nreverse whitespace-retval))))))
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
634
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
635 (defun whitespace-buffer-cleanup (regexp newregexp)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
636 "Search for any given whitespace REGEXP and replace it with the NEWREGEXP."
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
637 (save-excursion
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
638 (goto-char (point-min))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
639 (while (re-search-forward regexp nil t)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
640 (replace-match newregexp))))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
641
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
642 (defun whitespace-indent-cleanup ()
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
643 "Search for 8/more spaces at the start of a line and replace it with tabs."
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
644 (save-excursion
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
645 (goto-char (point-min))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
646 (while (re-search-forward whitespace-indent-regexp nil t)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
647 (let ((column (current-column))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
648 (indent-tabs-mode t))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
649 (delete-region (match-beginning 0) (point))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
650 (indent-to column)))))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
651
26245
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
652 (defun whitespace-unchecked-whitespaces ()
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
653 "Return the list of whitespaces whose testing has been suppressed."
36944
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
654 (let ((unchecked-spaces
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
655 (concat (if (not whitespace-check-buffer-ateol) "e")
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
656 (if (not whitespace-check-buffer-indent) "i")
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
657 (if (not whitespace-check-buffer-leading) "l")
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
658 (if (not whitespace-check-buffer-spacetab) "s")
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
659 (if (not whitespace-check-buffer-trailing) "t"))))
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
660 (if (not (equal unchecked-spaces ""))
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
661 unchecked-spaces
26245
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
662 nil)))
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
663
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
664 (defun whitespace-update-modeline (&optional whitespace-err)
32501
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
665 "Update modeline with whitespace errors.
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
666 Also with whitespaces whose testing has been turned off."
26245
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
667 (if whitespace-display-in-modeline
26259
912b004387d9 (whitespace-update-modeline): Bugfix to ensure
Gerd Moellmann <gerd@gnu.org>
parents: 26253
diff changeset
668 (progn
912b004387d9 (whitespace-update-modeline): Bugfix to ensure
Gerd Moellmann <gerd@gnu.org>
parents: 26253
diff changeset
669 (setq whitespace-mode-line nil)
912b004387d9 (whitespace-update-modeline): Bugfix to ensure
Gerd Moellmann <gerd@gnu.org>
parents: 26253
diff changeset
670 ;; Whitespace errors
912b004387d9 (whitespace-update-modeline): Bugfix to ensure
Gerd Moellmann <gerd@gnu.org>
parents: 26253
diff changeset
671 (if (and whitespace-err (not (equal whitespace-err "")))
912b004387d9 (whitespace-update-modeline): Bugfix to ensure
Gerd Moellmann <gerd@gnu.org>
parents: 26253
diff changeset
672 (setq whitespace-mode-line whitespace-err))
912b004387d9 (whitespace-update-modeline): Bugfix to ensure
Gerd Moellmann <gerd@gnu.org>
parents: 26253
diff changeset
673 ;; Whitespace suppressed errors
912b004387d9 (whitespace-update-modeline): Bugfix to ensure
Gerd Moellmann <gerd@gnu.org>
parents: 26253
diff changeset
674 (let ((whitespace-unchecked (whitespace-unchecked-whitespaces)))
912b004387d9 (whitespace-update-modeline): Bugfix to ensure
Gerd Moellmann <gerd@gnu.org>
parents: 26253
diff changeset
675 (if whitespace-unchecked
912b004387d9 (whitespace-update-modeline): Bugfix to ensure
Gerd Moellmann <gerd@gnu.org>
parents: 26253
diff changeset
676 (setq whitespace-mode-line
912b004387d9 (whitespace-update-modeline): Bugfix to ensure
Gerd Moellmann <gerd@gnu.org>
parents: 26253
diff changeset
677 (concat whitespace-mode-line "!" whitespace-unchecked))))
912b004387d9 (whitespace-update-modeline): Bugfix to ensure
Gerd Moellmann <gerd@gnu.org>
parents: 26253
diff changeset
678 ;; Add the whitespace modeline prefix
912b004387d9 (whitespace-update-modeline): Bugfix to ensure
Gerd Moellmann <gerd@gnu.org>
parents: 26253
diff changeset
679 (setq whitespace-mode-line (if whitespace-mode-line
912b004387d9 (whitespace-update-modeline): Bugfix to ensure
Gerd Moellmann <gerd@gnu.org>
parents: 26253
diff changeset
680 (concat " W:" whitespace-mode-line)
912b004387d9 (whitespace-update-modeline): Bugfix to ensure
Gerd Moellmann <gerd@gnu.org>
parents: 26253
diff changeset
681 nil))
42013
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
682 (whitespace-mode-line-update))))
25724
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
683
42013
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
684 (defun whitespace-highlight-the-space (b e)
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
685 "Highlight the current line, unhighlighting a previously jumped to line."
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
686 (if whitespace-display-spaces-in-color
61395
21f8452c722e (whitespace-highlight-the-space): Put the same overlay
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 61394
diff changeset
687 (let ((ol (whitespace-make-overlay b e)))
63200
eef21c221eff Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-371
Miles Bader <miles@gnu.org>
parents: 61492
diff changeset
688 (whitespace-overlay-put ol 'face 'whitespace-highlight))))
42013
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
689
61471
c85ac0c1b8e9 (whitespace-highlight-the-space):
Richard M. Stallman <rms@gnu.org>
parents: 61395
diff changeset
690 (defun whitespace-unhighlight-the-space()
42013
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
691 "Unhighlight the currently highlight line."
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
692 (if (and whitespace-display-spaces-in-color whitespace-highlighted-space)
61395
21f8452c722e (whitespace-highlight-the-space): Put the same overlay
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 61394
diff changeset
693 (progn
21f8452c722e (whitespace-highlight-the-space): Put the same overlay
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 61394
diff changeset
694 (mapc 'whitespace-delete-overlay whitespace-highlighted-space)
73666
b0f398ac4cbd (whitespace-indent-regexp): Make this match any multiples of eight spaces near
Eli Zaretskii <eliz@gnu.org>
parents: 72472
diff changeset
695 (setq whitespace-highlighted-space nil))))
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
696
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
697 (defun whitespace-check-buffer-list (buf-name buf-file)
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
698 "Add a buffer and its file to the whitespace monitor list.
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
699
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
700 The buffer named BUF-NAME and its associated file BUF-FILE are now monitored
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
701 periodically for whitespace."
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
702 (if (and whitespace-mode (not (member (list buf-file buf-name)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
703 whitespace-all-buffer-files)))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
704 (add-to-list 'whitespace-all-buffer-files (list buf-file buf-name))))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
705
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
706 (defun whitespace-tickle-timer ()
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
707 "Tickle timer to periodically to scan qualifying files for whitespace creep.
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
708
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
709 If timer is not set, then set it to scan the files in
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
710 `whitespace-all-buffer-files' periodically (defined by
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
711 `whitespace-rescan-timer-time') for whitespace creep."
84837
aff02a4292a0 (whitespace-tickle-timer): Don't install the timer if
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 78492
diff changeset
712 (if (and whitespace-rescan-timer-time
aff02a4292a0 (whitespace-tickle-timer): Don't install the timer if
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 78492
diff changeset
713 (/= whitespace-rescan-timer-time 0)
aff02a4292a0 (whitespace-tickle-timer): Don't install the timer if
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 78492
diff changeset
714 (not whitespace-rescan-timer))
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
715 (setq whitespace-rescan-timer
32501
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
716 (add-timeout whitespace-rescan-timer-time
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
717 'whitespace-rescan-files-in-buffers nil
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
718 whitespace-rescan-timer-time))))
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
719
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
720 (defun whitespace-rescan-files-in-buffers (&optional arg)
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
721 "Check monitored files for whitespace creep since last scan."
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
722 (let ((whitespace-all-my-files whitespace-all-buffer-files)
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
723 buffile bufname thiselt buf)
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
724 (if (not whitespace-all-my-files)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
725 (progn
32501
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
726 (disable-timeout whitespace-rescan-timer)
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
727 (setq whitespace-rescan-timer nil))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
728 (while whitespace-all-my-files
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
729 (setq thiselt (car whitespace-all-my-files))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
730 (setq whitespace-all-my-files (cdr whitespace-all-my-files))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
731 (setq buffile (car thiselt))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
732 (setq bufname (cadr thiselt))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
733 (setq buf (get-buffer bufname))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
734 (if (buffer-live-p buf)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
735 (save-excursion
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
736 ;;(message "buffer %s live" bufname)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
737 (set-buffer bufname)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
738 (if whitespace-mode
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
739 (progn
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
740 ;;(message "checking for whitespace in %s" bufname)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
741 (if whitespace-auto-cleanup
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
742 (progn
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
743 ;;(message "cleaning up whitespace in %s" bufname)
70927
1d492927a08d whitespace.el - make whitesspace-cleanup use the current active regoin, if there is one.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 68651
diff changeset
744 (whitespace-cleanup-internal))
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
745 (progn
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
746 ;;(message "whitespace-buffer %s." (buffer-name))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
747 (whitespace-buffer t))))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
748 ;;(message "Removing %s from refresh list" bufname)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
749 (whitespace-refresh-rescan-list buffile bufname)))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
750 ;;(message "Removing %s from refresh list" bufname)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
751 (whitespace-refresh-rescan-list buffile bufname))))))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
752
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
753 (defun whitespace-refresh-rescan-list (buffile bufname)
73666
b0f398ac4cbd (whitespace-indent-regexp): Make this match any multiples of eight spaces near
Eli Zaretskii <eliz@gnu.org>
parents: 72472
diff changeset
754 "Refresh the list of files to be rescanned for whitespace creep."
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
755 (if whitespace-all-buffer-files
32501
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
756 (setq whitespace-all-buffer-files
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
757 (delete (list buffile bufname) whitespace-all-buffer-files))
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
758 (when whitespace-rescan-timer
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
759 (disable-timeout whitespace-rescan-timer)
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
760 (setq whitespace-rescan-timer nil))))
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
761
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
762 ;;;###autoload
56763
e9a8ab6f16fc (global-whitespace-mode): New alias for whitespace-global-mode.
Richard M. Stallman <rms@gnu.org>
parents: 54770
diff changeset
763 (defalias 'global-whitespace-mode 'whitespace-global-mode)
e9a8ab6f16fc (global-whitespace-mode): New alias for whitespace-global-mode.
Richard M. Stallman <rms@gnu.org>
parents: 54770
diff changeset
764
e9a8ab6f16fc (global-whitespace-mode): New alias for whitespace-global-mode.
Richard M. Stallman <rms@gnu.org>
parents: 54770
diff changeset
765 ;;;###autoload
47420
b7a8fec8113c (whitespace-global-mode): Use define-minor-mode. Use the new file hook names.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42013
diff changeset
766 (define-minor-mode whitespace-global-mode
32501
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
767 "Toggle using Whitespace mode in new buffers.
78492
7c8949dbfa0d Replace `iff' in doc-strings and comments.
Glenn Morris <rgm@gnu.org>
parents: 78236
diff changeset
768 With ARG, turn the mode on if ARG is positive, otherwise turn it off.
32501
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
769
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
770 When this mode is active, `whitespace-buffer' is added to
47420
b7a8fec8113c (whitespace-global-mode): Use define-minor-mode. Use the new file hook names.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42013
diff changeset
771 `find-file-hook' and `kill-buffer-hook'."
50964
d5b5bbb27b2f Add :link to commentary section
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 48631
diff changeset
772 :global t
d5b5bbb27b2f Add :link to commentary section
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 48631
diff changeset
773 :group 'whitespace
47420
b7a8fec8113c (whitespace-global-mode): Use define-minor-mode. Use the new file hook names.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42013
diff changeset
774 (if whitespace-global-mode
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
775 (progn
47420
b7a8fec8113c (whitespace-global-mode): Use define-minor-mode. Use the new file hook names.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42013
diff changeset
776 (add-hook 'find-file-hook 'whitespace-buffer)
b7a8fec8113c (whitespace-global-mode): Use define-minor-mode. Use the new file hook names.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42013
diff changeset
777 (add-hook 'write-file-functions 'whitespace-write-file-hook nil t)
32501
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
778 (add-hook 'kill-buffer-hook 'whitespace-buffer))
47420
b7a8fec8113c (whitespace-global-mode): Use define-minor-mode. Use the new file hook names.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42013
diff changeset
779 (remove-hook 'find-file-hook 'whitespace-buffer)
b7a8fec8113c (whitespace-global-mode): Use define-minor-mode. Use the new file hook names.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42013
diff changeset
780 (remove-hook 'write-file-functions 'whitespace-write-file-hook t)
32501
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
781 (remove-hook 'kill-buffer-hook 'whitespace-buffer)))
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
782
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
783 ;;;###autoload
38882
ceec599316a4 whitespace 3.1
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38874
diff changeset
784 (defun whitespace-write-file-hook ()
47420
b7a8fec8113c (whitespace-global-mode): Use define-minor-mode. Use the new file hook names.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42013
diff changeset
785 "Hook function to be called on the buffer when whitespace check is enabled.
b7a8fec8113c (whitespace-global-mode): Use define-minor-mode. Use the new file hook names.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42013
diff changeset
786 This is meant to be added buffer-locally to `write-file-functions'."
38882
ceec599316a4 whitespace 3.1
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38874
diff changeset
787 (let ((werr nil))
ceec599316a4 whitespace 3.1
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38874
diff changeset
788 (if whitespace-auto-cleanup
70927
1d492927a08d whitespace.el - make whitesspace-cleanup use the current active regoin, if there is one.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 68651
diff changeset
789 (whitespace-cleanup-internal)
38882
ceec599316a4 whitespace 3.1
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38874
diff changeset
790 (setq werr (whitespace-buffer)))
ceec599316a4 whitespace 3.1
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38874
diff changeset
791 (if (and whitespace-abort-on-error werr)
ceec599316a4 whitespace 3.1
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38874
diff changeset
792 (error (concat "Abort write due to whitespaces in "
ceec599316a4 whitespace 3.1
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38874
diff changeset
793 buffer-file-name))))
ceec599316a4 whitespace 3.1
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38874
diff changeset
794 nil)
ceec599316a4 whitespace 3.1
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38874
diff changeset
795
79292
256e724f6460 (whitespace-write-file-hook): Remove interactive spec.
Juanma Barranquero <lekktu@gmail.com>
parents: 78492
diff changeset
796 (defun whitespace-unload-function ()
256e724f6460 (whitespace-write-file-hook): Remove interactive spec.
Juanma Barranquero <lekktu@gmail.com>
parents: 78492
diff changeset
797 "Unload the whitespace library."
79296
82de3a8b0f8d (whitespace-unload-function): New-style unload function.
Juanma Barranquero <lekktu@gmail.com>
parents: 79292
diff changeset
798 (if (unintern "whitespace-unload-hook")
82de3a8b0f8d (whitespace-unload-function): New-style unload function.
Juanma Barranquero <lekktu@gmail.com>
parents: 79292
diff changeset
799 ;; if whitespace-unload-hook is defined, let's get rid of it
82de3a8b0f8d (whitespace-unload-function): New-style unload function.
Juanma Barranquero <lekktu@gmail.com>
parents: 79292
diff changeset
800 ;; and recursively call `unload-feature'
82de3a8b0f8d (whitespace-unload-function): New-style unload function.
Juanma Barranquero <lekktu@gmail.com>
parents: 79292
diff changeset
801 (progn (unload-feature 'whitespace) t)
82de3a8b0f8d (whitespace-unload-function): New-style unload function.
Juanma Barranquero <lekktu@gmail.com>
parents: 79292
diff changeset
802 ;; this only happens in the recursive call
82de3a8b0f8d (whitespace-unload-function): New-style unload function.
Juanma Barranquero <lekktu@gmail.com>
parents: 79292
diff changeset
803 (whitespace-global-mode -1)
82de3a8b0f8d (whitespace-unload-function): New-style unload function.
Juanma Barranquero <lekktu@gmail.com>
parents: 79292
diff changeset
804 (save-current-buffer
82de3a8b0f8d (whitespace-unload-function): New-style unload function.
Juanma Barranquero <lekktu@gmail.com>
parents: 79292
diff changeset
805 (dolist (buf (buffer-list))
82de3a8b0f8d (whitespace-unload-function): New-style unload function.
Juanma Barranquero <lekktu@gmail.com>
parents: 79292
diff changeset
806 (set-buffer buf)
82de3a8b0f8d (whitespace-unload-function): New-style unload function.
Juanma Barranquero <lekktu@gmail.com>
parents: 79292
diff changeset
807 (remove-hook 'write-file-functions 'whitespace-write-file-hook t)))
82de3a8b0f8d (whitespace-unload-function): New-style unload function.
Juanma Barranquero <lekktu@gmail.com>
parents: 79292
diff changeset
808 ;; continue standard unloading
82de3a8b0f8d (whitespace-unload-function): New-style unload function.
Juanma Barranquero <lekktu@gmail.com>
parents: 79292
diff changeset
809 nil))
79292
256e724f6460 (whitespace-write-file-hook): Remove interactive spec.
Juanma Barranquero <lekktu@gmail.com>
parents: 78492
diff changeset
810
32501
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
811 (defun whitespace-unload-hook ()
47420
b7a8fec8113c (whitespace-global-mode): Use define-minor-mode. Use the new file hook names.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42013
diff changeset
812 (remove-hook 'find-file-hook 'whitespace-buffer)
47454
cf95d79a66c4 (whitespace-unload-hook): Call `remove-hook' with three arguments, not four.
Juanma Barranquero <lekktu@gmail.com>
parents: 47420
diff changeset
813 (remove-hook 'write-file-functions 'whitespace-write-file-hook t)
32501
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
814 (remove-hook 'kill-buffer-hook 'whitespace-buffer))
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
815
57522
3f7aa44cf697 (whitespace-unload-hook): Set the variable.
Richard M. Stallman <rms@gnu.org>
parents: 56763
diff changeset
816 (add-hook 'whitespace-unload-hook 'whitespace-unload-hook)
3f7aa44cf697 (whitespace-unload-hook): Set the variable.
Richard M. Stallman <rms@gnu.org>
parents: 56763
diff changeset
817
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
818 (provide 'whitespace)
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 51543
diff changeset
819
61395
21f8452c722e (whitespace-highlight-the-space): Put the same overlay
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 61394
diff changeset
820 ;; arch-tag: 4ff44e87-b63c-402d-95a6-15e51e58bd0c
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
821 ;;; whitespace.el ends here