[AC] whitespace.el upgrade

Didier Verna didier at xemacs.org
Mon Apr 30 11:51:46 EDT 2007


NOTE: This patch has been committed. The version below is
informational only (whitespace differences have been removed).

		Dear reviewers,

this is my upgrade of whitespace.el.	


xemacs-packages/text-modes/ChangeLog addition:

2007-04-30  Didier Verna  <didier at 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.


XEmacs Packages source patch:
Diff command:   cvs -q diff -u -t -b -B -w
Files affected: xemacs-packages/text-modes/whitespace.el

Index: xemacs-packages/text-modes/whitespace.el
===================================================================
RCS file: /pack/xemacscvs/XEmacs/packages/xemacs-packages/text-modes/whitespace.el,v
retrieving revision 1.3
diff -u -u -t -b -B -w -r1.3 whitespace.el
--- xemacs-packages/text-modes/whitespace.el	25 Mar 2005 17:09:08 -0000	1.3
+++ xemacs-packages/text-modes/whitespace.el	30 Apr 2007 15:47:08 -0000
@@ -1,11 +1,12 @@
 ;;; 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 at gnu.org>
+;; Maintainer: Didier Verna <didier at xemacs.org>
 ;; Keywords: convenience
 
-;; $Id: whitespace.el,v 1.2 2005/02/09 23:39:13 scop Exp $
+;; $Id: whitespace.el,v 1.3 2005/03/25 17:09:08 aidan Exp $
 ;; This file is part of GNU Emacs.
 
 ;; GNU Emacs is free software; you can redistribute it and/or modify
@@ -23,21 +24,26 @@
 ;; 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.
 
@@ -53,10 +59,10 @@
 ;; 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
@@ -74,24 +80,49 @@
 ;; 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:
-
-;; `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.
+
+;; Usage:
+;; ======
+
+;; 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.
@@ -227,7 +258,6 @@
   :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
@@ -259,6 +289,49 @@
   :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
@@ -271,20 +344,23 @@
                                        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':
-
-\(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)
+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.
+
+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
@@ -343,13 +419,37 @@
 (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 ()

-- 
Read the Jazz Blog !! http://jazzblog.didierverna.com

Didier Verna, didier at lrde.epita.fr, http://www.lrde.epita.fr/~didier

EPITA / LRDE, 14-16 rue Voltaire   Tel.+33 (1) 44 08 01 85
94276 Le Kremlin-Bicêtre, France   Fax.+33 (1) 53 14 59 22   didier at xemacs.org



More information about the XEmacs-Patches mailing list