Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [rfc + bad patch] Allow to get the current cursor command from zle, for doing a nicer run-help.



2008/10/5 Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>:
> On Oct 5,  3:40pm, Mikael Magnusson wrote:
> }
> } Let's say you have the command line
> } git add -u; git commit - # hmm, was it -m or -M for message? *press alt-h*
> } Now, also assume you have the run-help-git stuff set up, but it will still
> } show you the manpage for git-add instead of git-commit.
>
> This points out a more generalized bug in Functions/Misc/run-help as it
> currently is implemented.  If you have, for example
>
>    zsh% run-help-less() { print $* }
>    zsh% print this is not less but the next is; less /etc/termcap
>
> If you now hit ESC-h to invoke run-help, you get:
>
>    but the next is
>
> and then the command "less /etc/termcap" is *executed*.  The "eval" in
> Functions/Misc/run-help needs a (q) parameter expansion flag added, at
> the very least.
>
> } Since the run-help widget does a push-line, we can't use $CURSOR to
> } find out which is the actual command, this is how i solved it.
>
> It should be possible to solve this without resorting to hacking the C
> source.  All you need is a user-defined ZLE widget that runs as a wrapper
> around the run-help widget to save the value of CURSOR.  E.g.:
>
>    run_help_cursor () {
>        typeset -g HELPCURSOR=$CURSOR
>        zle .run-help "$@"
>    }
>    zle -N run-help run_help_cursor
>
> Except that you're using CURSOR in your _runhelp function, so it must
> already be a widget?  You didn't show a usage example.

Yeah it's a widget to use instead of run-help.

> It might be nice if the .run-help widget saved the cursor position itself,
> or behaved more like a completion widget and passed an array containing
> only the command words "around" the cursor, stripping from separators on
> either side.  *That* would require C hacking.
>
> In any case I think your function will still do the wrong thing for
> something like "git commit git", though that's admittedly not a very
> likely scenario.

Hm yeah, the only way to really solve it would be if the C code also gave
us the index into $BUFFER where the word is, I think?

-- 
Mikael Magnusson



Messages sorted by: Reverse Date, Date, Thread, Author