use-package

use-package

July 23, 2023 | permanent, seedling

tags :

Emacs Apps #

github Emacs package to manage ,install and configure , other packages. A use-package declaration for simplifying your .emacs The use-package macro allows you to isolate package configuration in your .emacs file in a way that is both performance-oriented and, well, tidy.

It uses elisp constructs to make the configurations easier.

It uses plist with cl module for the configurations.

(require 'cl)
(getf '(:a 1 :b 2) :a)

example:

(use-package foo
  :init
  (setq foo-variable t)
  :config
  (foo-mode 1))

:init #

Use the :init keyword to execute code before a package is loaded

(use-package foo
  :init
  (setq foo-variable t))

:config #

Similarly, :config can be used to execute code after a package is loaded.

(use-package foo
  :init
  (setq foo-variable t)
  :config
  (foo-mode 1))

:command #

In this case, I want to autoload the commands isearch-moccur and isearch-all from color-moccur.el, and bind keys both at the global level and within the isearch-mode-map (see next section). When the package is actually loaded (by using one of these commands), moccur-edit is also loaded, to allow editing of the moccur buffer.

(use-package color-moccur
  :commands (isearch-moccur isearch-all)
  :bind (("M-s O" . moccur)
         :map isearch-mode-map
         ("M-o" . isearch-moccur)
         ("M-O" . isearch-moccur-all))
  :init
  (setq isearch-lazy-highlight t)
  :config
  (use-package moccur-edit))

:autoload #

If you autoload non-interactive function, please use :autoload.

(use-package org-crypt
  :autoload org-crypt-use-before-save-magic)

:bind #

Another common thing to do when loading a module is to bind a key to primary commands within that module:

(use-package ace-jump-mode
  :bind ("C-." . ace-jump-mode))

This does two things: first, it creates an autoload for the ace-jump-mode command and defers loading of ace-jump-mode until you actually use it. Second, it binds the key C-. to that command. After loading, you can use M-x describe-personal-keybindings to see all such keybindings you’ve set throughout your .emacs file.

A more literal way to do the exact same thing is:

(use-package ace-jump-mode
  :commands ace-jump-mode
  :init
  (bind-key "C-." 'ace-jump-mode))

It takes cons or list of conses;

(use-package hi-lock
  :bind (("M-o l" . highlight-lines-matching-regexp)
         ("M-o r" . highlight-regexp)
         ("M-o w" . highlight-phrase)))

:custom #

The :custom keyword allows customization of package custom variables.

(use-package comint
  :custom
  (comint-buffer-maximum-size 20000 "Increase comint buffer size.")
  (comint-prompt-read-only t "Make the prompt read only."))


No notes link to this note

Go to random page

Previous Next