[Top][All Lists]

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

Re: How to whip Emacs into weird indentation rules with tabs+spaces?

From: Nikolaj Schumacher
Subject: Re: How to whip Emacs into weird indentation rules with tabs+spaces?
Date: Fri, 18 Jul 2008 23:53:53 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2.50 (darwin)

Alan Mackenzie <address@hidden> wrote:

> On Fri, Jul 18, 2008 at 02:35:57AM +0200, Juanma wrote:
>> |---| = tab     . = space
>> |---|while ( something &&
>> |---|........some_else )
>> |---|---|then_do_something();
>> The idea is that tab goes one level further, but for same-level adjustments
>> only spaces should be used.
>> How to force Emacs into that insanity? (no, it's not my personal
>> choice)

The way I see it, that would be the only /sane/ way to use tabs at all. :)
Because no matter what tab-width is set to, the code will always look
right...  Unfortunately there's probably not a single editor out there that
supports the scheme, so it's even less portable.

> (defun ms-space-for-alignment ()
>   "Make the current line use tabs for indentation and spaces for alignment.
> It is intended to be called from the hook
> `c-special-indent-hook'.  It assumes that `indent-tabs-mode' is
> non-nil and probably assumes that `c-basic-offset' is the same as
> `tab-width'."
>   (save-excursion
>       (let* ((indent-pos (progn (back-to-indentation) (point)))
>              (indent-col (current-column))
>              (syn-elt (car c-syntactic-context))
>              (syn-sym (c-langelem-sym syn-elt)))
>         (when (memq syn-sym '(arglist-cont-nonempty)) ;; <==============
>           (let* ((syn-anchor (c-langelem-pos syn-elt))
>                  (anchor-col (progn (goto-char syn-anchor)
>                                     (back-to-indentation)
>                                     (current-column)))
>                  num-tabs)
>         ;;
>             (goto-char indent-pos)
>             (delete-horizontal-space)
>             (insert-char ?\t (/ anchor-col tab-width))
>             (insert-char ?\  (- indent-col (current-column))))))))

Great, but it leaves the point at the beginning of space-only lines.
A quick fix would be to replace the last two lines with this:

(insert-before-markers (make-string (/ anchor-col tab-width) ?\t))
(insert-before-markers (make-string (- indent-col (current-column)) ?\ )))))))

Nikolaj Schumacher

reply via email to

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