Subject: 25.0.50; Enhance (fix) incremental `indent-rigidly'

From: Drew Adams <[email-masked]>
Date: Thu, 6 Nov 2014 10:36:27 -0800 (PST)

1. Please consider adding this binding, so you can simply do `C-x TAB
TAB...': (define-key indent-rigidly-map "\t" 'indent-rigidly-right).
And update the doc string and prompt, of course.

2. You cannot currently provide a numeric prefix arg to `indent-rigidly'
for incremental use.  The incremental indentation you get is either 1 
column (for <right>) or to the next tab stop (for <S-right>).

It would be good to be able to use a numeric prefix arg interactively to
indent not only once, but each time you hit <right>.

Ironically, this was possible before the Emacs 24.4 change to
`indent-rigidly' which provided for incremental indenting, by just doing
something like this:

(defun repeat-command (command)
  "Repeat COMMAND."
  (let ((repeat-message-function  'ignore))
    (setq last-repeatable-command  command)
    (repeat nil)))

(defun indent-rigidly-repeat (start end arg &optional interactive)
  "Indent all lines that start in the region.
You can repeat this by hitting the last key (e.g., `TAB') again...
A numeric prefix arg you provide to the command is used as the
indentation increment."
  (interactive "r\nP\np")
  (require 'repeat nil t)
  (repeat-command 'indent-rigidly))

(global-set-key [remap indent-rigidly] 'indent-rigidly-repeat)

Then `C-3 C-x TAB TAB...' indents 3 columns each time you hit `TAB';
`C-x TAB TAB...' indents 1 column for each `TAB'; and `C- 2 C-x TAB
TAB...' outdents 2 columns for each `TAB'.  Very handy.

This design is simple, and it lets you use the same key, `TAB', to
indent or outdent incrementally (outdent by using a negative prefix
arg).

As written above, this does not, however, provide the useful feature of
a single undo for all repeated indenting, as does the current
implementation of `indent-rigidly'.  And it does not provide for
indentation to tab stops.  I am not proposing such a simple
implementation as a replacement for the current one.

This is the request: Could you please adapt `indent-rigidly' to provide
similar behavior to that shown above: Instead of using a numeric prefix
arg *only* for a single indentation, let users repeat indenting (or
outdenting) in prefix-arg steps.

3. A related improvement would be to provide also the other advantage of
the above code: Indenting/outdenting is *immediate* for `C-x TAB'.

Currently, no indentation is done until you hit <right> (or you use a
prefix arg, which turns off incremental indenting).  This means that
currently you must hit at least 3 keys, `C-x TAB <right>' or `C-1 C-x
TAB', to indent.  You cannot hit just `C-x TAB', as you could prior to
Emacs 24.4.  (This is thus a minor regression in behavior.)

The best behavior is for `C-x TAB' to indent by the numerical prefix
number of columns, and to continue to do so as long as you continue to
hit <right> or `TAB'.  <left> should similarly outdent by the prefix
arg.  A negative prefix arg, and Bidi, should of course flip the
direction.

(Yes, if `C-x TAB' itself indents immediately then you will need to hit
<left> twice to outdent once.  Not a big deal, IMO - outweighed by the
convenience of not needing to hit 3 keys for the common case of
indenting.)

I started to take a stab at this myself, but I found no good way to
propagate the prefix arg using the current implementation, which does
(set-transient-map indent-rigidly-map t).

In GNU Emacs 25.0.50.1 (i686-pc-mingw32)
 of 2014-10-20 on LEG570
Bzr revision: 118168 [email-masked]
Windowing system distributor `Microsoft Corp.', version 6.1.7601
Configured using:
 `configure --enable-checking=yes,glyphs CPPFLAGS=-DGLYPH_DEBUG=1'