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 16:15:39 +0000 Message-ID: References: <83futh4ad0.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1463501778 1447 80.91.229.3 (17 May 2016 16:16:18 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 17 May 2016 16:16:18 +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 18:16:10 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 1b2hfD-0001Yt-Tr for geh-help-gnu-emacs@m.gmane.org; Tue, 17 May 2016 18:16:08 +0200 Original-Received: from localhost ([::1]:51359 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b2hfC-0003Ld-Ux for geh-help-gnu-emacs@m.gmane.org; Tue, 17 May 2016 12:16:06 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:59393) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b2hf0-0003LQ-8S for help-gnu-emacs@gnu.org; Tue, 17 May 2016 12:15:56 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b2hex-0006Ff-0N for help-gnu-emacs@gnu.org; Tue, 17 May 2016 12:15:53 -0400 Original-Received: from mail-oi0-x234.google.com ([2607:f8b0:4003:c06::234]:33808) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b2hew-0006FY-PI; Tue, 17 May 2016 12:15:50 -0400 Original-Received: by mail-oi0-x234.google.com with SMTP id k142so32952399oib.1; Tue, 17 May 2016 09:15:50 -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=Xzmy/GixPi68mDCUaIteje/sxnGdKzstqBrgAANR4mU=; b=fxg8qssbOkBJ5lHc4OD1XrxzPzGQ/zsRC+h2k/t2kk/VvbneGiyP7vb28g5CzHl3wX NVB4q7nzi/8sZ5NBicBo2ryylHyEpUWRDljHEkKUk5QD+sBpeoVu6+uwa90Sbvb757cA NuAFuE4lfM9LLWtrlcm5t7uaGyamJCVIljmPoPQ6UloO4S0X0sUOS6durmVhJxtg8kg7 7upV/7shKmCxvjlH7Jd/pcr7w417W7i24ngU+qTOKawrxhltaffVVpAgNsGx7jBervKX oHSV6tsB6tk7XP6CjI475FxYk9cmtrI9yUF5kvo+H2UcSpN3ZKR4G2Z/bSNa6Ki1zYuR ZsTA== 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=Xzmy/GixPi68mDCUaIteje/sxnGdKzstqBrgAANR4mU=; b=TsUont2syLzMn+JTBLW926lHdjbFrVaelMmWoitO7LS9Hjd3Kizawu6BJkb7xkTbSZ 21s7+Shgvvsv4SDFNfpwug0ZVZkycgkmRoCBJ7EquAUVBSU0HqA5B44qFJ3cUhh3Mfni 8rCIvt8TAohp5beUtC0hV3da4U1QUKQswScz0Yu2A4JTVIF2EOEbcrwTwh2PefU1INta 8I6udXcwBg629uxgHGm8J9eYLirrVwxXTTYuf6gdipA5VvxTn6KjYUlliKfb8hvAz78M +l+I1DeKQDJv6AEBSt9q0J8SWQGttL+nlApFsDcXYHvLqguqs4hIr2cDyNmGfZM8uoEt JW6A== X-Gm-Message-State: AOPr4FWiYi4PabuJy99jMh/RwI2oO6vyYr92l3UQ1tTZ3ESqsAXfmg5DoENUtNSHpvMob9WT3PoSPPgG1hfUJw== X-Received: by 10.202.88.86 with SMTP id m83mr1248976oib.52.1463501749825; Tue, 17 May 2016 09:15:49 -0700 (PDT) In-Reply-To: <83futh4ad0.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::234 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:110020 Archived-At: On Mon, May 16, 2016 at 11:44 PM Eli Zaretskii wrote: > There's nothing specific to daemon here, it is all just side effect of > how and when frames are created by Emacs. In particular, the daemon > creates frames when emacsclient connects to it, and doesn't have any > displayable frames before that. > > In general, _any_ call to make-frame will always run > after-make-frame-functions, you can clearly see that in the code. > Thanks. But I think that this side effect should be documented. I used the below test snippet in 3 different invocations of emacs: (1) emacs & (2) emacsclient -c -a '' & (3) emacs -nw =3D=3D=3D=3D=3D (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)) (add-hook hook `(lambda (&optional frame) (when frame (select-frame 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)) =3D=3D=3D=3D=3D In the "emacs &" invocation, I got: [1] Running =E2=80=98after-init-hook=E2=80=99 .. [1] Symbola: # For information about GNU Emacs and the GNU system, type C-h C-a. [2] Running =E2=80=98emacs-startup-hook=E2=80=99 .. [2] Symbola: # [3] Running =E2=80=98window-setup-hook=E2=80=99 .. [3] Symbola: # In the "emacsclient -c -a '' &" invocation, I got: [1] Running =E2=80=98after-init-hook=E2=80=99 .. [1] Symbola: nil Starting Emacs daemon. Restarting server [2] Running =E2=80=98emacs-startup-hook=E2=80=99 .. [2] Symbola: nil [3] Running =E2=80=98window-setup-hook=E2=80=99 .. [3] Symbola: nil [4] Running =E2=80=98before-make-frame-hook=E2=80=99 .. [4] Symbola: nil [5] Running =E2=80=98after-make-frame-functions=E2=80=99 .. [5] Symbola: # When done with this frame, type C-x 5 0 In the "emacs -nw" invocation, I got: [1] Running =E2=80=98after-init-hook=E2=80=99 .. [1] Symbola: nil For information about GNU Emacs and the GNU system, type C-h C-a. [2] Running =E2=80=98emacs-startup-hook=E2=80=99 .. [2] Symbola: nil [3] Running =E2=80=98window-setup-hook=E2=80=99 .. [3] Symbola: nil So in conclusion, it looks like however the user customizes the before-make-frame-hook and after-make-frame-functions, those would be ineffective when running non-daemon emacs and emacs -nw. It is obvious that frames are not being created for emacs -nw and so those hooks are not called. But it is not evident that the init.el/.emacs is called after frame generation when running emacs& and so those frame hook customizations serve no purpose in that case. > > (2) Is window-setup-hook supposed to run only in non-daemon emacs? > > No, of course not. It is supposed to be used by any customizations > that need to hook into stuff that Emacs does early on during its > startup (see startup.el), which you cannot do later. > Thanks. I now understand that. Just that I cannot use window-setup-hook for my font check when running emacsclient because the frame/fonts haven't been loaded yet (as we also see in the above experiment: [3] Running =E2=80=98window-setup-hook=E2=80=99 .. [3] Symbola: nil ... [5] Running =E2=80=98after-make-frame-functions=E2=80=99 .. [5] Symbola: # > (3) What would be a more concise manner to do stuff like linum > activation, > > find-font call, etc. correctly in both emacs and emacsclient? > > I don't understand the question. Emacs daemon can be started with a > non-empty ~/.emacs, so why is this an issue? IOW, what's wrong with > the answer "as you usually do with customizations"? > With the help of the above experiment, I think I now better understand which hooks to use and if I need to use those: I now have the below in my init: =3D=3D=3D=3D=3D (defun modi/symbola-font-check (&optional frame) (require 'setup-symbola)) (if (daemonp) (progn ;; The below `select-frame' call is mandatory for the `find-font' ;; to work correctly when using emacs daemon or emacsclient (learned ;; through experimentation). (add-hook 'after-make-frame-functions #'select-frame :append) ;; Need to delay font check till the fonts are actually available, which ;; does not happen until the point when `after-make-frame-functions' hook ;; is run (only for emacsclient launches). (add-hook 'after-make-frame-functions #'modi/symbola-font-check)) ;; For non-daemon, regular emacs launches, the frame/fonts are loaded *before* ;; the emacs config is read. So in that case there is no need to add the font ;; check function to any specific hook. (modi/symbola-font-check)) =3D=3D=3D=3D=3D There's something else too which is undocumented and I learned through experimentation; that I need to add select-frame to after-make-frame-functions first for the find-font to work as intended (else it always returns nil). Would adding that to that hook be a good default? At the end of this, let me know if you too think that the after-make-frame-functions needs more clarification in the documentation, and I will file a bug report for that. Thanks for going through my email in detail. Kaushal --=20 --=20 Kaushal Modi