Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: generalize sunkeyboardhack to user-chosen character
- X-seq: zsh-workers 27548
- From: Joakim Rosqvist <joakim.rosqvist@xxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: PATCH: generalize sunkeyboardhack to user-chosen character
- Date: Fri, 1 Jan 2010 17:32:50 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:message-id:subject :from:to:content-type; bh=R3dnsoBNpnHXeZ2e4sM2l6lIsxGvQljqbGcHYSrj3cA=; b=EPR2VbEgQg4nI1SDNry3Xbq+KJdUOIDE36mSJ1gfe+MwWSSX/3e5R1NVuLfIA4htcN cer2+oMCsAPt3TBzt8Z4H5z6xgRCll5DLG+XOzkwk8O5oxQy+INbc484dNEH3GV4eGmB maC8c34B/bw6FEprD9FC5Um+pP/pirwBRFVso=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=c0Uzwa3uNvkvZ2jXxfrCNKpBnfkNnIPOodPmQjPkXCG9g6F/xa7D4vWG7j8/NKY0zE DTXfOckBetHeZN2jb0NCxZ6UBJY/ib/VA5nMVVXSIj0QVMf3AgMmatKO/U2USUrlRlrc W7newMCm7CEqvTkPq1k2U0W9Z6prKmyg5NGs8=
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
On my keyboard, singlequote is too close to return and so often gets pressed
by mistake.
So I've extended the sunkeyboardhack option (which removes an extraneous
backquote
at the end of the command line). Now, one can put e.g.
KEYBOARD_HACK=\'
in .zshrc to have singlequote (or any other ascii character) removed from
the end of the
commandline before it is parsed. This applies only to interactive shells.
Should the character chosen be singlequote, backquote or doublequote, there
also
has to be an odd number of them on the line for the last one to be removed
(since they often appear there intentionally). The old sunkeyboardhack
option
still works and will make backquote the char-to-be-removed.
The Changelog file also need to be updated.
/Joakim Rosqvist
diff -r -u zsh-4.3.10/Doc/Zsh/options.yo
zsh-4.3.10.modified/Doc/Zsh/options.yo
--- zsh-4.3.10/Doc/Zsh/options.yo 2009-05-19 10:39:03.000000000
+0200
+++ zsh-4.3.10.modified/Doc/Zsh/options.yo 2010-01-01
13:53:25.033752054
+0100
@@ -1185,6 +1185,8
@@
of backquotes on the line, ignore the trailing
backquote.
This is useful on some keyboards where the return key
is
too small, and the backquote key lies annoyingly close to
it.
+Deprecated by tt(KEYBOARD_HACK), which lets you choose
the
+character to be
removed.
)
enditem()
diff -r -u zsh-4.3.10/Doc/Zsh/params.yo
zsh-4.3.10.modified/Doc/Zsh/params.yo
--- zsh-4.3.10/Doc/Zsh/params.yo 2009-05-19 13:24:24.000000000
+0200
+++ zsh-4.3.10.modified/Doc/Zsh/params.yo 2010-01-01
13:50:50.785752707
+0100
@@ -897,6 +897,16
@@
If the parameter is unset, the default is used. Note this
has
a different effect from setting the parameter to an empty
string.
)
+vindex(KEYBOARD_HACK)
+item(tt(KEYBOARD_HACK))(
+This variable defines a character to be removed from the end of
the
+command line before interpreting it (interactive shells only). It
is
+intended to fix the problem with keys placed annoyingly close to
return
+and deprecates the tt(SUNKEYBOARDHACK) option which did this
for
+backquotes only. Should the chosen character be one of
singlequote,
+doublequote or backquote, there must also be an odd number of
them
+on the command line for the last one to be
removed.
+)
vindex(KEYTIMEOUT)
item(tt(KEYTIMEOUT))(
The time the shell waits, in hundredths of seconds, for another key
to
diff -r -u zsh-4.3.10/FEATURES
zsh-4.3.10.modified/FEATURES
--- zsh-4.3.10/FEATURES 2005-08-01 11:45:56.000000000
+0200
+++ zsh-4.3.10.modified/FEATURES 2009-12-30 13:53:57.361753499
+0100
@@ -65,6 +65,7
@@
input line to be brought up for editing instead of being
executed
with sunkeyboardhack option, accidentally typed trailing `
characters
are removed from the input line (for those of you with Sun keyboards :-)
)
+with KEYBOARD_HACK, any accidentally typed trailing ascii character can be
junked
"cd old new" replaces "old" with "new" in directory
string
generalized argument completion, new system based on shell
functions:
- highly context
sensitive
diff -r -u zsh-4.3.10/Src/input.c
zsh-4.3.10.modified/Src/input.c
--- zsh-4.3.10/Src/input.c 2008-07-28 18:45:10.000000000
+0200
+++ zsh-4.3.10.modified/Src/input.c 2009-12-30 13:14:37.789752004
+0100
@@ -291,17 +291,22
@@
zputs(ingetcline,
stderr);
fflush(stderr);
}
- if (*ingetcline && ingetcline[strlen(ingetcline) - 1] == '\n'
&&
- interact && isset(SUNKEYBOARDHACK) && isset(SHINSTDIN)
&&
- SHTTY != -1 && *ingetcline && ingetcline[1]
&&
- ingetcline[strlen(ingetcline) - 2] == '`')
{
- /* Junk an unmatched "`" at the end of the line.
*/
- int
ct;
+ if (keyboardhackchar && *ingetcline
&&
+ ingetcline[strlen(ingetcline) - 1] == '\n'
&&
+ interact && isset(SHINSTDIN)
&&
+ SHTTY != -1 && ingetcline[1]
&&
+ ingetcline[strlen(ingetcline) - 2] == keyboardhackchar)
{
+ /* Junk an unwanted character at the end of the
line.
+ (key too close to return key)
*/
+ int ct = 1; /* force odd
*/
char
*ptr;
- for (ct = 0, ptr = ingetcline; *ptr;
ptr++)
- if (*ptr ==
'`')
-
ct++;
+ if (keyboardhackchar == '\'' || keyboardhackchar == '"' ||
keyboardhackchar == '`')
{
+ /* for the chars above, also require an odd count before junking
*/
+ for (ct = 0, ptr = ingetcline; *ptr;
ptr++)
+ if (*ptr ==
keyboardhackchar)
+
ct++;
+
}
if (ct & 1)
{
ptr[-2] =
'\n';
ptr[-1] =
'\0';
diff -r -u zsh-4.3.10/Src/options.c
zsh-4.3.10.modified/Src/options.c
--- zsh-4.3.10/Src/options.c 2009-03-03 18:00:41.000000000
+0100
+++ zsh-4.3.10.modified/Src/options.c 2009-12-30 13:40:15.093751141
+0100
@@ -746,6 +746,9
@@
} else if ((optno == EMACSMODE || optno == VIMODE) && value)
{
zleentry(ZLE_CMD_SET_KEYMAP,
optno);
opts[(optno == EMACSMODE) ? VIMODE : EMACSMODE] =
0;
+ } else if (optno == SUNKEYBOARDHACK)
{
+ /* for backward compatibility
*/
+ keyboardhackchar = (value ? '`' :
'\0');
}
opts[optno] =
value;
if (optno == BANGHIST || optno ==
SHINSTDIN)
diff -r -u zsh-4.3.10/Src/params.c
zsh-4.3.10.modified/Src/params.c
--- zsh-4.3.10/Src/params.c 2009-05-08 11:45:13.000000000
+0200
+++ zsh-4.3.10.modified/Src/params.c 2010-01-01 13:44:31.293753082
+0100
@@ -108,6 +108,9
@@
mod_export unsigned char
bangchar;
/**/
unsigned char hatchar,
hashchar;
+
+/**/
+unsigned char keyboardhackchar =
'\0';
/* $SECONDS = now.tv_sec -
shtimer.tv_sec
* + (now.tv_usec - shtimer.tv_usec) /
1000000.0
@@ -204,6 +207,8 @@
{ ifsgetfn, ifssetfn, stdunsetfn };
static const struct gsu_scalar underscore_gsu =
{ underscoregetfn, nullstrsetfn, stdunsetfn };
+static const struct gsu_scalar keyboard_hack_gsu =
+{ keyboardhackgetfn, keyboardhacksetfn, stdunsetfn };
#ifdef USE_LOCALE
static const struct gsu_scalar lc_blah_gsu =
{ strgetfn, lcsetfn, stdunsetfn };
@@ -273,6 +278,7 @@
IPDEF2("WORDCHARS", wordchars_gsu, 0),
IPDEF2("IFS", ifs_gsu, PM_DONTIMPORT),
IPDEF2("_", underscore_gsu, PM_READONLY),
+IPDEF2("KEYBOARD_HACK", keyboard_hack_gsu, PM_DONTIMPORT),
#ifdef USE_LOCALE
# define LCIPDEF(name) IPDEF2(name, lc_blah_gsu, PM_UNSET)
@@ -3824,6 +3830,46 @@
return errno;
}
+/* Function to get value for special parameter `KEYBOARD_HACK' */
+
+/**/
+char *
+keyboardhackgetfn(UNUSED(Param pm))
+{
+ static char buf[2];
+
+ buf[0] = keyboardhackchar;
+ buf[1] = '\0';
+ return buf;
+}
+
+
+/* Function to set value of special parameter `KEYBOARD_HACK' */
+
+/**/
+void
+keyboardhacksetfn(UNUSED(Param pm), char *x)
+{
+ if (x) {
+ int len, i;
+
+ unmetafy(x, &len);
+ if (len > 1) {
+ len = 1;
+ zwarn("Only one KEYBOARD_HACK character can be defined"); /*
could be changed if needed */
+ }
+ for (i = 0; i < len; i++) {
+ if (!isascii(STOUC(x[i]))) {
+ zwarn("KEYBOARD_HACK can only contain ASCII characters");
+ return;
+ }
+ }
+ keyboardhackchar = len ? STOUC(x[0]) : '\0';
+ free(x);
+ } else
+ keyboardhackchar = '\0';
+}
+
/* Function to get value for special parameter `histchar' */
/**/
Messages sorted by:
Reverse Date,
Date,
Thread,
Author