2

When I run emacs -nw (--no-window-system) emacs (v29.1 on macOS v13.6.1) initially begins running in the terminal window, with the terminal clearing and the modeline appearing at the bottom. Quite quickly, however, desktop-load-file begins and after a few seconds the terminal window reverts to showing the previous command line output and multiple frames (i.e. separate macOS windows) open containing my previously-visited buffers.

After desktop restoration completes, window-system is set to ns, even though it is normally nil when running -nw.

Is it expected that desktop restoration be able to override the -nw command line argument in this way?

I do not recall seeing this behaviour previously, but possibly because usually when I run emacs -nw I still have my main emacs process running so desktop prompts me whether I wish to restore the desktop and I decline.


Here's everything in my init.el that concern windowing system / desktop:

(when window-system
  (setq confirm-kill-emacs 'yes-or-no-p))
(when (memq window-system '(mac ns))
  (when (require 'exec-path-from-shell nil 'noerror)
    (exec-path-from-shell-initialize)))
(when window-system
  (if (fboundp 'gnuserv-start)
      (gnuserv-start))
  (server-start))
(require 'desktop)  ; Seems unnecessary - deleting has no effect.

(custom-set-variables
 '(desktop-restore-in-current-display nil)
 '(desktop-restore-reuses-frames nil)
 '(desktop-save-mode t)
 '(inhibit-startup-screen t)
 '(initial-frame-alist '((width . 132) (height . 50) (top . 100) (left . 300)))
 '(tool-bar-mode nil))

I was able to prevent this undesirable (to me) behaviour by removing desktop-save-mode from custom-set-variables and instead adding

(when window-system (desktop-save-mode t))

further up my init.el file.

1 Answer 1

2

-nw means "create the initial frame as a terminal frame", not "create only terminal frames". The resulting Emacs can still create graphical frames, as you've seen. If you don't want desktop restoring frames, you can set desktop-restore-frames to nil

2
  • Section C.2 (Initial Options) of the emacs manual says "‘--no-window-system’: Don’t communicate directly with the window system, disregarding the ‘DISPLAY’ environment variable even if it is set. This means that Emacs uses the terminal from which it was launched for all its display and input." Moreover, when I start emacs from the command line with -nw I am unable to create additional frames via C-x 5 2, and evaling (make-frame) returns (e.g.) #<frame F2 0x139acd980> but does not create any new macOS windows.
    – cpcallen
    Nov 15, 2023 at 18:00
  • @cpcallen Try M-x make-frame-on-display
    – rpluim
    Nov 16, 2023 at 9:44

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.