emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Include leaf in Emacs distribution


From: T.V Raman
Subject: Re: Include leaf in Emacs distribution
Date: Fri, 23 Oct 2020 11:11:23 -0700
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Naoya Yamashita <conao3@gmail.com> writes:
Another nice to have would be to rationalize lef/use-package vs the
custom file.

Custom-file: One file that holds all settings.

Leaf/use-package: refactors package-specific settings into
package-specific declarations

It would be nice to be able to look in one place (either
use-package/leaf or custom) rather than having to hunt down some rogue
setting in multiple places.

If leaf/use-package is built in to emacs, one possibility might be to
recommend  custom exclusively for   setting emacs builtin settings
e.g.find-file-hook -- but that "builtin definition" can become tenuous
fast.

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

-- 

Thanks,

--Raman
?7?4 Id: kg:/m/0285kf1  ?0?8



reply via email to

[Prev in Thread] Current Thread [Next in Thread]