Move yank-indent advice to +emacs.el

This commit is contained in:
Case Duckworth 2021-12-30 12:27:39 -06:00
parent ce4938b6a5
commit d71d36267e
2 changed files with 12 additions and 6 deletions

View File

@ -47,14 +47,11 @@
;; C-h deletes backward - see https://idiomdrottning.org/bad-emacs-defaults
(global-set-key (kbd "C-h") 'delete-backward-char)
(keyboard-translate ?\C-h ?\C-?)
;; https://old.reddit.com/r/emacs/comments/rlli0u/whats_your_favorite_defadvice/hph14un/
(define-advice keyboard-escape-quit (:around (fn &rest r))
"Don't close splits on `keyboard-escape-quit'."
(let ((buffer-quit-function #'ignore))
(apply fn r)))
(defun +yank@indent (&rest _)
(indent-region (min (point) (mark)) (max (point) (mark))))
(advice-add 'yank :after '+yank@indent)
(advice-add 'yank-pop :after '+yank@indent))
(apply fn r))))
(setup (:require +init)
(:bind "C-c s" #'+init-sort-then-save)

View File

@ -188,7 +188,7 @@ Do this only if the buffer is not visiting a file."
(add-hook 'after-save-hook 'executable-make-buffer-file-executable-if-script-p)
(add-hook 'minibuffer-setup-hook 'cursor-intangible-mode)
;;; Better-default functions
;;; Better-default functions ...
(defun +cycle-spacing (&optional n preserve-nl-back mode)
"Negate N argument on `cycle-spacing'.
@ -214,6 +214,15 @@ kill without asking."
(save-buffers-kill-emacs))
(server-save-buffers-kill-terminal nil)))
;; ... and advice
;; Indent the region after a yank.
(defun +yank@indent (&rest _)
"Indent the current region."
(indent-region (min (point) (mark)) (max (point) (mark))))
(advice-add #'yank :after #'+yank@indent)
(advice-add #'yank-pop :after #'+yank@indent)
;;; Bindings
;; I need to place these bindings under `+key-mode-map' so that they aren't