Subject: 23.3.50; Emacs doesn't properly initialize a TTY when resuming it

From: Courtney Bane <[email-masked]>
Date: Tue, 17 May 2011 17:12:33 -0500

When an Emacs server resumes a suspended frame on a TTY, it doesn't
switch back to the alternate screen. This causes the UI to still be
visible on the screen after closing the frame, which doesn't match the
behavior of a normal Emacs session. This occurs in the 23.3 release, and
in the latest versions on the "emacs-23" and "trunk" BZR branches.

I have attached a patch which allows Emacs to switch back to the
alternate screen when resuming a TTY frame.

Steps to reproduce:
($ == type at shell prompt; <> == commands for Emacs; # == comments)

$ emacs -Q --daemon
$ emacsclient -t
<press C-z to suspend frame>
# frame suspends, exiting alternate screen
$ fg
# Emacs resumes, but hasn't switched to alternate screen
<press C-x C-c to close frame>
# Emacs closes the frame, but the UI is still visible because it wasn't
# drawn on the alternate screen

What should happen:

An Emacs daemon should behave like a normal Emacs session.

Regular (non-server) Emacs behavior:

$ emacs -Q
<press C-z>
# Emacs exits the alternate screen and suspends
$ fg
# Emacs resumes, switching to alternate screen
<press C-x C-c>
# Emacs exits the alternate screen and quits

Desired client/server behavior:

$ emacs -Q --daemon
$ emacsclient -t
<press C-z to suspend frame>
# frame suspends, and exits alternate screen
$ fg
# Emacs resumes, and switches back to alternate screen
<press C-x C-c to close frame>
# Emacs closes the frame, and exits the alternate screen

In GNU Emacs 23.3.50.2 (x86_64-unknown-linux-gnu, GTK+ Version 2.24.4)
 of 2011-05-17 on titan
configured using `configure  '--prefix=/tmp/emacs''

Important settings:
  value of $LC_ALL: nil
  value of $LC_COLLATE: C
  value of $LC_CTYPE: nil
  value of $LC_MESSAGES: nil
  value of $LC_MONETARY: nil
  value of $LC_NUMERIC: nil
  value of $LC_TIME: nil
  value of $LANG: en_US.UTF-8
  value of $XMODIFIERS: nil
  locale-coding-system: utf-8-unix
  default enable-multibyte-characters: t

Major mode: Lisp Interaction

Minor modes in effect:
  show-paren-mode: t
  tooltip-mode: t
  mouse-wheel-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  column-number-mode: 1
  line-number-mode: 1
  transient-mark-mode: t

Recent input:
ESC x r e p o r t SPC b u g RET

Recent messages:
("/tmp/emacs/bin/emacs")
Ido mode enabled
For information about GNU Emacs and the GNU system, type <f1> C-a.

Load-path shadows:
None found.

Features:
(shadow sort mail-extr message sendmail ecomplete rfc822 mml easymenu
mml-sec password-cache mm-decode mm-bodies mm-encode mailcap mail-parse
rfc2231 rfc2047 rfc2045 qp ietf-drums mailabbrev nnheader gnus-util
netrc time-date mm-util mail-prsvr gmm-utils wid-edit mailheader canlock
sha1 hex-util hashcash mail-utils warnings emacsbug cc-styles cc-align
cc-engine cc-vars cc-defs regexp-opt jcb-bindings windmove edmacro
kmacro jcb-variables variables jcb-defuns imenu ffap saveplace ido paren
uniquify advice help-fns advice-preload column-marker tooltip ediff-hook
vc-hooks lisp-float-type mwheel x-win x-dnd font-setting tool-bar dnd
fontset image fringe lisp-mode register page menu-bar rfn-eshadow timer
select scroll-bar mldrag mouse jit-lock font-lock syntax facemenu
font-core frame cham georgian utf-8-lang misc-lang vietnamese tibetan
thai tai-viet lao korean japanese hebrew greek romanian slovak czech
european ethiopic indian cyrillic chinese case-table epa-hook
jka-cmpr-hook help simple abbrev loaddefs button minibuffer faces
cus-face files text-properties overlay md5 base64 format env code-pages
mule custom widget hashtable-print-readable backquote
make-network-process dbusbind system-font-setting font-render-setting
gtk x-toolkit x multi-tty emacs)
=== modified file 'src/term.c'
--- src/term.c	2011-04-08 18:44:36 +0000
+++ src/term.c	2011-05-17 21:24:33 +0000
@@ -2476,6 +2476,7 @@
 	  FRAME_SET_VISIBLE (XFRAME (t->display_info.tty->top_frame), 1);
 	}
 
+      set_tty_hooks (t);
       init_sys_modes (t->display_info.tty);
 
       /* Run `resume-tty-functions'.  */