2

I use GNU Emacs (28.2 (build 2, x86_64-w64-mingw32) of 2022-09-13) on Windows mostly, so I have set some modes in my early-init.el to prevent annoying flickering:

(tool-bar-mode -1)    ; Setting these in init.el is too late on Windows.
(scroll-bar-mode -1)  ; They will flicker. It's worse for other frame options.

However, these lead to issues whenever I use Emacs from the terminal, for example within WSL (GNU Emacs 27.1) with the same configuration:

$ emacs -nw --eval \
    '(progn (with-current-buffer "*Warnings*" (append-to-file nil nil "/dev/stderr")) (kill-emacs))' \
    2> warnings \
  && cat warnings
Warning (initialization): An error occurred while loading ‘/home/zeta/.emacs.d/early-init.el’:

Symbol's function definition is void: tool-bar-mode

To ensure normal operation, you should investigate and remove the
cause of the error in your initialization file.  Start Emacs with
the ‘--debug-init’ option to view a complete error backtrace.

Usually, I would wrap both mode setup calls within a check for (display-graphic-p), i.e.

(when (display-graphic-p)
  (tool-bar-mode -1)
  (scroll-bar-mode -1))

This is how most questions are answered here on Emacs SE: use that and you're golden.

However, there is no display during early-init.el:

‘~/.emacs.d/early-init.el’. This file is loaded before the package system and GUI is initialized [taken from (info "(emacs) Early Init File"), emphasis mine]

This method does not work and the scroll bar and tool bar are shown. How can I reliably detect whether I'm running Emacs on a terminal within early-init.el? The documentation mentions window-setup-hook, but that runs too late and the GUI flickers on Windows, as the scroll bars are shown for a split second.

3
  • Off-topic: “I use GNU Emacs (28.2 (build 2, x86_64-w64-mingw32) of 2022-09-13) on Windows mostly” -- v29.1 for MS-Windows has been released; it's worth a try.
    – shynur
    Commented Aug 1, 2023 at 10:14
  • @shynur I'm aware, and that's how I noticed that some parts of early-init.el do not work as intended :). Some parts of my Emacs configuration are not currently Emacs 29 ready though, mainly the package bootstrapping only during the initial use-package install (which is now no longer required)
    – Zeta
    Commented Aug 1, 2023 at 18:37
  • 1
    @Zeta Note, that disabling elements of the GUI in early-init.el (only) might not give an affect creating a new frame, f.i.
    – Y. E.
    Commented Aug 2, 2023 at 6:32

1 Answer 1

3

Check the value of initial-window-system.

For example, if you are using Emacs on MS-Windows, then the value should be nil when under TUI, w32 when under GUI.


41.1.1 Summary: Sequence of Actions at Startup

  1. If not running in batch mode, it initializes the window system that the variable initial-window-system specifies... If the value of initial-window-system is windowsystem, then the appropriate implementation of the initialization function is defined in the file term/windowsystem-win.el.

Though it must be noted that (info "(emacs) Early Init File") recommends against moving customizations to the early-init.el file, because

customizations related to GUI features will not work reliably in early-init.el

3
  • 3
    AFAICT, this is the only way to check in early-init.el, but do not use this method anywhere else. See Window Systems.
    – NickD
    Commented Aug 1, 2023 at 11:20
  • This mailing list thread adds context to why initial-window-system docstring says "Use of this variable as a boolean is deprecated."
    – Y. E.
    Commented Aug 1, 2023 at 13:00
  • I shall say this kind of thing shouldn't be done in early-init.el. But since OP asked this question, then I will answer this question. As for what OP is trying to implement by solving this problem -- "prevent annoying flickering", that can be another question.
    – shynur
    Commented Aug 1, 2023 at 13:05

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.