Anonymous avatar Anonymous committed c39d80c

whitespace.el upgrade

Comments (0)

Files changed (2)

+2007-04-30  Didier Verna  <didier@xemacs.org>
+
+	* whitespace.el: Doc update.
+	* whitespace.el (whitespace-version): Increase to 2.3.
+	* whitespace.el (cl): Require it.
+	* whitespace.el (whitespace-checks-custom-type): New.
+	* whitespace.el (whitespace-modes): Use it.
+	* whitespace.el (whitespace-files): New user option.
+	* whitespace.el (whitespace-check-whitespace-mode): Handle it.
+
 2006-11-20  Norbert Koch  <viteno@xemacs.org>
 
 	* Makefile (VERSION): XEmacs package 1.92 released.
 ;;; whitespace.el --- warn about and clean bogus whitespaces in the file
 
-;; Copyright (C) 1999, 2000 Free Software Foundation, Inc.
+;; Copyright (C) 1999, 2000, 2007 Free Software Foundation, Inc.
 
-;; Author: Rajesh Vaidheeswarran <rv@gnu.org>
-;; Keywords: convenience
+;; Author:     Rajesh Vaidheeswarran <rv@gnu.org>
+;; Maintainer: Didier Verna <didier@xemacs.org>
+;; Keywords:   convenience
 
 ;; $Id$
 ;; This file is part of GNU Emacs.
 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 ;; Boston, MA 02111-1307, USA.
 
-;;; Synched up with: FSF 21.3.
+;;; Synched up with: not synched with FSF.
 
 ;;; Commentary:
 
-;; Whitespace.el URL: http://www.dsmit.com/lisp/
+;; #### NOTE: this version is outdated -- dvl
+;; Whitespace.el URL: http://www.dsmit.com/lisp/whitespace.el
 
-;; The whitespace library is intended to find and help fix five different types
-;; of whitespace problems that commonly exist in source code.
 
-;; 1. Leading space (empty lines at the top of a file).
-;; 2. Trailing space (empty lines at the end of a file).
-;; 3. Indentation space (8 or more spaces at beginning of line, that should be
-;; 		      replaced with TABS).
-;; 4. Spaces followed by a TAB.  (Almost always, we never want that).
-;; 5. Spaces or TABS at the end of a line.
+;; Description:
+;; ============
+
+;; The whitespace library is intended to find and help fix the following five
+;; different types of whitespace problems that commonly exist in source code.
+
+;; 1. Leading space:  empty lines at the top of a file, that should be removed.
+;; 2. Trailing space: empty lines at the end of a file, that should be removed.
+;; 3. Indentation space: 8 or more spaces at beginning of line, that should be
+;;    replaced with TABS.
+;; 4. Spaces followed by a TAB, that should be replaced by TABS.
+;; 5. Spaces or TABS at the end of a line, that should be removed.
 
 ;; Whitespace errors are reported in a buffer, and on the modeline.
 
 ;; If any of the whitespace checks is turned off, the modeline will display a
 ;; !<y>.
 
-;;     (since (3) is the most controversial one, here is the rationale: Most
+;;     (since (3) is the most controversial one, here is the rationale: most
 ;;     terminal drivers and printer drivers have TAB configured or even
-;;     hardcoded to be 8 spaces.  (Some of them allow configuration, but almost
-;;     always they default to 8.)
+;;     hardcoded to be 8 spaces.  Some of them allow configuration, but almost
+;;     always they default to 8.
 
 ;;     Changing `tab-width' to other than 8 and editing will cause your code to
 ;;     look different from within Emacs, and say, if you cat it or more it, or
 ;; All the above have caused (and will cause) unwanted codeline integration and
 ;; merge problems.
 
-;; whitespace.el will complain if it detects whitespaces on opening a file, and
-;; warn you on closing a file also (in case you had inserted any
-;; whitespaces during the process of your editing).
 
-;; Exported functions:
+;; Usage:
+;; ======
 
-;; `whitespace-buffer' - To check the current buffer for whitespace problems.
-;; `whitespace-cleanup' - To cleanup all whitespaces in the current buffer.
-;; `whitespace-region' - To check between point and mark for whitespace
-;;                       problems.
-;; `whitespace-cleanup-region' - To cleanup all whitespaces between point
-;;                               and mark in the current buffer.
+;; Selecting which files / buffers to check:
+;; -----------------------------------------
+;; Whitespace decides whether to perform on a per-file, then per-mode basis.
+;; See the user options `whitespace-files' and `whitespace-modes' for more
+;; information.
+
+;; Checking files / buffers:
+;; -------------------------
+;; Use the functions `whitespace-buffer' or `whitespace-region' to perform
+;; checking. If the user option `whitespace-auto-cleanup' is set, checking for
+;; whitespace problems will also immediately trigger cleanup.
+
+;; Fixing whitespace problems:
+;; ---------------------------
+;; Use the functions `whitespace-cleanup' or `whitespace-cleanup-region' to
+;; cleanup whitespaces.
+
+;; Automatic whitespace checking / cleaning:
+;; -----------------------------------------
+;; To check (and possibly fix if `whitespace-auto-cleanup' is set) whitespace
+;; problems automatically on new buffers, you can turn
+;; `whitespace-global-mode' on.
+;;
+;; To check (and possibly fix if `whitespace-auto-cleanup' is set) whitespace
+;; problems automatically but only when saving buffers, you can add the
+;; function `whitespace-write-file-hook' to your `write-file-hooks'.
+
+;; There are others things that are customizable. The best thing to do in
+;; order to get an idea is to customize the whitespace group and see what's in
+;; it.
+
 
 ;;; Code:
 
+(require 'cl)
+
 (eval-when-compile (require 'easy-mmode))
 
-(defvar whitespace-version "3.2" "Version of the whitespace library.")
+(defvar whitespace-version "3.3" "Version of the whitespace library.")
 
 (defvar whitespace-all-buffer-files nil
   "An associated list of buffers and files checked for whitespace cleanliness.
   :type 'boolean
   :group 'whitespace)
 
-;; (defcustom whitespace-ateol-regexp "[ \t]$"
 (defcustom whitespace-ateol-regexp "[ \t]+$"
   "Regexp to match a TAB or a space at the EOL."
   :type 'regexp
   :type 'boolean
   :group 'whitespace)
 
+(defconst whitespace-checks-custom-type
+  '(repeat :inline t :tag "Checks"
+	   (choice :inline t
+		   (list :inline t :tag "Leading"
+			 :format "%{%t%}: %v"
+			 (const :tag "" :value leading)
+			 boolean)
+		   (list :inline t :tag "Trailing"
+			 :format "%{%t%}: %v"
+			 (const :tag "" :value trailing)
+			 boolean)
+		   (list :inline t :tag "Indent"
+			 :format "%{%t%}: %v"
+			 (const :tag "" :value indent)
+			 boolean)
+		   (list :inline t :tag "Space Tab"
+			 :format "%{%t%}: %v"
+			 (const :tag "" :value spacetab)
+			 boolean)
+		   (list :inline t :tag "At EOL"
+			 :format "%{%t%}: %v"
+			 (const :tag "" :value ateol)
+			 boolean)))
+  ;; Custom type for check options used both in `whitespace-files' and
+  ;; `whitespace-modes'.
+  )
+
+(defcustom whitespace-files nil
+  "Files in which we turn on whitespace checking.
+
+Each entry is either a regexp matching the file name,
+or looks like (REGEXP CHECK t|nil ...).
+CHECK is one of 'leading, 'trailing, 'indent, 'spacetab or 'ateol.
+Checks not specified will inherit from the default value.
+
+See also \`whitespace-check-whitespace-mode'."
+  :type `(repeat
+	  (choice (regexp :tag "File Name Matching")
+		  (group :value ("")
+			 (regexp :tag "File Name Matching")
+			 ,whitespace-checks-custom-type)))
+  :group 'whitespace)
+
 (defcustom whitespace-modes '(ada-mode asm-mode autoconf-mode awk-mode
 				       c-mode c++-mode cc-mode
 				       change-log-mode cperl-mode
 				       pascal-mode perl-mode prolog-mode
 				       python-mode scheme-mode sgml-mode
 				       sh-mode shell-script-mode simula-mode
-				       tcl-mode tex-mode texinfo-mode
+				       tcl-mode tex-mode
+				       (texinfo-mode indent nil spacetab nil)
 				       vrml-mode xml-mode)
 
   "Major Modes in which we turn on whitespace checking.
 
-These are mostly programming and documentation modes.  But you may add other
-modes that you want whitespaces checked in by adding something like the
-following to your `.emacs':
+Each entry is either a symbol corresponding to a major mode,
+or looks like (SYMBOL CHECK t|nil ...).
+CHECK is one of 'leading, 'trailing, 'indent, 'spacetab or 'ateol.
+Checks not specified will inherit from the default value.
 
-\(setq whitespace-modes (cons 'my-mode (cons 'my-other-mode
-					    whitespace-modes))\)
-
-Or, alternately, you can use the Emacs `customize' command to set this."
-  :type '(repeat symbol)
+See also \`whitespace-check-whitespace-mode'."
+  :type `(repeat
+	  (choice (symbol :tag "Major Mode")
+		  (group :value (fundamental)
+			 (symbol :tag "Major Mode")
+			 ,whitespace-checks-custom-type)))
   :group 'whitespace)
 
 (defcustom whitespace-rescan-timer-time 600
 (set-default 'whitespace-check-buffer-ateol
 	     whitespace-check-ateol-whitespace)
 
-(defun whitespace-check-whitespace-mode (&optional arg)
-  "Test and set the whitespace-mode in qualifying buffers."
-  (if (null whitespace-mode)
-      (setq whitespace-mode
-	    (if (or arg (member major-mode whitespace-modes))
-		t
-	      nil))))
+(defun whitespace-check-whitespace-mode (&optional force)
+  "Test and set the whitespace-mode in \"qualifying\" buffers.
+A buffer qualifies if its file name matches something in
+\`whitespace-files', or if its major mode matches something in
+\`whitespace-modes'."
+  (when (null whitespace-mode)
+    (if force
+	(setq whitespace-mode t)
+      (let (behavior)
+	(setq behavior (or
+			(find-if
+			 #'(lambda (item)
+			     (string-match (if (stringp item) item (car item))
+					   (buffer-file-name)))
+			 whitespace-files)
+			(find-if
+			 #'(lambda (item)
+			     (eq (if (symbolp item) item (car item))
+				 major-mode))
+			 whitespace-modes)))
+	(when behavior
+	  (setq whitespace-mode t)
+	  (when (listp behavior)
+	    (pop behavior)
+	    (when behavior
+	      (let (symbol)
+		(while (setq symbol (pop behavior))
+		  (set (intern (concat "whitespace-check-buffer-"
+				       (symbol-name symbol)))
+		       (pop behavior)))))))))))
+
 
 ;;;###autoload
 (defun whitespace-toggle-leading-check ()
 	(if whitespace-any
 	    (whitespace-cleanup)
 	  (progn
-           (if (not whitespace-silent) 
-               (message "%s clean" buffer-file-name)) 
+	   (if (not whitespace-silent)
+	       (message "%s clean" buffer-file-name))
 	    (whitespace-update-modeline)))
 	(setq tab-width whitespace-tabwith-saved))))
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.