help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Combine multiple (straight-)use-package commands into one.


From: Hongyi Zhao
Subject: Re: Combine multiple (straight-)use-package commands into one.
Date: Sun, 13 Jun 2021 09:29:34 +0800

On Sun, Jun 13, 2021 at 12:08 AM Omar Polo <op@omarpolo.com> wrote:
>
>
> Hongyi Zhao <hongyi.zhao@gmail.com> writes:
>
> > On Sat, Jun 12, 2021 at 5:57 PM Hongyi Zhao <hongyi.zhao@gmail.com> wrote:
> >>
> >> On Ubuntu 20.04, according to the instruction
> >> [here](https://github.com/raxod502/straight.el/issues/786#issuecomment-859155336),
> >> I use the following settings in my Emacs init file:
> >>
> >> ```
> >> ;;Bootstrap straight
> >> (defvar bootstrap-version)
> >> (let ((bootstrap-file
> >>        (expand-file-name "straight/repos/straight.el/bootstrap.el"
> >> user-emacs-directory))
> >>       (bootstrap-version 5))
> >>   (unless (file-exists-p bootstrap-file)
> >>     (with-current-buffer
> >>         (url-retrieve-synchronously
> >>          
> >> "https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el";
> >>          'silent 'inhibit-cookies)
> >>       (goto-char (point-max))
> >>       (eval-print-last-sexp)))
> >>   (load bootstrap-file nil 'nomessage))
> >>
> >> ;; Install use-package via straight
> >> (straight-use-package 'use-package)
> >>
> >> ;; Setting this to `t' makes it so that you don't need to include the 
> >> :straight
> >> ;; keyword in use-package declarations unless you want to add/extend the 
> >> package
> >> ;; installation recipe.
> >>
> >> (setq straight-use-package-by-default t) ; straight's equivalent of
> >> `use-package-always-ensure'.
> >> ```
> >> Now, I want to install multiple package hosted in recipe repositories
> >> (such as MELPA) as shown below with only one (straight-)use-package
> >> command, is it possible?
> >> ```
> >> (use-package flycheck)
> >> (use-package lsp-mode)
> >> (use-package dash)
> >> (use-package posframe)
> >> (use-package s)
> >> (use-package ein)
> >> (use-package smartparens)
> >> (use-package valign)
> >> (use-package multi-term)
> >> ```
> >
> > Based on the code snippets at
> > <https://github.com/flakyhermit/emacs.d/blob/6b488895071e980433facf648f482974526d6a13/init.el#L22>,
> > I figured out the following solution with `straight-use-package'
> > command:
> >
> > (defvar package-list)
> > (setq package-list '(
> >        flycheck lsp-mode dash posframe
> >        s ein smartparens valign
> >        multi-term
> > ))
> >
> > (mapc (lambda(package-name)
> > (straight-use-package package-name)) package-list)
> >
> > But I still don't know the corresponding implementation with
> > `use-package' command.
>
> C-h f use-package RET says that
>
> > use-package is a Lisp macro in ‘use-package-core.el’.
>
> being a macro and not a function[0], it means that it follows different
> rule for the evaluation.  (use-package foo ...) is something that gets
> *expanded* at *compile time* in some other lisp code, it's not something
> you can pass to mapc.  You need to expand the loop *at compile* time to
> load multiple packages, something like the following (untested)
>
> --------8<--------
> (defmacro use-multiple-packages (&rest packages)
>   `(progn
>     ,@(mapcar (lambda (p) `(use-package ,p))
>               packages)))
>
> (use-multiple-pacakges foo

There is typo:

 (use-multiple-packages foo

>                        bar
>                        baz
>                        ...)
> -------->8--------

Thank you. It works like a charm.

>
> but it becomes not useful, since the main point of use-package is IMHO
> the syntax sugar for adding hooks, bindings etc.  If you don't care
> about that stuff, a simple loop over package-install/package-installed-p
> is probably enough.
>
> > Regards
>
> [0]: see (info "(elisp)macros") for more information about how elisp
>      macros works.



-- 
Assoc. Prof. Hongyi Zhao <hongyi.zhao@gmail.com>
Theory and Simulation of Materials
Hebei Vocational University of Technology and Engineering
NO. 552 North Gangtie Road, Xingtai, China



reply via email to

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