annotate lisp/whitespace.el @ 50849:702762701b10

(gnus-group-parameters): Don't quote nil and t in docstrings.
author Juanma Barranquero <lekktu@gmail.com>
date Tue, 06 May 2003 17:30:13 +0000
parents 37ddf84a7528
children d5b5bbb27b2f d7ddb3e565de
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
34304
dd613770eb0f Fix copyright years.
Dave Love <fx@gnu.org>
parents: 32501
diff changeset
3 ;; Copyright (C) 1999, 2000 Free Software Foundation, Inc.
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
4
29333
189f70e66cab Update whitespace.el with a more tolerable timer scan time.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 27583
diff changeset
5 ;; Author: Rajesh Vaidheeswarran <rv@gnu.org>
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
6 ;; Keywords: convenience
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
7
48631
37ddf84a7528 (whitespace-highlight-face): Fix face spec.
Andreas Schwab <schwab@suse.de>
parents: 47454
diff changeset
8 ;; $Id: whitespace.el,v 1.21 2002/09/13 06:21:32 lektu Exp $
25582
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
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
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
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
24 ;; Boston, MA 02111-1307, USA.
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:
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
27
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
28 ;; Whitespace.el URL: http://www.dsmit.com/lisp/
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
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.
b7a8fec8113c (whitespace-global-mode): Use define-minor-mode. Use the new file hook names.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42013
diff changeset
32
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
b7a8fec8113c (whitespace-global-mode): Use define-minor-mode. Use the new file hook names.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42013
diff changeset
36 ;; replaced with TABS).
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.
b7a8fec8113c (whitespace-global-mode): Use define-minor-mode. Use the new file hook names.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42013
diff changeset
39
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.
b7a8fec8113c (whitespace-global-mode): Use define-minor-mode. Use the new file hook names.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42013
diff changeset
41
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:
b7a8fec8113c (whitespace-global-mode): Use define-minor-mode. Use the new file hook names.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42013
diff changeset
44
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.
b7a8fec8113c (whitespace-global-mode): Use define-minor-mode. Use the new file hook names.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42013
diff changeset
50
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>.
b7a8fec8113c (whitespace-global-mode): Use define-minor-mode. Use the new file hook names.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42013
diff changeset
53
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.)
b7a8fec8113c (whitespace-global-mode): Use define-minor-mode. Use the new file hook names.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42013
diff changeset
58
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.
b7a8fec8113c (whitespace-global-mode): Use define-minor-mode. Use the new file hook names.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42013
diff changeset
62
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.)
b7a8fec8113c (whitespace-global-mode): Use define-minor-mode. Use the new file hook names.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42013
diff changeset
71
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.
b7a8fec8113c (whitespace-global-mode): Use define-minor-mode. Use the new file hook names.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42013
diff changeset
74
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).
b7a8fec8113c (whitespace-global-mode): Use define-minor-mode. Use the new file hook names.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42013
diff changeset
78
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
79 ;; Exported functions:
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
80
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
42013
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
90 (defvar whitespace-version "3.2" "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 (put 'whitespace-mode 'permanent-local nil)
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
106
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
107 (defvar whitespace-mode-line nil
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
108 "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
109 (make-variable-buffer-local 'whitespace-mode-line)
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
110 (put 'whitespace-mode-line 'permanent-local nil)
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
111
36944
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
112 (defvar whitespace-check-buffer-leading nil
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
113 "Test leading whitespace for file in current buffer if t")
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
114 (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
115 (put 'whitespace-check-buffer-leading 'permanent-local nil)
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
116
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
117 (defvar whitespace-check-buffer-trailing nil
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
118 "Test trailing whitespace for file in current buffer if t")
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
119 (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
120 (put 'whitespace-check-buffer-trailing 'permanent-local nil)
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-indent nil
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
123 "Test indentation whitespace for file in current buffer if t")
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-indent)
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
125 (put 'whitespace-check-buffer-indent 'permanent-local nil)
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
126
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
127 (defvar whitespace-check-buffer-spacetab nil
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
128 "Test Space-followed-by-TABS whitespace for file in current buffer if t")
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
129 (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
130 (put 'whitespace-check-buffer-spacetab 'permanent-local nil)
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
131
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
132 (defvar whitespace-check-buffer-ateol nil
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
133 "Test end-of-line whitespace for file in current buffer if t")
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
134 (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
135 (put 'whitespace-check-buffer-ateol 'permanent-local nil)
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
136
42013
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
137 (defvar whitespace-highlighted-space nil
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
138 "The variable to store the extent to highlight")
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
139 (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
140 (put 'whitespace-highlighted-space 'permanent-local nil)
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
141
26253
3bb622df1c52 (whitespace-version): Update to 2.8
Gerd Moellmann <gerd@gnu.org>
parents: 26245
diff changeset
142 ;; 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
143 (eval-when-compile
26253
3bb622df1c52 (whitespace-version): Update to 2.8
Gerd Moellmann <gerd@gnu.org>
parents: 26245
diff changeset
144 (if (not (fboundp 'defgroup))
3bb622df1c52 (whitespace-version): Update to 2.8
Gerd Moellmann <gerd@gnu.org>
parents: 26245
diff changeset
145 (defmacro defgroup (sym memb doc &rest args)
3bb622df1c52 (whitespace-version): Update to 2.8
Gerd Moellmann <gerd@gnu.org>
parents: 26245
diff changeset
146 "Null macro for defgroup in all versions of Emacs that don't define
3bb622df1c52 (whitespace-version): Update to 2.8
Gerd Moellmann <gerd@gnu.org>
parents: 26245
diff changeset
147 defgroup"
3bb622df1c52 (whitespace-version): Update to 2.8
Gerd Moellmann <gerd@gnu.org>
parents: 26245
diff changeset
148 t))
3bb622df1c52 (whitespace-version): Update to 2.8
Gerd Moellmann <gerd@gnu.org>
parents: 26245
diff changeset
149 (if (not (fboundp 'defcustom))
3bb622df1c52 (whitespace-version): Update to 2.8
Gerd Moellmann <gerd@gnu.org>
parents: 26245
diff changeset
150 (defmacro defcustom (sym val doc &rest args)
3bb622df1c52 (whitespace-version): Update to 2.8
Gerd Moellmann <gerd@gnu.org>
parents: 26245
diff changeset
151 "Macro to alias defcustom to defvar in all versions of Emacs that
3bb622df1c52 (whitespace-version): Update to 2.8
Gerd Moellmann <gerd@gnu.org>
parents: 26245
diff changeset
152 don't define defcustom"
3bb622df1c52 (whitespace-version): Update to 2.8
Gerd Moellmann <gerd@gnu.org>
parents: 26245
diff changeset
153 `(defvar ,sym ,val ,doc))))
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
154
42013
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
155 (if (fboundp 'make-overlay)
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
156 (progn
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
157 (defalias 'whitespace-make-overlay 'make-overlay)
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
158 (defalias 'whitespace-overlay-put 'overlay-put)
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
159 (defalias 'whitespace-delete-overlay 'delete-overlay)
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
160 (defalias 'whitespace-overlay-start 'overlay-start)
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
161 (defalias 'whitespace-overlay-end 'overlay-end)
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
162 (defalias 'whitespace-mode-line-update 'force-mode-line-update))
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
163 (defalias 'whitespace-make-overlay 'make-extent)
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
164 (defalias 'whitespace-overlay-put 'set-extent-property)
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
165 (defalias 'whitespace-delete-overlay 'delete-extent)
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
166 (defalias 'whitespace-overlay-start 'extent-start)
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
167 (defalias 'whitespace-overlay-end 'extent-end)
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
168 (defalias 'whitespace-mode-line-update 'redraw-modeline))
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
169
32501
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
170 (if (featurep 'xemacs)
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
171 (defgroup whitespace nil
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
172 "Check for and fix five different types of whitespaces in source code."
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
173 ;; Since XEmacs doesn't have a 'convenience group, use the next best group
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
174 ;; which is 'editing?
32501
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
175 :group 'editing)
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
176 (defgroup whitespace nil
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
177 "Check for and fix five different types of whitespaces in source code."
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
178 :version "21.1"
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
179 :group 'convenience))
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
180
25724
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
181 (defcustom whitespace-check-leading-whitespace t
36944
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
182 "Flag to check leading whitespace. This is the global for the system.
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
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
184 `whitespace-check-buffer-leading'"
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
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
188 (defcustom whitespace-check-trailing-whitespace t
36944
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
189 "Flag to check trailing whitespace. This is the global for the system.
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
190 It can be overriden by setting a buffer local variable
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
191 `whitespace-check-buffer-trailing'"
25724
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
192 :type 'boolean
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
193 :group 'whitespace)
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
194
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
195 (defcustom whitespace-check-spacetab-whitespace t
36944
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
196 "Flag to check space followed by a TAB. This is the global for the system.
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
197 It can be overriden by setting a buffer local variable
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
198 `whitespace-check-buffer-spacetab'"
25724
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
199 :type 'boolean
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
200 :group 'whitespace)
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
201
42013
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
202 (defcustom whitespace-spacetab-regexp "[ ]+\t"
25724
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
203 "Regexp to match a space followed by a TAB."
32501
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
204 :type 'regexp
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
205 :group 'whitespace)
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
206
38882
ceec599316a4 whitespace 3.1
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38874
diff changeset
207 (defcustom whitespace-check-indent-whitespace indent-tabs-mode
36944
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
208 "Flag to check indentation whitespace. This is the global for the system.
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
209 It can be overriden by setting a buffer local variable
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
210 `whitespace-check-buffer-indent'"
25724
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
211 :type 'boolean
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
212 :group 'whitespace)
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
213
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
214 (defcustom whitespace-indent-regexp (concat "^\\(\t*\\) " " ")
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
215 "Regexp to match (any TABS followed by) 8/more whitespaces at start of line."
32501
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
216 :type 'regexp
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
217 :group 'whitespace)
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
218
25724
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
219 (defcustom whitespace-check-ateol-whitespace t
36944
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
220 "Flag to check end-of-line whitespace. This is the global for the system.
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
221 It can be overriden by setting a buffer local variable
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
222 `whitespace-check-buffer-ateol'"
25724
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
223 :type 'boolean
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
224 :group 'whitespace)
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
225
42013
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
226 ;; (defcustom whitespace-ateol-regexp "[ \t]$"
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
227 (defcustom whitespace-ateol-regexp "[ \t]+$"
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
228 "Regexp to match a TAB or a space at the EOL."
32501
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
229 :type 'regexp
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
230 :group 'whitespace)
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
231
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
232 (defcustom whitespace-errbuf "*Whitespace Errors*"
32501
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
233 "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
234 :type 'string
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
235 :group 'whitespace)
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
236
38882
ceec599316a4 whitespace 3.1
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38874
diff changeset
237 (defcustom whitespace-abort-on-error nil
ceec599316a4 whitespace 3.1
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38874
diff changeset
238 "While writing a file, abort if the file is unclean. If
ceec599316a4 whitespace 3.1
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38874
diff changeset
239 `whitespace-auto-cleanup' is set, that takes precedence over this
ceec599316a4 whitespace 3.1
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38874
diff changeset
240 variable."
ceec599316a4 whitespace 3.1
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38874
diff changeset
241 :type 'boolean
ceec599316a4 whitespace 3.1
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38874
diff changeset
242 :group 'whitespace)
ceec599316a4 whitespace 3.1
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38874
diff changeset
243
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
244 (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
245 "Cleanup a buffer automatically on finding it whitespace unclean."
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
246 :type 'boolean
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
247 :group 'whitespace)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
248
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
249 (defcustom whitespace-silent nil
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
250 "All whitespace errors will be shown only in the modeline when t.
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
251
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
252 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
253 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
254 Errors*' buffer before opening (or closing) another file."
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
255 :type 'boolean
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
256 :group 'whitespace)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
257
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
258 (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
259 c-mode c++-mode cc-mode
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
260 change-log-mode cperl-mode
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
261 electric-nroff-mode emacs-lisp-mode
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
262 f90-mode fortran-mode html-mode
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
263 html3-mode java-mode jde-mode
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
264 ksh-mode latex-mode LaTeX-mode
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
265 lisp-mode m4-mode makefile-mode
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
266 modula-2-mode nroff-mode objc-mode
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
267 pascal-mode perl-mode prolog-mode
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
268 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
269 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
270 tcl-mode tex-mode texinfo-mode
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
271 vrml-mode xml-mode)
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
272
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
273 "Major Modes in which we turn on whitespace checking.
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
274
32501
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
275 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
276 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
277 following to your `.emacs':
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
278
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
279 \(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
280 whitespace-modes))\)
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
281
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
282 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
283 :type '(repeat symbol)
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
284 :group 'whitespace)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
285
29333
189f70e66cab Update whitespace.el with a more tolerable timer scan time.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 27583
diff changeset
286 (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
287 "Period in seconds to rescan modified buffers for whitespace creep.
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
288
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
289 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
290 `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
291 modified buffers.
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
292
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
293 To disable timer scans, set this to zero."
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
294 :type 'integer
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
295 :group 'whitespace)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
296
26245
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
297 (defcustom whitespace-display-in-modeline t
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
298 "Display whitespace errors on the modeline."
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
299 :type 'boolean
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
300 :group 'whitespace)
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
301
42013
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
302 (defcustom whitespace-display-spaces-in-color t
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
303 "Display the bogus whitespaces by coloring them with
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
304 `whitespace-highlight-face'."
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
305 :type 'boolean
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
306 :group 'whitespace)
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
307
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
308 (defgroup whitespace-faces nil
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
309 "Faces used in whitespace."
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
310 :prefix "whitespace-"
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
311 :group 'whitespace
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
312 :group 'faces)
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
313
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
314 (defface whitespace-highlight-face '((((class color) (background light))
48631
37ddf84a7528 (whitespace-highlight-face): Fix face spec.
Andreas Schwab <schwab@suse.de>
parents: 47454
diff changeset
315 (:background "green"))
37ddf84a7528 (whitespace-highlight-face): Fix face spec.
Andreas Schwab <schwab@suse.de>
parents: 47454
diff changeset
316 (((class color) (background dark))
37ddf84a7528 (whitespace-highlight-face): Fix face spec.
Andreas Schwab <schwab@suse.de>
parents: 47454
diff changeset
317 (:background "sea green"))
37ddf84a7528 (whitespace-highlight-face): Fix face spec.
Andreas Schwab <schwab@suse.de>
parents: 47454
diff changeset
318 (((class grayscale mono)
37ddf84a7528 (whitespace-highlight-face): Fix face spec.
Andreas Schwab <schwab@suse.de>
parents: 47454
diff changeset
319 (background light))
37ddf84a7528 (whitespace-highlight-face): Fix face spec.
Andreas Schwab <schwab@suse.de>
parents: 47454
diff changeset
320 (:background "black"))
37ddf84a7528 (whitespace-highlight-face): Fix face spec.
Andreas Schwab <schwab@suse.de>
parents: 47454
diff changeset
321 (((class grayscale mono)
37ddf84a7528 (whitespace-highlight-face): Fix face spec.
Andreas Schwab <schwab@suse.de>
parents: 47454
diff changeset
322 (background dark))
37ddf84a7528 (whitespace-highlight-face): Fix face spec.
Andreas Schwab <schwab@suse.de>
parents: 47454
diff changeset
323 (:background "white")))
42013
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
324 "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
325 :group 'whitespace-faces)
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
326
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
327 (if (not (assoc 'whitespace-mode minor-mode-alist))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
328 (setq minor-mode-alist (cons '(whitespace-mode whitespace-mode-line)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
329 minor-mode-alist)))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
330
36944
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-leading
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
332 whitespace-check-leading-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-trailing
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
334 whitespace-check-trailing-whitespace)
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
335 (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
336 whitespace-check-indent-whitespace)
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
337 (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
338 whitespace-check-spacetab-whitespace)
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
339 (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
340 whitespace-check-ateol-whitespace)
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
341
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
342 (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
343 "Test and set the whitespace-mode in qualifying buffers."
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
344 (if (null whitespace-mode)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
345 (setq whitespace-mode
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
346 (if (or arg (member major-mode whitespace-modes))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
347 t
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
348 nil))))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
349
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
350 ;;;###autoload
36944
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
351 (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
352 "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
353 (interactive)
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
354 (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
355 (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
356 (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
357 (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
358 (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
359
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
360 ;;;###autoload
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
361 (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
362 "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
363 (interactive)
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
364 (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
365 (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
366 (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
367 (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
368 (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
369
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
370 ;;;###autoload
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
371 (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
372 "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
373 (interactive)
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
374 (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
375 (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
376 (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
377 (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
378 (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
379 (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
380
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
381 ;;;###autoload
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
382 (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
383 "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
384 (interactive)
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
385 (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
386 (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
387 (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
388 (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
389 (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
390 (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
391
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
392
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
393 ;;;###autoload
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
394 (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
395 "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
396 (interactive)
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
397 (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
398 (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
399 (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
400 (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
401 (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
402 (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
403
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
404
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
405 ;;;###autoload
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
406 (defun whitespace-buffer (&optional quiet)
32501
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
407 "Find five different types of white spaces in buffer.
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
408 These are:
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
409 1. Leading space \(empty lines at the top of a file\).
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
410 2. Trailing space \(empty lines at the end of a file\).
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
411 3. Indentation space \(8 or more spaces, that should be replaced with TABS\).
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
412 4. Spaces followed by a TAB. \(Almost always, we never want that\).
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
413 5. Spaces or TABS at the end of a line.
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
414
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
415 Check for whitespace only if this buffer really contains a non-empty file
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
416 and:
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
417 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
418 2. `whitespace-buffer' was explicitly called with a prefix argument."
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
419 (interactive)
26245
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
420 (let ((whitespace-error nil))
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
421 (whitespace-check-whitespace-mode current-prefix-arg)
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
422 (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
423 (progn
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
424 (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
425 (whitespace-tickle-timer)
42013
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
426 (whitespace-unhighlight-the-space)
26245
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
427 (if whitespace-auto-cleanup
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
428 (if buffer-read-only
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
429 (if (not quiet)
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
430 (message "Can't cleanup: %s is read-only" (buffer-name)))
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
431 (whitespace-cleanup))
36944
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
432 (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
433 (whitespace-buffer-leading)
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
434 nil))
36944
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
435 (whitespace-trailing (if whitespace-check-buffer-trailing
26245
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
436 (whitespace-buffer-trailing)
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
437 nil))
36944
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
438 (whitespace-indent (if whitespace-check-buffer-indent
26245
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
439 (whitespace-buffer-search
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
440 whitespace-indent-regexp)
25724
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
441 nil))
36944
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
442 (whitespace-spacetab (if whitespace-check-buffer-spacetab
26245
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
443 (whitespace-buffer-search
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
444 whitespace-spacetab-regexp)
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
445 nil))
36944
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
446 (whitespace-ateol (if whitespace-check-buffer-ateol
26245
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
447 (whitespace-buffer-search
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
448 whitespace-ateol-regexp)
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
449 nil))
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
450 (whitespace-errmsg nil)
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
451 (whitespace-filename buffer-file-name)
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
452 (whitespace-this-modeline ""))
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 ;; 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
455 (setq whitespace-error (or whitespace-leading whitespace-indent
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
456 whitespace-spacetab whitespace-ateol
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
457 whitespace-trailing))
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
458
26245
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
459 (if whitespace-error
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
460 (progn
26245
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
461 (setq whitespace-errmsg
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
462 (concat whitespace-filename " contains:\n"
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
463 (if whitespace-leading
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
464 "Leading whitespace\n")
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
465 (if whitespace-indent
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
466 (concat "Indentation whitespace"
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
467 whitespace-indent "\n"))
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
468 (if whitespace-spacetab
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
469 (concat "Space followed by Tab"
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
470 whitespace-spacetab "\n"))
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
471 (if whitespace-ateol
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
472 (concat "End-of-line whitespace"
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
473 whitespace-ateol "\n"))
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
474 (if whitespace-trailing
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
475 "Trailing whitespace\n")
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
476 "\ntype `M-x whitespace-cleanup' to "
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
477 "cleanup the file."))
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
478 (setq whitespace-this-modeline
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
479 (concat (if whitespace-ateol "e")
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
480 (if whitespace-indent "i")
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
481 (if whitespace-leading "l")
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
482 (if whitespace-spacetab "s")
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
483 (if whitespace-trailing "t")))))
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
484 (whitespace-update-modeline whitespace-this-modeline)
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
485 (save-excursion
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
486 (get-buffer-create whitespace-errbuf)
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
487 (kill-buffer whitespace-errbuf)
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
488 (get-buffer-create whitespace-errbuf)
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
489 (set-buffer whitespace-errbuf)
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
490 (if whitespace-errmsg
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
491 (progn
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
492 (insert whitespace-errmsg)
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
493 (if (not (or quiet whitespace-silent))
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
494 (display-buffer whitespace-errbuf t))
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
495 (if (not quiet)
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
496 (message "Whitespaces: [%s%s] in %s"
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
497 whitespace-this-modeline
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
498 (let ((whitespace-unchecked
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
499 (whitespace-unchecked-whitespaces)))
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
500 (if whitespace-unchecked
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
501 (concat "!" whitespace-unchecked)
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
502 ""))
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
503 whitespace-filename)))
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
504 (if (not quiet)
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
505 (message "%s clean" whitespace-filename))))))))
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
506 (if whitespace-error
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
507 t
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
508 nil)))
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
509
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
510 ;;;###autoload
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
511 (defun whitespace-region (s e)
32501
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
512 "Check the region for whitespace errors."
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
513 (interactive "r")
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
514 (save-excursion
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
515 (save-restriction
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
516 (narrow-to-region s e)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
517 (whitespace-buffer))))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
518
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
519 ;;;###autoload
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
520 (defun whitespace-cleanup ()
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
521 "Cleanup the five different kinds of whitespace problems.
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
522
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
523 Use \\[describe-function] whitespace-describe to read a summary of the
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
524 whitespace problems."
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
525 (interactive)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
526 ;; If this buffer really contains a file, then run, else quit.
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
527 (whitespace-check-whitespace-mode current-prefix-arg)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
528 (if (and buffer-file-name whitespace-mode)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
529 (let ((whitespace-any nil)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
530 (whitespace-tabwith 8)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
531 (whitespace-tabwith-saved tab-width))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
532
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
533 ;; since all printable TABS should be 8, irrespective of how
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
534 ;; they are displayed.
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
535 (setq tab-width whitespace-tabwith)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
536
36944
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
537 (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
538 (whitespace-buffer-leading))
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
539 (progn
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
540 (whitespace-buffer-leading-cleanup)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
541 (setq whitespace-any t)))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
542
36944
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
543 (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
544 (whitespace-buffer-trailing))
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
545 (progn
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
546 (whitespace-buffer-trailing-cleanup)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
547 (setq whitespace-any t)))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
548
36944
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
549 (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
550 (whitespace-buffer-search whitespace-indent-regexp))
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
551 (progn
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
552 (whitespace-indent-cleanup)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
553 (setq whitespace-any t)))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
554
36944
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
555 (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
556 (whitespace-buffer-search whitespace-spacetab-regexp))
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
557 (progn
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
558 (whitespace-buffer-cleanup whitespace-spacetab-regexp "\t")
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
559 (setq whitespace-any t)))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
560
36944
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
561 (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
562 (whitespace-buffer-search whitespace-ateol-regexp))
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
563 (progn
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
564 (whitespace-buffer-cleanup whitespace-ateol-regexp "")
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
565 (setq whitespace-any t)))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
566
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
567 ;; 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
568 (if whitespace-any
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
569 (whitespace-cleanup)
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
570 (progn
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
571 (message "%s clean" buffer-file-name)
26245
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
572 (whitespace-update-modeline)))
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
573 (setq tab-width whitespace-tabwith-saved))))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
574
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
575 ;;;###autoload
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
576 (defun whitespace-cleanup-region (s e)
32501
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
577 "Whitespace cleanup on the region."
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
578 (interactive "r")
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
579 (save-excursion
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
580 (save-restriction
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
581 (narrow-to-region s e)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
582 (whitespace-cleanup))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
583 (whitespace-buffer t)))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
584
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
585 (defun whitespace-buffer-leading ()
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
586 "Check to see if there are any empty lines at the top of the file."
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
587 (save-excursion
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
588 (let ((pmin nil)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
589 (pmax nil))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
590 (goto-char (point-min))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
591 (beginning-of-line)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
592 (setq pmin (point))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
593 (end-of-line)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
594 (setq pmax (point))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
595 (if (equal pmin pmax)
42013
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
596 (progn
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
597 (whitespace-highlight-the-space pmin pmax)
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
598 t)
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
599 nil))))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
600
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
601 (defun whitespace-buffer-leading-cleanup ()
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
602 "Remove any empty lines at the top of the file."
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
603 (save-excursion
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
604 (let ((pmin nil)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
605 (pmax nil))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
606 (goto-char (point-min))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
607 (beginning-of-line)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
608 (setq pmin (point))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
609 (end-of-line)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
610 (setq pmax (point))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
611 (if (equal pmin pmax)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
612 (progn
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
613 (kill-line)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
614 (whitespace-buffer-leading-cleanup))))))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
615
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
616 (defun whitespace-buffer-trailing ()
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
617 "Check to see if are is more than one empty line at the bottom."
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
618 (save-excursion
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
619 (let ((pmin nil)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
620 (pmax nil))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
621 (goto-char (point-max))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
622 (beginning-of-line)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
623 (setq pmin (point))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
624 (end-of-line)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
625 (setq pmax (point))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
626 (if (equal pmin pmax)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
627 (progn
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
628 (goto-char (- (point) 1))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
629 (beginning-of-line)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
630 (setq pmin (point))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
631 (end-of-line)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
632 (setq pmax (point))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
633 (if (equal pmin pmax)
42013
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
634 (progn
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
635 (whitespace-highlight-the-space pmin pmax)
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
636 t)
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
637 nil))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
638 nil))))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
639
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
640 (defun whitespace-buffer-trailing-cleanup ()
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
641 "Delete all the empty lines at the bottom."
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
642 (save-excursion
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
643 (let ((pmin nil)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
644 (pmax nil))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
645 (goto-char (point-max))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
646 (beginning-of-line)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
647 (setq pmin (point))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
648 (end-of-line)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
649 (setq pmax (point))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
650 (if (equal pmin pmax)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
651 (progn
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
652 (goto-char (1- pmin))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
653 (beginning-of-line)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
654 (setq pmin (point))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
655 (end-of-line)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
656 (setq pmax (point))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
657 (if (equal pmin pmax)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
658 (progn
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
659 (goto-char (1- (point-max)))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
660 (beginning-of-line)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
661 (kill-line)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
662 (whitespace-buffer-trailing-cleanup))))))))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
663
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
664 (defun whitespace-buffer-search (regexp)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
665 "Search for any given whitespace REGEXP."
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
666 (let ((whitespace-retval ""))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
667 (save-excursion
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
668 (goto-char (point-min))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
669 (while (re-search-forward regexp nil t)
42013
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
670 (progn
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
671 (setq whitespace-retval (format "%s %s" whitespace-retval
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
672 (match-beginning 0)))
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
673 (whitespace-highlight-the-space (match-beginning 0) (match-end 0))))
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
674 (if (equal "" whitespace-retval)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
675 nil
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
676 whitespace-retval))))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
677
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
678 (defun whitespace-buffer-cleanup (regexp newregexp)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
679 "Search for any given whitespace REGEXP and replace it with the NEWREGEXP."
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
680 (save-excursion
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
681 (goto-char (point-min))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
682 (while (re-search-forward regexp nil t)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
683 (replace-match newregexp))))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
684
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
685 (defun whitespace-indent-cleanup ()
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
686 "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
687 (save-excursion
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
688 (goto-char (point-min))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
689 (while (re-search-forward whitespace-indent-regexp nil t)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
690 (let ((column (current-column))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
691 (indent-tabs-mode t))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
692 (delete-region (match-beginning 0) (point))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
693 (indent-to column)))))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
694
26245
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
695 (defun whitespace-unchecked-whitespaces ()
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
696 "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
697 (let ((unchecked-spaces
4d294c5bb2ac whitespace.el version 3.0 with buffer local toggle capability.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 35050
diff changeset
698 (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
699 (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
700 (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
701 (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
702 (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
703 (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
704 unchecked-spaces
26245
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
705 nil)))
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
706
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
707 (defun whitespace-update-modeline (&optional whitespace-err)
32501
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
708 "Update modeline with whitespace errors.
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
709 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
710 (if whitespace-display-in-modeline
26259
912b004387d9 (whitespace-update-modeline): Bugfix to ensure
Gerd Moellmann <gerd@gnu.org>
parents: 26253
diff changeset
711 (progn
912b004387d9 (whitespace-update-modeline): Bugfix to ensure
Gerd Moellmann <gerd@gnu.org>
parents: 26253
diff changeset
712 (setq whitespace-mode-line nil)
912b004387d9 (whitespace-update-modeline): Bugfix to ensure
Gerd Moellmann <gerd@gnu.org>
parents: 26253
diff changeset
713 ;; Whitespace errors
912b004387d9 (whitespace-update-modeline): Bugfix to ensure
Gerd Moellmann <gerd@gnu.org>
parents: 26253
diff changeset
714 (if (and whitespace-err (not (equal whitespace-err "")))
912b004387d9 (whitespace-update-modeline): Bugfix to ensure
Gerd Moellmann <gerd@gnu.org>
parents: 26253
diff changeset
715 (setq whitespace-mode-line whitespace-err))
912b004387d9 (whitespace-update-modeline): Bugfix to ensure
Gerd Moellmann <gerd@gnu.org>
parents: 26253
diff changeset
716 ;; Whitespace suppressed errors
912b004387d9 (whitespace-update-modeline): Bugfix to ensure
Gerd Moellmann <gerd@gnu.org>
parents: 26253
diff changeset
717 (let ((whitespace-unchecked (whitespace-unchecked-whitespaces)))
912b004387d9 (whitespace-update-modeline): Bugfix to ensure
Gerd Moellmann <gerd@gnu.org>
parents: 26253
diff changeset
718 (if whitespace-unchecked
912b004387d9 (whitespace-update-modeline): Bugfix to ensure
Gerd Moellmann <gerd@gnu.org>
parents: 26253
diff changeset
719 (setq whitespace-mode-line
912b004387d9 (whitespace-update-modeline): Bugfix to ensure
Gerd Moellmann <gerd@gnu.org>
parents: 26253
diff changeset
720 (concat whitespace-mode-line "!" whitespace-unchecked))))
912b004387d9 (whitespace-update-modeline): Bugfix to ensure
Gerd Moellmann <gerd@gnu.org>
parents: 26253
diff changeset
721 ;; Add the whitespace modeline prefix
912b004387d9 (whitespace-update-modeline): Bugfix to ensure
Gerd Moellmann <gerd@gnu.org>
parents: 26253
diff changeset
722 (setq whitespace-mode-line (if whitespace-mode-line
912b004387d9 (whitespace-update-modeline): Bugfix to ensure
Gerd Moellmann <gerd@gnu.org>
parents: 26253
diff changeset
723 (concat " W:" whitespace-mode-line)
912b004387d9 (whitespace-update-modeline): Bugfix to ensure
Gerd Moellmann <gerd@gnu.org>
parents: 26253
diff changeset
724 nil))
42013
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
725 (whitespace-mode-line-update))))
25724
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
726
42013
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
727 (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
728 "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
729 (if whitespace-display-spaces-in-color
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
730 (progn
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
731 (whitespace-unhighlight-the-space)
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
732 (add-to-list 'whitespace-highlighted-space
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
733 (whitespace-make-overlay b e))
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
734 (whitespace-overlay-put (whitespace-make-overlay b e) 'face
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
735 'whitespace-highlight-face))))
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
736 ;; (add-hook 'pre-command-hook 'whitespace-unhighlight-the-space))
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
737
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
738 (defun whitespace-unhighlight-the-space ()
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
739 "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
740 (if (and whitespace-display-spaces-in-color whitespace-highlighted-space)
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
741 (let ((whitespace-this-space nil))
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
742 (while whitespace-highlighted-space
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
743 (setq whitespace-this-space (car whitespace-highlighted-space))
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
744 (setq whitespace-highlighted-space
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
745 (cdr whitespace-highlighted-space))
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
746 (whitespace-delete-overlay whitespace-this-space))
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
747 (setq whitespace-highlighted-space nil))
0ad4d3e3bfe6 Whitespace.el v3.2 for colorized display of bogus whitespaces.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38882
diff changeset
748 (remove-hook 'pre-command-hook 'whitespace-unhighlight-the-space)))
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
749
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
750 (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
751 "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
752
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
753 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
754 periodically for whitespace."
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
755 (if (and whitespace-mode (not (member (list buf-file buf-name)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
756 whitespace-all-buffer-files)))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
757 (add-to-list 'whitespace-all-buffer-files (list buf-file buf-name))))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
758
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
759 (defun whitespace-tickle-timer ()
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
760 "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
761
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
762 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
763 `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
764 `whitespace-rescan-timer-time') for whitespace creep."
25724
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
765 (if (and whitespace-rescan-timer-time (not whitespace-rescan-timer))
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
766 (setq whitespace-rescan-timer
32501
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
767 (add-timeout whitespace-rescan-timer-time
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
768 'whitespace-rescan-files-in-buffers nil
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
769 whitespace-rescan-timer-time))))
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
770
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
771 (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
772 "Check monitored files for whitespace creep since last scan."
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
773 (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
774 buffile bufname thiselt buf)
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
775 (if (not whitespace-all-my-files)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
776 (progn
32501
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
777 (disable-timeout whitespace-rescan-timer)
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
778 (setq whitespace-rescan-timer nil))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
779 (while whitespace-all-my-files
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
780 (setq thiselt (car whitespace-all-my-files))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
781 (setq whitespace-all-my-files (cdr whitespace-all-my-files))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
782 (setq buffile (car thiselt))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
783 (setq bufname (cadr thiselt))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
784 (setq buf (get-buffer bufname))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
785 (if (buffer-live-p buf)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
786 (save-excursion
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
787 ;;(message "buffer %s live" bufname)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
788 (set-buffer bufname)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
789 (if whitespace-mode
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
790 (progn
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
791 ;;(message "checking for whitespace in %s" bufname)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
792 (if whitespace-auto-cleanup
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
793 (progn
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
794 ;;(message "cleaning up whitespace in %s" bufname)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
795 (whitespace-cleanup))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
796 (progn
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
797 ;;(message "whitespace-buffer %s." (buffer-name))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
798 (whitespace-buffer t))))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
799 ;;(message "Removing %s from refresh list" bufname)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
800 (whitespace-refresh-rescan-list buffile bufname)))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
801 ;;(message "Removing %s from refresh list" bufname)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
802 (whitespace-refresh-rescan-list buffile bufname))))))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
803
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
804 (defun whitespace-refresh-rescan-list (buffile bufname)
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
805 "Refresh the list of files to be rescaned for whitespace creep."
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
806 (if whitespace-all-buffer-files
32501
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
807 (setq whitespace-all-buffer-files
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
808 (delete (list buffile bufname) whitespace-all-buffer-files))
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
809 (when whitespace-rescan-timer
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
810 (disable-timeout whitespace-rescan-timer)
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
811 (setq whitespace-rescan-timer nil))))
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
812
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
813 ;;;###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
814 (define-minor-mode whitespace-global-mode
32501
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
815 "Toggle using Whitespace mode in new buffers.
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
816 With ARG, turn the mode on if and only iff ARG is positive.
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
817
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
818 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
819 `find-file-hook' and `kill-buffer-hook'."
b7a8fec8113c (whitespace-global-mode): Use define-minor-mode. Use the new file hook names.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42013
diff changeset
820 :global t :group '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
821 (if whitespace-global-mode
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
822 (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
823 (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
824 (add-hook 'write-file-functions 'whitespace-write-file-hook nil t)
32501
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
825 (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
826 (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
827 (remove-hook 'write-file-functions 'whitespace-write-file-hook t)
32501
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
828 (remove-hook 'kill-buffer-hook 'whitespace-buffer)))
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
829
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
830 ;;;###autoload
38882
ceec599316a4 whitespace 3.1
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38874
diff changeset
831 (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
832 "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
833 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
834 (interactive)
ceec599316a4 whitespace 3.1
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38874
diff changeset
835 (let ((werr nil))
ceec599316a4 whitespace 3.1
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38874
diff changeset
836 (if whitespace-auto-cleanup
ceec599316a4 whitespace 3.1
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38874
diff changeset
837 (whitespace-cleanup)
ceec599316a4 whitespace 3.1
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38874
diff changeset
838 (setq werr (whitespace-buffer)))
ceec599316a4 whitespace 3.1
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38874
diff changeset
839 (if (and whitespace-abort-on-error werr)
ceec599316a4 whitespace 3.1
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38874
diff changeset
840 (error (concat "Abort write due to whitespaces in "
ceec599316a4 whitespace 3.1
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38874
diff changeset
841 buffer-file-name))))
ceec599316a4 whitespace 3.1
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38874
diff changeset
842 nil)
ceec599316a4 whitespace 3.1
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 38874
diff changeset
843
32501
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
844 (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
845 (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
846 (remove-hook 'write-file-functions 'whitespace-write-file-hook t)
32501
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
847 (remove-hook 'kill-buffer-hook 'whitespace-buffer))
616755d12f93 Doc fixes.
Dave Love <fx@gnu.org>
parents: 29499
diff changeset
848
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
849 (provide 'whitespace)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
850 ;;; whitespace.el ends here