2

I have no problems starting Emacs from a terminal, while if I start it from the desktop (I have a desktop file containing emacsclient -ca '') Emacs starts with a putt-ugly font (see below a screenshot).

To debug the issue I started emacsclient from the command line and, again see below for the transcript, I've got

Warning (initialization): An error occurred while loading ‘/home/boffi/.emacs’:

Wrong type argument: font, unspecified

BUT when I start Emacs directly I have no problems at all, emacsclient does not recognize --debug-init and the error message is not meaningful to me...

Moreover, if I visit the "broken" Emacs and I type M-x load-file RET ~/.emacs RET my init file is executed w/o problems!

What can be done to fix this issue?


The Emacs version is apparent from the 1st screenshot, I'm on Debian Sid, fairly current.

17:46 boffi@debian:~ $ emacs --debug-init
17:46 boffi@debian:~ $ # see screenshot

enter image description here

17:47 boffi@debian:~ $ emacsclient -ca ''
emacsclient: can't find socket; have you started the server?
To start the server in Emacs, type "M-x server-start".

Warning: due to a long standing Gtk+ bug
http://bugzilla.gnome.org/show_bug.cgi?id=85715
Emacs might crash when run in daemon mode and the X11 connection is unexpectedly lost.
Using an Emacs configured with --with-x-toolkit=lucid does not have this problem.
Loading /etc/emacs/site-start.d/00debian.el (source)...
Loading /etc/emacs/site-start.d/00debian.el (source)...done
Loading /etc/emacs/site-start.d/50asymptote.el (source)...
Loading /etc/emacs/site-start.d/50asymptote.el (source)...done
Loading /etc/emacs/site-start.d/50autoconf.el (source)...
Loading /etc/emacs/site-start.d/50autoconf.el (source)...done
Loading /etc/emacs/site-start.d/50dictionaries-common.el (source)...
Loading debian-ispell...
Loading /var/cache/dictionaries-common/emacsen-ispell-default.el (source)...
Loading /var/cache/dictionaries-common/emacsen-ispell-default.el (source)...done
Loading debian-ispell...done
Loading /var/cache/dictionaries-common/emacsen-ispell-dicts.el (source)...
Loading /var/cache/dictionaries-common/emacsen-ispell-dicts.el (source)...done
Loading /etc/emacs/site-start.d/50dictionaries-common.el (source)...done
Loading /etc/emacs/site-start.d/50figlet.el (source)...
Loading /etc/emacs/site-start.d/50figlet.el (source)...done
Loading /etc/emacs/site-start.d/50latexmk.el (source)...
Loading /etc/emacs/site-start.d/50latexmk.el (source)...done
Loading /etc/emacs/site-start.d/50texlive-lang-english.el (source)...
Loading /etc/emacs/site-start.d/50texlive-lang-english.el (source)...done
Loading /home/boffi/.emacs.d/synctex.el (source)...
Loading /home/boffi/.emacs.d/synctex.el (source)...done
Warning (initialization): An error occurred while loading ‘/home/boffi/.emacs’:

Wrong type argument: font, unspecified

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.
Starting Emacs daemon.
Emacs daemon should have started, trying to connect again
Waiting for Emacs...
17:48 boffi@debian:~ $ # see screenshot

enter image description here

2 Answers 2

1

Try bisecting your init file (.emacs), to see which part of it causes the problem:

Comment out 1/2 of it, and try that with emacsclient to see which 1/2 is problematic. Then comment out 1/4 of it, and try emacsclient again, to see which 1/4 is problematic. Then 1/8, 1/16, 1/32,...

At the very least this will remove most of your init file from the problem search space. And with a bit of luck identifying the minimal bit of code that causes the problem will suggest a solution to you.

1

In my question I said that I cannot use --debug-init with emacsclient but I was wrong, I can indeed use --debug-init.

emacsclient, per its man page, possibly starts Emacs as emacs -daemon and this is is equivalent, as I've found, to emacs -nw -daemon, so that every init file code that references frame/desktop stuff is bound to fail...

But I can use emacs --debug-init -nw to get a lisp backtrace!

Debugger entered--Lisp error: (wrong-type-argument font unspecified)
  font-get(unspecified :user-spec)
  eval-buffer(#<buffer  *load*> nil "/home/boffi/.emacs" nil t)  ; Reading at buffer position 4349
  load-with-code-conversion("/home/boffi/.emacs" "/home/boffi/.emacs" t t)
  load("~/.emacs" t t)
  #f(compiled-function () #<bytecode 0x1ddeb9>)()
  command-line()
  normal-top-level()

I came to identify the culprit to these two lines

(font-get
 (face-attribute 'default :font (selected-frame) 'default) :user-spec)

that, as far as I can remember, was put in to debug some issue with Emacs not obeying my font choice (correct me if I'm wrong).

I removed said two lines and everything is now fine...

I wonder if emacs -daemon could check for a DISPLAY environment variable and load the init file in an appropriate environment.

1
  • In retrospect, I'm afraid of a regression because emacs -daemon used to load my init file w/o a glitch and suddenly started to cough on the selected-frame stuff...
    – gboffi
    Commented Aug 1, 2019 at 20:53

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.