help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Indenting Emacs Lisp only with tabs?


From: Oliver Scholz
Subject: Re: Indenting Emacs Lisp only with tabs?
Date: Fri, 04 Sep 2009 07:51:45 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)

Following up on myself ...

I don't follow the discussion on 'elastic tabstops'. Whatever makes one
happy, I guess.

However with regard to using proportional fonts for programming modes in
Emacs, I wrote:

[...]
> I actually thought about this some time ago. I believe it would be
> possible, not really complicated even, to fix this. Emacs could simply
> put a display property with the value
>
> `(space :align-to <number of whitespace chars from line beginning to first 
> non-whitespace>)
>
> on the leading space or tab characters on each line. And there you go:
> proportional fonts with flawless indentation.
>
> The only complication would be that font-lock does not naturally handle
> the `display' property; but if my memory serves well, all the necessary
> mechanics are in place and this would only be a minor obstacle.

The proof-of-concept turns out to be quite trivial. I am putting it
here, in case anybody actually wants to play with it. The following
assumes that indentation consists only of space characters.


(defconst propindent-font-lock-keywords
  `(("^ +"
     (0 (progn (propindent-fix-whitespace (match-beginning 0) (match-end 0))
               nil)))))

(defun propindent-fix-whitespace (from to)
  (put-text-property from to 'display `(space :align-to ,(- to from))))

(defun propindent-spice-up-font-lock ()
  (add-to-list 'font-lock-extra-managed-props
               'display)
  (font-lock-add-keywords nil propindent-font-lock-keywords))


One Problem is, that this fixes indentation only relative to the
*beginning* of the previous line. So, if you have for instance a typical
`let' expression in Lisp, the clauses starting from the second one would
be lined up vertically, but the first one on line with the "let" would
not. To fix this, the function would have to check for the pixel
position of the corresponding character on the previous line and fix the
visible indentation accordingly. It seems that the :align-to property
may take a pixel value; unfortunately I am not aware of any way to check
for the pixel position of a character position in a window. There are
drawbacks, anyways: since proportional fonts in general take
considerably less horizontal space, fixing this would actually reduce
visible indentation.


    Oliver
-- 
18 Fructidor an 217 de la Révolution
Liberté, Egalité, Fraternité!


reply via email to

[Prev in Thread] Current Thread [Next in Thread]