From 5520e85ee437f62953ac4f2d5b8f89401c362253 Mon Sep 17 00:00:00 2001
From: David Lawrence Ramsey <pooka109@gmail.com>
Date: Wed, 7 Apr 2004 00:44:35 +0000
Subject: [PATCH] make sure the special control keys are handled the same way
 after a continue or a window resize

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1708 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
---
 ChangeLog   |  3 +++
 src/nano.c  | 36 ++++++++++++++++++++++--------------
 src/winio.c |  6 +++---
 3 files changed, 28 insertions(+), 17 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index f13f9a79..73f0b384 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,9 @@
 CVS code -
 - General:
 	- Minor comment cleanups. (DLR)
+	- Make sure the special control keys are handled the same way
+	  after the window is resized or we come out of suspend mode.
+	  Changes to do_cont() and handle_sigwinch(). (DLR)
 - files.c:
   add_open_file()
 	- Rearrange the NANO_SMALL #ifdef so that the code to set the
diff --git a/src/nano.c b/src/nano.c
index 7174462c..1e37e9a8 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -2768,18 +2768,20 @@ void signal_init(void)
     struct termios term;
 #endif
 
-    /* Trap SIGINT and SIGQUIT cuz we want them to do useful things. */
+    /* Trap SIGINT and SIGQUIT because we want them to do useful
+     * things. */
     memset(&act, 0, sizeof(struct sigaction));
     act.sa_handler = SIG_IGN;
     sigaction(SIGINT, &act, NULL);
     sigaction(SIGQUIT, &act, NULL);
 
-    /* Trap SIGHUP and SIGTERM cuz we want to write the file out. */
+    /* Trap SIGHUP and SIGTERM because we want to write the file out. */
     act.sa_handler = handle_hupterm;
     sigaction(SIGHUP, &act, NULL);
     sigaction(SIGTERM, &act, NULL);
 
 #ifndef NANO_SMALL
+    /* Trap SIGWINCH because we want to handle window resizes. */
     act.sa_handler = handle_sigwinch;
     sigaction(SIGWINCH, &act, NULL);
     allow_pending_sigwinch(FALSE);
@@ -2789,18 +2791,21 @@ void signal_init(void)
     tcgetattr(0, &term);
 
     if (!ISSET(PRESERVE)) {
-	/* Ignore ^S and ^Q, much to Chris' chagrin */
+	/* Trap XOFF (^S) and XON (^Q), much to Chris' chagrin, because
+	 * we want to block them. */
 	term.c_cc[VSTOP] = _POSIX_VDISABLE;
 	term.c_cc[VSTART] = _POSIX_VDISABLE;
     }
 #ifdef VDSUSP
+    /* Trap delayed suspend (^Y) so we can handle it ourselves. */
     term.c_cc[VDSUSP] = _POSIX_VDISABLE;
-#endif /* VDSUSP */
+#endif
 
 #endif /* _POSIX_VDISABLE */
 
     if (!ISSET(SUSPEND)) {
-	/* Insane! */
+        /* Trap normal suspend (^Z) so we can handle it ourselves.  If
+	 * we can't trap the key, trap the signal instead.  Insane! */
 #ifdef _POSIX_VDISABLE
 	term.c_cc[VSUSP] = _POSIX_VDISABLE;
 #else
@@ -2808,9 +2813,8 @@ void signal_init(void)
 	sigaction(SIGTSTP, &act, NULL);
 #endif
     } else {
-	/* If we don't do this, it seems other stuff interrupts the
-	   suspend handler!  Try using nano with mutt without this
-	   line. */
+	/* Block all other signals in the suspend and continue handlers.
+	 * If we don't do this, other stuff interrupts them! */
 	sigfillset(&act.sa_mask);
 
 	act.sa_handler = do_suspend;
@@ -2825,7 +2829,7 @@ void signal_init(void)
 #endif
 }
 
-/* Handler for SIGHUP and SIGTERM */
+/* Handler for SIGHUP and SIGTERM. */
 RETSIGTYPE handle_hupterm(int signal)
 {
     die(_("Received SIGHUP or SIGTERM\n"));
@@ -2857,16 +2861,16 @@ RETSIGTYPE do_suspend(int signal)
 RETSIGTYPE do_cont(int signal)
 {
     /* Now we just update the screen instead of having to reenable the
-       SIGTSTP handler. */
+     * SIGTSTP handler. */
     doupdate();
 
-    /* The Hurd seems to need this, otherwise a ^Y after a ^Z will
-       start suspending again. */
-    signal_init();
-
 #ifndef NANO_SMALL
     /* Perhaps the user resized the window while we slept. */
     handle_sigwinch(0);
+#else
+    /* Set up the signal handlers again, so that the special control
+     * keys all work the same as before. */
+    signal_init();
 #endif
 }
 
@@ -2943,6 +2947,10 @@ void handle_sigwinch(int s)
     keypad(edit, TRUE);
     keypad(bottomwin, TRUE);
 
+    /* Set up the signal handlers again, so that the special control
+     * keys all work the same as before. */
+    signal_init();
+
     /* Jump back to the main loop. */
     siglongjmp(jmpbuf, 1);
 }
diff --git a/src/winio.c b/src/winio.c
index 27317dc1..45204300 100644
--- a/src/winio.c
+++ b/src/winio.c
@@ -75,9 +75,9 @@ int *get_verbatim_kbinput(WINDOW *win, int *kbinput_len, int
 #endif
 
     /* Switch to raw mode so that we can type ^C, ^Q, ^S, ^Z, and ^\
-     * (and ^Y on the Hurd) without getting interrupts, and Turn the
-     * keypad off so that we don't get extended keypad values all of
-     * which are outside the ASCII range. */
+     * (and ^Y on systems supporting delayed suspend) without getting
+     * interrupts, and turn the keypad off so that we don't get extended
+     * keypad values, all of which are outside the ASCII range. */
 #ifdef _POSIX_VDISABLE
     raw();
 #endif
-- 
GitLab