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