Index: lisp/whitespace.el =================================================================== RCS file: /sources/emacs/emacs/lisp/whitespace.el,v retrieving revision 1.50 diff -c -r1.50 whitespace.el *** lisp/whitespace.el 5 Dec 2006 06:55:48 -0000 1.50 --- lisp/whitespace.el 20 Dec 2006 13:50:35 -0000 *************** *** 32,39 **** ;; ;; 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. ;; --- 32,39 ---- ;; ;; 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 (`tab-width' 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. ;; *************** *** 51,60 **** ;; If any of the whitespace checks is turned off, the modeline will display a ;; !. ;; ! ;; (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.) ;; ;; 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 --- 51,57 ---- ;; If any of the whitespace checks is turned off, the modeline will display a ;; !. ;; ! ;; (For (3), here is a warning: ;; ;; 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 *************** *** 62,68 **** ;; ;; Almost all the popular programming modes let you define an offset (like ;; c-basic-offset or perl-indent-level) to configure the offset, so you ! ;; should never have to set your `tab-width' to be other than 8 in all ;; these modes. In fact, with an indent level of say, 4, 2 TABS will cause ;; Emacs to replace your 8 spaces with one \t (try it). If vi users in ;; your office complain, tell them to use vim, which distinguishes between --- 59,65 ---- ;; ;; Almost all the popular programming modes let you define an offset (like ;; c-basic-offset or perl-indent-level) to configure the offset, so you ! ;; probably never have to set your `tab-width' to be other than 8 in all ;; these modes. In fact, with an indent level of say, 4, 2 TABS will cause ;; Emacs to replace your 8 spaces with one \t (try it). If vi users in ;; your office complain, tell them to use vim, which distinguishes between *************** *** 205,213 **** :type 'boolean :group 'whitespace) ! (defcustom whitespace-indent-regexp "^\t*\\( \\)+" ! "Regexp to match multiples of eight spaces near line beginnings. ! The default value ignores leading TABs." :type 'regexp :group 'whitespace) --- 202,211 ---- :type 'boolean :group 'whitespace) ! (defcustom whitespace-indent-regexp "^\t*\\( \\{%d\\}\\)+" ! "Regexp to match multiples of an amount of spaces near line beginnings. ! The default value ignores leading TABs. ! If a `%d' is in the string, it is replaced by the value of `tab-width'." :type 'regexp :group 'whitespace) *************** *** 378,384 **** (message "Will%s check for indentation space in buffer." (if whitespace-check-buffer-indent "" " not")) (if whitespace-check-buffer-indent ! (whitespace-buffer-search whitespace-indent-regexp)))) ;;;###autoload (defun whitespace-toggle-spacetab-check () --- 376,382 ---- (message "Will%s check for indentation space in buffer." (if whitespace-check-buffer-indent "" " not")) (if whitespace-check-buffer-indent ! (whitespace-buffer-search (whitespace-indent-regexp))))) ;;;###autoload (defun whitespace-toggle-spacetab-check () *************** *** 410,416 **** These are: 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, 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. --- 408,415 ---- These are: 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 \(`tab-width' or more spaces, 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. *************** *** 440,446 **** nil)) (whitespace-indent (if whitespace-check-buffer-indent (whitespace-buffer-search ! whitespace-indent-regexp) nil)) (whitespace-spacetab (if whitespace-check-buffer-spacetab (whitespace-buffer-search --- 439,445 ---- nil)) (whitespace-indent (if whitespace-check-buffer-indent (whitespace-buffer-search ! (whitespace-indent-regexp)) nil)) (whitespace-spacetab (if whitespace-check-buffer-spacetab (whitespace-buffer-search *************** *** 531,543 **** ;; If this buffer really contains a file, then run, else quit. (whitespace-check-whitespace-mode current-prefix-arg) (if (and buffer-file-name whitespace-mode) ! (let ((whitespace-any nil) ! (whitespace-tabwith 8) ! (whitespace-tabwith-saved tab-width)) ! ! ;; since all printable TABS should be 8, irrespective of how ! ;; they are displayed. ! (setq tab-width whitespace-tabwith) (if (and whitespace-check-buffer-leading (whitespace-buffer-leading)) --- 530,536 ---- ;; If this buffer really contains a file, then run, else quit. (whitespace-check-whitespace-mode current-prefix-arg) (if (and buffer-file-name whitespace-mode) ! (let ((whitespace-any nil)) (if (and whitespace-check-buffer-leading (whitespace-buffer-leading)) *************** *** 552,558 **** (setq whitespace-any t))) (if (and whitespace-check-buffer-indent ! (whitespace-buffer-search whitespace-indent-regexp)) (progn (whitespace-indent-cleanup) (setq whitespace-any t))) --- 545,551 ---- (setq whitespace-any t))) (if (and whitespace-check-buffer-indent ! (whitespace-buffer-search (whitespace-indent-regexp))) (progn (whitespace-indent-cleanup) (setq whitespace-any t))) *************** *** 578,585 **** (if region-only (message "The region is now clean") (message "%s is now clean" buffer-file-name))) ! (whitespace-update-modeline))) ! (setq tab-width whitespace-tabwith-saved)))) ;;;###autoload (defun whitespace-cleanup-region (s e) --- 571,578 ---- (if region-only (message "The region is now clean") (message "%s is now clean" buffer-file-name))) ! (whitespace-update-modeline)))))) ! ;;;###autoload (defun whitespace-cleanup-region (s e) *************** *** 647,661 **** (while (re-search-forward regexp nil t) (replace-match newregexp)))) (defun whitespace-indent-cleanup () ! "Search for 8/more spaces at the start of a line and replace it with tabs." (save-excursion (goto-char (point-min)) ! (while (re-search-forward whitespace-indent-regexp nil t) ! (let ((column (current-column)) ! (indent-tabs-mode t)) ! (delete-region (match-beginning 0) (point)) ! (indent-to column))))) (defun whitespace-unchecked-whitespaces () "Return the list of whitespaces whose testing has been suppressed." --- 640,660 ---- (while (re-search-forward regexp nil t) (replace-match newregexp)))) + (defun whitespace-indent-regexp () + "Give the actual regexp that matches spaces to be replaced by tabs." + (format whitespace-indent-regexp tab-width)) + (defun whitespace-indent-cleanup () ! "Search for `tab-width'/more spaces at line starts and replace it with tabs. ! See `whitespace-indent-regexp' for how these spaces are searched." (save-excursion (goto-char (point-min)) ! (let ((indent-regexp (whitespace-indent-regexp))) ! (while (re-search-forward indent-regexp nil t) ! (let ((column (current-column)) ! (indent-tabs-mode t)) ! (delete-region (match-beginning 0) (point)) ! (indent-to column)))))) (defun whitespace-unchecked-whitespaces () "Return the list of whitespaces whose testing has been suppressed." Index: lisp/ChangeLog =================================================================== RCS file: /sources/emacs/emacs/lisp/ChangeLog,v retrieving revision 1.10462 diff -C0 -r1.10462 ChangeLog *** lisp/ChangeLog 20 Dec 2006 05:57:40 -0000 1.10462 --- lisp/ChangeLog 20 Dec 2006 13:50:44 -0000 *************** *** 0 **** --- 1,12 ---- + 2006-12-20 Michaël Cadilhac + + * whitespace.el: Change comments to say that `tab-width' is used + instead of 8. + (whitespace-indent-regexp): (Variable) Use a `%d' that will be + replaced by `tab-width'. + (whitespace-indent-regexp): (Function) New. Compute the actual + value of `whitespace-indent-regexp' and return it. + (whitespace-toggle-indent-check, whitespace-buffer) + (whitespace-cleanup-internal, whitespace-indent-cleanup): Use it. + (whitespace-buffer): Doc change. +