mirror of
https://gitlab.com/dwt1/dotfiles.git
synced 2026-04-24 12:00:24 +10:00
Updating Doom Emacs.
This commit is contained in:
@@ -1,19 +1,22 @@
|
||||
;;; config/default/config.el -*- lexical-binding: t; -*-
|
||||
|
||||
(defvar +default-want-RET-continue-comments t
|
||||
"If non-nil, RET will continue commented lines.")
|
||||
|
||||
(defvar +default-minibuffer-maps
|
||||
`(minibuffer-local-map
|
||||
minibuffer-local-ns-map
|
||||
minibuffer-local-completion-map
|
||||
minibuffer-local-must-match-map
|
||||
minibuffer-local-isearch-map
|
||||
read-expression-map
|
||||
,@(cond ((featurep! :completion ivy)
|
||||
'(ivy-minibuffer-map
|
||||
ivy-switch-buffer-map))
|
||||
((featurep! :completion helm)
|
||||
'(helm-map
|
||||
helm-ag-map
|
||||
helm-read-file-map))))
|
||||
(append '(minibuffer-local-map
|
||||
minibuffer-local-ns-map
|
||||
minibuffer-local-completion-map
|
||||
minibuffer-local-must-match-map
|
||||
minibuffer-local-isearch-map
|
||||
read-expression-map)
|
||||
(cond ((featurep! :completion ivy)
|
||||
'(ivy-minibuffer-map
|
||||
ivy-switch-buffer-map))
|
||||
((featurep! :completion helm)
|
||||
'(helm-map
|
||||
helm-ag-map
|
||||
helm-read-file-map))))
|
||||
"A list of all the keymaps used for the minibuffer.")
|
||||
|
||||
|
||||
@@ -23,20 +26,32 @@
|
||||
;;;###package avy
|
||||
(setq avy-all-windows nil
|
||||
avy-all-windows-alt t
|
||||
avy-background t)
|
||||
avy-background t
|
||||
;; the unpredictability of this (when enabled) makes it a poor default
|
||||
avy-single-candidate-jump nil)
|
||||
|
||||
|
||||
(after! epa
|
||||
(setq epa-file-encrypt-to
|
||||
(or epa-file-encrypt-to
|
||||
;; Collect all public key IDs with your username
|
||||
(unless (string-empty-p user-full-name)
|
||||
(cl-loop for key in (ignore-errors (epg-list-keys (epg-make-context) user-full-name))
|
||||
collect (epg-sub-key-id (car (epg-key-sub-key-list key)))))
|
||||
user-mail-address)
|
||||
;; With GPG 2.1, this forces gpg-agent to use the Emacs minibuffer to
|
||||
;; prompt for the key passphrase.
|
||||
epa-pinentry-mode 'loopback))
|
||||
;; With GPG 2.1+, this forces gpg-agent to use the Emacs minibuffer to prompt
|
||||
;; for the key passphrase.
|
||||
(set (if EMACS27+
|
||||
'epg-pinentry-mode
|
||||
'epa-pinentry-mode) ; DEPRECATED `epa-pinentry-mode'
|
||||
'loopback)
|
||||
;; Default to the first secret key available in your keyring.
|
||||
(setq-default
|
||||
epa-file-encrypt-to
|
||||
(or (default-value 'epa-file-encrypt-to)
|
||||
(unless (string-empty-p user-full-name)
|
||||
(cl-loop for key in (ignore-errors (epg-list-keys (epg-make-context) user-full-name))
|
||||
collect (epg-sub-key-id (car (epg-key-sub-key-list key)))))
|
||||
user-mail-address))
|
||||
;; And suppress prompts if epa-file-encrypt-to has a default value (without
|
||||
;; overwriting file-local values).
|
||||
(defadvice! +default--dont-prompt-for-keys-a (&rest _)
|
||||
:before #'epa-file-write-region
|
||||
(unless (local-variable-p 'epa-file-encrypt-to)
|
||||
(setq-local epa-file-encrypt-to (default-value 'epa-file-encrypt-to)))))
|
||||
|
||||
|
||||
(use-package! drag-stuff
|
||||
@@ -62,11 +77,6 @@
|
||||
;; or specific :post-handlers with:
|
||||
;; (sp-pair "{" nil :post-handlers '(:rem ("| " "SPC")))
|
||||
(after! smartparens
|
||||
;; Smartparens is broken in `cc-mode' as of Emacs 27. See
|
||||
;; <https://github.com/Fuco1/smartparens/issues/963>.
|
||||
(unless EMACS27+
|
||||
(pushnew! sp--special-self-insert-commands 'c-electric-paren 'c-electric-brace))
|
||||
|
||||
;; Smartparens' navigation feature is neat, but does not justify how
|
||||
;; expensive it is. It's also less useful for evil users. This may need to
|
||||
;; be reactivated for non-evil users though. Needs more testing!
|
||||
@@ -76,7 +86,7 @@
|
||||
sp-navigate-consider-sgml-tags nil)))
|
||||
|
||||
;; Autopair quotes more conservatively; if I'm next to a word/before another
|
||||
;; quote, I likely don't want to open a new pair.
|
||||
;; quote, I don't want to open a new pair or it would unbalance them.
|
||||
(let ((unless-list '(sp-point-before-word-p
|
||||
sp-point-after-word-p
|
||||
sp-point-before-same-p)))
|
||||
@@ -97,10 +107,13 @@
|
||||
(sp-local-pair sp-lisp-modes "(" ")" :unless '(:rem sp-point-before-same-p))
|
||||
|
||||
;; Major-mode specific fixes
|
||||
(sp-local-pair '(ruby-mode enh-ruby-mode) "{" "}"
|
||||
(sp-local-pair 'ruby-mode "{" "}"
|
||||
:pre-handlers '(:rem sp-ruby-pre-handler)
|
||||
:post-handlers '(:rem sp-ruby-post-handler))
|
||||
|
||||
;; Don't eagerly escape Swift style string interpolation
|
||||
(sp-local-pair 'swift-mode "\\(" ")" :when '(sp-in-string-p))
|
||||
|
||||
;; Don't do square-bracket space-expansion where it doesn't make sense to
|
||||
(sp-local-pair '(emacs-lisp-mode org-mode markdown-mode gfm-mode)
|
||||
"[" nil :post-handlers '(:rem ("| " "SPC")))
|
||||
@@ -114,9 +127,7 @@
|
||||
;; Disable electric keys in C modes because it interferes with smartparens
|
||||
;; and custom bindings. We'll do it ourselves (mostly).
|
||||
(after! cc-mode
|
||||
(c-toggle-electric-state -1)
|
||||
(c-toggle-auto-newline -1)
|
||||
(setq c-electric-flag nil)
|
||||
(setq-default c-electric-flag nil)
|
||||
(dolist (key '("#" "{" "}" "/" "*" ";" "," ":" "(" ")" "\177"))
|
||||
(define-key c-mode-base-map key nil))
|
||||
|
||||
@@ -176,7 +187,7 @@
|
||||
(sp-local-pair "(*" "*)" :actions nil)
|
||||
(sp-local-pair "(*" "*"
|
||||
:actions '(insert)
|
||||
:post-handlers '(("| " "SPC") ("|\n[i]*)[d-2]" "RET")))))
|
||||
:post-handlers '(("| " "SPC") ("|[i]*)[d-2]" "RET")))))
|
||||
|
||||
(after! smartparens-markdown
|
||||
(sp-with-modes '(markdown-mode gfm-mode)
|
||||
@@ -196,32 +207,52 @@
|
||||
|
||||
;; This keybind allows * to skip over **.
|
||||
(map! :map markdown-mode-map
|
||||
:ig "*" (λ! (if (looking-at-p "\\*\\* *$")
|
||||
(forward-char 2)
|
||||
(call-interactively 'self-insert-command)))))
|
||||
|
||||
;; Highjacks backspace to:
|
||||
;; a) balance spaces inside brackets/parentheses ( | ) -> (|)
|
||||
;; b) delete up to nearest column multiple of `tab-width' at a time
|
||||
;; c) close empty multiline brace blocks in one step:
|
||||
;; {
|
||||
;; |
|
||||
;; }
|
||||
;; becomes {|}
|
||||
;; d) refresh smartparens' :post-handlers, so SPC and RET expansions work
|
||||
;; even after a backspace.
|
||||
;; e) properly delete smartparen pairs when they are encountered, without
|
||||
;; the need for strict mode.
|
||||
;; f) do none of this when inside a string
|
||||
(advice-add #'delete-backward-char :override #'+default--delete-backward-char-a))
|
||||
|
||||
;; Makes `newline-and-indent' continue comments (and more reliably)
|
||||
(advice-add #'newline-and-indent :override #'+default--newline-indent-and-continue-comments-a))
|
||||
:ig "*" (general-predicate-dispatch nil
|
||||
(looking-at-p "\\*\\* *")
|
||||
(cmd! (forward-char 2)))))))
|
||||
|
||||
|
||||
;;
|
||||
;;; Keybinding fixes
|
||||
|
||||
;; Highjacks backspace to delete up to nearest column multiple of `tab-width' at
|
||||
;; a time. If you have smartparens enabled, it will also:
|
||||
;; a) balance spaces inside brackets/parentheses ( | ) -> (|)
|
||||
;; b) close empty multiline brace blocks in one step:
|
||||
;; {
|
||||
;; |
|
||||
;; }
|
||||
;; becomes {|}
|
||||
;; c) refresh smartparens' :post-handlers, so SPC and RET expansions work even
|
||||
;; after a backspace.
|
||||
;; d) properly delete smartparen pairs when they are encountered, without the
|
||||
;; need for strict mode.
|
||||
;; e) do none of this when inside a string
|
||||
(advice-add #'delete-backward-char :override #'+default--delete-backward-char-a)
|
||||
|
||||
;; HACK Makes `newline-and-indent' continue comments (and more reliably).
|
||||
;; Consults `doom-point-in-comment-functions' to detect a commented region
|
||||
;; and uses that mode's `comment-line-break-function' to continue comments.
|
||||
;; If neither exists, it will fall back to the normal behavior of
|
||||
;; `newline-and-indent'.
|
||||
;;
|
||||
;; We use an advice here instead of a remapping because many modes define
|
||||
;; and remap to their own newline-and-indent commands, and tackling all
|
||||
;; those cases was judged to be more work than dealing with the edge cases
|
||||
;; on a case by case basis.
|
||||
(defadvice! +default--newline-indent-and-continue-comments-a (&rest _)
|
||||
"A replacement for `newline-and-indent'.
|
||||
|
||||
Continues comments if executed from a commented line. Consults
|
||||
`doom-point-in-comment-functions' to determine if in a comment."
|
||||
:before-until #'newline-and-indent
|
||||
(interactive "*")
|
||||
(when (and +default-want-RET-continue-comments
|
||||
(doom-point-in-comment-p)
|
||||
(fboundp comment-line-break-function))
|
||||
(funcall comment-line-break-function nil)
|
||||
t))
|
||||
|
||||
;; This section is dedicated to "fixing" certain keys so that they behave
|
||||
;; sensibly (and consistently with similar contexts).
|
||||
|
||||
@@ -252,6 +283,7 @@
|
||||
"s-c" (if (featurep 'evil) #'evil-yank #'copy-region-as-kill)
|
||||
"s-v" #'yank
|
||||
"s-s" #'save-buffer
|
||||
"s-x" #'execute-extended-command
|
||||
:v "s-x" #'kill-region
|
||||
;; Buffer-local font scaling
|
||||
"s-+" #'doom/reset-font-size
|
||||
@@ -259,7 +291,7 @@
|
||||
"s--" #'doom/decrease-font-size
|
||||
;; Conventional text-editing keys & motions
|
||||
"s-a" #'mark-whole-buffer
|
||||
"s-/" (λ! (save-excursion (comment-line 1)))
|
||||
"s-/" (cmd! (save-excursion (comment-line 1)))
|
||||
:n "s-/" #'evilnc-comment-or-uncomment-lines
|
||||
:v "s-/" #'evilnc-comment-operator
|
||||
:gi [s-backspace] #'doom/backward-kill-to-bol-and-indent
|
||||
@@ -278,6 +310,7 @@
|
||||
(define-key! help-map
|
||||
;; new keybinds
|
||||
"'" #'describe-char
|
||||
"u" #'doom/help-autodefs
|
||||
"E" #'doom/sandbox
|
||||
"M" #'doom/describe-active-minor-mode
|
||||
"O" #'+lookup/online
|
||||
@@ -313,25 +346,27 @@
|
||||
|
||||
;; replaces `apropos-documentation' b/c `apropos' covers this
|
||||
"d" nil
|
||||
"da" #'doom/help-autodefs
|
||||
"db" #'doom/report-bug
|
||||
"dd" #'doom/toggle-debug-mode
|
||||
"dc" #'doom/goto-private-config-file
|
||||
"dC" #'doom/goto-private-init-file
|
||||
"dd" #'doom-debug-mode
|
||||
"df" #'doom/help-faq
|
||||
"dh" #'doom/help
|
||||
"dk" #'doom/goto-packages-file
|
||||
"dl" #'doom/help-search-load-path
|
||||
"dL" #'doom/help-search-loaded-files
|
||||
"dm" #'doom/help-modules
|
||||
"dn" #'doom/help-news
|
||||
"dN" #'doom/help-news-search
|
||||
"di" #'doom/goto-doomblock
|
||||
"dp" #'doom/help-packages
|
||||
"dP" #'doom/help-package-homepage
|
||||
"dc" #'doom/goto-config-file
|
||||
"dC" #'doom/help-package-config
|
||||
"ds" #'doom/help-search
|
||||
"dx" #'doom/sandbox
|
||||
"dN" #'doom/help-search-news
|
||||
"dpc" #'doom/help-package-config
|
||||
"dpd" #'doom/goto-private-packages-file
|
||||
"dph" #'doom/help-package-homepage
|
||||
"dpp" #'doom/help-packages
|
||||
"ds" #'doom/help-search-headings
|
||||
"dS" #'doom/help-search
|
||||
"dt" #'doom/toggle-profiler
|
||||
"du" #'doom/help-autodefs
|
||||
"dv" #'doom/version
|
||||
"dx" #'doom/sandbox
|
||||
|
||||
;; replaces `apropos-command'
|
||||
"a" #'apropos
|
||||
@@ -348,7 +383,7 @@
|
||||
"t" #'load-theme
|
||||
;; replaces `finder-by-keyword' b/c not useful
|
||||
"p" #'doom/help-packages
|
||||
;; replaces `describe-package' b/c redundant w/ `doom/describe-package'
|
||||
;; replaces `describe-package' b/c redundant w/ `doom/help-packages'
|
||||
"P" #'find-library)
|
||||
|
||||
(after! which-key
|
||||
@@ -372,10 +407,15 @@
|
||||
|
||||
;; A Doom convention where C-s on popups and interactive searches will invoke
|
||||
;; ivy/helm for their superior filtering.
|
||||
(define-key! :keymaps +default-minibuffer-maps
|
||||
"C-s" (if (featurep! :completion ivy)
|
||||
#'counsel-minibuffer-history
|
||||
#'helm-minibuffer-history))
|
||||
(when-let (command (cond ((featurep! :completion ivy)
|
||||
#'counsel-minibuffer-history)
|
||||
((featurep! :completion helm)
|
||||
#'helm-minibuffer-history)))
|
||||
(define-key!
|
||||
:keymaps (append +default-minibuffer-maps
|
||||
(when (featurep! :editor evil +everywhere)
|
||||
'(evil-ex-completion-map)))
|
||||
"C-s" command))
|
||||
|
||||
;; Smarter C-a/C-e for both Emacs and Evil. C-a will jump to indentation.
|
||||
;; Pressing it again will send you to the true bol. Same goes for C-e, except
|
||||
@@ -387,14 +427,11 @@
|
||||
;; which ctrl+RET will add a new "item" below the current one and
|
||||
;; cmd+RET (Mac) / meta+RET (elsewhere) will add a new, blank line below
|
||||
;; the current one.
|
||||
:gni [C-return] #'+default/newline-below
|
||||
:gni [C-S-return] #'+default/newline-above
|
||||
:gn [C-return] #'+default/newline-below
|
||||
:gn [C-S-return] #'+default/newline-above
|
||||
(:when IS-MAC
|
||||
:gni [s-return] #'+default/newline-below
|
||||
:gni [S-s-return] #'+default/newline-above)
|
||||
(:unless IS-MAC
|
||||
:gni [M-return] #'+default/newline-below
|
||||
:gni [M-S-return] #'+default/newline-above)))
|
||||
:gn [s-return] #'+default/newline-below
|
||||
:gn [S-s-return] #'+default/newline-above)))
|
||||
|
||||
|
||||
;;
|
||||
|
||||
Reference in New Issue
Block a user