From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6046 invoked by alias); 5 Apr 2018 21:48:10 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: List-Unsubscribe: X-Seq: 23314 Received: (qmail 4752 invoked by uid 1010); 5 Apr 2018 21:48:10 -0000 X-Qmail-Scanner-Diagnostics: from mail-wm0-f43.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(74.125.82.43):SA:0(-1.9/5.0):. Processed in 1.320483 secs); 05 Apr 2018 21:48:10 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_PASS, T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: doron.behar@gmail.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:subject:message-id:mime-version:content-disposition :user-agent; bh=sFjIFW7g0rOO5cedglf/60p6ZCgLtaTuBzNlJxe5af4=; b=NG74uYUUYQNLNtgZjgKrvg1o4f0b+lPUkMfnskJiyv0mRYMTKDZ7icWxw3oCpCRCEz 6S7jQRXE2cLG/GxT7v0gZMeznjy8a1AfgeyudcA+MVpM5ZXk6meqgJ8FndV1tVi7DdaX wDLNbW41zCJ+c0WR3jEVzsOZSf6tNFgmBwxdjpzjxJSZjTnzkh6yz+oCXcFq25fMJNFL cgAH1jsJ/Bd1lVBo59VFaQ9EdV/LizPcWhF99uL+48KC3F9Eabb1sHo2R4D4xDPj0L82 8EDLdSB+z4GWDl/QfmFEdWeVXm+Wr05Ey2gAzlXqbQd0KnKxCx8MVlABgs0JhhoPI9E2 e8Yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-disposition:user-agent; bh=sFjIFW7g0rOO5cedglf/60p6ZCgLtaTuBzNlJxe5af4=; b=c4ZRbzgdlkOtgGhmSipeefhYGQoE+z0Ag7rcfhn31lHDNXPyLmy11Al4xi1K6uAfjd jJPpwFDIFON42lgk7gPEVZ0PSgzV/slvvwvMsDE7y9cF5MeVwMeFf8INdhovc1h+owCD UNRduhGurMBwazA+3eZuX/U7NpVZIeofuGJWGAdQ69u20uN8Zro2AL4agFhKkBEEMUF9 36tK2TQuKi8FCwn1HGtlJS2+Z0n2z4Or5AWqO8mBG4I1ha3QP0nvwMrG7B9lrmyQ7lTU 85reSPg1LD6ycuZK7A5mTk0Q52yAdf75IUBLesXFUeBDPUWnPCP9Ms8F9VrVvmBREf4l Lunw== X-Gm-Message-State: ALQs6tDGouvxavAkn9qI9vUzBbUqEF3VIaThiEgXUfqfI+0sS4SSm/4n GIo7h/qKNgMRW49qsJ06JCDGeH4R X-Google-Smtp-Source: AIpwx4810agy2M0gP4db7ocvRcowM8QvUquPi1C2hIOI0CxQVC7XIsn1BNOEdR1Aqnd6EtsBvNCJQA== X-Received: by 10.80.171.22 with SMTP id s22mr4473086edc.263.1522964885112; Thu, 05 Apr 2018 14:48:05 -0700 (PDT) Date: Fri, 6 Apr 2018 00:47:58 +0300 From: Doron Behar To: zsh-users@zsh.org Subject: zle defined widget inside a prompt_theme_setup function Message-ID: <20180405214758.alnikbtegg5sp7rd@NUC.doronbehar.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline User-Agent: NeoMutt/20180323 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.