Skip to content

Instantly share code, notes, and snippets.

@RhubarbSin
Last active March 3, 2022 00:32
Show Gist options
  • Save RhubarbSin/b778f17f541f7bad92dd24301a2dd66b to your computer and use it in GitHub Desktop.
Save RhubarbSin/b778f17f541f7bad92dd24301a2dd66b to your computer and use it in GitHub Desktop.
Reference for Emacs use-package macro

:init execute code before a package is loaded

Summary

Accepts one or more forms, up to the next keyword.

Example

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

:config execute code after a package is loaded

Example

(use-package foo
  :config
  (foo-mode 1))

:custom customize package custom variables

Example

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

:bind bind a key to primary commands within a module

Summary

Takes either a cons or a list of conses.

Example

(use-package helm
  :bind (("M-x" . helm-M-x)
         ("M-<f5>" . helm-find-files)
         ([f10] . helm-buffers-list)
         ([S-f10] . helm-recentf)))

(use-package helm
  :bind (:map helm-command-map
         ("C-c h" . helm-execute-persistent-action)))

:hook add functions onto package hooks

Examples

(use-package ace-jump-mode
  :hook prog-mode)

(use-package ace-jump-mode
  :hook (prog-mode text-mode))

:disabled turn off a module

Example

(use-package foo
  :disabled)

:demand override package deferral

Summary

Forces immediate loading even with :bind.

Example

(use-package foo
  :demand t)

:mode specify mode for file names that match regular expressions

Example

(use-package jinja2-mode
  :mode "\\.js2")

(use-package yaml-mode
  :mode (("\\.yaml\\'" . yaml-mode)
         ("\\.yml\\'" . yaml-mode)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment