unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Paul Moore <p.f.moore@gmail.com>
Cc: 23689@debbugs.gnu.org
Subject: bug#23689: Daemon-mode on Windows - "w32-initialized" is set too early
Date: Sat, 04 Jun 2016 18:01:15 +0300	[thread overview]
Message-ID: <83porxuhfo.fsf@gnu.org> (raw)
In-Reply-To: <CACac1F9Gt4mffLSLjJ+TcyG51zeDZ4dRR5RKG91nSpEuEJzD2Q@mail.gmail.com> (message from Paul Moore on Sat, 4 Jun 2016 13:54:59 +0100)

> From: Paul Moore <p.f.moore@gmail.com>
> Date: Sat, 4 Jun 2016 13:54:59 +0100
> Cc: 23689@debbugs.gnu.org
> 
> When spacemacs starts up, it wants to set the fonts as configured by
> the user. To do so, it checks that the user-selected font exists using
> find-font (there's new code in the develop branch that allows the user
> to set a list of fonts, and picks the first on the list that actually
> exists on the system). But in daemon mode, find-font doesn't return a
> useful value until the display system is initialised, so there's a
> macro:
> 
> (defmacro spacemacs|do-after-display-system-init (&rest body)
>   "If the display-system is initialized, run `BODY', otherwise,
> add it to a queue of actions to perform after the first graphical frame is
> created."
>   `(let ((init (cond ((boundp 'ns-initialized) 'ns-initialized)
>                      ((boundp 'w32-initialized) 'w32-initialized)
>                      ((boundp 'x-initialized) 'x-initialized)
>                      (t 't))))           ; fallback to normal loading behavior
>      (if (symbol-value init)
>          (progn
>            ,@body)
>        (push (lambda () ,@body) spacemacs--after-display-system-init-list))))
> 
> The actions on spacemacs--after-display-system-init-list are executed
> when the first GUI frame is displayed, via advice on
> server-create-window-system-frame.

If spacemacs has a way to run code when the first GUI frame is
created, why cannot it do everything at that time?  Why does it have
to test the above conditions on top of that?

> This process works fine on non-Windows systems, I guess because
> ns-initialized and x-initialized are false during daemon startup. But
> on Windows it fails and from my testing this appears to be because
> w32-initialized is true at this point (unlike the other two). As a
> result, the font selection code gets run immediately - specifically
> *before* the point when find-font will give a correct answer.

I think spacemacs should not rely on the other FOO-initialized
variables, either, even if they appear to work for now.  They are not
intended to serve as evidence or trigger for any application-level
logic.  Instead, it should do this in a hook function (make-frame
provides at least 2).

> To demonstrate, create a .emacs.d/init.el containing
> 
> (progn
>     (message "%S" w32-initialized)
>     (message "%S" (find-font (font-spec :name "Courier New")))
>     (message "%S" w32-initialized))
> 
> Set HOME to the directory containing .emacs.d and run emacs --daemon.
> The result is
> 
> t
> nil
> t
> 
> Do the same on Unix (I used Ubuntu) using x-initialized (and a font
> that exists on the Unix system in place of Courier New) and you get
> 
> nil
> nil
> nil
> 
> Do the same using emacs (no --daemon) and look in the *Messages*
> buffer, and you see
> 
> t
> <a font object>
> t
> 
> in both cases.

That "window-system initialized" automatically implies that find-font
will work is IMO an invalid assumption.  Exactly what parts of the
initialization are run in FOO-initialize functions is implementation
detail.  I recommend to stay away of such assumption and instead use
the hooks we provide during startup.  Even if you come to the
conclusion that no existing hook serves spacemacs well enough, and we
then (say) add yet another hook, the result will be cleaner than
relying on semi-documented variables and undocumented assumptions.





  reply	other threads:[~2016-06-04 15:01 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-03 10:33 bug#23689: Daemon-mode on Windows - "w32-initialized" is set too early Paul Moore
2016-06-04 10:07 ` Eli Zaretskii
2016-06-04 10:29   ` Paul Moore
2016-06-04 10:58     ` Eli Zaretskii
2016-06-04 12:54       ` Paul Moore
2016-06-04 15:01         ` Eli Zaretskii [this message]
2016-06-04 15:17           ` Paul Moore
2016-06-08 13:57             ` Paul Moore
2016-06-14 17:10               ` Eli Zaretskii
2016-06-14 18:20                 ` Paul Moore
2016-06-14 18:55                   ` Eli Zaretskii
2016-06-14 19:55                     ` Paul Moore
2016-06-15  2:33                       ` Eli Zaretskii
2016-06-15  7:08                         ` Paul Moore
2016-06-15 11:11                           ` Paul Moore
2016-06-15 14:55                             ` Eli Zaretskii
2016-06-15 15:26                               ` Paul Moore
2016-06-15 15:47                                 ` Eli Zaretskii
2016-06-15 16:58                                   ` Paul Moore
2019-11-02  1:07                                     ` Stefan Kangas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=83porxuhfo.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=23689@debbugs.gnu.org \
    --cc=p.f.moore@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).