Why whitespace denotation of blocks doesn't work.

Michael Vanier mvanier at endor.bbb.caltech.edu
Mon Jun 19 20:05:55 EDT 2000


Toby J Sargeant <tjs at cs.monash.edu.au> writes:

> On Mon, Jun 19, 2000 at 01:05:13AM +0000, Neil Hodgson wrote:
> >    You can change the colour to silver to make it less heavy. Or hack the
> > code to any colour you want. Originally tabs where displayed as round
> > cornered rectangles but Mark thought this was too heavy. Perhaps vertical
> > lines at the start of tabs instead would be lighter and make it easy to
> > match up code.
> > 
> >    Neil
> 
> I saw a screenshot once of a vim session that used the ; (ascii 0273)
> character to display tabs. It was actually very visually appealing, and I was
> a little annoyed when I failed to get emacs to do the same thing.
> 
> Toby.
> 

Put this in your .emacs file:

;;; ---------------------------------------------------------------------------
;;; Functions to display tabs as ^I.
;;; ---------------------------------------------------------------------------

(setq display-table-with-visible-tabs (make-display-table))
(let ((i 0))
  (while (< i 32)
    (or (= i ?\n)
        (aset display-table-with-visible-tabs i (vector ?^ (+ i 64))))
    (setq i (1+ i)))
  (aset display-table-with-visible-tabs 127 (vector ?^ ??)))

(defun make-tabs-visible ()
  "Make tabs display as ^I in the current buffer."
  (interactive)
  (setq buffer-display-table display-table-with-visible-tabs))

(defun make-tabs-invisible ()
  "Make tabs display as whitespace in the current buffer."
  (interactive)
  (setq buffer-display-table standard-display-table))

;; End of .emacs additions

BTW I *loathe* tabs with a white-hot passion bordering on psychosis.  It
comes from having to work in a cross-platform environment where the same code
was edited using emacs and also the Visual C++ editor, which had been
configured to use two-space tabs (!).  I hate tabs so much I've written
scripts to replace them with four spaces, and I also hacked the emacs python
mode to insert spaces where tabs are normally used.  Since then I don't have
problems with tabs in python.

Also re the indentation wars:

Pro-indentation:

-- I like the look of indented code as opposed to code with {} or begin-end
   blocks.  I think most people agree with this.  We can all find a style of
   {} that we like too, but the key is that with python the SAME style suits
   almost everybody.

Anti-indentation:

-- For long functions/classes I like to see an end marker.  Right now I
   usually use a comment e.g.:

class foo:
    # lots of code

    # End of class foo.

... but this is a bit hokey.

-- For code that may go into an environment that can munge whitespace
   (e.g. an active server page, or something that will be processed by
   another program), having tab-based indentation is asking for trouble.

-- Indentation-based grouping makes it hard to write multi-line lambda
   statements.   Of course, begin-end isn't that much better in this
   regard, but {} is (as is parenthesis-based grouping like in lisp).

I suppose in a perfect world we'd be able to have a pragma that would allow
us to select different block options e.g.

#pragma blocks {}
#pragma blocks begin-end

but I wouldn't hold my breath :-)  On balance, I believe the current system
in python does more good than harm.


Mike



--------------------------------------------------------------
Mike Vanier	mvanier at bbb.caltech.edu
Department of Computation and Neural Systems, Caltech 216-76
GNU/Linux: We can't lose; we're on a mission from God.



More information about the Python-list mailing list