From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#23689: Daemon-mode on Windows - "w32-initialized" is set too early Date: Sat, 04 Jun 2016 18:01:15 +0300 Message-ID: <83porxuhfo.fsf@gnu.org> References: <8337otw9m0.fsf@gnu.org> <83shwtusoj.fsf@gnu.org> Reply-To: Eli Zaretskii NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1465052492 16040 80.91.229.3 (4 Jun 2016 15:01:32 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 4 Jun 2016 15:01:32 +0000 (UTC) Cc: 23689@debbugs.gnu.org To: Paul Moore Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Jun 04 17:01:21 2016 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1b9D4h-000115-VL for geb-bug-gnu-emacs@m.gmane.org; Sat, 04 Jun 2016 17:01:20 +0200 Original-Received: from localhost ([::1]:32954 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b9D4g-00085n-T0 for geb-bug-gnu-emacs@m.gmane.org; Sat, 04 Jun 2016 11:01:18 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:49321) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b9D4W-00085V-Nk for bug-gnu-emacs@gnu.org; Sat, 04 Jun 2016 11:01:13 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b9D4Q-0005HP-Bv for bug-gnu-emacs@gnu.org; Sat, 04 Jun 2016 11:01:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:42149) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b9D4Q-0005HL-8W for bug-gnu-emacs@gnu.org; Sat, 04 Jun 2016 11:01:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1b9D4P-0005Bd-Vz for bug-gnu-emacs@gnu.org; Sat, 04 Jun 2016 11:01:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 04 Jun 2016 15:01:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 23689 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 23689-submit@debbugs.gnu.org id=B23689.146505245919921 (code B ref 23689); Sat, 04 Jun 2016 15:01:01 +0000 Original-Received: (at 23689) by debbugs.gnu.org; 4 Jun 2016 15:00:59 +0000 Original-Received: from localhost ([127.0.0.1]:54486 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1b9D4N-0005BF-KR for submit@debbugs.gnu.org; Sat, 04 Jun 2016 11:00:59 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:58324) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1b9D4L-0005B0-MC for 23689@debbugs.gnu.org; Sat, 04 Jun 2016 11:00:58 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b9D4B-0005CG-Nn for 23689@debbugs.gnu.org; Sat, 04 Jun 2016 11:00:52 -0400 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:39585) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b9D4B-0005CB-KF; Sat, 04 Jun 2016 11:00:47 -0400 Original-Received: from 84.94.185.246.cable.012.net.il ([84.94.185.246]:2698 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.82) (envelope-from ) id 1b9D49-0000Mx-QE; Sat, 04 Jun 2016 11:00:46 -0400 In-reply-to: (message from Paul Moore on Sat, 4 Jun 2016 13:54:59 +0100) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:119052 Archived-At: > From: Paul Moore > 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 > > 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.