2

When I run emacs, everything is ok, my init.el is read. However, after starting a daemon (emacs --daemon), an emacsclient GUI frame (emacsclient -c) is not configured for the following setting:

  • font size
(set-face-attribute 'default nil :font "Inconsolata-12.5")
  • icons in the mode line (doom mode line)
(use-package doom-modeline
  :init (doom-modeline-mode 1))
  • ivy package (until I use it)
(use-package ivy
  :diminish
  :bind (("C-s" . swiper)
     :map ivy-minibuffer-map
     ("TAB" . ivy-alt-done)
     ("C-l" . ivy-alt-done)
     ("C-j" . ivy-next-line)
     ("C-k" . ivy-previous-line)
     :map ivy-switch-buffer-map
     ("C-k" . ivy-previous-line)
     ("C-l" . ivy-done)
     ("C-d" . ivy-switch-buffer-kill)
     :map ivy-reverse-i-search-map
     ("C-k" . ivy-previous-line)
     ("C-d" . ivy-reverse-i-search-kill))
  :config
  (ivy-mode 1))

Here and here, it is mentioned that Emacs daemon doesn't know about the graphical frame, so every/some option that is needed for GUI is sort of neglected. In my init.el I commented out every line that has that option, but it didn't help.

I couldn't find anything helpful in the Emacs or Emacsclient manuals. Are there any arguments that I should add when starting Emacs daemon (other than --daemon) or emacsclient (other than -c)? or do I have to edit init.el file?

Debian Buster/Sid -- Emacs version: 27.1

5
  • 1
    Have you tried calling set-face-attribute from after-make-frame-functions? The Emacs daemon reads your user-init-file with a dummy initial frame that is never shown, so settings against that frame don't usually affect normal frames created thereafter with emacsclient -t or emacsclient -c.
    – Basil
    Nov 5, 2020 at 13:41
  • I couldn't figure out how to do that call. could you give me hint?
    – ali b
    Nov 6, 2020 at 5:57
  • 1
    (add-hook 'after-make-frame-functions (lambda (f) (set-face-attribute 'default f :font "Inconsolata-12.5")))
    – Basil
    Nov 6, 2020 at 7:23
  • BTW, see (info "(emacs) Fonts") for preferred ways of changing the font.
    – Basil
    Nov 6, 2020 at 7:25
  • It works. Thanks Basil!!
    – ali b
    Nov 6, 2020 at 7:26

1 Answer 1

0

Use the --eval flag provided by emacsclient to explicitly load your init file.

Here is my fish script for starting an emacs daemon and load init.el file. After executing this script, you can use emacsclient -c -n to create or edit files.

#!/usr/local/bin/fish

# Default server socket location
# This is queried with C-h v RET server-socket-dir RET in emacs
set server_socket_dir /var/folders/mk/wdnp3v29757bd0018d_64_z40000gn/T//emacs501

read -p "echo 'Name of Emacs daemon (default is bg_emacs): '" name
if not test "$name"
   set name bg_emacs
end

if not test $server-socket-dir/$name
   emacs --daemon=$name
end

# Explicitly load init.el file otherwise font setting will not be correct
emacsclient  --socket-name=$name -c -n --eval '(load-file "~/.emacs.d/init.el")'
3
  • Init files tend to get larger and more complicated with time, so loading your init file every time you start an emacsclient will slow you down substantially. It is better to do the setup once when you start the daemon.
    – NickD
    Feb 18 at 20:45
  • Yes I only load my init file when starting the daemon process. Afterwards 'emacsclient -c -n` is enough to open/edit files
    – Silentroar
    Feb 19 at 6:50
  • Never mind - I misread your answer.
    – NickD
    Feb 19 at 20:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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