[Top][All Lists]

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

RE: TAB when the region is active

From: Drew Adams
Subject: RE: TAB when the region is active
Date: Tue, 18 Sep 2007 22:11:18 -0700

1. `indent-region' only indents lines that start within the region. There's
probably a good reason for that, but I'm not sure that's the behavior we
want here. I wonder if it wouldn't be better here to apply `indent-line'
(e.g. `lisp-indent-line') to each line, in turn, that has at least one
character (not necessarily its first character) in the region.

A typical use case for me is wanting to see what really changes when I do
`C-M-q' on a large defun (> one screen). I want, for instance, to see if
only some comment positions change or if some sexps move because I might
have an extra or a missing paren. I'll hit TAB for each of several
successive lines to see if/how they move. (You might have an alternative
that you prefer, but I often do this.)

If TAB, as proposed, will now affect the region, then I'll just select some
lines and hit TAB - great.

But, IIUC, the first line selected would need to have its beginning selected
also, or else `indent-region' won't apply to it. It would be handier, I
think, to have `lisp-indent-line' applied to each selected line, in turn.

That way, the region would show all of the lines that would be affected by
the operation. You could quickly zap the mouse over some lines to select
them, without regard to the exact beginning or end of the region, and TAB
would indent them all appropriately (in turn).

(No, I didn't try the patch; I just scanned it.)

2. BTW, does `lisp-indent-region' really do the right thing? E.g., if you
select all lines after the first one here, and then do (lisp-indent-region
(region-beginning) (region-end)), the last three lines are not indented
correctly. Is that THT?

(cond (foobar
         (fibrillate) ; select this and subsequent lines
           (message "Fabulous!"))
       (message "Bar none.")))

`lisp-indent-region' gives this (is it a bug or intended?):

(cond (foobar
       (message "Fabulous!"))
      (barn-owl) ; incorrectly indented
      (message "Bar none.")))

The problem I was referring to in #1 is the difference between this and what
happens if you don't start the selection at the beginning of the second
line, but in some other part of the second line (e.g. at its opening paren).
The result is then this:

(cond (foobar
         (fibrillate) ; incorrect indentation (not moved)
         (frobnicate) ; correctly indented relative to previous
         (message "Fabulous!"))
      (message "Bar none."))))

(Yes, you can, remembering this gotcha, always start selecting one line
ahead of what you want to indent, but I think it's clearer if the region
clearly indicates the lines to be affected.)

3. Wrt my use case mentioned in #1, yes, it might be nice to have a visual
indication of the first significant (i.e. non-comment) change in
indentation, starting at point, when you do `C-M-q'. Or perhaps even an
indication of all indentation changes. That might be done by highlighting
any added whitespace and indicating any removed whitespace in some other
way - perhaps by highlighting (differently) the chars that were moved
leftward to replace previous whitespace.

E.g., moving from the first sexp above to the second would show something
like this, where `x' indicates removed whitespace (but highlighting would be
used, not `x').

(cond (foobar
       xxxxsage "Fabulous!"))
      (message "Bar none.")))

Apologies for adding topics. Only #1 is relevant to this thread. (And
perhaps #2.)

reply via email to

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