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

zle defined widget inside a prompt_theme_setup function

Hello ZSH users,

As explained under section 26.6 of the manual

I've created a function `prompt_my_setup` which I've putt in my `fpath`
for my theme called `my` as follows:

		PS1='%M %% '

Since I use vi like keys in ZLE, I wanted to have an indicator telling
me whether I'm on INSERT mode or NORMAL mode. I've googled the subject
and encountered this answer:

That works. I was trying to use this `prompt_my_setup` file:

		add-zsh-hook preexec prompt_my_preexec
		PS1_base='%M %% '
		zle -N zle-line-init
		zle -N zle-keymap-select
	prompt_my_precmd () {
	function zle-line-init zle-keymap-select {
		PS1_2="${${KEYMAP/vicmd/-- NORMAL --}/(main|viins)/-- INSERT --}"
		zle reset-prompt
	prompt_my_preexec () {
		print -rn -- $terminfo[el];

That works as well but the problem is that after running `prompt my`, I
can't revert back to any other prompt and the prompt stays the same
unless I make the functions `zle-line-init` and `zle-keymap-select`

I've read throughly the manual and especially section 26.6.4:

It seems that the `prompt_cleanup` should do it but it doesn't work
neither it's usage makes any sense to me. Allow me to explain:

I tried to add the following to the file `prompt_my_setup`, please
correct me if this usage is wrong:

	prompt_my_cleanup () {
		function zle-line-init zle-keymap-select {
	prompt_cleanup prompt_my_cleanup

If I run `prompt my` on startup, I get my prompt setup just fine, with
my ZLE indicator showing just fine.

As I said, if for example I run afterwards `prompt adam1`, I don't see
any change in the prompt, unless I manually run `prompt_my_cleanup`
which makes `zle-line-init` and `zle-keymap-select` empty.

Wouldn't it make more sense if in the same manner as when a user
defines `prompt_THEME_setup` and `prompt_THEME_help` or
`prompt_THEME_preview`, he would define `prompt_THEME_clean`? So that
this function will be ran whenever his prompt is removed?

I'd appreciate any help / opinions, thanks.

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