* Re: the function to show a digit argument while it is being typed
[not found] ` <m3r5s35on8.fsf@klanderman.net>
@ 2009-12-16 17:31 ` Greg Klanderman
2009-12-16 18:03 ` Peter Stephenson
0 siblings, 1 reply; 3+ messages in thread
From: Greg Klanderman @ 2009-12-16 17:31 UTC (permalink / raw)
To: Zsh list
[moved from zsh-users]
>>>>> On November 12, 2009 Greg Klanderman <gak@klanderman.net> wrote:
> So I hacked up a proof of concept in C for showing the argument in the
> universal-argument code.. let me know what you think.
Is there any interest in including a cleaned up version of this patch?
Has been working well for me..
Greg
Index: Src/Zle/zle_misc.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_misc.c,v
retrieving revision 1.58
diff -u -r1.58 zle_misc.c
--- Src/Zle/zle_misc.c 24 Apr 2009 09:00:38 -0000 1.58
+++ Src/Zle/zle_misc.c 16 Dec 2009 17:24:03 -0000
@@ -709,16 +709,81 @@
return 0;
}
+static char *
+baseprefix(char *buf, int base)
+{
+ if (base == 10)
+ buf[0] = (char)0;
+ else if (base == 2)
+ strcpy(buf, "0b");
+ else if (base == 8)
+ strcpy(buf, "0o");
+ else if (base == 16)
+ strcpy(buf, "0x");
+ else
+ sprintf(buf, "%d#", base);
+ return buf;
+}
+
+static char *
+int2string(char *buf, int i, int base)
+{
+ char *b = buf;
+ int p, v;
+
+ if (i < 0) {
+ *b++ = '-';
+ i = -i;
+ }
+
+ baseprefix(b, base);
+ b += strlen(b);
+
+ for (p = 1; p <= i; p *= base)
+ ;
+
+ while (p > 1) {
+ p /= base;
+ v = i / p;
+ i -= v * p;
+ *b++ = (v < 10) ? v+'0' : v-10+'A';
+ }
+
+ *b = (char)0;
+ return buf;
+}
+
+static void
+showarg(int digcnt, int pref, int minus)
+{
+ char msg[100], buf[100], buf2[10];
+
+ if (!digcnt)
+ /* implicit multiplier; will be replaced if digits are entered */
+ sprintf(msg, "arg: (%s)", int2string(buf, 4*zmod.tmult, zmod.base));
+ else if (minus < 0 && digcnt <= 1)
+ /* no digits, just a '-' has been entered so far */
+ sprintf(msg, "arg: -%s", baseprefix(buf2, zmod.base));
+ else
+ /* digits have been entered */
+ sprintf(msg, "arg: %s", int2string(buf, minus * (pref ? pref : 1), zmod.base));
+
+ showmsg(msg);
+ zrefresh();
+}
+
/**/
int
universalargument(char **args)
{
int digcnt = 0, pref = 0, minus = 1, gotk;
+
if (*args) {
zmod.mult = atoi(*args);
zmod.flags |= MOD_MULT;
return 0;
}
+
/*
* TODO: this is quite tricky to do when trying to maintain
* compatibility between the old input system and Unicode.
@@ -734,16 +799,19 @@
*
* Hence for now this remains byte-by-byte.
*/
+ showarg(digcnt, pref, minus);
while ((gotk = getbyte(0L, NULL)) != EOF) {
if (gotk == '-' && !digcnt) {
minus = -1;
digcnt++;
+ showarg(digcnt, pref, minus);
} else {
int newdigit = parsedigit(gotk);
if (newdigit >= 0) {
pref = pref * zmod.base + newdigit;
digcnt++;
+ showarg(digcnt, pref, minus);
} else {
ungetbyte(gotk);
break;
@@ -756,6 +824,8 @@
zmod.tmult *= 4;
zmod.flags |= MOD_TMULT;
prefixflag = 1;
+ showmsg("");
+ zrefresh();
return 0;
}
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: the function to show a digit argument while it is being typed
2009-12-16 17:31 ` the function to show a digit argument while it is being typed Greg Klanderman
@ 2009-12-16 18:03 ` Peter Stephenson
2009-12-16 18:46 ` Greg Klanderman
0 siblings, 1 reply; 3+ messages in thread
From: Peter Stephenson @ 2009-12-16 18:03 UTC (permalink / raw)
To: Zsh list
Greg Klanderman wrote:
> > So I hacked up a proof of concept in C for showing the argument in the
> > universal-argument code.. let me know what you think.
>
> Is there any interest in including a cleaned up version of this patch?
> Has been working well for me..
Looks fairly uncontroversial; could you make it generic to all argument
handling (e.g. ESC-1 ESC-4)? Are there cases where you get clashing use
of the minibuffer?
--
Peter Stephenson <pws@csr.com> Software Engineer
Tel: +44 (0)1223 692070 Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK
Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: the function to show a digit argument while it is being typed
2009-12-16 18:03 ` Peter Stephenson
@ 2009-12-16 18:46 ` Greg Klanderman
0 siblings, 0 replies; 3+ messages in thread
From: Greg Klanderman @ 2009-12-16 18:46 UTC (permalink / raw)
To: zsh-workers
>>>>> On December 16, 2009 Peter Stephenson <pws@csr.com> wrote:
> Looks fairly uncontroversial;
OK, I'll work on this a bit then..
> could you make it generic to all argument handling (e.g. ESC-1 ESC-4)?
Yes, that would be my plan. This thread originally started with how
to do that with user defined widgets for digit-argument and
negative-argument, and a good solution was found, but the same could
not be done for universal-argument.
> Are there cases where you get clashing use of the minibuffer?
Not that I've noticed.
thanks,
Greg
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2009-12-16 18:46 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <10081257897632@webmail89.yandex.ru>
[not found] ` <237967ef0911101822g5bfcf4fao25fc33ba0a2e8604@mail.gmail.com>
[not found] ` <091110204748.ZM28704@torch.brasslantern.com>
[not found] ` <237967ef0911102217m1325dc59y8d7388e9f6f21c7b@mail.gmail.com>
[not found] ` <091111001419.ZM28852@torch.brasslantern.com>
[not found] ` <m3eio56o4i.fsf@klanderman.net>
[not found] ` <091111094507.ZM30174@torch.brasslantern.com>
[not found] ` <m3r5s35on8.fsf@klanderman.net>
2009-12-16 17:31 ` the function to show a digit argument while it is being typed Greg Klanderman
2009-12-16 18:03 ` Peter Stephenson
2009-12-16 18:46 ` Greg Klanderman
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).