unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#22743: 25.0.91: set-quit-char does not work if emacs lacks a controlling tty
@ 2016-02-20  5:31 Duncan Burke
  2016-02-20  8:04 ` John Wiegley
  2016-02-20  9:40 ` Eli Zaretskii
  0 siblings, 2 replies; 9+ messages in thread
From: Duncan Burke @ 2016-02-20  5:31 UTC (permalink / raw)
  To: 22743

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

I have heavily customised keybindings on a dvorak layout and this 
necessitates
rebinding quit away from its default value of C-g.

I have rebound C-g in keymaps where it is already defined (such as 
global-map,
minibuffer-local-map and query-replace-map), and have found this to work in
most cases with one major issue in flyspell-mode.

flyspell-post-command-hook calls flyspell-check-word-p, which calls sit-for,
which ultimately calls read_char in keyboard.c.

quit_char in keyboard.c is by default set to ?\C-g and as a consequence in
flyspell-mode if C-g is pressed immediately after entering some text a 
quit is
signalled rather than running the command bound to C-g.

set-quit-char should be able to change quit_char to my desired value of 
?\C-p,
however I run emacs in a graphical window and set-quit-char silently does
nothing if emacs does not have a controlling tty.


To reproduce this issue in emacs 25.0.91.7 with emacs -Q in a graphical
window:

(define-key global-map [?\C-g] 'backward-delete-char)
(define-key global-map [?\C-p] 'keyboard-quit)
(set-quit-char ?\C-p)

;; observe that quit_char is unchanged from original value of ?\C-g
(current-input-mode)


By running flyspell mode, typing something and pressing C-g it can be 
observed
that backward-delete-char is not run as would be expected.

I have attached a patch that changes the behaviour of set-quit-char so that
quit_char is set even if emacs does not have a controlling tty.

[-- Attachment #2: 0001-Fix-set-quit-char-when-there-s-no-controlling-tty.patch --]
[-- Type: text/x-patch, Size: 1957 bytes --]

From e33022f19c91012a9f2f158daa9e29cc2fbb79c5 Mon Sep 17 00:00:00 2001
From: Duncan Burke <duncankburke@gmail.com>
Date: Sat, 20 Feb 2016 00:33:58 +1100
Subject: [PATCH] Fix set-quit-char when there's no controlling tty

set-quit-char currently does nothing if get_named_terminal("/dev/tty")
is NULL. However it is useful to be able to set quit_char when in a
graphical window as this allows it to be bound to something other than
C-g in an alternate keybinding setup.

This patch allows quit_char to be set when there is no controlling
tty. quit_char is masked to 7 bits as the 8th bit is not used for the
meta modifier in X.
---
 src/keyboard.c | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/src/keyboard.c b/src/keyboard.c
index 546c012..f3ce4b1 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -10557,24 +10557,29 @@ See also `current-input-mode'.  */)
   struct terminal *t = get_named_terminal ("/dev/tty");
   struct tty_display_info *tty;
 
-  if (!t)
-    return Qnil;
-  tty = t->display_info.tty;
-
   if (NILP (quit) || !INTEGERP (quit) || XINT (quit) < 0 || XINT (quit) > 0400)
     error ("QUIT must be an ASCII character");
 
+  if (t)
+    {
+      tty = t->display_info.tty;
 #ifndef DOS_NT
-  /* this causes startup screen to be restored and messes with the mouse */
-  reset_sys_modes (tty);
+      /* this causes startup screen to be restored and messes with the mouse */
+      reset_sys_modes (tty);
 #endif
 
-  /* Don't let this value be out of range.  */
-  quit_char = XINT (quit) & (tty->meta_key == 0 ? 0177 : 0377);
+      /* Don't let this value be out of range.  */
+      quit_char = XINT (quit) & (tty->meta_key == 0 ? 0177 : 0377);
 
 #ifndef DOS_NT
-  init_sys_modes (tty);
+      init_sys_modes (tty);
 #endif
+    }
+  else
+    {
+      /* No associated TTY, accept 7-bit ASCII characters */
+      quit_char = XINT (quit) & 0177;
+    }
 
   return Qnil;
 }
-- 
2.7.0


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

* bug#22743: 25.0.91: set-quit-char does not work if emacs lacks a controlling tty
  2016-02-20  5:31 bug#22743: 25.0.91: set-quit-char does not work if emacs lacks a controlling tty Duncan Burke
@ 2016-02-20  8:04 ` John Wiegley
  2016-02-20 11:48   ` Duncan Burke
  2016-02-20  9:40 ` Eli Zaretskii
  1 sibling, 1 reply; 9+ messages in thread
From: John Wiegley @ 2016-02-20  8:04 UTC (permalink / raw)
  To: Duncan Burke; +Cc: 22743

>>>>> Duncan Burke <duncankburke@gmail.com> writes:

> I have heavily customised keybindings on a dvorak layout and this
> necessitates rebinding quit away from its default value of C-g.

Hi Duncan,

I'm also a Dvorak user of many years; I find C-g to be quite convenient,
actually; why did you need to rebind it?  (I ask mainly out of curiosity).

-- 
John Wiegley                  GPG fingerprint = 4710 CF98 AF9B 327B B80F
http://newartisans.com                          60E1 46C4 BD1A 7AC1 4BA2





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

* bug#22743: 25.0.91: set-quit-char does not work if emacs lacks a controlling tty
  2016-02-20  5:31 bug#22743: 25.0.91: set-quit-char does not work if emacs lacks a controlling tty Duncan Burke
  2016-02-20  8:04 ` John Wiegley
@ 2016-02-20  9:40 ` Eli Zaretskii
  2016-02-20 11:37   ` Duncan Burke
  2016-02-20 20:36   ` Glenn Morris
  1 sibling, 2 replies; 9+ messages in thread
From: Eli Zaretskii @ 2016-02-20  9:40 UTC (permalink / raw)
  To: Duncan Burke; +Cc: 22743

> From: Duncan Burke <duncankburke@gmail.com>
> Date: Sat, 20 Feb 2016 16:31:54 +1100
> 
> I have heavily customised keybindings on a dvorak layout and this 
> necessitates
> rebinding quit away from its default value of C-g.
> 
> I have rebound C-g in keymaps where it is already defined (such as 
> global-map,
> minibuffer-local-map and query-replace-map), and have found this to work in
> most cases with one major issue in flyspell-mode.
> 
> flyspell-post-command-hook calls flyspell-check-word-p, which calls sit-for,
> which ultimately calls read_char in keyboard.c.
> 
> quit_char in keyboard.c is by default set to ?\C-g and as a consequence in
> flyspell-mode if C-g is pressed immediately after entering some text a 
> quit is
> signalled rather than running the command bound to C-g.
> 
> set-quit-char should be able to change quit_char to my desired value of 
> ?\C-p,
> however I run emacs in a graphical window and set-quit-char silently does
> nothing if emacs does not have a controlling tty.

That's documented in the doc string of set-quit-char, so this is by
design.  On a TTY, C-g triggers a signal, and Emacs uses a system API
to change the character which does that.  But on GUI frames, this is
not possible.

> I have attached a patch that changes the behaviour of set-quit-char so that
> quit_char is set even if emacs does not have a controlling tty.

I don't think this patch will work reliably, because the parts of code
you changed are not the whole picture.  C-g is supported implicitly
and explicitly in many more places.  Grep the Lisp sources for C-g to
see that.

FWIW, my NSHO is that we should deprecate set-quit-char and remove it
in a future Emacs version.  It is no longer reasonable to have a
feature that only works on text terminals.





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

* bug#22743: 25.0.91: set-quit-char does not work if emacs lacks a controlling tty
  2016-02-20  9:40 ` Eli Zaretskii
@ 2016-02-20 11:37   ` Duncan Burke
  2016-02-20 20:36   ` Glenn Morris
  1 sibling, 0 replies; 9+ messages in thread
From: Duncan Burke @ 2016-02-20 11:37 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 22743

On 20/02/16 20:40, Eli Zaretskii wrote:
 > I don't think this patch will work reliably, because the parts of code
 > you changed are not the whole picture.  C-g is supported implicitly
 > and explicitly in many more places.  Grep the Lisp sources for C-g to
 > see that.

I think it should be possible to rebind C-g. If it cannot be rebound, then
that is an exceptional wart which significantly compromises emacs'
configurability.

It is extremely common for lisp code, whether in emacs or an external 
package,
to make assumptions about default bindings. C-g is far from unique in this
respect and while it would be nice if emacs had a way of globally changing
these assumptions, this is an understood cost when one deviates 
significantly
from emacs defaults. I accept that changing something fundamental like this
requires scouring through lisp source and finding all the places this
assumption is made. Anything in lisp can be patched or configured at 
runtime,
so I am not particularly concerned about such issues.

This patch is required because in this specific instance an assumption 
is made
in the C code about the user's intended purpose of C-g, which has an 
effect in
a graphical frame (demonstrated by my example), but that cannot be 
configured
through lisp from a graphical frame.

 > That's documented in the doc string of set-quit-char, so this is by
 > design.  On a TTY, C-g triggers a signal, and Emacs uses a system API
 > to change the character which does that.  But on GUI frames, this is
 > not possible.

If this is the intended behaviour of set-quit-char, then how is one supposed
to set quit_char from a graphical frame? quit_char is demonstrably not
TTY-specific, so it should be configurable and I cannot see a better place
than set-quit-char.

 > FWIW, my NSHO is that we should deprecate set-quit-char and remove it
 > in a future Emacs version.  It is no longer reasonable to have a
 > feature that only works on text terminals.

Do you mean that quit_char should be removed entirely from the C code? 
Perhaps
that would be best, I do not know enough to have an informed
optinion. However, as long as quit_char exists I have a demonstrated need to
be able to configure it at runtime.





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

* bug#22743: 25.0.91: set-quit-char does not work if emacs lacks a controlling tty
  2016-02-20  8:04 ` John Wiegley
@ 2016-02-20 11:48   ` Duncan Burke
  0 siblings, 0 replies; 9+ messages in thread
From: Duncan Burke @ 2016-02-20 11:48 UTC (permalink / raw)
  To: John Wiegley; +Cc: 22743



On 20/02/16 19:04, John Wiegley wrote:
>>>>>> Duncan Burke <duncankburke@gmail.com> writes:
>> I have heavily customised keybindings on a dvorak layout and this
>> necessitates rebinding quit away from its default value of C-g.
> Hi Duncan,
>
> I'm also a Dvorak user of many years; I find C-g to be quite convenient,
> actually; why did you need to rebind it?  (I ask mainly out of curiosity).
>
You're right, C-g is actually pretty convenient for Dvorak, I move it 
because
it conflicts with other bindings I've chosen.

I have C-h/t/n/s as backward-char, previous-line, next-line and forward 
char.
Then, M-h/t/n/s are backward-word, backward-paragraph, 
forward-paragraph, and
forward-word. M-H/T/N/S continue this pattern, and C-M-h/t/n/s move between
windows.

Going up one row, the commands are the same except killing instead of 
movement
so C-g/c/r/l are backward-delete-char, kill-previous-line, 
kill-next-line and
delete-forward-char.






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

* bug#22743: 25.0.91: set-quit-char does not work if emacs lacks a controlling tty
  2016-02-20  9:40 ` Eli Zaretskii
  2016-02-20 11:37   ` Duncan Burke
@ 2016-02-20 20:36   ` Glenn Morris
  2016-02-20 20:44     ` Eli Zaretskii
  1 sibling, 1 reply; 9+ messages in thread
From: Glenn Morris @ 2016-02-20 20:36 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Duncan Burke, 22743

Eli Zaretskii wrote:

>  C-g is supported implicitly and explicitly in many more places. Grep
> the Lisp sources for C-g to see that.

This is http://debbugs.gnu.org/1218, which has seen zero interest since
it was filed 6 years ago, following

http://lists.gnu.org/archive/html/emacs-devel/2008-10/msg00485.html

and subsequent.





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

* bug#22743: 25.0.91: set-quit-char does not work if emacs lacks a controlling tty
  2016-02-20 20:36   ` Glenn Morris
@ 2016-02-20 20:44     ` Eli Zaretskii
  2016-02-20 20:49       ` Glenn Morris
  0 siblings, 1 reply; 9+ messages in thread
From: Eli Zaretskii @ 2016-02-20 20:44 UTC (permalink / raw)
  To: Glenn Morris; +Cc: duncankburke, 22743

> From: Glenn Morris <rgm@gnu.org>
> Cc: Duncan Burke <duncankburke@gmail.com>,  22743@debbugs.gnu.org
> Date: Sat, 20 Feb 2016 15:36:50 -0500
> 
> Eli Zaretskii wrote:
> 
> >  C-g is supported implicitly and explicitly in many more places. Grep
> > the Lisp sources for C-g to see that.
> 
> This is http://debbugs.gnu.org/1218, which has seen zero interest since
> it was filed 6 years ago, following
> 
> http://lists.gnu.org/archive/html/emacs-devel/2008-10/msg00485.html

In which there's a suggestion to remove the feature.





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

* bug#22743: 25.0.91: set-quit-char does not work if emacs lacks a controlling tty
  2016-02-20 20:44     ` Eli Zaretskii
@ 2016-02-20 20:49       ` Glenn Morris
  2016-02-20 21:04         ` Eli Zaretskii
  0 siblings, 1 reply; 9+ messages in thread
From: Glenn Morris @ 2016-02-20 20:49 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: duncankburke, 22743

Eli Zaretskii wrote:

>> http://lists.gnu.org/archive/html/emacs-devel/2008-10/msg00485.html
>
> In which there's a suggestion to remove the feature.

Indeed (gets my vote), but IIUC you objected at that time

http://lists.gnu.org/archive/html/emacs-devel/2008-10/msg00487.html





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

* bug#22743: 25.0.91: set-quit-char does not work if emacs lacks a controlling tty
  2016-02-20 20:49       ` Glenn Morris
@ 2016-02-20 21:04         ` Eli Zaretskii
  0 siblings, 0 replies; 9+ messages in thread
From: Eli Zaretskii @ 2016-02-20 21:04 UTC (permalink / raw)
  To: Glenn Morris; +Cc: duncankburke, 22743

> From: Glenn Morris <rgm@gnu.org>
> Cc: duncankburke@gmail.com,  22743@debbugs.gnu.org
> Date: Sat, 20 Feb 2016 15:49:15 -0500
> 
> Eli Zaretskii wrote:
> 
> >> http://lists.gnu.org/archive/html/emacs-devel/2008-10/msg00485.html
> >
> > In which there's a suggestion to remove the feature.
> 
> Indeed (gets my vote), but IIUC you objected at that time
> 
> http://lists.gnu.org/archive/html/emacs-devel/2008-10/msg00487.html

Yeah, seven and half years ago!  Lots of water under the bridge since
then.





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

end of thread, other threads:[~2016-02-20 21:04 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-20  5:31 bug#22743: 25.0.91: set-quit-char does not work if emacs lacks a controlling tty Duncan Burke
2016-02-20  8:04 ` John Wiegley
2016-02-20 11:48   ` Duncan Burke
2016-02-20  9:40 ` Eli Zaretskii
2016-02-20 11:37   ` Duncan Burke
2016-02-20 20:36   ` Glenn Morris
2016-02-20 20:44     ` Eli Zaretskii
2016-02-20 20:49       ` Glenn Morris
2016-02-20 21:04         ` Eli Zaretskii

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).