An open API service indexing awesome lists of open source software.

https://github.com/akirak/use-package-tags

Add :tags keyword to use-package, to allow contextual package activation
https://github.com/akirak/use-package-tags

emacs use-package

Last synced: about 2 months ago
JSON representation

Add :tags keyword to use-package, to allow contextual package activation

Awesome Lists containing this project

README

        

* :tags keyword for use-package
This library adds =:tags= keyword to =use-package=, which can be used
to enable only packages that belong to certain groups.
You can group packages using the keyword, and select packages
to enable by setting =use-package-tags-current-profile= variable.

It also provides a function for enumerating packages in a
file/buffer based on tags. This can be used to install packages
for your init file without relying on =package.el=, e.g. in Nix.

#+BEGIN_HTML
CI
#+END_HTML
** Table of contents
:PROPERTIES:
:TOC: siblings
:END:
- [[#installation][Installation]]
- [[#usage][Usage]]
- [[#tags-keyword-for-use-package][:tags keyword for use-package]]
- [[#extracting-package-names-from-an-init-file][Extracting package names from an init file]]

** Installation
This package is not available on MELPA yet.
** Usage
*** =:tags= keyword for =use-package=
#+begin_src emacs-lisp
(require 'use-package)
(use-package use-package-tags)

;; Select packages using tags
;; This can be put in your custom-file, but it should be set
;; before you load use-package forms.
(setq use-package-tags-current-profile '(work))

;; Since it has no :tags, this package is always enabled
(use-package lsp-mode)

;; This package has a tag in the current profile, so it is enabled.
(use-package lsp-java
;; You wouldn't want to write Java at home (unless you are working
;; from home), so it doesn't have to be enabled outside of work.
:tags (work))

;; This package has no tag in the current profile, so it is disabled.
(use-package my-game-on-emacs
:tags (personal))
#+end_src

You can specify multiple tags in a =:tags= keyword field.
If a package has at least one keyword in your current profile, it will be enabled.
*** Extracting package names from an init file
Another functionality provided by this package is to extract a list of packages from an initialization file.
This feature is primarily targeted at Nix users.
You can get a list of all packages in =use-package= forms in a file, or select packages using tags:

#+begin_src emacs-lisp
;; Get a list of packages in the current buffer by tags
(use-package-tags-select '(programming blog))

;; You can specify a file name using :from keyword
(use-package-tags-select '(programming blog)
:from (expand-file-name "init.el" user-emacs-directory))

;; The :from argument also accepts t, which is evaluated to
;; `use-package-tags-init-files' (default: user-init-file)
(use-package-tags-select '(programming blog)
:from t)

;; You can select all packages by passing t as the query
(use-package-tags-select t)

;; If you set :installable to t, it returns packages on the registry
;; (requires epkg.el)
(use-package-tags-select t :installable t)
#+end_src

You can save the result to a file:

#+begin_src emacs-lisp
;; Save the list of packages to packages.txt in plain text
(with-temp-buffer
(setq buffer-file-name "packages.txt")
(insert (use-package-tags-select t :from "init.el"
:installable t
:as 'lines))
(save-buffer))
#+end_src

The function handles some built-in keywords of =use-package= to exclude packages that satisfy at least one of the following conditions:

- Having a non-nil =:disabled= property.
- Having an =:if= property that evaluates to nil.

Not all keywords are supported right now, but it can be extended to support more keywords.

This package also provides =use-package-tags-collect-tags= function, which returns a list of all tags in a source.