zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: keyboardhack to replace sunkeyboardhack
@ 2010-01-11 21:37 Joakim Rosqvist
  2010-01-12 10:07 ` Peter Stephenson
  0 siblings, 1 reply; 4+ messages in thread
From: Joakim Rosqvist @ 2010-01-11 21:37 UTC (permalink / raw)
  To: zsh-workers


[-- Attachment #1.1: Type: text/plain, Size: 891 bytes --]

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.

(I apologize for sending the patch as an attachment. It is formatted with
git format-patch,
but my ISP is playing tricks that prevents me from getting sendmail to work)

/Joakim Rosqvist

[-- Attachment #1.2: Type: text/html, Size: 970 bytes --]

[-- Attachment #2: 0001-Add-Keyboardhack-variable-to-extend-sunkeyboardhack.patch --]
[-- Type: text/x-patch, Size: 7187 bytes --]

From f3e8e1e817493cf6193f58642fb854d091c5bd96 Mon Sep 17 00:00:00 2001
From: Joakim Rosqvist <joakim.rosqvist@gmail.com>
Date: Wed, 6 Jan 2010 19:20:30 +0100
Subject: [PATCH] Add Keyboardhack variable to extend sunkeyboardhack

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.

/Joakim Rosqvist
---
 Doc/Zsh/options.yo |    2 ++
 Doc/Zsh/params.yo  |   10 ++++++++++
 FEATURES           |    1 +
 Src/input.c        |   23 ++++++++++++++---------
 Src/options.c      |    3 +++
 Src/params.c       |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 76 insertions(+), 9 deletions(-)

diff --git a/Doc/Zsh/options.yo b/Doc/Zsh/options.yo
index 46e21d6..50dc3c9 100644
--- a/Doc/Zsh/options.yo
+++ b/Doc/Zsh/options.yo
@@ -1209,6 +1209,8 @@ If a line ends with a backquote, and there are an odd number
 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 --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo
index 18c1468..17955b9 100644
--- a/Doc/Zsh/params.yo
+++ b/Doc/Zsh/params.yo
@@ -897,6 +897,16 @@ space character.
 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 --git a/FEATURES b/FEATURES
index 2dc2736..9b0d0c2 100644
--- a/FEATURES
+++ b/FEATURES
@@ -66,6 +66,7 @@ with histverify option, performing csh-style history expansions causes the
   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 --git a/Src/input.c b/Src/input.c
index 80f8ec8..d750ea7 100644
--- a/Src/input.c
+++ b/Src/input.c
@@ -291,17 +291,22 @@ inputline(void)
 	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 --git a/Src/options.c b/Src/options.c
index c5b7c3b..a5f299e 100644
--- a/Src/options.c
+++ b/Src/options.c
@@ -748,6 +748,9 @@ dosetopt(int optno, int value, int force)
     } 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 --git a/Src/params.c b/Src/params.c
index 0425e07..abc4c00 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -108,6 +108,9 @@ zlong lineno,		/* $LINENO      */
 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 @@ static const struct gsu_scalar ifs_gsu =
 { 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("TERM", term_gsu, 0),
 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)
@@ -3834,6 +3840,46 @@ errnogetfn(UNUSED(Param pm))
     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' */
 
 /**/
-- 
1.6.3.3


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: PATCH: keyboardhack to replace sunkeyboardhack
  2010-01-11 21:37 PATCH: keyboardhack to replace sunkeyboardhack Joakim Rosqvist
@ 2010-01-12 10:07 ` Peter Stephenson
  2010-01-12 13:35   ` Joakim Rosqvist
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Stephenson @ 2010-01-12 10:07 UTC (permalink / raw)
  To: zsh-workers

On Mon, 11 Jan 2010 22:37:27 +0100
Joakim Rosqvist <joakim.rosqvist@gmail.com> wrote:
> 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.

Thanks.  The pointer arithmetic for removing the character was wrong (try
it with a non-quote character), and in practice we're not going to remove
the existing option, so I've made a couple of local changes.

Index: FEATURES
===================================================================
RCS file: /cvsroot/zsh/zsh/FEATURES,v
retrieving revision 1.3
diff -u -r1.3 FEATURES
--- FEATURES	10 Nov 2009 22:16:37 -0000	1.3
+++ FEATURES	12 Jan 2010 10:03:10 -0000
@@ -66,6 +66,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
Index: Doc/Zsh/options.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/options.yo,v
retrieving revision 1.87
diff -u -r1.87 options.yo
--- Doc/Zsh/options.yo	2 Dec 2009 09:56:42 -0000	1.87
+++ Doc/Zsh/options.yo	12 Jan 2010 10:03:11 -0000
@@ -1209,6 +1209,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.
+As an alternative the variable tt(KEYBOARD_HACK) lets you choose the
+character to be removed.
 )
 enditem()
 
Index: Doc/Zsh/params.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/params.yo,v
retrieving revision 1.56
diff -u -r1.56 params.yo
--- Doc/Zsh/params.yo	20 May 2009 09:04:39 -0000	1.56
+++ Doc/Zsh/params.yo	12 Jan 2010 10:03:11 -0000
@@ -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 replaces 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
Index: Src/input.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/input.c,v
retrieving revision 1.18
diff -u -r1.18 input.c
--- Src/input.c	16 Dec 2009 18:39:07 -0000	1.18
+++ Src/input.c	12 Jan 2010 10:03:11 -0000
@@ -291,20 +291,32 @@
 	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;
-	char *ptr;
-
-	for (ct = 0, ptr = ingetcline; *ptr; ptr++)
-	    if (*ptr == '`')
-		ct++;
-	if (ct & 1) {
-	    ptr[-2] = '\n';
-	    ptr[-1] = '\0';
+    if (keyboardhackchar && *ingetcline &&
+	ingetcline[strlen(ingetcline) - 1] == '\n' &&
+	interact && isset(SHINSTDIN) &&
+	SHTTY != -1 && ingetcline[1])
+    {
+	char *stripptr = ingetcline + strlen(ingetcline) - 2;
+	if (*stripptr == keyboardhackchar) {
+	    /* Junk an unwanted character at the end of the line.
+	       (key too close to return key) */
+	    int ct = 1;  /* force odd */
+	    char *ptr;
+
+	    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) {
+		stripptr[0] = '\n';
+		stripptr[1] = '\0';
+	    }
 	}
     }
     isfirstch = 1;
Index: Src/options.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/options.c,v
retrieving revision 1.51
diff -u -r1.51 options.c
--- Src/options.c	19 Jul 2009 19:08:53 -0000	1.51
+++ Src/options.c	12 Jan 2010 10:03:11 -0000
@@ -748,6 +748,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)
Index: Src/params.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/params.c,v
retrieving revision 1.157
diff -u -r1.157 params.c
--- Src/params.c	5 Sep 2009 19:49:20 -0000	1.157
+++ Src/params.c	12 Jan 2010 10:03:11 -0000
@@ -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)
@@ -3834,6 +3840,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' */
 
 /**/


-- 
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] 4+ messages in thread

* Re: PATCH: keyboardhack to replace sunkeyboardhack
  2010-01-12 10:07 ` Peter Stephenson
@ 2010-01-12 13:35   ` Joakim Rosqvist
  2010-01-12 13:43     ` Peter Stephenson
  0 siblings, 1 reply; 4+ messages in thread
From: Joakim Rosqvist @ 2010-01-12 13:35 UTC (permalink / raw)
  To: Peter Stephenson, zsh-workers

[-- Attachment #1: Type: text/plain, Size: 9078 bytes --]

I never intended to remove the existing option, that's why my patch
sets the char-to-be-removed to backquote when the sunkeyboardhack option is
set.

/Joakim Rosqvist

On Tue, Jan 12, 2010 at 11:07, Peter Stephenson <pws@csr.com> wrote:

> On Mon, 11 Jan 2010 22:37:27 +0100
> Joakim Rosqvist <joakim.rosqvist@gmail.com> wrote:
> > 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.
>
> Thanks.  The pointer arithmetic for removing the character was wrong (try
> it with a non-quote character), and in practice we're not going to remove
> the existing option, so I've made a couple of local changes.
>
> Index: FEATURES
> ===================================================================
> RCS file: /cvsroot/zsh/zsh/FEATURES,v
> retrieving revision 1.3
> diff -u -r1.3 FEATURES
> --- FEATURES    10 Nov 2009 22:16:37 -0000      1.3
> +++ FEATURES    12 Jan 2010 10:03:10 -0000
> @@ -66,6 +66,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
> Index: Doc/Zsh/options.yo
> ===================================================================
> RCS file: /cvsroot/zsh/zsh/Doc/Zsh/options.yo,v
> retrieving revision 1.87
> diff -u -r1.87 options.yo
> --- Doc/Zsh/options.yo  2 Dec 2009 09:56:42 -0000       1.87
> +++ Doc/Zsh/options.yo  12 Jan 2010 10:03:11 -0000
> @@ -1209,6 +1209,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.
> +As an alternative the variable tt(KEYBOARD_HACK) lets you choose the
> +character to be removed.
>  )
>  enditem()
>
> Index: Doc/Zsh/params.yo
> ===================================================================
> RCS file: /cvsroot/zsh/zsh/Doc/Zsh/params.yo,v
> retrieving revision 1.56
> diff -u -r1.56 params.yo
> --- Doc/Zsh/params.yo   20 May 2009 09:04:39 -0000      1.56
> +++ Doc/Zsh/params.yo   12 Jan 2010 10:03:11 -0000
> @@ -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 replaces 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
> Index: Src/input.c
> ===================================================================
> RCS file: /cvsroot/zsh/zsh/Src/input.c,v
> retrieving revision 1.18
> diff -u -r1.18 input.c
> --- Src/input.c 16 Dec 2009 18:39:07 -0000      1.18
> +++ Src/input.c 12 Jan 2010 10:03:11 -0000
> @@ -291,20 +291,32 @@
>        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;
> -       char *ptr;
> -
> -       for (ct = 0, ptr = ingetcline; *ptr; ptr++)
> -           if (*ptr == '`')
> -               ct++;
> -       if (ct & 1) {
> -           ptr[-2] = '\n';
> -           ptr[-1] = '\0';
> +    if (keyboardhackchar && *ingetcline &&
> +       ingetcline[strlen(ingetcline) - 1] == '\n' &&
> +       interact && isset(SHINSTDIN) &&
> +       SHTTY != -1 && ingetcline[1])
> +    {
> +       char *stripptr = ingetcline + strlen(ingetcline) - 2;
> +       if (*stripptr == keyboardhackchar) {
> +           /* Junk an unwanted character at the end of the line.
> +              (key too close to return key) */
> +           int ct = 1;  /* force odd */
> +           char *ptr;
> +
> +           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) {
> +               stripptr[0] = '\n';
> +               stripptr[1] = '\0';
> +           }
>        }
>     }
>     isfirstch = 1;
> Index: Src/options.c
> ===================================================================
> RCS file: /cvsroot/zsh/zsh/Src/options.c,v
> retrieving revision 1.51
> diff -u -r1.51 options.c
> --- Src/options.c       19 Jul 2009 19:08:53 -0000      1.51
> +++ Src/options.c       12 Jan 2010 10:03:11 -0000
> @@ -748,6 +748,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)
> Index: Src/params.c
> ===================================================================
> RCS file: /cvsroot/zsh/zsh/Src/params.c,v
> retrieving revision 1.157
> diff -u -r1.157 params.c
> --- Src/params.c        5 Sep 2009 19:49:20 -0000       1.157
> +++ Src/params.c        12 Jan 2010 10:03:11 -0000
> @@ -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)
> @@ -3834,6 +3840,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' */
>
>  /**/
>
>
> --
> 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] 4+ messages in thread

* Re: PATCH: keyboardhack to replace sunkeyboardhack
  2010-01-12 13:35   ` Joakim Rosqvist
@ 2010-01-12 13:43     ` Peter Stephenson
  0 siblings, 0 replies; 4+ messages in thread
From: Peter Stephenson @ 2010-01-12 13:43 UTC (permalink / raw)
  To: zsh-workers

On Tue, 12 Jan 2010 14:35:30 +0100
Joakim Rosqvist <joakim.rosqvist@gmail.com> wrote:
> I never intended to remove the existing option, that's why my patch
> sets the char-to-be-removed to backquote when the sunkeyboardhack option is
> set.

That was simply the documentation which said the option was deprecated.  If
we're actually never going to remove it, it's not deprecated.

-- 
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] 4+ messages in thread

end of thread, other threads:[~2010-01-12 14:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-01-11 21:37 PATCH: keyboardhack to replace sunkeyboardhack Joakim Rosqvist
2010-01-12 10:07 ` Peter Stephenson
2010-01-12 13:35   ` Joakim Rosqvist
2010-01-12 13:43     ` Peter Stephenson

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).