I want to have "read-only-mode" enabled in all programming buffers, including the starting buffer "scratch".

If I add the line

(add-hook 'prog-mode-hook 'read-only-mode)

Running emacs as daemon with "emacs --daemon" will halt at

Due to a limitation in GTK 3, Emacs built with PGTK will simply exit when a
display connection is closed.  The problem is especially difficult to fix,
such that Emacs on Wayland with multiple displays is unlikely ever to be able
to survive disconnects.
Starting Emacs daemon.

And the process is kept "halting" where the prompt is not returned.

Here are other situations:

  • Running as non-daemon works fine.
  • Specifying another function to "prog-mode-hook" works fine.
  • I've tried "(add-hook 'after-init-hook (lambda () (add-hook 'prog-mode-hook 'read-only-mode)))", but it still halts.
  • I've tried "(add-hook 'emacs-startup-hook (lambda () (add-hook 'prog-mode-hook 'read-only-mode)))", this tiime it finishes daemonizing, but the "scratch buffer of an emacs client is not locked with "read-only-mode", only later for other source files when opened.

Running version "GNU Emacs 29.1" with pgtk under wayland.

What's happening?

I know it's almost achievable to the goal, by adding function that checks for every buffer if it's "scratch", but this is extremely ugly and consumes unnecessary resouces. Is there a better solution?

1 Answer 1


It looks like the inability to insert the regular message into the *scratch* buffer is responsible.

I can't tell you why that's hanging the server rather than signalling an error, but try this as a workaround:

(setq initial-scratch-message nil)
  • 1
    It works, I can't tell how grateful I'm now! Thanks for answering the question! I want to but can't vote now because of low-reputation, sorry
    – Akari
    Dec 10, 2023 at 11:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.