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

Re: Conditionally complete on space.



On 08/17/2017 11:07 PM, Daniel Shahaf wrote:
That doesn't seem to have anything to do with the widget:

     $ zsh -f
     % autoload compinit
     % compinit
     % sipcalc(){}
     % sipc<TAB><space>

results in BUFFER="sipcalc " with just one space.

Well I'll be....

I never noticed it before, but it sure is there. - I guess that means that I won't mind it henceforth either. :-)

You can always <Ctrl+V><Space> to enter a literal space.

Ya, I was doing that during my diagnostics.

My goal is to overload space so that I don't need to hit special keys.  ;-)

The REC_EXACT option works if you change expand-or-complete
to complete-word.  (In this case you may want to add _expand
to your 'completer' zstyle.)

You've gotten me a LOT closer. And some brute force hacking (less than gracefully) got me to what I think I want.

maybe-expand-or-complete() {
	if [[ $LBUFFER[-1] != ' ' && -z "$JUSTCOMPLETED" ]]; then
		zle expand-or-complete
		if [[ $LBUFFER[-1] != ' ' ]]; then
			JUSTCOMPLETED=true
		fi
	else
		unset JUSTCOMPLETED
		zle self-insert
	fi
}
zle -N maybe-expand-or-complete
bindkey ' ' maybe-expand-or-complete
setopt recexact

The key was to retain state between maybe-expand-or-complete() executions via JUSTCOMPLETED so as to not call expand-or-complete successively when there were multiple matches.

Thanks to your help Daniel, I believe I have something that I can start using and deal with any annoyances as they come up. :-)



--
Grant. . . .
unix || die

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature



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