From d71d36267e830daf35e511f69e85736a5449dc31 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Thu, 30 Dec 2021 12:27:39 -0600 Subject: Move yank-indent advice to +emacs.el --- init.el | 7 ++----- lisp/+emacs.el | 11 ++++++++++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/init.el b/init.el index 6cfc405..6e45383 100644 --- a/init.el +++ b/init.el @@ -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) diff --git a/lisp/+emacs.el b/lisp/+emacs.el index 2d63e82..39b064c 100644 --- a/lisp/+emacs.el +++ b/lisp/+emacs.el @@ -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 -- cgit 1.4.1-21-gabe81