2022-03-28 15:03:21 +02:00
|
|
|
#+title: API Demos
|
|
|
|
#+property: header-args:elisp :results pp
|
2019-07-21 14:53:19 +02:00
|
|
|
|
2021-01-17 15:53:12 -05:00
|
|
|
This file contains demos of Doom's public API; its core library, macros, and
|
|
|
|
autodefs. It is used by the =elisp-demos= package to display examples of their
|
2022-06-17 14:43:36 +02:00
|
|
|
usage in the documentation displayed by either ~describe-function~ or
|
|
|
|
~helpful-function~ (on [[kbd:][SPC h f]]).
|
2019-07-21 14:53:19 +02:00
|
|
|
|
2019-09-07 19:56:52 -04:00
|
|
|
* Table of Contents :TOC_3:
|
2022-07-30 21:49:00 +02:00
|
|
|
- [[#doom-lib][doom-lib]]
|
2021-01-17 15:53:12 -05:00
|
|
|
- [[#add-hook][add-hook!]]
|
|
|
|
- [[#add-transient-hook][add-transient-hook!]]
|
|
|
|
- [[#after][after!]]
|
|
|
|
- [[#appendq][appendq!]]
|
|
|
|
- [[#custom-set-faces][custom-set-faces!]]
|
|
|
|
- [[#custom-theme-set-faces][custom-theme-set-faces!]]
|
|
|
|
- [[#defer-feature][defer-feature!]]
|
|
|
|
- [[#defer-until][defer-until!]]
|
|
|
|
- [[#disable-packages][disable-packages!]]
|
|
|
|
- [[#doom][doom!]]
|
|
|
|
- [[#file-exists-p][file-exists-p!]]
|
|
|
|
- [[#cmd][cmd!]]
|
|
|
|
- [[#cmd-1][cmd!!]]
|
|
|
|
- [[#cmds][cmds!]]
|
|
|
|
- [[#kbd][kbd!]]
|
2022-06-21 23:32:02 +02:00
|
|
|
- [[#lambda][lambda!]]
|
|
|
|
- [[#fn][fn!]]
|
2021-01-17 15:53:12 -05:00
|
|
|
- [[#letenv][letenv!]]
|
|
|
|
- [[#load][load!]]
|
|
|
|
- [[#map][map!]]
|
|
|
|
- [[#package][package!]]
|
|
|
|
- [[#pushnew][pushnew!]]
|
|
|
|
- [[#prependq][prependq!]]
|
|
|
|
- [[#quiet][quiet!]]
|
|
|
|
- [[#remove-hook][remove-hook!]]
|
|
|
|
- [[#setq][setq!]]
|
|
|
|
- [[#setq-hook][setq-hook!]]
|
|
|
|
- [[#unsetq-hook][unsetq-hook!]]
|
|
|
|
- [[#use-package][use-package!]]
|
|
|
|
|
2022-07-30 21:49:00 +02:00
|
|
|
* doom-lib
|
2021-01-17 15:53:12 -05:00
|
|
|
** add-hook!
|
2022-06-17 14:43:36 +02:00
|
|
|
:PROPERTIES:
|
|
|
|
:added: pre-3.0.0
|
|
|
|
:END:
|
2021-10-18 11:43:44 +02:00
|
|
|
#+begin_src emacs-lisp :eval no
|
2019-07-21 14:53:19 +02:00
|
|
|
;; With only one hook and one function, this is identical to `add-hook'. In that
|
|
|
|
;; case, use that instead.
|
2019-07-26 19:57:13 +02:00
|
|
|
(add-hook! 'some-mode-hook #'enable-something)
|
2019-07-21 14:53:19 +02:00
|
|
|
|
|
|
|
;; Adding many-to-many functions to hooks
|
2019-07-26 19:57:13 +02:00
|
|
|
(add-hook! some-mode #'enable-something #'and-another)
|
2022-04-03 14:48:22 +02:00
|
|
|
(add-hook! some-mode '(enable-something and-another))
|
2019-07-26 19:57:13 +02:00
|
|
|
(add-hook! '(one-mode-hook second-mode-hook) #'enable-something)
|
|
|
|
(add-hook! (one-mode second-mode) #'enable-something)
|
2019-07-21 14:53:19 +02:00
|
|
|
|
|
|
|
;; Appending and local hooks
|
2019-07-26 19:57:13 +02:00
|
|
|
(add-hook! (one-mode second-mode) :append #'enable-something)
|
|
|
|
(add-hook! (one-mode second-mode) :local #'enable-something)
|
2019-07-21 14:53:19 +02:00
|
|
|
|
|
|
|
;; With arbitrary forms
|
|
|
|
(add-hook! (one-mode second-mode) (setq v 5) (setq a 2))
|
2019-07-26 19:57:13 +02:00
|
|
|
(add-hook! (one-mode second-mode) :append :local (setq v 5) (setq a 2))
|
2019-07-21 14:53:19 +02:00
|
|
|
|
|
|
|
;; Inline named hook functions
|
|
|
|
(add-hook! '(one-mode-hook second-mode-hook)
|
|
|
|
(defun do-something ()
|
|
|
|
...)
|
|
|
|
(defun do-another-thing ()
|
|
|
|
...))
|
2021-10-18 11:43:44 +02:00
|
|
|
#+end_src
|
2019-07-21 14:53:19 +02:00
|
|
|
|
2021-01-17 15:53:12 -05:00
|
|
|
** TODO add-transient-hook!
|
2022-06-17 14:43:36 +02:00
|
|
|
:PROPERTIES:
|
|
|
|
:added: pre-3.0.0
|
|
|
|
:END:
|
2021-01-17 15:53:12 -05:00
|
|
|
** after!
|
2022-06-17 14:43:36 +02:00
|
|
|
:PROPERTIES:
|
|
|
|
:added: pre-3.0.0
|
|
|
|
:END:
|
2021-10-18 11:43:44 +02:00
|
|
|
#+begin_src emacs-lisp :eval no
|
2019-09-09 19:21:17 -04:00
|
|
|
;;; `after!' will take:
|
|
|
|
|
|
|
|
;; An unquoted package symbol (the name of a package)
|
|
|
|
(after! helm ...)
|
|
|
|
|
|
|
|
;; An unquoted list of package symbols (i.e. BODY is evaluated once both magit
|
|
|
|
;; and git-gutter have loaded)
|
|
|
|
(after! (magit git-gutter) ...)
|
|
|
|
|
|
|
|
;; An unquoted, nested list of compound package lists, using any combination of
|
|
|
|
;; :or/:any and :and/:all
|
|
|
|
(after! (:or package-a package-b ...) ...)
|
|
|
|
(after! (:and package-a package-b ...) ...)
|
|
|
|
(after! (:and package-a (:or package-b package-c) ...) ...)
|
|
|
|
;; (Without :or/:any/:and/:all, :and/:all are implied.)
|
|
|
|
|
|
|
|
;; A common mistake is to pass it the names of major or minor modes, e.g.
|
|
|
|
(after! rustic-mode ...)
|
|
|
|
(after! python-mode ...)
|
|
|
|
;; But the code in them will never run! rustic-mode is in the `rustic' package
|
|
|
|
;; and python-mode is in the `python' package. This is what you want:
|
|
|
|
(after! rustic ...)
|
|
|
|
(after! python ...)
|
2021-10-18 11:43:44 +02:00
|
|
|
#+end_src
|
2021-01-17 15:53:12 -05:00
|
|
|
** appendq!
|
2022-06-17 14:43:36 +02:00
|
|
|
:PROPERTIES:
|
|
|
|
:added: pre-3.0.0
|
|
|
|
:END:
|
2021-10-18 11:43:44 +02:00
|
|
|
#+begin_src emacs-lisp
|
2019-12-15 04:49:51 -05:00
|
|
|
(let ((x '(a b c)))
|
|
|
|
(appendq! x '(c d e))
|
|
|
|
x)
|
2021-10-18 11:43:44 +02:00
|
|
|
#+end_src
|
2019-09-09 19:21:17 -04:00
|
|
|
|
2019-12-15 22:54:24 -05:00
|
|
|
#+RESULTS:
|
|
|
|
: (a b c c d e)
|
|
|
|
|
2021-10-18 11:43:44 +02:00
|
|
|
#+begin_src emacs-lisp
|
2019-12-15 22:54:24 -05:00
|
|
|
(let ((x '(a b c))
|
|
|
|
(y '(c d e))
|
|
|
|
(z '(f g)))
|
|
|
|
(appendq! x y z '(h))
|
|
|
|
x)
|
2021-10-18 11:43:44 +02:00
|
|
|
#+end_src
|
2019-12-15 22:54:24 -05:00
|
|
|
|
|
|
|
#+RESULTS:
|
|
|
|
: (a b c c d e f g h)
|
|
|
|
|
2021-01-17 15:53:12 -05:00
|
|
|
** custom-set-faces!
|
2022-06-17 14:43:36 +02:00
|
|
|
:PROPERTIES:
|
|
|
|
:added: pre-3.0.0
|
|
|
|
:END:
|
2021-10-18 11:43:44 +02:00
|
|
|
#+begin_src emacs-lisp :eval no
|
2019-09-07 19:56:52 -04:00
|
|
|
(custom-set-faces!
|
2019-08-18 14:38:45 -04:00
|
|
|
'(outline-1 :weight normal)
|
|
|
|
'(outline-2 :weight normal)
|
|
|
|
'(outline-3 :weight normal)
|
|
|
|
'(outline-4 :weight normal)
|
|
|
|
'(outline-5 :weight normal)
|
|
|
|
'(outline-6 :weight normal)
|
|
|
|
'(default :background "red" :weight bold)
|
|
|
|
'(region :background "red" :weight bold))
|
2019-07-25 12:25:23 +02:00
|
|
|
|
2019-09-07 19:56:52 -04:00
|
|
|
(custom-set-faces!
|
2019-08-18 14:38:45 -04:00
|
|
|
'((outline-1 outline-2 outline-3 outline-4 outline-5 outline-6)
|
2019-07-25 12:25:23 +02:00
|
|
|
:weight normal)
|
2019-08-18 14:38:45 -04:00
|
|
|
'((default region)
|
2019-07-25 12:25:23 +02:00
|
|
|
:background "red" :weight bold))
|
|
|
|
|
|
|
|
(let ((red-bg-faces '(default region)))
|
2019-09-07 19:56:52 -04:00
|
|
|
(custom-set-faces!
|
2019-07-25 12:25:23 +02:00
|
|
|
`(,(cl-loop for i from 0 to 6 collect (intern (format "outline-%d" i)))
|
|
|
|
:weight normal)
|
|
|
|
`(,red-bg-faces
|
|
|
|
:background "red" :weight bold)))
|
2019-09-09 21:55:27 -04:00
|
|
|
|
2021-02-18 11:53:10 -05:00
|
|
|
;; You may utilise `doom-themes's theme API to fetch or tweak colors from their
|
|
|
|
;; palettes. No need to wait until the theme or package is loaded. e.g.
|
2019-09-09 21:55:27 -04:00
|
|
|
(custom-set-faces!
|
|
|
|
`(outline-1 :foreground ,(doom-color 'red))
|
|
|
|
`(outline-2 :background ,(doom-color 'blue)))
|
2021-10-18 11:43:44 +02:00
|
|
|
#+end_src
|
2019-07-25 12:25:23 +02:00
|
|
|
|
2021-01-17 15:53:12 -05:00
|
|
|
** custom-theme-set-faces!
|
2022-06-17 14:43:36 +02:00
|
|
|
:PROPERTIES:
|
|
|
|
:added: pre-3.0.0
|
|
|
|
:END:
|
2021-10-18 11:43:44 +02:00
|
|
|
#+begin_src emacs-lisp :eval no
|
2020-08-25 05:12:54 -04:00
|
|
|
(custom-theme-set-faces! 'doom-one
|
2019-08-18 14:38:45 -04:00
|
|
|
'(outline-1 :weight normal)
|
|
|
|
'(outline-2 :weight normal)
|
|
|
|
'(outline-3 :weight normal)
|
|
|
|
'(outline-4 :weight normal)
|
|
|
|
'(outline-5 :weight normal)
|
|
|
|
'(outline-6 :weight normal)
|
|
|
|
'(default :background "red" :weight bold)
|
|
|
|
'(region :background "red" :weight bold))
|
2019-07-25 12:25:23 +02:00
|
|
|
|
2019-09-07 19:56:52 -04:00
|
|
|
(custom-theme-set-faces! '(doom-one-theme doom-one-light-theme)
|
2019-08-18 14:38:45 -04:00
|
|
|
'((outline-1 outline-2 outline-3 outline-4 outline-5 outline-6)
|
2019-07-25 12:25:23 +02:00
|
|
|
:weight normal)
|
2019-08-18 14:38:45 -04:00
|
|
|
'((default region)
|
2019-07-25 12:25:23 +02:00
|
|
|
:background "red" :weight bold))
|
|
|
|
|
|
|
|
(let ((red-bg-faces '(default region)))
|
2019-09-07 19:56:52 -04:00
|
|
|
(custom-theme-set-faces! '(doom-one-theme doom-one-light-theme)
|
2019-07-25 12:25:23 +02:00
|
|
|
`(,(cl-loop for i from 0 to 6 collect (intern (format "outline-%d" i)))
|
|
|
|
:weight normal)
|
|
|
|
`(,red-bg-faces
|
|
|
|
:background "red" :weight bold)))
|
2019-09-09 21:55:27 -04:00
|
|
|
|
2021-02-18 11:53:10 -05:00
|
|
|
;; You may utilise `doom-themes's theme API to fetch or tweak colors from their
|
|
|
|
;; palettes. No need to wait until the theme or package is loaded. e.g.
|
2019-09-09 21:55:27 -04:00
|
|
|
(custom-theme-set-faces! 'doom-one
|
|
|
|
`(outline-1 :foreground ,(doom-color 'red))
|
|
|
|
`(outline-2 :background ,(doom-color 'blue)))
|
2021-10-18 11:43:44 +02:00
|
|
|
#+end_src
|
2019-07-25 12:25:23 +02:00
|
|
|
|
2021-01-17 15:53:12 -05:00
|
|
|
** TODO defer-feature!
|
2022-06-17 14:43:36 +02:00
|
|
|
:PROPERTIES:
|
|
|
|
:added: pre-3.0.0
|
|
|
|
:END:
|
2021-01-17 15:53:12 -05:00
|
|
|
** TODO defer-until!
|
2022-06-17 14:43:36 +02:00
|
|
|
:PROPERTIES:
|
|
|
|
:added: pre-3.0.0
|
|
|
|
:END:
|
2021-01-17 15:53:12 -05:00
|
|
|
** disable-packages!
|
2022-06-17 14:43:36 +02:00
|
|
|
:PROPERTIES:
|
|
|
|
:added: pre-3.0.0
|
|
|
|
:END:
|
2021-10-18 11:43:44 +02:00
|
|
|
#+begin_src emacs-lisp :eval no
|
2019-10-03 14:51:08 -04:00
|
|
|
;; Disable packages enabled by DOOM
|
|
|
|
(disable-packages! some-package second-package)
|
2021-10-18 11:43:44 +02:00
|
|
|
#+end_src
|
2019-10-03 14:51:08 -04:00
|
|
|
|
2021-01-17 15:53:12 -05:00
|
|
|
** doom!
|
2022-06-17 14:43:36 +02:00
|
|
|
:PROPERTIES:
|
|
|
|
:added: pre-3.0.0
|
|
|
|
:END:
|
2021-10-18 11:43:44 +02:00
|
|
|
#+begin_src emacs-lisp :eval no
|
2019-07-26 12:05:13 +02:00
|
|
|
(doom! :completion
|
|
|
|
company
|
|
|
|
ivy
|
|
|
|
;;helm
|
|
|
|
|
|
|
|
:tools
|
|
|
|
(:if IS-MAC macos)
|
|
|
|
docker
|
|
|
|
lsp
|
|
|
|
|
|
|
|
:lang
|
|
|
|
(cc +lsp)
|
|
|
|
(:cond ((string= system-name "work-pc")
|
|
|
|
python
|
|
|
|
rust
|
|
|
|
web)
|
|
|
|
((string= system-name "writing-pc")
|
|
|
|
(org +dragndrop)
|
|
|
|
ruby))
|
|
|
|
(:if IS-LINUX
|
|
|
|
(web +lsp)
|
|
|
|
web)
|
|
|
|
|
|
|
|
:config
|
|
|
|
literate
|
|
|
|
(default +bindings +smartparens))
|
2021-10-18 11:43:44 +02:00
|
|
|
#+end_src
|
2019-07-26 12:05:13 +02:00
|
|
|
|
2021-01-17 15:53:12 -05:00
|
|
|
** file-exists-p!
|
2022-06-17 14:43:36 +02:00
|
|
|
:PROPERTIES:
|
|
|
|
:added: pre-3.0.0
|
|
|
|
:END:
|
2021-10-18 11:43:44 +02:00
|
|
|
#+begin_src emacs-lisp
|
2019-07-23 20:32:40 +02:00
|
|
|
(file-exists-p! "init.el" doom-emacs-dir)
|
2021-10-18 11:43:44 +02:00
|
|
|
#+end_src
|
2019-07-23 20:32:40 +02:00
|
|
|
|
|
|
|
#+RESULTS:
|
|
|
|
: /home/hlissner/.emacs.d/init.el
|
|
|
|
|
2021-10-18 11:43:44 +02:00
|
|
|
#+begin_src emacs-lisp
|
2019-07-23 20:32:40 +02:00
|
|
|
(file-exists-p! (and (or "doesnotexist" "init.el")
|
|
|
|
"LICENSE")
|
|
|
|
doom-emacs-dir)
|
2021-10-18 11:43:44 +02:00
|
|
|
#+end_src
|
2019-07-23 20:32:40 +02:00
|
|
|
|
|
|
|
#+RESULTS:
|
|
|
|
: /home/hlissner/.emacs.d/LICENSE
|
|
|
|
|
2021-01-17 15:53:12 -05:00
|
|
|
** cmd!
|
2022-06-17 14:43:36 +02:00
|
|
|
:PROPERTIES:
|
|
|
|
:added: pre-3.0.0
|
|
|
|
:END:
|
2021-10-18 11:43:44 +02:00
|
|
|
#+begin_src emacs-lisp :eval no
|
2020-05-27 16:12:45 -04:00
|
|
|
(map! "C-j" (cmd! (newline) (indent-according-to-mode)))
|
2021-10-18 11:43:44 +02:00
|
|
|
#+end_src
|
2020-05-27 16:12:45 -04:00
|
|
|
|
2021-01-17 15:53:12 -05:00
|
|
|
** cmd!!
|
2022-06-17 14:43:36 +02:00
|
|
|
:PROPERTIES:
|
|
|
|
:added: pre-3.0.0
|
|
|
|
:END:
|
2019-12-13 14:30:42 -05:00
|
|
|
When ~newline~ is passed a numerical prefix argument (=C-u 5 M-x newline=), it
|
2020-05-27 16:12:45 -04:00
|
|
|
inserts N newlines. We can use ~cmd!!~ to easily create a keybinds that bakes in
|
|
|
|
the prefix arg into the command call:
|
2019-12-13 14:30:42 -05:00
|
|
|
|
2021-10-18 11:43:44 +02:00
|
|
|
#+begin_src emacs-lisp :eval no
|
2020-05-27 16:12:45 -04:00
|
|
|
(map! "C-j" (cmd!! #'newline 5))
|
2021-10-18 11:43:44 +02:00
|
|
|
#+end_src
|
2019-12-13 14:30:42 -05:00
|
|
|
|
|
|
|
Or to create aliases for functions that behave differently:
|
|
|
|
|
2021-10-18 11:43:44 +02:00
|
|
|
#+begin_src emacs-lisp :eval no
|
2020-05-27 16:12:45 -04:00
|
|
|
(fset 'insert-5-newlines (cmd!! #'newline 5))
|
2019-12-13 14:30:42 -05:00
|
|
|
|
|
|
|
;; The equivalent of C-u M-x org-global-cycle, which resets the org document to
|
|
|
|
;; its startup visibility settings.
|
2020-05-27 16:12:45 -04:00
|
|
|
(fset 'org-reset-global-visibility (cmd!! #'org-global-cycle '(4))
|
2021-10-18 11:43:44 +02:00
|
|
|
#+end_src
|
2020-05-27 16:12:45 -04:00
|
|
|
|
2021-01-17 15:53:12 -05:00
|
|
|
** cmds!
|
2022-06-17 14:43:36 +02:00
|
|
|
:PROPERTIES:
|
|
|
|
:added: pre-3.0.0
|
|
|
|
:END:
|
2021-10-18 11:43:44 +02:00
|
|
|
#+begin_src emacs-lisp :eval no
|
2022-08-12 20:29:19 +02:00
|
|
|
(map! :i [tab] (cmds! (and (modulep! :editor snippets)
|
2020-12-11 17:50:04 -05:00
|
|
|
(bound-and-true-p yas-minor-mode)
|
|
|
|
(yas-maybe-expand-abbrev-key-filter 'yas-expand))
|
|
|
|
#'yas-expand
|
2022-08-12 20:29:19 +02:00
|
|
|
(modulep! :completion company +tng)
|
2020-12-11 17:50:04 -05:00
|
|
|
#'company-indent-or-complete-common)
|
|
|
|
:m [tab] (cmds! (and (bound-and-true-p yas-minor-mode)
|
|
|
|
(evil-visual-state-p)
|
|
|
|
(or (eq evil-visual-selection 'line)
|
|
|
|
(not (memq (char-after) (list ?\( ?\[ ?\{ ?\} ?\] ?\))))))
|
|
|
|
#'yas-insert-snippet
|
2022-08-12 20:29:19 +02:00
|
|
|
(and (modulep! :editor fold)
|
2020-12-11 17:50:04 -05:00
|
|
|
(save-excursion (end-of-line) (invisible-p (point))))
|
|
|
|
#'+fold/toggle
|
|
|
|
(fboundp 'evil-jump-item)
|
|
|
|
#'evil-jump-item))
|
2021-10-18 11:43:44 +02:00
|
|
|
#+end_src
|
2020-12-11 17:50:04 -05:00
|
|
|
|
2021-01-17 15:53:12 -05:00
|
|
|
** kbd!
|
2022-06-17 14:43:36 +02:00
|
|
|
:PROPERTIES:
|
|
|
|
:added: pre-3.0.0
|
|
|
|
:END:
|
2021-10-18 11:43:44 +02:00
|
|
|
#+begin_src emacs-lisp :eval no
|
2020-12-11 17:50:04 -05:00
|
|
|
(map! "," (kbd! "SPC")
|
|
|
|
";" (kbd! ":"))
|
2021-10-18 11:43:44 +02:00
|
|
|
#+end_src
|
2020-12-11 17:50:04 -05:00
|
|
|
|
2022-06-21 21:27:00 +02:00
|
|
|
** lambda!
|
|
|
|
#+begin_src emacs-lisp
|
|
|
|
(mapcar (lambda! ((&key foo bar baz))
|
|
|
|
(list foo bar baz))
|
|
|
|
'((:foo 10 :bar 25)
|
|
|
|
(:baz hello :boop nil)
|
|
|
|
(:bar 42)))
|
|
|
|
#+end_src
|
|
|
|
|
|
|
|
#+RESULTS:
|
|
|
|
: ((10 25 nil) (nil nil hello) (nil 42 nil))
|
|
|
|
|
|
|
|
** fn!
|
|
|
|
#+begin_src emacs-lisp
|
|
|
|
(mapcar (fn! (symbol-name %)) '(hello world))
|
|
|
|
#+end_src
|
|
|
|
|
|
|
|
#+RESULTS:
|
|
|
|
: ("hello" "world")
|
|
|
|
|
|
|
|
#+begin_src emacs-lisp
|
|
|
|
(seq-sort (fn! (string-lessp (symbol-name %1)
|
|
|
|
(symbol-name %2)))
|
|
|
|
'(bonzo foo bar buddy doomguy baz zombies))
|
|
|
|
#+end_src
|
|
|
|
|
|
|
|
#+RESULTS:
|
|
|
|
: (bar baz bonzo buddy doomguy foo zombies)
|
|
|
|
|
|
|
|
#+begin_src emacs-lisp
|
|
|
|
(format "You passed %d arguments to this function"
|
|
|
|
(funcall (fn! (length %*)) :foo :bar :baz "hello" 123 t))
|
|
|
|
#+end_src
|
|
|
|
|
|
|
|
#+RESULTS:
|
|
|
|
: "You passed 6 arguments to this function"
|
|
|
|
|
2021-01-17 15:53:12 -05:00
|
|
|
** letenv!
|
2022-06-17 14:43:36 +02:00
|
|
|
:PROPERTIES:
|
|
|
|
:added: pre-3.0.0
|
|
|
|
:END:
|
2021-10-18 11:43:44 +02:00
|
|
|
#+begin_src emacs-lisp
|
2019-12-15 22:54:47 -05:00
|
|
|
(letenv! (("SHELL" "/bin/sh"))
|
|
|
|
(shell-command-to-string "echo $SHELL"))
|
2021-10-18 11:43:44 +02:00
|
|
|
#+end_src
|
2019-12-15 22:54:47 -05:00
|
|
|
|
|
|
|
#+RESULTS:
|
|
|
|
: "/bin/sh\n"
|
|
|
|
|
2021-01-17 15:53:12 -05:00
|
|
|
** load!
|
2022-06-17 14:43:36 +02:00
|
|
|
:PROPERTIES:
|
|
|
|
:added: pre-3.0.0
|
|
|
|
:END:
|
2021-10-18 11:43:44 +02:00
|
|
|
#+begin_src emacs-lisp :eval no
|
2019-09-09 19:13:51 -04:00
|
|
|
;;; Lets say we're in ~/.doom.d/config.el
|
|
|
|
(load! "lisp/module") ; loads ~/.doom.d/lisp/module.el
|
|
|
|
(load! "somefile" doom-emacs-dir) ; loads ~/.emacs.d/somefile.el
|
|
|
|
(load! "anotherfile" doom-private-dir) ; loads ~/.doom.d/anotherfile.el
|
|
|
|
|
|
|
|
;; If you don't want a `load!' call to throw an error if the file doesn't exist:
|
|
|
|
(load! "~/.maynotexist" nil t)
|
2021-10-18 11:43:44 +02:00
|
|
|
#+end_src
|
2019-09-09 19:13:51 -04:00
|
|
|
|
2021-01-17 15:53:12 -05:00
|
|
|
** map!
|
2022-06-17 14:43:36 +02:00
|
|
|
:PROPERTIES:
|
|
|
|
:added: pre-3.0.0
|
|
|
|
:END:
|
2021-10-18 11:43:44 +02:00
|
|
|
#+begin_src emacs-lisp :eval no
|
2019-10-03 14:51:08 -04:00
|
|
|
(map! :map magit-mode-map
|
|
|
|
:m "C-r" 'do-something ; C-r in motion state
|
|
|
|
:nv "q" 'magit-mode-quit-window ; q in normal+visual states
|
|
|
|
"C-x C-r" 'a-global-keybind
|
|
|
|
:g "C-x C-r" 'another-global-keybind ; same as above
|
|
|
|
|
|
|
|
(:when IS-MAC
|
|
|
|
:n "M-s" 'some-fn
|
2020-07-28 15:50:25 -04:00
|
|
|
:i "M-o" (cmd! (message "Hi"))))
|
2019-10-03 14:51:08 -04:00
|
|
|
|
2022-08-12 20:29:19 +02:00
|
|
|
(map! (:when (modulep! :completion company) ; Conditional loading
|
2019-10-03 14:51:08 -04:00
|
|
|
:i "C-@" #'+company/complete
|
|
|
|
(:prefix "C-x" ; Use a prefix key
|
|
|
|
:i "C-l" #'+company/whole-lines)))
|
|
|
|
|
2022-08-12 20:29:19 +02:00
|
|
|
(map! (:when (modulep! :lang latex) ; local conditional
|
2019-10-03 14:51:08 -04:00
|
|
|
(:map LaTeX-mode-map
|
|
|
|
:localleader ; Use local leader
|
|
|
|
:desc "View" "v" #'TeX-view)) ; Add which-key description
|
|
|
|
:leader ; Use leader key from now on
|
|
|
|
:desc "Eval expression" ";" #'eval-expression)
|
2021-10-18 11:43:44 +02:00
|
|
|
#+end_src
|
2019-10-03 14:51:08 -04:00
|
|
|
|
2019-11-14 15:43:44 -05:00
|
|
|
These are side-by-side comparisons, showing how to bind keys with and without
|
|
|
|
~map!~:
|
|
|
|
|
2021-10-18 11:43:44 +02:00
|
|
|
#+begin_src emacs-lisp :eval no
|
2019-11-14 15:43:44 -05:00
|
|
|
;; bind a global key
|
|
|
|
(global-set-key (kbd "C-x y") #'do-something)
|
|
|
|
(map! "C-x y" #'do-something)
|
|
|
|
|
|
|
|
;; bind a key on a keymap
|
2020-08-06 14:22:41 -04:00
|
|
|
(define-key emacs-lisp-mode-map (kbd "C-c p") #'do-something)
|
|
|
|
(map! :map emacs-lisp-mode-map "C-c p" #'do-something)
|
2019-11-14 15:43:44 -05:00
|
|
|
|
|
|
|
;; unbind a key defined elsewhere
|
|
|
|
(define-key lua-mode-map (kbd "SPC m b") nil)
|
|
|
|
(map! :map lua-mode-map "SPC m b" nil)
|
|
|
|
|
|
|
|
;; bind multiple keys
|
2019-11-25 15:28:38 -05:00
|
|
|
(global-set-key (kbd "C-x x") #'do-something)
|
|
|
|
(global-set-key (kbd "C-x y") #'do-something-else)
|
|
|
|
(global-set-key (kbd "C-x z") #'do-another-thing)
|
2019-11-14 15:43:44 -05:00
|
|
|
(map! "C-x x" #'do-something
|
|
|
|
"C-x y" #'do-something-else
|
|
|
|
"C-x z" #'do-another-thing)
|
|
|
|
|
|
|
|
;; bind global keys in normal mode
|
|
|
|
(evil-define-key* 'normal 'global
|
|
|
|
(kbd "C-x x") #'do-something
|
|
|
|
(kbd "C-x y") #'do-something-else
|
|
|
|
(kbd "C-x z") #'do-another-thing)
|
|
|
|
(map! :n "C-x x" #'do-something
|
|
|
|
:n "C-x y" #'do-something-else
|
|
|
|
:n "C-x z" #'do-another-thing)
|
|
|
|
|
|
|
|
;; or on a deferred keymap
|
|
|
|
(evil-define-key 'normal emacs-lisp-mode-map
|
|
|
|
(kbd "C-x x") #'do-something
|
|
|
|
(kbd "C-x y") #'do-something-else
|
|
|
|
(kbd "C-x z") #'do-another-thing)
|
|
|
|
(map! :map emacs-lisp-mode-map
|
|
|
|
:n "C-x x" #'do-something
|
|
|
|
:n "C-x y" #'do-something-else
|
|
|
|
:n "C-x z" #'do-another-thing)
|
|
|
|
|
|
|
|
;; or multiple maps
|
|
|
|
(dolist (map (list emacs-lisp-mode go-mode-map ivy-minibuffer-map))
|
|
|
|
(evil-define-key '(normal insert) map
|
|
|
|
"a" #'a
|
|
|
|
"b" #'b
|
|
|
|
"c" #'c))
|
|
|
|
(map! :map (emacs-lisp-mode go-mode-map ivy-minibuffer-map)
|
|
|
|
:ni "a" #'a
|
|
|
|
:ni "b" #'b
|
|
|
|
:ni "c" #'c)
|
|
|
|
|
|
|
|
;; or in multiple states (order of states doesn't matter)
|
|
|
|
(evil-define-key* '(normal visual) emacs-lisp-mode-map (kbd "C-x x") #'do-something)
|
|
|
|
(evil-define-key* 'insert emacs-lisp-mode-map (kbd "C-x x") #'do-something-else)
|
|
|
|
(evil-define-key* '(visual normal insert emacs) emacs-lisp-mode-map (kbd "C-x z") #'do-another-thing)
|
|
|
|
(map! :map emacs-lisp-mode
|
|
|
|
:nv "C-x x" #'do-something ; normal+visual
|
|
|
|
:i "C-x y" #'do-something-else ; insert
|
|
|
|
:vnie "C-x z" #'do-another-thing) ; visual+normal+insert+emacs
|
|
|
|
|
|
|
|
;; You can nest map! calls:
|
|
|
|
(evil-define-key* '(normal visual) emacs-lisp-mode-map (kbd "C-x x") #'do-something)
|
|
|
|
(evil-define-key* 'normal go-lisp-mode-map (kbd "C-x x") #'do-something-else)
|
|
|
|
(map! (:map emacs-lisp-mode :nv "C-x x" #'do-something)
|
|
|
|
(:map go-lisp-mode :n "C-x x" #'do-something-else))
|
2021-10-18 11:43:44 +02:00
|
|
|
#+end_src
|
2019-11-14 15:43:44 -05:00
|
|
|
|
2021-01-17 15:53:12 -05:00
|
|
|
** package!
|
2022-06-17 14:43:36 +02:00
|
|
|
:PROPERTIES:
|
|
|
|
:added: pre-3.0.0
|
|
|
|
:END:
|
2021-10-18 11:43:44 +02:00
|
|
|
#+begin_src emacs-lisp :eval no
|
2019-09-09 19:10:12 -04:00
|
|
|
;; To install a package that can be found on ELPA or any of the sources
|
2020-02-02 16:03:34 -05:00
|
|
|
;; specified in `straight-recipe-repositories':
|
2019-09-09 19:10:12 -04:00
|
|
|
(package! evil)
|
|
|
|
(package! js2-mode)
|
|
|
|
(package! rainbow-delimiters)
|
|
|
|
|
|
|
|
;; To disable a package included with Doom (which will no-op all its `after!'
|
|
|
|
;; and `use-package!' blocks):
|
|
|
|
(package! evil :disable t)
|
|
|
|
(package! rainbow-delimiters :disable t)
|
|
|
|
|
|
|
|
;; To install a package from a github repo
|
|
|
|
(package! so-long :recipe (:host github :repo "hlissner/emacs-so-long"))
|
|
|
|
|
|
|
|
;; If a package is particularly big and comes with submodules you don't need,
|
|
|
|
;; you can tell the package manager not to clone the repo recursively:
|
|
|
|
(package! ansible :recipe (:nonrecursive t))
|
|
|
|
|
2019-12-28 14:00:08 -05:00
|
|
|
;; To pin a package to a specific commit:
|
2020-01-25 03:49:42 -05:00
|
|
|
(package! evil :pin "e7bc39de2f9")
|
2019-12-28 14:00:08 -05:00
|
|
|
;; ...or branch:
|
2019-09-09 19:10:12 -04:00
|
|
|
(package! evil :recipe (:branch "stable"))
|
2019-12-28 14:00:08 -05:00
|
|
|
;; To unpin a pinned package:
|
|
|
|
(package! evil :pin nil)
|
2019-09-09 19:10:12 -04:00
|
|
|
|
|
|
|
;; If you share your config between two computers, and don't want bin/doom
|
|
|
|
;; refresh to delete packages used only on one system, use :ignore
|
|
|
|
(package! evil :ignore (not (equal system-name "my-desktop")))
|
2021-10-18 11:43:44 +02:00
|
|
|
#+end_src
|
2019-09-09 19:10:12 -04:00
|
|
|
|
2021-01-17 15:53:12 -05:00
|
|
|
** pushnew!
|
2022-06-17 14:43:36 +02:00
|
|
|
:PROPERTIES:
|
|
|
|
:added: pre-3.0.0
|
|
|
|
:END:
|
2021-10-18 11:43:44 +02:00
|
|
|
#+begin_src emacs-lisp
|
2019-12-15 04:49:51 -05:00
|
|
|
(let ((list '(a b c)))
|
|
|
|
(pushnew! list 'c 'd 'e)
|
|
|
|
list)
|
2021-10-18 11:43:44 +02:00
|
|
|
#+end_src
|
2019-12-15 22:54:24 -05:00
|
|
|
|
|
|
|
#+RESULTS:
|
|
|
|
: (e d a b c)
|
|
|
|
|
2021-01-17 15:53:12 -05:00
|
|
|
** prependq!
|
2022-06-17 14:43:36 +02:00
|
|
|
:PROPERTIES:
|
|
|
|
:added: pre-3.0.0
|
|
|
|
:END:
|
2021-10-18 11:43:44 +02:00
|
|
|
#+begin_src emacs-lisp
|
2019-12-15 04:49:51 -05:00
|
|
|
(let ((x '(a b c)))
|
|
|
|
(prependq! x '(c d e))
|
|
|
|
x)
|
2021-10-18 11:43:44 +02:00
|
|
|
#+end_src
|
2019-12-15 04:49:51 -05:00
|
|
|
|
2019-12-15 22:54:24 -05:00
|
|
|
#+RESULTS:
|
|
|
|
: (c d e a b c)
|
|
|
|
|
2021-10-18 11:43:44 +02:00
|
|
|
#+begin_src emacs-lisp
|
2019-12-15 04:49:51 -05:00
|
|
|
(let ((x '(a b c))
|
|
|
|
(y '(c d e))
|
|
|
|
(z '(f g)))
|
|
|
|
(prependq! x y z '(h))
|
|
|
|
x)
|
2021-10-18 11:43:44 +02:00
|
|
|
#+end_src
|
2019-12-15 22:54:24 -05:00
|
|
|
|
|
|
|
#+RESULTS:
|
|
|
|
: (c d e f g h a b c)
|
|
|
|
|
2021-01-17 15:53:12 -05:00
|
|
|
** quiet!
|
2022-06-17 14:43:36 +02:00
|
|
|
:PROPERTIES:
|
|
|
|
:added: pre-3.0.0
|
|
|
|
:END:
|
2021-10-18 11:43:44 +02:00
|
|
|
#+begin_src emacs-lisp :eval no
|
2019-10-03 14:51:08 -04:00
|
|
|
;; Enters recentf-mode without extra output
|
|
|
|
(quiet! (recentf-mode +1))
|
2021-10-18 11:43:44 +02:00
|
|
|
#+end_src
|
2021-01-17 15:53:12 -05:00
|
|
|
** remove-hook!
|
2022-06-17 14:43:36 +02:00
|
|
|
:PROPERTIES:
|
|
|
|
:added: pre-3.0.0
|
|
|
|
:END:
|
2021-10-18 11:43:44 +02:00
|
|
|
#+begin_src emacs-lisp :eval no
|
2019-07-29 18:56:49 +02:00
|
|
|
;; With only one hook and one function, this is identical to `remove-hook'. In
|
|
|
|
;; that case, use that instead.
|
2019-07-26 19:57:13 +02:00
|
|
|
(remove-hook! 'some-mode-hook #'enable-something)
|
2019-07-21 14:53:19 +02:00
|
|
|
|
2019-07-29 18:56:49 +02:00
|
|
|
;; Removing N functions from M hooks
|
2019-07-26 19:57:13 +02:00
|
|
|
(remove-hook! some-mode #'enable-something #'and-another)
|
|
|
|
(remove-hook! some-mode #'(enable-something and-another))
|
|
|
|
(remove-hook! '(one-mode-hook second-mode-hook) #'enable-something)
|
|
|
|
(remove-hook! (one-mode second-mode) #'enable-something)
|
2019-07-21 14:53:19 +02:00
|
|
|
|
2019-07-29 18:56:49 +02:00
|
|
|
;; Removing buffer-local hooks
|
2019-07-26 19:57:13 +02:00
|
|
|
(remove-hook! (one-mode second-mode) :local #'enable-something)
|
2019-07-21 14:53:19 +02:00
|
|
|
|
2019-07-29 18:56:49 +02:00
|
|
|
;; Removing arbitrary forms (must be exactly the same as the definition)
|
2019-07-21 14:53:19 +02:00
|
|
|
(remove-hook! (one-mode second-mode) (setq v 5) (setq a 2))
|
2021-10-18 11:43:44 +02:00
|
|
|
#+end_src
|
2021-01-17 15:53:12 -05:00
|
|
|
** setq!
|
2022-06-17 14:43:36 +02:00
|
|
|
:PROPERTIES:
|
|
|
|
:added: pre-3.0.0
|
|
|
|
:END:
|
2021-10-18 11:43:44 +02:00
|
|
|
#+begin_src emacs-lisp
|
2020-01-24 17:50:45 -05:00
|
|
|
;; Each of these have a setter associated with them, which must be triggered in
|
|
|
|
;; order for their new values to have an effect.
|
|
|
|
(setq! evil-want-Y-yank-to-eol nil
|
|
|
|
evil-want-C-u-scroll nil
|
|
|
|
evil-want-C-d-scroll nil)
|
2021-10-18 11:43:44 +02:00
|
|
|
#+end_src
|
2021-01-17 15:53:12 -05:00
|
|
|
** setq-hook!
|
2022-06-17 14:43:36 +02:00
|
|
|
:PROPERTIES:
|
|
|
|
:added: pre-3.0.0
|
|
|
|
:END:
|
2021-10-18 11:43:44 +02:00
|
|
|
#+begin_src emacs-lisp :eval no
|
2019-10-03 14:51:08 -04:00
|
|
|
;; Set multiple variables after a hook
|
|
|
|
(setq-hook! 'markdown-mode-hook
|
|
|
|
line-spacing 2
|
|
|
|
fill-column 80)
|
|
|
|
|
|
|
|
;; Set variables after multiple hooks
|
|
|
|
(setq-hook! '(eshell-mode-hook term-mode-hook)
|
|
|
|
hscroll-margin 0)
|
2021-10-18 11:43:44 +02:00
|
|
|
#+end_src
|
2019-10-03 14:51:08 -04:00
|
|
|
|
2021-01-17 15:53:12 -05:00
|
|
|
** unsetq-hook!
|
2022-06-17 14:43:36 +02:00
|
|
|
:PROPERTIES:
|
|
|
|
:added: pre-3.0.0
|
|
|
|
:END:
|
2021-10-18 11:43:44 +02:00
|
|
|
#+begin_src emacs-lisp :eval no
|
2019-10-03 14:51:08 -04:00
|
|
|
(unsetq-hook! 'markdown-mode-hook line-spacing)
|
|
|
|
|
|
|
|
;; Removes the following variable hook
|
|
|
|
(setq-hook! 'markdown-mode-hook line-spacing 2)
|
2019-09-07 19:56:52 -04:00
|
|
|
|
2019-10-03 14:51:08 -04:00
|
|
|
;; Removing N variables from M hooks
|
|
|
|
(unsetq-hook! some-mode enable-something and-another)
|
|
|
|
(unsetq-hook! some-mode (enable-something and-another))
|
|
|
|
(unsetq-hook! '(one-mode-hook second-mode-hook) enable-something)
|
|
|
|
(unsetq-hook! (one-mode second-mode) enable-something)
|
2021-10-18 11:43:44 +02:00
|
|
|
#+end_src
|
2019-10-03 14:51:08 -04:00
|
|
|
|
2021-01-17 15:53:12 -05:00
|
|
|
** use-package!
|
2022-06-17 14:43:36 +02:00
|
|
|
:PROPERTIES:
|
|
|
|
:added: pre-3.0.0
|
|
|
|
:END:
|
2021-10-18 11:43:44 +02:00
|
|
|
#+begin_src emacs-lisp :eval no
|
2019-10-03 14:51:08 -04:00
|
|
|
;; Use after-call to load package before hook
|
|
|
|
(use-package! projectile
|
|
|
|
:after-call (pre-command-hook after-find-file dired-before-readin-hook))
|
|
|
|
|
|
|
|
;; defer recentf packages one by one
|
|
|
|
(use-package! recentf
|
|
|
|
:defer-incrementally easymenu tree-widget timer
|
|
|
|
:after-call after-find-file)
|
|
|
|
|
|
|
|
;; This is equivalent to :defer-incrementally (abc)
|
|
|
|
(use-package! abc
|
|
|
|
:defer-incrementally t)
|
2021-10-18 11:43:44 +02:00
|
|
|
#+end_src
|