Re: Negative or zero arguments to yank-last-arg in bound keystrokes

2010-12-06 Thread Chet Ramey
On 11/8/10 6:26 PM, Dennis Williamson wrote:

> Bash Version: 4.1
> Patch Level: 9
> Release Status: release
> 
> Description:
> 
> Negative or zero arguments to yank-last-arg in bound keystrokes do not perform
> as expected when the keystroke is pressed repeatedly.
> 
> Comparing to yank-last-arg with no arguments or positive arguments which step
> backwards successively through history entries, when the argument is zero or
> negative, repeated keypresses only alternate between the two previous history
> entries.
> 
> Also present in:
> 
> GNU bash, version 4.1.0(1)-release (i686-pc-linux-gnu)
> GNU bash, version 4.0.33(1)-release (i486-pc-linux-gnu)
> GNU bash, version 3.2.51(24)-release (i686-pc-cygwin)
> 
> Repeat-By:
> 
> Create these keystroke bindings using whatever keystrokes you like. The demo
> below will use Alt-h, Alt-i, Alt-j, Alt-k and Alt-m:
> 
>   bind '"\eh": "\e1\e."'
>   bind '"\ei": "\e0\e."'
>   bind '"\ej": "\e-\e."'
>   bind '"\ek": "\e-1\e."'
>   bind '"\em": "\e-2\e."'
> 
> Enter four example commands for testing. It doesn't matter what they are as
> long as they are different commands and have a few arguments that differ so
> it's easy to see the demonstration.
> 
>   printf '%s\n' foo bar
>   echo aaa bbb ccc
>   ls -ld . ..
>   getent passwd root sys
> 
> Press Alt-h four times, you should correctly get "passwd", "-ld", "aaa"
> and "'%s\n'" in succession. Clear the line (Ctrl-u).
> 
> Alt-. also correctly gives "sys", "..", "ccc" and "bar". (Ctrl-u to clear)
> 
> Now try the same thing with each of the other keystrokes, clearing the line
> between each test.
> 
> Alt-i: Instead of "getent", "ls", "echo" and "printf" you will see "getent",
> "getent", "ls" and "getent". Subsequent repetitions will alternate between
> "ls" and "getent".

This is a bug.  A zero count shouldn't change the direction (see below).
This will be fixed in the next version.

> Alt-j: Instead of "root", ".", "bbb" and "foo" you will see "root",
> "root", "." and "root". Subsequent repetitions will alternate between
> "." and "root".
> 
> Alt-k: Same behavior as Alt-j.
> 
> Alt-m: Instead of "passwd", "-ld", "aaa" and "'%s\n'" you will see "passwd",
> "passwd", "-ld" and "passwd". Subsequent repetitions will alternate between
> "-ld" and "passwd".
> 
> Other negative arguments behave similarly.

Yes.  In this case, the documentation is less than clear.  The count
argument is actually set by the first call to yank-last-arg, and that
argument sets the word to extract from the history entry.  Subsequent
calls to yank-last-arg without a different intervening editing command
use that same count as the argument to extract while moving through the
history, and any count given to those subsequent calls sets the number
of history entries to move.  A negative count on those calls changes the
direction.

You can get the behavior you want by using M-. (without an argument) on
the second and later successive calls to yank-last-arg.

Clearly the documentation needs updating.

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/



Re: Negative or zero arguments to yank-last-arg in bound keystrokes

2010-12-06 Thread Chet Ramey
On 12/6/10 8:22 PM, Chet Ramey wrote:

> Yes.  In this case, the documentation is less than clear.  The count
> argument is actually set by the first call to yank-last-arg, and that
> argument sets the word to extract from the history entry.  Subsequent
> calls to yank-last-arg without a different intervening editing command
> use that same count as the argument to extract while moving through the
> history, and any count given to those subsequent calls sets the number
> of history entries to move.  A negative count on those calls changes the
> direction.

Sorry, that was partly a future direction.  The count to the second and
subsequent calls just changes the direction, not the number of history
entries to skip.

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/



Re: Negative or zero arguments to yank-last-arg in bound keystrokes

2010-12-06 Thread Dennis Williamson
On Mon, Dec 6, 2010 at 7:29 PM, Chet Ramey  wrote:
> On 12/6/10 8:22 PM, Chet Ramey wrote:
>
>> Yes.  In this case, the documentation is less than clear.  The count
>> argument is actually set by the first call to yank-last-arg, and that
>> argument sets the word to extract from the history entry.  Subsequent
>> calls to yank-last-arg without a different intervening editing command
>> use that same count as the argument to extract while moving through the
>> history, and any count given to those subsequent calls sets the number
>> of history entries to move.  A negative count on those calls changes the
>> direction.
>
> Sorry, that was partly a future direction.  The count to the second and
> subsequent calls just changes the direction, not the number of history
> entries to skip.
>
> Chet
>
> --
> ``The lyf so short, the craft so long to lerne.'' - Chaucer
>                 ``Ars longa, vita brevis'' - Hippocrates
> Chet Ramey, ITS, CWRU    c...@case.edu    http://cnswww.cns.cwru.edu/~chet/
>

As you may have been able to tell from the macros I included in my
report, I was trying to create a macro analogous to yank-last-arg but
instead of "last" it would be some fixed n or last-minus-n, such as
"yank-last-1-arg" or "yank-3-arg" with a repeatable, unchanging
keystroke akin to Meta-. Using a positive argument, this works exactly
as I intended. It would have been nice to be able to do something like
"yank-last-n-arg".