From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Kaushal Modi Newsgroups: gmane.emacs.help Subject: Re: Understanding after-make-frame-functions Date: Tue, 17 May 2016 18:08:43 +0000 Message-ID: References: <83futh4ad0.fsf@gnu.org> <83a8jo4p5v.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: ger.gmane.org 1463508562 17270 80.91.229.3 (17 May 2016 18:09:22 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 17 May 2016 18:09:22 +0000 (UTC) To: Eli Zaretskii , help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue May 17 20:09:17 2016 Return-path: Envelope-to: geh-help-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 1b2jQi-00088i-5B for geh-help-gnu-emacs@m.gmane.org; Tue, 17 May 2016 20:09:16 +0200 Original-Received: from localhost ([::1]:51889 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b2jQh-0004gf-HB for geh-help-gnu-emacs@m.gmane.org; Tue, 17 May 2016 14:09:15 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36099) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b2jQO-0004fp-Ub for help-gnu-emacs@gnu.org; Tue, 17 May 2016 14:09:02 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b2jQM-0008Pm-5r for help-gnu-emacs@gnu.org; Tue, 17 May 2016 14:08:55 -0400 Original-Received: from mail-oi0-x22c.google.com ([2607:f8b0:4003:c06::22c]:36700) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b2jQL-0008Ph-U5; Tue, 17 May 2016 14:08:54 -0400 Original-Received: by mail-oi0-x22c.google.com with SMTP id x201so38126855oif.3; Tue, 17 May 2016 11:08:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=8krjObg5DmC0SHPpPBTkVN7PvJfOhHBc1LBoXvXK3sQ=; b=EbvUGVWM/LqeuKwPjWdYoHeRe6I0JnF41XU0Z5Ptq0WgVpG4wFsA9Mbfcw9fByQ6qc 0wAN5LSvTzcQBPtfM0Lk/b0zidc8el+A20+U8H496nXE30teWk+McOD3FIZV/dV6ySwv TMFXhx6hLKmyetlr2m8zse4QN1gBkmKXjbQSfwv6R+Qtz+/6UN/qB3U9O26f44N0QLXb kkuY77hQUR/SEooaoGOK71k6DvPIX9xpvJKvE+vjcmpKfFNOAyhTINs6uuxbqkg8H03r o+MYwqoSdSLtZPYqjxEuMctn2H/69y7vVcG8fvW3L39nB2FuIaIM5wLQuLxRQ2UAUFTm d59g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=8krjObg5DmC0SHPpPBTkVN7PvJfOhHBc1LBoXvXK3sQ=; b=VqS5ovZlp4waPOGImwPUoj97pOD62sacjRUB5lzXYCxcIANfMbVWEwEMB/n07yl+eD R40uTTubZlbkzdsRfGz0Xs4C2XFEcb1IAaW28WspgwvTvz6oYEk/aH717D2790a/yAIt ksvExMXUmDq+M1D2kdA/xWj/JBIeAp4TwZ3ClD/txw+3R+0FZLbtPqc84XuBydJyIOL7 kXCzQ6laozYqZc52NkBwuHf/SIfe0CxKnjlitXNQh3/Hq0YUEdhnqvSDemn5ThCZ0Jmo VP+MMD3Xa2FXK4AYdSxYb6Sxdd+N0Yacz8bUnzDMZTaafjEiDbW99QPj+VA6VbsAVJDd OL+w== X-Gm-Message-State: AOPr4FVGTn0kLaTYsUUB07Okucufce977OUDYPauOWQi6qGTiYMiDchVvltxelD+O45SHPhQbiB/5dOQPbLqPQ== X-Received: by 10.157.6.164 with SMTP id 33mr1562995otx.164.1463508533351; Tue, 17 May 2016 11:08:53 -0700 (PDT) In-Reply-To: <83a8jo4p5v.fsf@gnu.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:4003:c06::22c X-Content-Filtered-By: Mailman/MimeDel 2.1.21 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:110027 Archived-At: On Tue, May 17, 2016 at 12:37 PM Eli Zaretskii wrote: > What Emacs does during startup is documented in the ELisp manual, see > the node "Startup Summary". If you have specific suggestions for > amendments there, please file a bug report with those suggestions. > I had already gone through that but it does not talk about the nuance that in daemon mode case, the frame is created after the window-setup-hook is run; whereas it is created before evaluating the init in the case of non-daemon mode. The side effect of that on after-make-frame-functions hook being useful only for daemon cases is also not mentioned anywhere. The above-mentioned node in the manual describes more hooks, so maybe > you should simply use a different hook for your needs. > Thanks! I had already gone through the list of startup hooks in (elisp) Standard Hooks node. I went through it once again and figured out that focus-in-hook is what I need (the only drawback being that hook is called each time a frame gets in focus, not just at startup. And for that reason, I didn't even consider using it. But now I am, as shown after the below test snippet). I updated my test snippet to add the debug statement to focus-in-hook too! ===== (defvar my-index 1 "Index that increments after each hook is called.") (dolist (hook '(before-init-hook after-init-hook emacs-startup-hook window-setup-hook before-make-frame-hook after-make-frame-functions after-setting-font-hook focus-in-hook)) (add-hook hook `(lambda (&optional frame) (message "[%d] Running `%s' .." my-index (symbol-name (quote ,hook))) (message "[%d] Symbola: %S" my-index (find-font (font-spec :name "Symbola"))) (setq my-index (1+ my-index))) :append)) ===== Based on what I learned, I updated the font check code to below: ===== (defun modi/font-check (&optional frame) "Do font-check; require `setup-font-check' just once." (unless (featurep 'setup-font-check) (require 'setup-font-check))) (add-hook 'focus-in-hook #'modi/font-check) ===== Explanation for the above: For non-daemon, regular emacs launches, the frame/fonts are loaded *before* the emacs config is read. But when emacs is launched as a daemon (using emacsclient, the fonts are not actually loaded until the point when the `after-make-frame-functions' hook is run. But even at that point, the frame is not yet selected (for the daemon case). Without a selected frame, the `find-font' will not work correctly. So we do the font check in `focus-in-hook' instead by which all the below are true: - Fonts are loaded (in both daemon and non-daemon cases). - The frame is selected and so `find-font' calls work correctly. I would suggest moving the code to a hook that runs later, when the > initial frame is already the selected one. > Looks like focus-in-hook is the next one available when the frame is selected. > Not sure, but if there's specific information you'd like to be there, > let's talk specifics. > I do not know what's the correct terminology to be used for "user emacs config", "daemon mode" and "non-daemon mode" in documentation, but the idea for after-make-frame-functions documentation is as below: ===== Functions to run after a frame is created. The functions are run with one arg, the newly created frame. In daemon mode (emacs --daemon or emacsclient), the frame is created at some point after the `window-setup-hook' is run (after the user emacs config is evaluated). So this hook is called _after_ the user config evaluation. But in the non-daemon mode, the frame is created before the user emacs config is evaluated. So this hook is run before that, and so any user customization done to this hook would be ineffective in the non-daemon case. ===== -- -- Kaushal Modi