emacs-devel
[Top][All Lists]
Advanced

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

Re: cl-lib warnings


From: Milan Glacier
Subject: Re: cl-lib warnings
Date: Mon, 26 Dec 2022 18:48:53 -0500
User-agent: NeoMutt/20220429

On 12/26/22 15:10, João Távora wrote:
On Mon, Dec 26, 2022 at 3:13 AM Milan Glacier <news@milanglacier.com> wrote:

use-package is a macro, so if someone uses use-package to configure the
package, when he needs to debug (for example minimal configuration), he
can always present the expanded form. (which basically just expands to
stuffs like setq, autoload, add-hook stuffs).


Yes, this was my initial hope too, that something like
`pp-macroexpand-last-sexp` could help me.  But it's got
enough fluff to make it tiring to read.  Here's what a simple
'(use-package foo)' with no options expands to:

(progn
 (defvar use-package--warning1
   #'(lambda
       (keyword err)
       (let
           ((msg
             (format "%s/%s: %s" 'foo keyword
                     (error-message-string err))))
         (display-warning 'use-package msg :error))))
 (condition-case-unless-debug err
     (if
         (not
          (require 'foo nil t))
         (display-warning 'use-package
                          (format "Cannot load %s" 'foo)
                          :error))
   (error
    (funcall use-package--warning1 :catch err))))

I'm afraid mode options will make this even more
complicated.  And what's with that defvar?

use-package is really a magic. But nobody uses a blank `(use-package
foo)`, usually a simple and pracctical use-package call would be
something like this:
(use-package foo
    :config (setq foo-1 nil)
    :init (setq foo-2 nil)
    :hook ((python-mode emacs-lisp-mode) . foo-mode))

which specifies the code to be evaluated before foo is loaded (:init
part), the code to be evaluated after foo is loaded (:config part), and
the hook related to this package, which expands to:

    (progn
      (unless
          (fboundp 'foo-mode)
        (autoload
          (function foo-mode)
          "foo" nil t))
      (setq foo-2 nil)
      (eval-after-load 'foo
        '(progn
           (setq foo-1 nil)
           t))
      (add-hook 'python-mode-hook
                (function foo-mode))
      (add-hook 'emacs-lisp-mode-hook
                (function foo-mode)))

I think the expanded form are not that hard to read.

(I personally am not a fan of use-package, I don't think it brings any
thing new. Often I need to expand it to see if its behavior is expected,
then why shouldn't I just write plain setq, add-hook stuffs directly?)



reply via email to

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