unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Naoya Yamashita <conao3@gmail.com>
To: monnier@iro.umontreal.ca
Cc: caiohcs0@gmail.com, stefankangas@gmail.com, emacs-devel@gnu.org
Subject: Re: Include leaf in Emacs distribution
Date: Sat, 24 Oct 2020 00:53:02 +0900 (JST)	[thread overview]
Message-ID: <20201024.005302.2225963876712457330.conao3@gmail.com> (raw)
In-Reply-To: <jwv4kml10bd.fsf-monnier+emacs@gnu.org>


> 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)))
```



  reply	other threads:[~2020-10-23 15:53 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-08  1:37 Include leaf in Emacs distribution Naoya Yamashita
2020-10-08  9:00 ` Ergus
2020-10-08  9:22   ` Naoya Yamashita
2020-10-10 10:11     ` Eli Zaretskii
2020-10-11  5:24       ` Richard Stallman
2020-10-11  8:39         ` Naoya Yamashita
2020-10-11  9:52           ` Thibaut Verron
2020-10-11 16:50             ` Naoya Yamashita
2020-10-11 17:12               ` Thibaut Verron
2020-10-12  2:10                 ` Naoya Yamashita
2020-10-12 20:23                   ` Ergus via Emacs development discussions.
2020-10-11 17:02           ` Stefan Kangas
2020-10-11 16:51   ` Stefan Kangas
2020-10-12 20:53     ` Mingde (Matthew) Zeng
2020-10-11 17:22 ` Stefan Kangas
2020-10-12  1:35   ` Naoya Yamashita
2020-10-12 22:13     ` Stefan Kangas
2020-10-12 22:19       ` Qiantan Hong
2020-10-12 22:39       ` Caio Henrique
2020-10-13 13:23         ` Stefan Monnier
2020-10-13 14:14           ` Thibaut Verron
2020-10-13 14:29             ` Stefan Monnier
2020-10-13 15:29               ` Thibaut Verron
2020-10-18  9:32                 ` Phil Sainty
2020-10-13 15:25           ` Caio Henrique
2020-10-23  2:37             ` Naoya Yamashita
2020-10-23  3:41               ` John Wiegley
2020-10-23 14:33                 ` Stefan Monnier
2020-10-23 15:53                   ` Naoya Yamashita [this message]
2020-10-23 16:46                     ` Warnings in init files (was: Include leaf in Emacs distribution) Stefan Monnier
2020-10-23 18:11                     ` Include leaf in Emacs distribution T.V Raman
2020-10-23 18:41               ` Stefan Kangas
2020-10-23 20:04                 ` John Wiegley
2020-11-16  5:29                   ` Naoya Yamashita
2020-11-17  0:39                     ` John Wiegley
2020-11-20 11:04                       ` Naoya Yamashita
2020-11-20 11:29                         ` Pankaj Jangid
2020-11-20 15:44                         ` T.V Raman

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=20201024.005302.2225963876712457330.conao3@gmail.com \
    --to=conao3@gmail.com \
    --cc=caiohcs0@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    --cc=stefankangas@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).