comparison .elisp/show-wspace.el @ 0:c30d68fbd368

Initial import from svn.
author Augie Fackler <durin42@gmail.com>
date Wed, 26 Nov 2008 10:56:09 -0600
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:c30d68fbd368
1 ;;; show-wspace.el --- Highlight whitespace of various kinds.
2 ;;
3 ;; Filename: show-wspace.el
4 ;; Description: Highlight whitespace of various kinds.
5 ;; Author: Peter Steiner <unistein@isbe.ch>, Drew Adams
6 ;; Maintainer: Drew Adams
7 ;; Copyright (C) 2000-2008, Drew Adams, all rights reserved.
8 ;; Created: Wed Jun 21 08:54:53 2000
9 ;; Version: 21.0
10 ;; Last-Updated: Tue Jan 01 13:59:36 2008 (-28800 Pacific Standard Time)
11 ;; By: dradams
12 ;; Update #: 264
13 ;; URL: http://www.emacswiki.org/cgi-bin/wiki/show-wspace.el
14 ;; Keywords: highlight, whitespace
15 ;; Compatibility: GNU Emacs 20.x, GNU Emacs 21.x, GNU Emacs 22.x
16 ;;
17 ;; Features that might be required by this library:
18 ;;
19 ;; None
20 ;;
21 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
22 ;;
23 ;;; Commentary:
24 ;;
25 ;; Highlight whitespace of various kinds.
26 ;;
27 ;; To use this library:
28 ;;
29 ;; Add this to your initialization file (~/.emacs or ~/_emacs):
30 ;;
31 ;; (require 'show-wspace) ; Load this library.
32 ;;
33 ;; Then you can use commands `toggle-*' (see below) to turn the
34 ;; various kinds of whitespace highlighting on and off in Font-Lock
35 ;; mode.
36 ;;
37 ;; If you want to always use a particular kind of whitespace
38 ;; highlighting, by default, then add the corresponding
39 ;; `show-ws-highlight-*' function (see below) to the hook
40 ;; `font-lock-mode-hook'. Then, whenever Font-Lock mode is turned on,
41 ;; whitespace highlighting will also be turned on.
42 ;;
43 ;; For example, you can turn on tab highlighting by default by adding
44 ;; function `show-ws-highlight-tabs' to `font-lock-mode-hook' in your
45 ;; .emacs file, as follows:
46 ;;
47 ;; (add-hook 'font-lock-mode-hook 'show-ws-highlight-tabs)
48 ;;
49 ;;
50 ;; Faces defined here:
51 ;;
52 ;; `show-ws-hard-space', `show-ws-tab', `show-ws-trailing-whitespace'.
53 ;;
54 ;; Commands defined here:
55 ;;
56 ;; `show-ws-toggle-show-hard-spaces', `show-ws-toggle-show-tabs',
57 ;; `show-ws-toggle-show-trailing-whitespace',
58 ;; `toggle-show-hard-spaces-show-ws' (alias),
59 ;; `toggle-show-tabs-show-ws' (alias),
60 ;; `toggle-show-trailing-whitespace-show-ws' (alias).
61 ;;
62 ;; Non-interactive functions defined here:
63 ;;
64 ;; `show-ws-highlight-hard-spaces', `show-ws-highlight-tabs',
65 ;; `show-ws-highlight-trailing-whitespace'.
66 ;;
67 ;; Internal variables defined here:
68 ;;
69 ;; `show-ws-highlight-hard-spaces-p', `show-ws-highlight-tabs-p',
70 ;; `show-ws-highlight-trailing-whitespace-p'.
71 ;;
72 ;; Drew Adams wrote the `toggle-*' commands and `*-p' variables.
73 ;;
74 ;; Peter Steiner wrote the original code that did the equivalent of
75 ;; the `show-ws-highlight-*' commands here in his `hilite-trail.el'.
76 ;;
77 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
78 ;;
79 ;;; Change log:
80 ;;
81 ;; 2007/09/25 dadams
82 ;; Renamed to use prefix show-ws-. Thx to Cyril Brulebois.
83 ;; 2006/11/11 dadams
84 ;; Corrected doc strings. Clarified: hard space is non-breaking space, \240.
85 ;; Included hard space in highlight-trailing-whitespace.
86 ;; 2006/04/06 dadams
87 ;; highlight-*: Use font-lock-add-keywords. Thanks to Karl Chen.
88 ;; 2006/02/20 dadams
89 ;; Mentioned in Commentary how to use non-interactively.
90 ;; 2006/01/07 dadams
91 ;; Added :link for sending bug report.
92 ;; 2006/01/06 dadams
93 ;; Added defgroup and use it.
94 ;; 2005/12/30 dadams
95 ;; Removed require of def-face-const.el.
96 ;; Renamed faces, without "-face".
97 ;; 2005/01/25 dadams
98 ;; Removed ###autoload for defvars.
99 ;; 2004/06/10 dadams
100 ;; Fixed minor bug in highlight-* functions.
101 ;;
102 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
103 ;;
104 ;; This program is free software; you can redistribute it and/or modify
105 ;; it under the terms of the GNU General Public License as published by
106 ;; the Free Software Foundation; either version 2, or (at your option)
107 ;; any later version.
108
109 ;; This program is distributed in the hope that it will be useful,
110 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
111 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
112 ;; GNU General Public License for more details.
113
114 ;; You should have received a copy of the GNU General Public License
115 ;; along with this program; see the file COPYING. If not, write to
116 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
117 ;; Floor, Boston, MA 02110-1301, USA.
118 ;;
119 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
120 ;;
121 ;;; Code:
122
123 (and (< emacs-major-version 20) (eval-when-compile (require 'cl))) ;; when, push
124
125 ;;;;;;;;;;;;;;;;;;;;;;;;;
126
127 (defgroup Show-Whitespace nil
128 "Highlight whitespace of various kinds."
129 :prefix "show-ws-"
130 :group 'convenience :group 'matching
131 :link `(url-link :tag "Send Bug Report"
132 ,(concat "mailto:" "drew.adams" "@" "oracle" ".com?subject=\
133 show-wspace.el bug: \
134 &body=Describe bug here, starting with `emacs -q'. \
135 Don't forget to mention your Emacs and library versions."))
136 :link '(url-link :tag "Other Libraries by Drew"
137 "http://www.emacswiki.org/cgi-bin/wiki/DrewsElispLibraries")
138 :link '(url-link :tag "Download"
139 "http://www.emacswiki.org/cgi-bin/wiki/show-wspace.el")
140 :link '(url-link :tag "Description"
141 "http://www.emacswiki.org/cgi-bin/wiki/ShowWhiteSpace#ShowWspace")
142 :link '(emacs-commentary-link :tag "Commentary" "show-wspace")
143 )
144
145 (defface show-ws-tab '((t (:background "LemonChiffon")))
146 "*Face for highlighting tab characters (`C-i') in Font-Lock mode."
147 :group 'Show-Whitespace :group 'font-lock :group 'faces)
148
149 (defface show-ws-trailing-whitespace '((t (:background "Gold")))
150 "*Face for highlighting whitespace at line ends in Font-Lock mode."
151 :group 'Show-Whitespace :group 'font-lock :group 'faces)
152
153 (defface show-ws-hard-space '((t (:background "PaleGreen")))
154 "*Face for highlighting non-breaking spaces (`\240')in Font-Lock mode."
155 :group 'Show-Whitespace :group 'font-lock :group 'faces)
156
157
158 (defvar show-ws-highlight-tabs-p nil
159 "Non-nil means font-lock mode highlights TAB characters (`C-i').")
160
161 (defvar show-ws-highlight-trailing-whitespace-p nil
162 "Non-nil means font-lock mode highlights whitespace at line ends.")
163
164 (defvar show-ws-highlight-hard-spaces-p nil
165 "Non-nil means font-lock mode highlights non-breaking spaces (`\240').")
166
167 ;;;###autoload
168 (defalias 'toggle-show-tabs-show-ws 'show-ws-toggle-show-tabs)
169 ;;;###autoload
170 (defun show-ws-toggle-show-tabs ()
171 "Toggle highlighting of TABs, using face `show-ws-tab'."
172 (interactive)
173 (if show-ws-highlight-tabs-p
174 (remove-hook 'font-lock-mode-hook 'show-ws-highlight-tabs)
175 (add-hook 'font-lock-mode-hook 'show-ws-highlight-tabs))
176 (setq show-ws-highlight-tabs-p (not show-ws-highlight-tabs-p))
177 (font-lock-mode) (font-lock-mode)
178 (message "TAB highlighting is now %s." (if show-ws-highlight-tabs-p "ON" "OFF")))
179
180 ;;;###autoload
181 (defalias 'toggle-show-hard-spaces-show-ws 'show-ws-toggle-show-hard-spaces)
182 ;;;###autoload
183 (defun show-ws-toggle-show-hard-spaces ()
184 "Toggle highlighting of non-breaking space characters (`\240').
185 Uses face `show-ws-hard-space'."
186 (interactive)
187 (if show-ws-highlight-hard-spaces-p
188 (remove-hook 'font-lock-mode-hook 'show-ws-highlight-hard-spaces)
189 (add-hook 'font-lock-mode-hook 'show-ws-highlight-hard-spaces))
190 (setq show-ws-highlight-hard-spaces-p (not show-ws-highlight-hard-spaces-p))
191 (font-lock-mode) (font-lock-mode)
192 (message "Hard (non-breaking) space highlighting is now %s."
193 (if show-ws-highlight-hard-spaces-p "ON" "OFF")))
194
195 ;;;###autoload
196 (defalias 'toggle-show-trailing-whitespace-show-ws
197 'show-ws-toggle-show-trailing-whitespace)
198 ;;;###autoload
199 (defun show-ws-toggle-show-trailing-whitespace ()
200 "Toggle highlighting of trailing whitespace.
201 Uses face `show-ws-trailing-whitespace'."
202 (interactive)
203 (if show-ws-highlight-trailing-whitespace-p
204 (remove-hook 'font-lock-mode-hook 'show-ws-highlight-trailing-whitespace)
205 (add-hook 'font-lock-mode-hook 'show-ws-highlight-trailing-whitespace))
206 (setq show-ws-highlight-trailing-whitespace-p
207 (not show-ws-highlight-trailing-whitespace-p))
208 (font-lock-mode) (font-lock-mode)
209 (message "Trailing whitespace highlighting is now %s."
210 (if show-ws-highlight-trailing-whitespace-p "ON" "OFF")))
211
212 (defun show-ws-highlight-tabs ()
213 "Highlight tab characters (`C-i')."
214 (font-lock-add-keywords nil '(("[\t]+" (0 'show-ws-tab t)))))
215 (defun show-ws-highlight-hard-spaces ()
216 "Highlight hard (non-breaking) space characters (`\240')."
217 (font-lock-add-keywords nil '(("[\240]+" (0 'show-ws-hard-space t)))))
218 (defun show-ws-highlight-trailing-whitespace ()
219 "Highlight whitespace characters at line ends."
220 (font-lock-add-keywords
221 nil '(("[\240\040\t]+$" (0 'show-ws-trailing-whitespace t)))))
222
223 ;;;;;;;;;;;;;;;;;;;;;;;
224
225 (provide 'show-wspace)
226
227 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
228 ;;; show-wspace.el ends here