From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Naoya Yamashita Newsgroups: gmane.emacs.devel Subject: Re: Include leaf in Emacs distribution Date: Sat, 24 Oct 2020 00:53:02 +0900 (JST) Message-ID: <20201024.005302.2225963876712457330.conao3@gmail.com> References: <20201023.113723.2024617143609727683.conao3@gmail.com> Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="22660"; mail-complaints-to="usenet@ciao.gmane.io" Cc: caiohcs0@gmail.com, stefankangas@gmail.com, emacs-devel@gnu.org To: monnier@iro.umontreal.ca Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Oct 23 18:34:21 2020 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kW01E-0005kt-PI for ged-emacs-devel@m.gmane-mx.org; Fri, 23 Oct 2020 18:34:20 +0200 Original-Received: from localhost ([::1]:59742 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kW01D-0003s5-RO for ged-emacs-devel@m.gmane-mx.org; Fri, 23 Oct 2020 12:34:19 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:40092) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kVzPL-0007k7-AV for emacs-devel@gnu.org; Fri, 23 Oct 2020 11:55:11 -0400 Original-Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]:37183) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kVzPJ-00052K-6A for emacs-devel@gnu.org; Fri, 23 Oct 2020 11:55:10 -0400 Original-Received: by mail-pg1-x544.google.com with SMTP id h6so1581855pgk.4 for ; Fri, 23 Oct 2020 08:55:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:message-id:to:cc:subject:from:in-reply-to:references :mime-version:content-transfer-encoding; bh=onTbogmXdeu1rPt+XOc+fLMvMRvYQk2eThAwx1Kbhyg=; b=gqxbp3nZ0tj9Kvvym1pDLlmLyxUzRpACEM72dCx0LJRmkb+hOb8eziCr2UKonlrMyO dl2cRVtd6zh44ksrxRNX9vhCxJksdMbkXSSfVEb9QvR9JhSe968493O4+1hL2bcVKJw9 TUG4p4BcoFyU0JAcNmeMxZtre6tf7Te+y5bZJo2CFhWazH5+DashxpYQQrv3xdeS3q5a XOUe0Tm894seOc/boLlXw/Nkt1QfvEliIo875rcfeWwP4bqLDaItv50mWpWM807wHXkr MPJYx8hlRnlBmtBaJ1WTq/JISFnEf4kh4gtZ2P09BkwaWa2HLU51QRNdh2xzKG1LVt6b Mofw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:to:cc:subject:from:in-reply-to :references:mime-version:content-transfer-encoding; bh=onTbogmXdeu1rPt+XOc+fLMvMRvYQk2eThAwx1Kbhyg=; b=l2Zl3AjBWVMBk2WPU3CBTy2RebIptLjRZWWbLwIbYQqWfkXx/0lDBQM0XGttcjk1M9 /eRXw4TddFSMg8HsRoHGZ4CNx/pWdOzrhBD/61Bt26TxCoWYsNEF2ri/6V5Y6KaeCWwZ ENY8Uoa4KiAhnKSSAlx1prnFBPfNN4G2h2krtnOjZ59l5WMThvHcdkoB7naZkF9LykmP h/snnV00uC6DO5w4YP7vYqQg4C+FyKevBMMTiAuvlirAtipciz89egyYvK1UjMYtWoWM KvgrDnp1LRLG3XOppBuJNp7Ia+Xz591Nj5ObgsedML1v39T63+DdGjCysx7TAuD4DVdi jcsQ== X-Gm-Message-State: AOAM531HBvjuP6Ig+Abxq9pRv4JwkRJRx3mLOFUXu+uoLA4MRPnWidDw ocCTtm6LAb+ABcG2ckm6dbI= X-Google-Smtp-Source: ABdhPJx5sFBeI0l6cmqHLyCeIDtzF1FuPgPkJP1H5UMZ0q1NqYQJyeLKtyMPTTo5u5aQBrGEiCeZMA== X-Received: by 2002:a17:90a:ee48:: with SMTP id bu8mr3331517pjb.143.1603468507617; Fri, 23 Oct 2020 08:55:07 -0700 (PDT) Original-Received: from localhost (p210141-ipngn200407niho.hiroshima.ocn.ne.jp. [118.4.79.141]) by smtp.gmail.com with ESMTPSA id v3sm2171666pfu.165.2020.10.23.08.55.03 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 23 Oct 2020 08:55:07 -0700 (PDT) In-Reply-To: X-Mailer: Mew version 6.8 on Emacs 27.1 Received-SPF: pass client-ip=2607:f8b0:4864:20::544; envelope-from=conao3@gmail.com; helo=mail-pg1-x544.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:258365 Archived-At: > I also hope we can use it to make init files "compatible" with flymake. > IOW make it so byte-compiling your init file doesn't result in lots and > lots of "spurious" warnings. I believe john say same thing, leaf and use-package have the feature to generate `defvar` and `declare-function` to prevent warnings in byte compiling. So my init.el also uses flycheck, but there are no warnings. References to undefined functions/variables are shown as usual, and the warnings are very useful. ``` (macroexpand-1 '(leaf server :doc "Lisp code for GNU Emacs running as server process" :defvar server-temp-file-regexp :defun server-running-p :config (setq server-temp-file-regexp (rx-to-string `(or (regexp ,server-temp-file-regexp) ".DS_Store") t)) (unless (server-running-p) (server-start)))) ;;=> (prog1 'server ;; (declare-function server-running-p "server") ;; (defvar server-temp-file-regexp) ;; (setq server-temp-file-regexp ;; (rx-to-string `(or (regexp ,server-temp-file-regexp) ".DS_Store") t)) ;; (unless (server-running-p) ;; (server-start))) (let ((byte-compile-current-file "bar")) (macroexpand-1 '(use-package server :defines server-temp-file-regexp :functions server-running-p :config (setq server-temp-file-regexp (rx-to-string `(or (regexp ,server-temp-file-regexp) ".DS_Store") t)) (unless (server-running-p) (server-start))))) ;;=> (progn ;; (eval-and-compile ;; (defvar server-temp-file-regexp) ;; (declare-function server-running-p "server") ;; (eval-when-compile ;; (with-demoted-errors "Cannot load server: %S" ;; nil ;; (unless (featurep 'server) ;; (load "server" nil t))))) ;; (require 'server nil nil) ;; (setq server-temp-file-regexp ;; (rx-to-string `(or (regexp ,server-temp-file-regexp) ".DS_Store") t)) ;; (unless (server-running-p) ;; (server-start)) ;; t) ``` I've also compared leaf and use-package. - The leaf has document keywords such as :doc. The advantage of this is that the text is easier to recognize than the comments due to the color scheme. In addition, other packages can use the strings specified by this keyword. - The :defines of use-package becomes a :defvar in the leaf. It's very analogous to defvar, considering that defvar prevents warnings on variable references. - A :function of use-package is a :defun in the leaf. It is a function version of :defvar to suppress function warnings. There is a possibility of misunderstanding because there're no actual `defun`, but it's an acceptable confusion compared to the disadvantage of not knowing whether `:defines` are variables or functions. - use-package has an expression that is secretly output only during byte-compilation. In this case, if `byte-compile-current-file` is nil, then `:defines` and `:functions` will not output any expressions. This makes debugging difficult; leaf does not have this feature. It's consistent. - use-package will add a `t` to the use-package's own return value, as shown in this example, to make the overall return value to `t`, while sometimes returning a set right-hand side value. This is a confusion, and the leaf solves it; the return value returned by the leaf is always a symbol of the first argument. ### Sample init.el I tested. We (I and john) want to remove this bootstrap code. ``` ;;; init.el --- Sample clean init.el -*- lexical-binding: t; -*- ;; ~/.debug.emacs.d/leaf-byte-compile/init.el ;; you can run like 'emacs -q -l ~/.debug.emacs.d/leaf-byte-compile/init.el' (when load-file-name (setq user-emacs-directory (expand-file-name (file-name-directory load-file-name)))) (eval-when-compile (setq user-emacs-directory (expand-file-name (file-name-directory default-directory)))) (eval-and-compile (prog1 "leaf" (custom-set-variables '(package-archives '(("org" . "https://orgmode.org/elpa/") ("melpa" . "https://melpa.org/packages/") ("gnu" . "https://elpa.gnu.org/packages/")))) (package-initialize) (unless (package-installed-p 'leaf) (package-refresh-contents) (package-install 'leaf)))) ;; --- (leaf server :doc "Lisp code for GNU Emacs running as server process" :defvar server-temp-file-regexp :defun server-running-p :config (setq server-temp-file-regexp (rx-to-string `(or (regexp ,server-temp-file-regexp) ".DS_Store") t)) (unless (server-running-p) (server-start))) ```