zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: "zsh-workers@zsh.org" <zsh-workers@zsh.org>
Subject: Re: In Vi mode, show whether "insert" or "command" state is active
Date: Mon, 22 Dec 2014 20:40:28 -0800	[thread overview]
Message-ID: <141222204028.ZM9033@torch.brasslantern.com> (raw)
In-Reply-To: <8569631419273880@web5h.yandex.ru>

On Dec 22,  9:44pm, ZyX wrote:
}
} [...]  I think it may be adding as a question issued by
} zsh-newuser-install when user selects Vi keymap, but behaviour when
} `zsh -f` is run or when .zshrc exists because I am pretty sure that in
} the first case some tests rely on it and in the second case chances
} that user has already configured what he needs is higher then chances
} that he has failed to find the solution.
} 
} And this should be changed prompt/rprompt, not changing cursor because
} changing cursor shape is less likely to work.

Then perhaps there should be a prompt escape for the keymap?  The letters
'z' and 'Z' are not yet taken.  (I hate requiring PROMPT_SUBST.)

Minimally:

diff --git a/Src/prompt.c b/Src/prompt.c
index 3552575..ef27699 100644
--- a/Src/prompt.c
+++ b/Src/prompt.c
@@ -404,6 +404,10 @@ putpromptchar(int doprint, int endchar, unsigned int *txtchangep)
 			    test = 1;
 		    }
 		    break;
+		case 'z':
+		    if ((ss = getsparam("KEYMAP")))
+			test = !!strcmp(ss, "main");
+		    break;
 		case '_':
 		    test = (cmdsp >= arg);
 		    break;
@@ -854,6 +858,14 @@ putpromptchar(int doprint, int endchar, unsigned int *txtchangep)
 		    promptpath(scriptfilename ? scriptfilename : argzero,
 			       arg, 0);
 		break;
+	    case 'z':
+		if ((ss = getsparam("KEYMAP")))
+		    stradd(ss);
+		break;
+	    case 'Z':
+		if ((ss = getsparam("ZLE_STATE")))
+		    stradd(ss);
+		break;
 	    case '\0':
 		return 0;
 	    case Meta:


This still requires one to write

zle-keymap-select() { zle reset-prompt }
zle -N zle-keymap-select

because the ZLE parameter set is only installed for user-defined widgets.

There's probably something more clever that could be done, particualarly
with ZLE_STATE and with the conditional.  The above is just an example.

Incidentally you have to "fix" the keymap name etc. in zle-line-init as
well as in zle-keymap-select.  Maybe zle-keymap-select should be called
just before (after?) zle-line-init, since the keymap is initialized at
that time.


  reply	other threads:[~2014-12-23  4:40 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-22  0:07 Fwd: " Jason Spiro
2014-12-22  1:57 ` Bart Schaefer
2014-12-22 18:25   ` Peter Stephenson
2014-12-22 18:44     ` Ray Andrews
2014-12-22 18:44   ` ZyX
2014-12-23  4:40     ` Bart Schaefer [this message]
2014-12-25  4:15     ` Jason Spiro
2014-12-25 20:34       ` ZyX
2014-12-25 23:18         ` Bart Schaefer
2014-12-26 11:32           ` Oliver Kiddle
2014-12-26 19:21             ` Bart Schaefer
2014-12-26 21:58               ` Christian Neukirchen
2014-12-27  0:31                 ` Bart Schaefer
2014-12-29  3:43 Jason Spiro

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=141222204028.ZM9033@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-workers@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).