jwiegley / use-package

A use-package declaration for simplifying your .emacs
https://jwiegley.github.io/use-package
GNU General Public License v3.0
4.42k stars 260 forks source link

Using :mode with a variable #908

Open Ergus opened 3 years ago

Ergus commented 3 years ago

Hi:

I want to use something like:

(defconst myregex "BLA")

(use-package mymode
  :mode (myregex . mymode)
  ...)

But I don't find any documentation about how to do that because (as expected) :mode (const myregex ...) does not expands... Any suggestion? Is something like that possible?

I know that I can use the

(add-to-list 'auto-mode-alist (cons myregex mymode))       

But the implied mode does not defines mymode as an autoload, so I will need an extra explicit autoload call.. something use-package does for the user (and simplifies the init code)

conao3 commented 3 years ago

This eval is not permitted in use-package, but leaf can.

(defconst myregex "BLA")
;;=> myregex

(setq leaf-expand-minimally t)
;;=> t

(macroexpand
 '(leaf mymode
    :mode `(,myregex . mymode)))
;;=> (prog1 'mymode
;;     (unless (fboundp 'mymode) (autoload #'mymode "mymode" nil t))
;;     (add-to-list 'auto-mode-alist '("BLA" . mymode)))