progfolio / elpaca

An elisp package manager
GNU General Public License v3.0
633 stars 31 forks source link

[Support]: is use-package necesarry #203

Closed Zerogaku closed 10 months ago

Zerogaku commented 11 months ago

Confirmation

Elpaca Version

0.6

Operating System

Artix linux

Description

Is using the use-package syntax essential or does it provide any benefits over the "default" elpaca syntax, i want to start creating a vanilla emacs configuration from scratch and would prefer to use the default elpaca syntax (i have used use-package before but would like to try something new) but am genuinely having a hard time wrapping my head around the syntax, the wiki uses "example" as placeholder names when showing the usage and im not sure what its referring to, sorry if this comes off as a silly question.

progfolio commented 11 months ago

Thanks for taking the time to fill out a support ticket.

Is using the use-package syntax essential or does it provide any benefits over the "default" elpaca syntax

The elpaca macro can be used without using use-package. The use-package macro offers a language to easily configure packages. It also optionally integrates with package managers to install packages. The same can be done without it and it's a matter of preference.

having a hard time wrapping my head around the syntax

The elpaca macro takes an ORDER as its first argument. The bare minimum ORDER is a symbol which translates to "Find me the first menu item matching this symbol in the items provided by elpaca-menu-functions. e.g.

(elpaca org) ;; Install Org

You can review menu items via the elpaca-menu-item or elpaca-info commands. For example, on my system, M-x elpaca-menu-item org returns:

(org :source "Org"
     :description "Outline-based notes management and organizer"
     :url "https:/orgmode.org"
     :recipe
     ( :package "org"
       :local-repo "org"
       :repo "https://git.savannah.gnu.org/git/emacs/org-mode.git"
       :pre-build (progn (require 'elpaca-menu-org) (elpaca-menu-org--build))
       :autoloads "org-loaddefs.el"
       :build (:not elpaca--generate-autoloads-async)
       :files (:defaults ("etc/styles/" "etc/styles/*" "doc/*.texi"))))

You can view other menu-items from other menus on the elpaca-info page for Org. Below is the output on my system, which also contains items from the GNU-devel and GNU ELPAs:

org [Org|GNU-devel ELPA|GNU ELPA] ;;<-these are buttons in Emacs to display the info according to a particular menu
Outline-based notes management and organizer

source: Org
url:    https:/orgmode.org
menu item:
( :package   "org"
  :local-repo "org"
  :repo      "https://git.savannah.gnu.org/git/emacs/org-mode.git"
  :pre-build (progn (require 'elpaca-menu-org) (elpaca-menu-org--build))
  :autoloads "org-loaddefs.el"
  :build     (:not elpaca--generate-autoloads-async)
  :files    
  (:defaults ("etc/styles/" "etc/styles/*" "doc/*.texi")))

The menu-item contains metadata about the package. Part of that metadata is the package recipe. The recipe contains the information used to download/install/build the package. You can specify parts of the recipe yourself and the rest will be inherited from the menu item. For example, this would add a :post-build keyword to the recipe in addition to everything inherited from the menu item.

(elpaca (org :post-build (message "Org is done building")))

The elpaca-info command will show you the computed recipe (meaning everything you've specified in the ORDER, plus all the inherited stuff) below the menu-item. Using the example above, it would be:

source: Org
url:    https:/orgmode.org
menu item:
( :package   "org"
  :local-repo "org"
  :repo      "https://git.savannah.gnu.org/git/emacs/org-mode.git"
  :pre-build (progn (require 'elpaca-menu-org) (elpaca-menu-org--build))
  :autoloads "org-loaddefs.el"
  :build     (:not elpaca--generate-autoloads-async)
  :files    
  (:defaults ("etc/styles/" "etc/styles/*" "doc/*.texi")))
recipe:
( :package   "org"
  :autoloads "org-loaddefs.el"
  :local-repo "org"
  :repo      "https://git.savannah.gnu.org/git/emacs/org-mode.git"
  :pre-build (progn (require 'elpaca-menu-org) (elpaca-menu-org--build))
  :build     (:not elpaca--generate-autoloads-async)
  :files    
  (:defaults ("etc/styles/" "etc/styles/*" "doc/*.texi"))
  :post-build (message "Org is done building")
  :protocol  https
  :inherit   t
  :depth     1)

You can also specify a full recipe in the case where there is no menu item to match what you want install. For example, if someone has their "shiny-new-package.el" on their Github and it hasn't been published to MELPA or any other ELPA:

(elpaca (shiny-new-package :host github :repo "user/shiny-new-package.el"))

After the ORDER any number of elisp forms make up the BODY of the elpaca macro. The forms are evaluated after the package's queue is complete. This is where you would configure your packages. For example:

(elpaca org ;; Install/activate Org
  (setq org-directory (expand-file-name "~/my/org/path")) ;; Then set a user option
  ;; etc
  )

Does that help?