From: Doron Behar <doron.behar@gmail.com>
To: zsh-users@zsh.org
Subject: zle defined widget inside a prompt_theme_setup function
Date: Fri, 6 Apr 2018 00:47:58 +0300 [thread overview]
Message-ID: <20180405214758.alnikbtegg5sp7rd@NUC.doronbehar.com> (raw)
Hello ZSH users,
As explained under section 26.6 of the manual
(http://zsh.sourceforge.net/Doc/Release/User-Contributions.html#Prompt-Themes)
I've created a function `prompt_my_setup` which I've putt in my `fpath`
for my theme called `my` as follows:
prompt_my_setup(){
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:
https://unix.stackexchange.com/a/1029/135796
That works. I was trying to use this `prompt_my_setup` file:
prompt_my_setup(){
add-zsh-hook preexec prompt_my_preexec
PS1_base='%M %% '
zle -N zle-line-init
zle -N zle-keymap-select
terminfo_down_sc=$terminfo[cud1]$terminfo[cuu1]$terminfo[sc]$terminfo[cud1]
}
prompt_my_precmd () {
vcs_info
}
function zle-line-init zle-keymap-select {
PS1_2="${${KEYMAP/vicmd/-- NORMAL --}/(main|viins)/-- INSERT --}"
PS1="%{$terminfo_down_sc$PS1_2$terminfo[rc]%}$PS1_base"
zle reset-prompt
}
prompt_my_preexec () {
print -rn -- $terminfo[el];
}
prompt_my_setup
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`
empty.
I've read throughly the manual and especially section 26.6.4:
http://zsh.sourceforge.net/Doc/Release/User-Contributions.html#Writing-Themes
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.
reply other threads:[~2018-04-05 21:48 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180405214758.alnikbtegg5sp7rd@NUC.doronbehar.com \
--to=doron.behar@gmail.com \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).