annotate lisp/whitespace.el @ 29720:a297debe5d12

*** empty log message ***
author Kenichi Handa <handa@m17n.org>
date Mon, 19 Jun 2000 05:04:49 +0000
parents a293ec8516e0
children 616755d12f93
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
1 ;;; whitespace.el --- Warn about and clean bogus whitespaces in the file.
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
2
29499
a293ec8516e0 Update whitespace.el - comment out the :version string, since it
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 29333
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
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
9
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
13 ;; any later version.
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
14
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
18 ;; GNU General Public License for more details.
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
19
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
23 ;; Boston, MA 02111-1307, USA.
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
24
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
25 ;;; Commentary:
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
26
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
27 ;; Whitespace.el URL: http://www.dsmit.com/lisp/
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
28
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
29 ;; Exported functions:
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
30
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
31 ;; `whitespace-buffer' - To check the current buffer for whitespace problems.
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
32 ;; `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
33 ;; `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
34 ;; problems.
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
35 ;; `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
36 ;; and mark in the current buffer.
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
37 ;; `whitespace-describe' - A simple introduction to the library.
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
38
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
39 ;;; Code:
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
40
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
41 ;; add a hook to find-file-hooks and kill-buffer-hook
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
42 (add-hook 'find-file-hooks 'whitespace-buffer)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
43 (add-hook 'kill-buffer-hook 'whitespace-buffer)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
44
26253
3bb622df1c52 (whitespace-version): Update to 2.8
Gerd Moellmann <gerd@gnu.org>
parents: 26245
diff changeset
45 (defvar whitespace-version "2.8" "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
46 ;; Find out what type of Emacs we are running in.
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
47 (defvar whitespace-running-emacs (if (string-match "XEmacs\\|Lucid"
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
48 emacs-version) nil t)
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
49 "If this is Emacs, not XEmacs, this is t.")
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
50
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
51 (if whitespace-running-emacs (require 'timer))
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
52
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
53 (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
54 "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
55
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
56 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
57 visited by the buffers.")
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
58
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
59 (defvar whitespace-rescan-timer nil
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
60 "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
61
26245
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
62 ;; 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
63 (defvar whitespace-mode nil
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
64 "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
65 (make-variable-buffer-local 'whitespace-mode)
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
66 (put 'whitespace-mode 'permanent-local nil)
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
67
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
68 (defvar whitespace-mode-line nil
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
69 "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
70 (make-variable-buffer-local 'whitespace-mode-line)
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
71 (put 'whitespace-mode-line 'permanent-local nil)
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
72
26253
3bb622df1c52 (whitespace-version): Update to 2.8
Gerd Moellmann <gerd@gnu.org>
parents: 26245
diff changeset
73 ;; 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
74 (eval-when-compile
26253
3bb622df1c52 (whitespace-version): Update to 2.8
Gerd Moellmann <gerd@gnu.org>
parents: 26245
diff changeset
75 (if (not (fboundp 'defgroup))
3bb622df1c52 (whitespace-version): Update to 2.8
Gerd Moellmann <gerd@gnu.org>
parents: 26245
diff changeset
76 (defmacro defgroup (sym memb doc &rest args)
3bb622df1c52 (whitespace-version): Update to 2.8
Gerd Moellmann <gerd@gnu.org>
parents: 26245
diff changeset
77 "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
78 defgroup"
3bb622df1c52 (whitespace-version): Update to 2.8
Gerd Moellmann <gerd@gnu.org>
parents: 26245
diff changeset
79 t))
3bb622df1c52 (whitespace-version): Update to 2.8
Gerd Moellmann <gerd@gnu.org>
parents: 26245
diff changeset
80 (if (not (fboundp 'defcustom))
3bb622df1c52 (whitespace-version): Update to 2.8
Gerd Moellmann <gerd@gnu.org>
parents: 26245
diff changeset
81 (defmacro defcustom (sym val doc &rest args)
3bb622df1c52 (whitespace-version): Update to 2.8
Gerd Moellmann <gerd@gnu.org>
parents: 26245
diff changeset
82 "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
83 don't define defcustom"
3bb622df1c52 (whitespace-version): Update to 2.8
Gerd Moellmann <gerd@gnu.org>
parents: 26245
diff changeset
84 `(defvar ,sym ,val ,doc))))
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
85
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
86 (defgroup whitespace nil
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
87 "Check for and fix five different types of whitespaces in source code."
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
88 ;; Since XEmacs doesn't have a 'convenience group, use the next best group
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
89 ;; which is 'editing?
29499
a293ec8516e0 Update whitespace.el - comment out the :version string, since it
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 29333
diff changeset
90 ;; :version "21.1"
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
91 :group (if whitespace-running-emacs 'convenience 'editing))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
92
25724
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
93 (defcustom whitespace-check-leading-whitespace t
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
94 "Flag to check leading whitespace."
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
95 :type 'boolean
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
96 :group 'whitespace)
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
97
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
98 (defcustom whitespace-check-trailing-whitespace t
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
99 "Flag to check trailing whitespace."
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
100 :type 'boolean
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
101 :group 'whitespace)
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
102
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
103 (defcustom whitespace-check-spacetab-whitespace t
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
104 "Flag to check space followed by a TAB."
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
105 :type 'boolean
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
106 :group 'whitespace)
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
107
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
108 (defcustom whitespace-spacetab-regexp " \t"
25724
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
109 "Regexp to match a space followed by a TAB."
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
110 :type 'string
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
111 :group 'whitespace)
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
112
25724
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
113 (defcustom whitespace-check-indent-whitespace t
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
114 "Flag to check indentation whitespace."
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
115 :type 'boolean
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
116 :group 'whitespace)
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
117
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
118 (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
119 "Regexp to match (any TABS followed by) 8/more whitespaces at start of line."
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
120 :type 'string
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
121 :group 'whitespace)
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
122
25724
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
123 (defcustom whitespace-check-ateol-whitespace t
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
124 "Flag to check end-of-line whitespace."
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
125 :type 'boolean
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
126 :group 'whitespace)
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
127
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
128 (defcustom whitespace-ateol-regexp "[ \t]$"
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
129 "Regexp to match a TAB or a space at the EOL."
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
130 :type 'string
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
131 :group 'whitespace)
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
132
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
133 (defcustom whitespace-errbuf "*Whitespace Errors*"
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
134 "The buffer where whitespace related messages will be logged."
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
135 :type 'string
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
136 :group 'whitespace)
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
137
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
138 (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
139 "Cleanup a buffer automatically on finding it whitespace unclean."
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
140 :type 'boolean
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
141 :group 'whitespace)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
142
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
143 (defcustom whitespace-silent nil
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
144 "All whitespace errors will be shown only in the modeline when t.
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
145
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
146 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
147 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
148 Errors*' buffer before opening (or closing) another file."
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
149 :type 'boolean
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
150 :group 'whitespace)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
151
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
152 (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
153 c-mode c++-mode cc-mode
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
154 change-log-mode cperl-mode
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
155 electric-nroff-mode emacs-lisp-mode
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
156 f90-mode fortran-mode html-mode
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
157 html3-mode java-mode jde-mode
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
158 ksh-mode latex-mode LaTeX-mode
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
159 lisp-mode m4-mode makefile-mode
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
160 modula-2-mode nroff-mode objc-mode
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
161 pascal-mode perl-mode prolog-mode
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
162 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
163 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
164 tcl-mode tex-mode texinfo-mode
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
165 vrml-mode xml-mode)
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
166
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
167 "Major Modes in which we turn on whitespace checking.
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
168
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
169 These are mostly programming and documentation modes. But you may add other
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
170 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
171 following to your `.emacs':
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
172
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
173 \(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
174 whitespace-modes))\)
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
175
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
176 Or, alternately, you can use the Emacs `customize' command to set this."
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
177 :group 'whitespace)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
178
29333
189f70e66cab Update whitespace.el with a more tolerable timer scan time.
Rajesh Vaidheeswarran <rv@gnu.org>
parents: 27583
diff changeset
179 (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
180 "Period in seconds to rescan modified buffers for whitespace creep.
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
181
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
182 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
183 `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
184 modified buffers.
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
185
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
186 To disable timer scans, set this to zero."
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
187 :type 'integer
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
188 :group 'whitespace)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
189
26245
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
190 (defcustom whitespace-display-in-modeline t
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
191 "Display whitespace errors on the modeline."
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
192 :type 'boolean
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
193 :group 'whitespace)
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
194
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
195 (if (not (assoc 'whitespace-mode minor-mode-alist))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
196 (setq minor-mode-alist (cons '(whitespace-mode whitespace-mode-line)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
197 minor-mode-alist)))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
198
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
199 (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
200 "Test and set the whitespace-mode in qualifying buffers."
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
201 (if (null whitespace-mode)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
202 (setq whitespace-mode
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
203 (if (or arg (member major-mode whitespace-modes))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
204 t
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
205 nil))))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
206
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
207 ;;;###autoload
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
208 (defun whitespace-buffer (&optional quiet)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
209 "Find five different types of white spaces in buffer:
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
210
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
211 1. Leading space \(empty lines at the top of a file\).
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
212 2. Trailing space \(empty lines at the end of a file\).
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
213 3. Indentation space \(8 or more spaces, that should be replaced with TABS\).
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
214 4. Spaces followed by a TAB. \(Almost always, we never want that\).
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
215 5. Spaces or TABS at the end of a line.
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
216
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
217 Check for whitespace only if this buffer really contains a non-empty file
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
218 and:
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
219 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
220 2. `whitespace-buffer' was explicitly called with a prefix argument."
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
221 (interactive)
26245
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
222 (let ((whitespace-error nil))
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
223 (whitespace-check-whitespace-mode current-prefix-arg)
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
224 (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
225 (progn
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
226 (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
227 (whitespace-tickle-timer)
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
228 (if whitespace-auto-cleanup
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
229 (if buffer-read-only
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
230 (if (not quiet)
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
231 (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
232 (whitespace-cleanup))
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
233 (let ((whitespace-leading (if whitespace-check-leading-whitespace
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
234 (whitespace-buffer-leading)
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
235 nil))
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
236 (whitespace-trailing (if whitespace-check-trailing-whitespace
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
237 (whitespace-buffer-trailing)
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
238 nil))
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
239 (whitespace-indent (if whitespace-check-indent-whitespace
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
240 (whitespace-buffer-search
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
241 whitespace-indent-regexp)
25724
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
242 nil))
26245
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
243 (whitespace-spacetab (if whitespace-check-spacetab-whitespace
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
244 (whitespace-buffer-search
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
245 whitespace-spacetab-regexp)
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
246 nil))
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
247 (whitespace-ateol (if whitespace-check-ateol-whitespace
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
248 (whitespace-buffer-search
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
249 whitespace-ateol-regexp)
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
250 nil))
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
251 (whitespace-errmsg nil)
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
252 (whitespace-filename buffer-file-name)
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
253 (whitespace-this-modeline ""))
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
254
26245
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
255 ;; 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
256 (setq whitespace-error (or whitespace-leading whitespace-indent
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
257 whitespace-spacetab whitespace-ateol
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
258 whitespace-trailing))
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
259
26245
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
260 (if whitespace-error
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
261 (progn
26245
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
262 (setq whitespace-errmsg
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
263 (concat whitespace-filename " contains:\n"
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
264 (if whitespace-leading
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
265 "Leading whitespace\n")
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
266 (if whitespace-indent
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
267 (concat "Indentation whitespace"
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
268 whitespace-indent "\n"))
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
269 (if whitespace-spacetab
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
270 (concat "Space followed by Tab"
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
271 whitespace-spacetab "\n"))
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
272 (if whitespace-ateol
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
273 (concat "End-of-line whitespace"
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
274 whitespace-ateol "\n"))
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
275 (if whitespace-trailing
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
276 "Trailing whitespace\n")
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
277 "\ntype `M-x whitespace-cleanup' to "
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
278 "cleanup the file."))
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
279 (setq whitespace-this-modeline
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
280 (concat (if whitespace-ateol "e")
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
281 (if whitespace-indent "i")
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
282 (if whitespace-leading "l")
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
283 (if whitespace-spacetab "s")
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
284 (if whitespace-trailing "t")))))
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
285 (whitespace-update-modeline whitespace-this-modeline)
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
286 (save-excursion
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
287 (get-buffer-create whitespace-errbuf)
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
288 (kill-buffer whitespace-errbuf)
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
289 (get-buffer-create whitespace-errbuf)
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
290 (set-buffer whitespace-errbuf)
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
291 (if whitespace-errmsg
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
292 (progn
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
293 (insert whitespace-errmsg)
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
294 (if (not (or quiet whitespace-silent))
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
295 (display-buffer whitespace-errbuf t))
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
296 (if (not quiet)
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
297 (message "Whitespaces: [%s%s] in %s"
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
298 whitespace-this-modeline
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
299 (let ((whitespace-unchecked
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
300 (whitespace-unchecked-whitespaces)))
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
301 (if whitespace-unchecked
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
302 (concat "!" whitespace-unchecked)
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
303 ""))
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
304 whitespace-filename)))
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
305 (if (not quiet)
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
306 (message "%s clean" whitespace-filename))))))))
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
307 (if whitespace-error
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
308 t
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
309 nil)))
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
310
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
311 ;;;###autoload
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
312 (defun whitespace-region (s e)
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
313 "Check a region specified by point and mark for whitespace errors."
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
314 (interactive "r")
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
315 (save-excursion
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
316 (save-restriction
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
317 (narrow-to-region s e)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
318 (whitespace-buffer))))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
319
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
320 ;;;###autoload
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
321 (defun whitespace-cleanup ()
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
322 "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
323
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
324 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
325 whitespace problems."
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
326 (interactive)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
327 ;; If this buffer really contains a file, then run, else quit.
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
328 (whitespace-check-whitespace-mode current-prefix-arg)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
329 (if (and buffer-file-name whitespace-mode)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
330 (let ((whitespace-any nil)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
331 (whitespace-tabwith 8)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
332 (whitespace-tabwith-saved tab-width))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
333
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
334 ;; since all printable TABS should be 8, irrespective of how
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
335 ;; they are displayed.
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
336 (setq tab-width whitespace-tabwith)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
337
25724
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
338 (if (and whitespace-check-leading-whitespace
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
339 (whitespace-buffer-leading))
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
340 (progn
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
341 (whitespace-buffer-leading-cleanup)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
342 (setq whitespace-any t)))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
343
25724
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
344 (if (and whitespace-check-trailing-whitespace
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
345 (whitespace-buffer-trailing))
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
346 (progn
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
347 (whitespace-buffer-trailing-cleanup)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
348 (setq whitespace-any t)))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
349
25724
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
350 (if (and whitespace-check-indent-whitespace
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
351 (whitespace-buffer-search whitespace-indent-regexp))
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
352 (progn
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
353 (whitespace-indent-cleanup)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
354 (setq whitespace-any t)))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
355
25724
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
356 (if (and whitespace-check-spacetab-whitespace
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
357 (whitespace-buffer-search whitespace-spacetab-regexp))
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
358 (progn
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
359 (whitespace-buffer-cleanup whitespace-spacetab-regexp "\t")
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
360 (setq whitespace-any t)))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
361
25724
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
362 (if (and whitespace-check-ateol-whitespace
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
363 (whitespace-buffer-search whitespace-ateol-regexp))
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
364 (progn
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
365 (whitespace-buffer-cleanup whitespace-ateol-regexp "")
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
366 (setq whitespace-any t)))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
367
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
368 ;; 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
369 (if whitespace-any
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
370 (whitespace-cleanup)
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
371 (progn
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
372 (message "%s clean" buffer-file-name)
26245
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
373 (whitespace-update-modeline)))
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
374 (setq tab-width whitespace-tabwith-saved))))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
375
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
376 ;;;###autoload
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
377 (defun whitespace-cleanup-region (s e)
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
378 "Whitespace cleanup on a region specified by point and mark."
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
379 (interactive "r")
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
380 (save-excursion
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
381 (save-restriction
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
382 (narrow-to-region s e)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
383 (whitespace-cleanup))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
384 (whitespace-buffer t)))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
385
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
386 (defun whitespace-buffer-leading ()
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
387 "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
388 (save-excursion
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
389 (let ((pmin nil)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
390 (pmax nil))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
391 (goto-char (point-min))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
392 (beginning-of-line)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
393 (setq pmin (point))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
394 (end-of-line)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
395 (setq pmax (point))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
396 (if (equal pmin pmax)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
397 t
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
398 nil))))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
399
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
400 (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
401 "Remove any empty lines at the top of the file."
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
402 (save-excursion
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
403 (let ((pmin nil)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
404 (pmax nil))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
405 (goto-char (point-min))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
406 (beginning-of-line)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
407 (setq pmin (point))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
408 (end-of-line)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
409 (setq pmax (point))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
410 (if (equal pmin pmax)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
411 (progn
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
412 (kill-line)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
413 (whitespace-buffer-leading-cleanup))))))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
414
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
415 (defun whitespace-buffer-trailing ()
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
416 "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
417 (save-excursion
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
418 (let ((pmin nil)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
419 (pmax nil))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
420 (goto-char (point-max))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
421 (beginning-of-line)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
422 (setq pmin (point))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
423 (end-of-line)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
424 (setq pmax (point))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
425 (if (equal pmin pmax)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
426 (progn
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
427 (goto-char (- (point) 1))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
428 (beginning-of-line)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
429 (setq pmin (point))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
430 (end-of-line)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
431 (setq pmax (point))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
432 (if (equal pmin pmax)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
433 t
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
434 nil))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
435 nil))))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
436
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
437 (defun whitespace-buffer-trailing-cleanup ()
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
438 "Delete all the empty lines at the bottom."
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
439 (save-excursion
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
440 (let ((pmin nil)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
441 (pmax nil))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
442 (goto-char (point-max))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
443 (beginning-of-line)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
444 (setq pmin (point))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
445 (end-of-line)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
446 (setq pmax (point))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
447 (if (equal pmin pmax)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
448 (progn
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
449 (goto-char (1- pmin))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
450 (beginning-of-line)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
451 (setq pmin (point))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
452 (end-of-line)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
453 (setq pmax (point))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
454 (if (equal pmin pmax)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
455 (progn
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
456 (goto-char (1- (point-max)))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
457 (beginning-of-line)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
458 (kill-line)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
459 (whitespace-buffer-trailing-cleanup))))))))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
460
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
461 (defun whitespace-buffer-search (regexp)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
462 "Search for any given whitespace REGEXP."
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
463 (let ((whitespace-retval ""))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
464 (save-excursion
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
465 (goto-char (point-min))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
466 (while (re-search-forward regexp nil t)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
467 (setq whitespace-retval (format "%s %s " whitespace-retval
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
468 (match-beginning 0))))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
469 (if (equal "" whitespace-retval)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
470 nil
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
471 whitespace-retval))))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
472
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
473 (defun whitespace-buffer-cleanup (regexp newregexp)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
474 "Search for any given whitespace REGEXP and replace it with the NEWREGEXP."
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
475 (save-excursion
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
476 (goto-char (point-min))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
477 (while (re-search-forward regexp nil t)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
478 (replace-match newregexp))))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
479
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
480 (defun whitespace-indent-cleanup ()
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
481 "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
482 (save-excursion
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
483 (goto-char (point-min))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
484 (while (re-search-forward whitespace-indent-regexp nil t)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
485 (let ((column (current-column))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
486 (indent-tabs-mode t))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
487 (delete-region (match-beginning 0) (point))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
488 (indent-to column)))))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
489
26245
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
490 (defun whitespace-unchecked-whitespaces ()
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
491 "Return the list of whitespaces whose testing has been suppressed."
25724
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
492 (let ((whitespace-this-modeline
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
493 (concat (if (not whitespace-check-ateol-whitespace) "e")
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
494 (if (not whitespace-check-indent-whitespace) "i")
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
495 (if (not whitespace-check-leading-whitespace) "l")
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
496 (if (not whitespace-check-spacetab-whitespace) "s")
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
497 (if (not whitespace-check-trailing-whitespace) "t"))))
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
498 (if (not (equal whitespace-this-modeline ""))
26245
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
499 whitespace-this-modeline
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
500 nil)))
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
501
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
502 (defun whitespace-update-modeline (&optional whitespace-err)
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
503 "Update modeline with whitespace errors and whitespaces whose testing has
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
504 been turned off."
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
505 (if whitespace-display-in-modeline
26259
912b004387d9 (whitespace-update-modeline): Bugfix to ensure
Gerd Moellmann <gerd@gnu.org>
parents: 26253
diff changeset
506 (progn
912b004387d9 (whitespace-update-modeline): Bugfix to ensure
Gerd Moellmann <gerd@gnu.org>
parents: 26253
diff changeset
507 (setq whitespace-mode-line nil)
912b004387d9 (whitespace-update-modeline): Bugfix to ensure
Gerd Moellmann <gerd@gnu.org>
parents: 26253
diff changeset
508 ;; Whitespace errors
912b004387d9 (whitespace-update-modeline): Bugfix to ensure
Gerd Moellmann <gerd@gnu.org>
parents: 26253
diff changeset
509 (if (and whitespace-err (not (equal whitespace-err "")))
912b004387d9 (whitespace-update-modeline): Bugfix to ensure
Gerd Moellmann <gerd@gnu.org>
parents: 26253
diff changeset
510 (setq whitespace-mode-line whitespace-err))
912b004387d9 (whitespace-update-modeline): Bugfix to ensure
Gerd Moellmann <gerd@gnu.org>
parents: 26253
diff changeset
511 ;; Whitespace suppressed errors
912b004387d9 (whitespace-update-modeline): Bugfix to ensure
Gerd Moellmann <gerd@gnu.org>
parents: 26253
diff changeset
512 (let ((whitespace-unchecked (whitespace-unchecked-whitespaces)))
912b004387d9 (whitespace-update-modeline): Bugfix to ensure
Gerd Moellmann <gerd@gnu.org>
parents: 26253
diff changeset
513 (if whitespace-unchecked
912b004387d9 (whitespace-update-modeline): Bugfix to ensure
Gerd Moellmann <gerd@gnu.org>
parents: 26253
diff changeset
514 (setq whitespace-mode-line
912b004387d9 (whitespace-update-modeline): Bugfix to ensure
Gerd Moellmann <gerd@gnu.org>
parents: 26253
diff changeset
515 (concat whitespace-mode-line "!" whitespace-unchecked))))
912b004387d9 (whitespace-update-modeline): Bugfix to ensure
Gerd Moellmann <gerd@gnu.org>
parents: 26253
diff changeset
516 ;; Add the whitespace modeline prefix
912b004387d9 (whitespace-update-modeline): Bugfix to ensure
Gerd Moellmann <gerd@gnu.org>
parents: 26253
diff changeset
517 (setq whitespace-mode-line (if whitespace-mode-line
912b004387d9 (whitespace-update-modeline): Bugfix to ensure
Gerd Moellmann <gerd@gnu.org>
parents: 26253
diff changeset
518 (concat " W:" whitespace-mode-line)
912b004387d9 (whitespace-update-modeline): Bugfix to ensure
Gerd Moellmann <gerd@gnu.org>
parents: 26253
diff changeset
519 nil))
912b004387d9 (whitespace-update-modeline): Bugfix to ensure
Gerd Moellmann <gerd@gnu.org>
parents: 26253
diff changeset
520 (whitespace-force-mode-line-update))))
25724
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
521
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
522 ;; Force mode line updation for different Emacs versions
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
523 (defun whitespace-force-mode-line-update ()
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
524 "Force the mode line update for different flavors of Emacs."
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
525 (if whitespace-running-emacs
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
526 (force-mode-line-update) ; Emacs
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
527 (redraw-modeline))) ; XEmacs
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
528
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
529 (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
530 "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
531
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
532 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
533 periodically for whitespace."
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
534 (if (and whitespace-mode (not (member (list buf-file buf-name)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
535 whitespace-all-buffer-files)))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
536 (add-to-list 'whitespace-all-buffer-files (list buf-file buf-name))))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
537
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
538 (defun whitespace-tickle-timer ()
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
539 "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
540
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
541 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
542 `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
543 `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
544 (if (and whitespace-rescan-timer-time (not whitespace-rescan-timer))
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
545 (setq whitespace-rescan-timer
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
546 (if whitespace-running-emacs
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
547 (run-at-time nil whitespace-rescan-timer-time
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
548 'whitespace-rescan-files-in-buffers)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
549 (add-timeout whitespace-rescan-timer-time
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
550 'whitespace-rescan-files-in-buffers nil
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
551 whitespace-rescan-timer-time)))))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
552
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
553 (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
554 "Check monitored files for whitespace creep since last scan."
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
555 (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
556 buffile bufname thiselt buf)
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
557 (if (not whitespace-all-my-files)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
558 (progn
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
559 (if whitespace-running-emacs
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
560 (cancel-timer whitespace-rescan-timer)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
561 (disable-timeout whitespace-rescan-timer))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
562 (setq whitespace-rescan-timer nil))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
563 (while whitespace-all-my-files
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
564 (setq thiselt (car whitespace-all-my-files))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
565 (setq whitespace-all-my-files (cdr whitespace-all-my-files))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
566 (setq buffile (car thiselt))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
567 (setq bufname (cadr thiselt))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
568 (setq buf (get-buffer bufname))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
569 (if (buffer-live-p buf)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
570 (save-excursion
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
571 ;;(message "buffer %s live" bufname)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
572 (set-buffer bufname)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
573 (if whitespace-mode
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
574 (progn
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
575 ;;(message "checking for whitespace in %s" bufname)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
576 (if whitespace-auto-cleanup
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
577 (progn
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
578 ;;(message "cleaning up whitespace in %s" bufname)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
579 (whitespace-cleanup))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
580 (progn
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
581 ;;(message "whitespace-buffer %s." (buffer-name))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
582 (whitespace-buffer t))))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
583 ;;(message "Removing %s from refresh list" bufname)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
584 (whitespace-refresh-rescan-list buffile bufname)))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
585 ;;(message "Removing %s from refresh list" bufname)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
586 (whitespace-refresh-rescan-list buffile bufname))))))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
587
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
588 (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
589 "Refresh the list of files to be rescaned for whitespace creep."
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
590 (if whitespace-all-buffer-files
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
591 (progn
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
592 (setq whitespace-all-buffer-files
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
593 (delete (list buffile bufname) whitespace-all-buffer-files)))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
594 (progn
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
595 (if (and whitespace-running-emacs (timerp whitespace-rescan-timer))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
596 (cancel-timer whitespace-rescan-timer))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
597 (if (and (not whitespace-running-emacs) whitespace-rescan-timer)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
598 (disable-timeout whitespace-rescan-timer))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
599 (if whitespace-rescan-timer
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
600 (setq whitespace-rescan-timer nil)))))
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
601
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
602 ;;;###autoload
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
603 (defun whitespace-describe ()
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
604 "A summary of whitespaces and what this library can do about them.
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
605
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
606 The whitespace library is intended to find and help fix five different types
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
607 of whitespace problems that commonly exist in source code.
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
608
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
609 1. Leading space (empty lines at the top of a file).
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
610 2. Trailing space (empty lines at the end of a file).
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
611 3. Indentation space (8 or more spaces at beginning of line, that should be
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
612 replaced with TABS).
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
613 4. Spaces followed by a TAB. (Almost always, we never want that).
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
614 5. Spaces or TABS at the end of a line.
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
615
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
616 Whitespace errors are reported in a buffer, and on the modeline.
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
617
26245
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
618 Modeline will show a W:<x>!<y> to denote a particular type of whitespace,
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
619 where `x' and `y' can be one (or more) of:
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
620
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
621 e - End-of-Line whitespace.
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
622 i - Indentation whitespace.
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
623 l - Leading whitespace.
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
624 s - Space followed by Tab.
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
625 t - Trailing whitespace.
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
626
25724
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
627 If any of the whitespace checks is turned off, the modeline will display a
26245
2dbd5efce8ee (whitespace-version): Update to 2.6
Gerd Moellmann <gerd@gnu.org>
parents: 25732
diff changeset
628 !<y>.
25724
6664d8f25ea5 (whitespace-version): Update version to 2.4
Richard M. Stallman <rms@gnu.org>
parents: 25625
diff changeset
629
25625
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
630 (since (3) is the most controversial one, here is the rationale: Most
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
631 terminal drivers and printer drivers have TAB configured or even
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
632 hardcoded to be 8 spaces. (Some of them allow configuration, but almost
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
633 always they default to 8.)
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
634
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
635 Changing tab-width to other than 8 and editing will cause your code to
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
636 look different from within Emacs, and say, if you cat it or more it, or
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
637 even print it.
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
638
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
639 Almost all the popular programming modes let you define an offset (like
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
640 c-basic-offset or perl-indent-level) to configure the offset, so you
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
641 should never have to set your tab-width to be other than 8 in all these
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
642 modes. In fact, with an indent level of say, 4, 2 TABS will cause Emacs
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
643 to replace your 8 spaces with one \t (try it). If vi users in your
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
644 office complain, tell them to use vim, which distinguishes between
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
645 tabstop and shiftwidth (vi equivalent of our offsets), and also ask them
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
646 to set smarttab.)
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
647
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
648 All the above have caused (and will cause) unwanted codeline integration and
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
649 merge problems.
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
650
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
651 whitespace.el will complain if it detects whitespaces on opening a file, and
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
652 warn you on closing a file also. (if in case you had inserted any
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
653 whitespaces during the process of your editing.)"
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
654 (interactive)
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
655 (message "Use C-h f whitespace-describe to read about whitespace.el v%s."
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
656 whitespace-version))
c0e27d3ce645 Finish making it fit Emacs conventions. Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 25582
diff changeset
657
25582
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
658 (provide 'whitespace)
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
659
e8428725fec3 Initial revision
Dave Love <fx@gnu.org>
parents:
diff changeset
660 ;;; whitespace.el ends here