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

Re: the function to show a digit argument while it is being typed



On Nov 11, 11:07am, Greg Klanderman wrote:
} 
} This is pretty nice.. is there any way to have the argument appear on
} the following line instead?

Here's a summarized version based on everything that's gone by so far.

   function digit-argument-show {
     emulate -R zsh
     if [[ $LASTWIDGET == neg-argument && -n $NUMERIC ]]
     then zle -M "arg: $((NUMERIC*$KEYS[-1]))"
     else zle -M "arg: $NUMERIC$KEYS[-1]"
     fi
     zle -R
     zle .digit-argument
     if zle read-command
     then [[ $REPLY != digit-argument ]] && zle -M ""
     else zle send-break
     fi
     [[ -n $KEYS ]] && zle -U $KEYS
   }

I'm not sure why the "zle -R" is needed; odd things happen [*] if it's
left out, probably because .digit-argument does not normally change
BUFFER or CURSOR and therefore doesn't cause a full refresh.

[*] cursor moves to status line but message is not printed, then all the
messages spew out when something does change BUFFER.

} I had to add 'setopt localoptions unset'

The "emulate" should take care of that -- things like shwordsplit also
needed to be handled.

} Also would be nice if this worked with universal-argument.

Hmm, that one is a lot trickier; universal-argument effectively is a
trap on the next self-insert, such that if a digit is typed it behaves
like digit-argument (and also discards any "pending" neg-argument,
which may be yet another bug).  It handles that next keypress in a
way that makes it impossible to intercept in a wrapper widget, which
requires that the new widget not call .universal-argument.

For example, .universal-argument followed by the tty interrupt character
does not accomplish a send-break, which is another in the long line of
bugs that this exercise is uncovering.

Things get even hairier when argument-base is thrown in.



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