Subject: Re: bug#35180: 27.0.50; emacs daemon and “package” often inserts [I when opening file

From: "Basil L. Contovounesios" <[email-masked]>
Date: Sat, 27 Apr 2019 13:00:11 +0100

Andreas Schwab <[email-masked]> writes:

> On Apr 27 2019, Han Boetes <[email-masked]> wrote:
>
>> 6288  write(8, "\33[44d\33[K\33[2d\33[?25l[I\33[43;7H\33[30m"..., 80) = 80
>
> "\e[I" is the xterm focus-in event, so it looks like some race condition.

Indeed.  This behaviour is present in master, but not emacs-26.  Here's
the simplest repro for me under gnome-terminal on GNU/Linux:

0. emacs -Q --daemon=test
1. emacsclient -t -s test

Some environment variables follow my signature.  Although the above is
not reproducible 100% of the time, the following brings it down to 0% of
the time for me:

0. emacs -Q --daemon=test
1. TERM=xterm-direct emacsclient -t -s test

Another thing that brings the reproducibility down to 0% is the
following:

diff --git a/lisp/faces.el b/lisp/faces.el
index fa526c3506..195430d980 100644
--- a/lisp/faces.el
+++ b/lisp/faces.el
@@ -2266,6 +2266,7 @@ tty-run-terminal-initialization
 this runs the hook `tty-setup-hook'.
 
 If you set `term-file-prefix' to nil, this function does nothing."
+  (message "")
   (setq type (or type (tty-type frame)))
   (let ((alias (tty-find-type
 		(lambda (typ) (assoc typ term-file-aliases)) type)))

I also tried the following:

diff --git a/lisp/term/xterm.el b/lisp/term/xterm.el
index c4b0a8fb6e..94b5d57a06 100644
--- a/lisp/term/xterm.el
+++ b/lisp/term/xterm.el
@@ -117,6 +117,7 @@ global-map
 (defun xterm-translate-focus-in (_prompt)
   (setf (terminal-parameter nil 'tty-focus-state) 'focused)
   (funcall after-focus-change-function)
+  (message ">>> focus in")
   [])
 
 (defun xterm-translate-focus-out (_prompt)

On successful startup (where [I is not inserted), I am greeted by the
"focus in" message.

On unsuccessful startup (where [I is inserted), the message never
appears, but term/xterm and xterm are present in features.

Could this race somehow be caused by the pdumper?

Thanks,

-- 
Basil

SHELL=/bin/bash
COLORTERM=truecolor
XDG_SESSION_PATH=/org/freedesktop/DisplayManager/Session0
LANGUAGE=en_IE:en
XDG_CONFIG_HOME=/home/blc/.config
DESKTOP_SESSION=lightdm-xsession
XDG_SEAT=seat0
PWD=/home/blc/.local/src/emacs
XDG_SESSION_DESKTOP=lightdm-xsession
LOGNAME=blc
XDG_SESSION_TYPE=x11
XAUTHORITY=/home/blc/.Xauthority
XDG_GREETER_DATA_DIR=/var/lib/lightdm/data/blc
HOME=/home/blc
LANG=en_IE.UTF-8
VTE_VERSION=5402
XDG_SEAT_PATH=/org/freedesktop/DisplayManager/Seat0
GNOME_TERMINAL_SCREEN=/org/gnome/Terminal/screen/a0c755f7_f6cf_4729_b8a6_05f4947bd3eb
XDG_SESSION_CLASS=user
TERM=xterm-256color
USER=blc
GNOME_TERMINAL_SERVICE=:1.66
DISPLAY=:0
SHLVL=1
XDG_VTNR=7
XDG_SESSION_ID=2
XDG_RUNTIME_DIR=/run/user/1000
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
_=/usr/bin/printenv

In GNU Emacs 27.0.50 (build 6, x86_64-pc-linux-gnu, X toolkit, Xaw3d scroll bars)
 of 2019-04-27 built on thunk
Repository revision: 8dc00b2f1e6523c634df3e24379afbe712a32b27
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12003000
System Description: Debian GNU/Linux buster/sid

Configured using:
 'configure 'CC=ccache gcc' 'CFLAGS=-O2 -march=native' --config-cache
 --prefix=/home/blc/.local --with-mailutils --with-x-toolkit=lucid
 --with-modules --with-file-notification=yes --with-x'

Configured features:
XAW3D XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK SOUND GPM DBUS GSETTINGS
GLIB NOTIFY INOTIFY ACL LIBSELINUX GNUTLS LIBXML2 FREETYPE M17N_FLT
LIBOTF XFT ZLIB TOOLKIT_SCROLL_BARS LUCID X11 XDBE XIM MODULES THREADS
LIBSYSTEMD JSON PDUMPER LCMS2 GMP

Important settings:
  value of $LANG: en_IE.UTF-8
  locale-coding-system: utf-8-unix