3

I have the following for ridding of the toolbar on startup in graphical mode in my init configuration:

(if window-system
    (tool-bar-mode -1)
)

the issue:

it works fine (albeit slow...see this post) when starting emacs but does not work with the emacs --daemon , starting emacsclient c starts a graphical client with toolbar ( I want without). Does emacs graphical client require a seperate code to the if window-system?

I run:

emacs 25.3 on Linux manjaro 17.1.5 Hakolla

manandearth
  • 2,068
  • 1
  • 11
  • 23

1 Answers1

3

The most simple solution to your actual problem -- avoiding the tool bar -- is to customize tool-bar-mode to nil. Alternatively you can also put (setq tool-bar-mode nil) into your init file.

The problem with window-system in emacs daemon is that the virtual frame of the emacs daemon is not connected to any display. Since the init file runs in the daemon window-system is nil.

Furthermore, you shouldn't use windows-system as bool variable. Use display-graphic-p instead. See the last section of the windows-systems doc.

The server creates display frames for clients on demand (with option --create-frame).

Therefore, after-make-frame-functions is the right place to hook in if you want to tweak your graphical frames generated by an emacs daemon. In the following I give you an example:

(defun my-frame-tweaks (&optional frame)
  "My personal frame tweaks."
  (unless frame
    (setq frame (selected-frame)))
  (when frame
    (with-selected-frame frame
      (when (display-graphic-p)
    (tool-bar-mode -1)))))

;; For the case that the init file runs after the frame has been created.
;; Call of emacs without --daemon option.
(my-frame-tweaks) 
;; For the case that the init file runs before the frame is created.
;; Call of emacs with --daemon option.
(add-hook 'after-make-frame-functions #'my-frame-tweaks t)
Tobias
  • 32,569
  • 1
  • 34
  • 75
  • and thanks for the explenation. I will read the windows-systems doc now. @Tobias – manandearth Mar 11 '18 at 14:32
  • @manandearth Have you tried just to customize the variable `tool-bar-mode` to nil? That should work for global modes like `tool-bar-mode`. (I never tried in connection with the emacs daemon.) That would be the simplest solution and if you checked it positively I would add it in front of my answer. – Tobias Mar 11 '18 at 14:40
  • It's also possible to just make a check with `featurep`. –  Mar 11 '18 at 14:44
  • @Tobias It doesn't work with `tool-bar-mode` set to nil. not for the `emacsclient` – manandearth Mar 11 '18 at 14:44
  • @manandearth I've just tried it and it works for me. So I added it in front of my answer. – Tobias Mar 11 '18 at 14:48
  • @Tobias Yes it does work with `(setq tool-bar-mode nil)` , I was trying to set it to nil in my original `(if window-system (tool-bar-mode -1) )` which doesn't work, of course for the reasons you mention regarding the `window-sytem` in your answer – manandearth Mar 11 '18 at 14:59