From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19707 invoked from network); 24 Jan 2006 21:02:16 -0000 X-Spam-Checker-Version: SpamAssassin 3.1.0 (2005-09-13) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00, FORGED_RCVD_HELO autolearn=ham version=3.1.0 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 24 Jan 2006 21:02:16 -0000 Received: (qmail 84076 invoked from network); 24 Jan 2006 21:02:10 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 24 Jan 2006 21:02:10 -0000 Received: (qmail 26999 invoked by alias); 24 Jan 2006 21:02:05 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 22169 Received: (qmail 26973 invoked from network); 24 Jan 2006 21:02:04 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 24 Jan 2006 21:02:04 -0000 Received: (qmail 83717 invoked from network); 24 Jan 2006 21:02:04 -0000 Received: from mta09-winn.ispmail.ntl.com (81.103.221.49) by a.mx.sunsite.dk with SMTP; 24 Jan 2006 21:02:03 -0000 Received: from aamta09-winn.ispmail.ntl.com ([81.103.221.35]) by mta09-winn.ispmail.ntl.com with ESMTP id <20060124210202.CULM15755.mta09-winn.ispmail.ntl.com@aamta09-winn.ispmail.ntl.com> for ; Tue, 24 Jan 2006 21:02:02 +0000 Received: from pwslaptop.csr.com ([81.105.238.64]) by aamta09-winn.ispmail.ntl.com with SMTP id <20060124210202.JCRI1154.aamta09-winn.ispmail.ntl.com@pwslaptop.csr.com> for ; Tue, 24 Jan 2006 21:02:02 +0000 Date: Tue, 24 Jan 2006 21:01:51 +0000 From: Peter Stephenson To: zsh-workers@sunsite.dk Subject: Re: change color depending on vi-mode Message-Id: <20060124210151.5b093d47.p.w.stephenson@ntlworld.com> In-Reply-To: <1060123161718.ZM28725@candle.brasslantern.com> References: <1060123161718.ZM28725@candle.brasslantern.com> X-Mailer: Sylpheed version 0.9.12 (GTK+ 1.2.10; i386-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Mon, 23 Jan 2006 16:17:18 +0000 Bart Schaefer wrote: > The short answer is that the only way to do it is to create your own > widget functions for all of the vi commands that change modes. There > is no "callback" associated with changing the keymap that can be used > to update the prompt. It's easy to add, however (redirected to zsh-workers). The following function provides a simple example, but I'm sure there's a better one for inclusion with the supplied Zle functions. (Bits of http://www.gott-gehabt.de/800_wer_wir_sind/thomas/Homepage/Computer/zsh/vi-showmode could be included; it looks like that works perfectly well but redefining every vi widget is a bit heavy going and this is more general.) I tried it with "/" within vi command mode and it looks like the mechanism is fairly robust, although I wouldn't be surprised if there were gotchas. I'm not prepared to hold my breath until we have get and set advice functions for variables... By the way, this is partly because I realise I've been extremely slow getting out another 4.3 test release and there's nothing really hindering it. I've been fairly busy. zle-keymap-select() { local showcmd="" if [[ $KEYMAP = vicmd ]]; then if [[ $PS1 != ""* ]]; then PS1="$showcmd$PS1" zle reset-prompt fi else if [[ $PS1 = ""* ]]; then PS1=${PS1##$showcmd} zle reset-prompt fi fi } zle -N zle-keymap-select The name chosen isn't entirely to be illogical, it's because I expect functions of this sort to have a vaguely object-oriented naming convention along the lines of --. Compare zsh-mime-handler and zsh-mime-setup. Index: Doc/Zsh/zle.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/zle.yo,v retrieving revision 1.48 diff -u -r1.48 zle.yo --- Doc/Zsh/zle.yo 24 Nov 2005 10:25:34 -0000 1.48 +++ Doc/Zsh/zle.yo 24 Jan 2006 20:46:27 -0000 @@ -763,8 +763,8 @@ subsect(Special Widget) -There is one user-defined widget which is special to the shell. -If it does not exist, no special action is taken. The environment +There are a few user-defined widgets which are special to the shell. +If they do not exist, no special action is taken. The environment provided is identical to that for any other editing widget. startitem() @@ -780,6 +780,19 @@ (The command inside the function sets the keymap directly; it is equivalent to tt(zle vi-cmd-mode).) ) +tindex(zle-keymap-select) +item(tt(zle-keymap-select))( +Executed every time the keymap changes, i.e. the special parameter +tt(KEYMAP) is set to a different value, while the line editor is active. +Initialising the keymap when the line editor starts does not cause the +widget to be called. + +The value tt($KEYMAP) within the function reflects the new keymap. The +old keymap is passed as the sole argument. + +This can been used for detecting switches between the vi command +(tt(vicmd)) and insert (usually tt(main)) keymaps. +) enditem() sect(Standard Widgets) Index: Src/Zle/zle_keymap.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_keymap.c,v retrieving revision 1.23 diff -u -r1.23 zle_keymap.c --- Src/Zle/zle_keymap.c 28 Oct 2005 17:42:07 -0000 1.23 +++ Src/Zle/zle_keymap.c 24 Jan 2006 20:46:28 -0000 @@ -400,8 +400,24 @@ km = openkeymap(name = ".safe"); } if(name != curkeymapname) { - zsfree(curkeymapname); + char *oname = curkeymapname; + Thingy chgthingy; + curkeymapname = ztrdup(name); + + if (oname && zleactive && strcmp(oname, curkeymapname) && + (chgthingy = rthingy_nocreate("zle-keymap-select"))) { + char *args[2]; + int saverrflag = errflag, savretflag = retflag; + args[0] = oname; + args[1] = NULL; + errflag = retflag = 0; + execzlefunc(chgthingy, args); + unrefthingy(chgthingy); + errflag = saverrflag; + retflag = savretflag; + } + zsfree(oname); } curkeymap = km; return 0; -- Peter Stephenson Web page still at http://www.pwstephenson.fsnet.co.uk/