unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Whitespace cleanup, tab-width and religion.
@ 2006-12-20 14:11 Michaël Cadilhac
  2006-12-20 15:00 ` Kim F. Storm
  0 siblings, 1 reply; 8+ messages in thread
From: Michaël Cadilhac @ 2006-12-20 14:11 UTC (permalink / raw)



[-- Attachment #1.1.1: Type: text/plain, Size: 813 bytes --]

Well, this discussion has probably been made a few times, but I can't
find a thread.

First, some facts:
- Whitespace cleanup considers 8 (and only 8) spaces to be
a tabulation, and discards the fact that `tab-width' could have been
changed.
- On the contrary, `tabify' uses `tab-width'.

And  this is  inconsistent, as  I  see whitespace-cleanup  as a  super
tabify.delete-trailing-whitespace.do-some-magic function.

Second, a « mylife » part:
My company uses « tab » as indentation char. Not two spaces, not
whatever, but tabs. And it looks, well, IMHO, awful. For MY (very own)
eyes, I wish I could see tabs as 2 spaces, and this is hopefully
possible in the Mighty Editor by setting `tab-width' to 2.

Is it completely politically incorrect (or simply wrong) to consider
such a patch :


[-- Attachment #1.1.2: whitespace.patch --]
[-- Type: text/x-patch, Size: 10031 bytes --]

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
  ;; !<y>.
  ;;
! ;;     (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
  ;; !<y>.
  ;;
! ;;     (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  <michael.cadilhac@lrde.org>
+ 
+ 	* 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.
+ 

[-- Attachment #1.1.3: Type: text/plain, Size: 411 bytes --]


TIA!

-- 
/!\ My mail address has changed, please update your files accordingly.
 |      Michaël `Micha' Cadilhac     |  ... KVim is cited in the talk.        |
 |         Epita/LRDE Promo 2007     |   "I can't tell if I am more sorry     |
 |  http://michael.cadilhac.name     |        for vim or for KDE."            |
 `--JID: michael.cadilhac@gmail.com--'          -- RMS                   -  --'

[-- Attachment #1.2: Type: application/pgp-signature, Size: 188 bytes --]

[-- Attachment #2: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2007-01-05  1:55 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-12-20 14:11 Whitespace cleanup, tab-width and religion Michaël Cadilhac
2006-12-20 15:00 ` Kim F. Storm
2006-12-20 15:11   ` Michaël Cadilhac
2006-12-20 16:04     ` Kim F. Storm
2007-01-01 18:55       ` Rajesh Vaidheeswarran
2007-01-01 20:24         ` Michaël Cadilhac
2007-01-02  9:56         ` Kim F. Storm
2007-01-05  1:55           ` Rajesh Vaidheeswarran

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).