Subject: 27.1; Incompatibility between daemon, desktop and highlight-changes-mode

From: Gilles <[email-masked]>
Date: Tue, 23 Mar 2021 01:30:36 +0100

When restoring a desktop session where a buffer has
highlight-changes-mode enabled, if Emacs is starting in daemon mode, it
locks up before opening the socket. There is no error message.

If Emacs is not starting in daemon mode, or if the desktop session file
does not list highlight-changes-mode, everything is fine.

I have observed this problem both with Emacs 27.1 on macOS and with
Emacs 26.3 on Ubuntu 20.04. Below I give the server an explicit name for
convenience but this is optional to reproduce the bug.

Here is a precise recipe to reproduce. (Lines beginning with a letter
are shell commands; lines beginning with `|` are terminal output.)

mkdir -p /var/tmp/bugs/emacs-daemon-desktop-highlight-changes/.emacs.d
cd /var/tmp/bugs/emacs-daemon-desktop-highlight-changes
echo "(setq desktop-restore-frames nil)" >.emacs.d/init.el
echo "(desktop-save-mode)" >>.emacs.d/init.el
HOME=$PWD emacs --no-site-file -nw .emacs.d/init.el
# C-x C-c y ; Exit, saving the session
cp .emacs.d/.emacs.desktop desktop.ok.el
HOME=$PWD emacs --no-site-file --daemon=foo
| Wrote
/var/tmp/bugs/emacs-daemon-desktop-highlight-changes/.emacs.d/.emacs.desktop.lock
| Desktop: 1 frame, 1 buffer restored.
| Starting Emacs daemon.
emacsclient -s foo -c -nw
# C-x b RET ; Switch to init.el
# M-x highlight-changes-mode RET
# M-x kill-emacs RET
cp .emacs.d/.emacs.desktop desktop.bad.el
HOME=$PWD emacs --no-site-file --daemon=foo

At this point, there are two Emacs processes (the original one and its
daemon child), but they do not reach the point of creating the server
socket. No message is displayed on the terminal. On the other hand, if I
kill the Emacs processes and run ``HOME=$PWD emacs --no-site-file -nw``,
Emacs starts normally.

Here are the working (desktop.ok.el) and non-working (desktop.bad.el)
versions of .emacs.desktop from above.

----------------------------------------------------------------
;; -*- mode: emacs-lisp; lexical-binding:t; coding: utf-8-emacs; -*-
;; --------------------------------------------------------------------------
;; Desktop File for Emacs
;; --------------------------------------------------------------------------
;; Created Tue Mar 23 00:57:14 2021
;; Desktop file format version 208
;; Emacs version 27.1

;; Global section:
(setq desktop-saved-frameset nil)
(setq desktop-missing-file-warning nil)
(setq tags-file-name nil)
(setq tags-table-list nil)
(setq search-ring nil)
(setq regexp-search-ring nil)
(setq register-alist nil)
(setq file-name-history nil)

;; Buffer section -- buffers listed in same order as in buffer list:
(desktop-create-buffer 208
  "/var/tmp/bugs/emacs-daemon-desktop-highlight-changes/.emacs.d/init.el"
  "init.el"
  'emacs-lisp-mode
  '(eldoc-mode)
  1
  '(nil nil)
  nil
  nil
  '((buffer-display-time 24665 11993 439843 0)
(buffer-file-coding-system . prefer-utf-8-unix))
  '((mark-ring nil)))

----------------------------------------------------------------
;; -*- mode: emacs-lisp; lexical-binding:t; coding: utf-8-emacs; -*-
;; --------------------------------------------------------------------------
;; Desktop File for Emacs
;; --------------------------------------------------------------------------
;; Created Tue Mar 23 00:58:04 2021
;; Desktop file format version 208
;; Emacs version 27.1

;; Global section:
(setq desktop-saved-frameset nil)
(setq desktop-missing-file-warning nil)
(setq tags-file-name nil)
(setq tags-table-list nil)
(setq search-ring nil)
(setq regexp-search-ring nil)
(setq register-alist nil)
(setq file-name-history nil)

;; Buffer section -- buffers listed in same order as in buffer list:
(desktop-create-buffer 208
  "/var/tmp/bugs/emacs-daemon-desktop-highlight-changes/.emacs.d/init.el"
  "init.el"
  'emacs-lisp-mode
  '(eldoc-mode highlight-changes-mode)
  1
  '(nil nil)
  nil
  nil
  '((buffer-display-time 24665 12038 824402 0)
(buffer-file-coding-system . prefer-utf-8-unix)
(highlight-changes-mode . t))
  '((mark-ring nil)))

----------------------------------------------------------------

In GNU Emacs 27.1 (build 1, x86_64-apple-darwin18.7.0, NS
appkit-1671.60 Version 10.14.6 (Build 18G95))
 of 2020-08-12 built on builder10-14.porkrind.org
Windowing system distributor 'Apple', version 10.3.2022
System Description:  macOS 11.2.3

Configured using:
 'configure --with-ns '--enable-locallisppath=/Library/Application
 Support/Emacs/${version}/site-lisp:/Library/Application
 Support/Emacs/site-lisp' --with-modules'

Configured features:
NOTIFY KQUEUE ACL GNUTLS LIBXML2 ZLIB TOOLKIT_SCROLL_BARS NS MODULES
THREADS JSON PDUMPER

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

Major mode: Lisp Interaction

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message rmc puny dired dired-loaddefs
format-spec rfc822 mml easymenu mml-sec password-cache epa derived epg
epg-config gnus-util rmail rmail-loaddefs text-property-search time-date
subr-x seq byte-opt gv bytecomp byte-compile cconv mm-decode mm-bodies
mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader cl-loaddefs
cl-lib sendmail rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mail-utils
tooltip eldoc electric uniquify ediff-hook vc-hooks lisp-float-type
mwheel term/ns-win ns-win ucs-normalize mule-util term/common-win
tool-bar dnd fontset image regexp-opt fringe tabulated-list replace
newcomment text-mode elisp-mode lisp-mode prog-mode register page
tab-bar menu-bar rfn-eshadow isearch timer select scroll-bar mouse
jit-lock font-lock syntax facemenu font-core term/tty-colors frame
minibuffer cl-generic cham georgian utf-8-lang misc-lang vietnamese
tibetan thai tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek
romanian slovak czech european ethiopic indian cyrillic chinese
composite charscript charprop case-table epa-hook jka-cmpr-hook help
simple abbrev obarray cl-preloaded nadvice loaddefs button faces
cus-face macroexp files text-properties overlay sha1 md5 base64 format
env code-pages mule custom widget hashtable-print-readable backquote
threads kqueue cocoa ns multi-tty make-network-process emacs)

Memory information:
((conses 16 44980 8398)
 (symbols 48 5927 1)
 (strings 32 15288 1607)
 (string-bytes 1 506711)
 (vectors 16 10173)
 (vector-slots 8 126873 5444)
 (floats 8 20 38)
 (intervals 56 191 0)
 (buffers 1000 11))