From 4dee486f1f1d39ebc523e03f61705656d8e9c326 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Thu, 6 Jan 2022 15:47:42 -0600 Subject: Add +kill-word-backward-or-region --- init.el | 11 +++++++++-- lisp/+emacs.el | 9 +++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/init.el b/init.el index 5bf4dee..a822cb8 100644 --- a/init.el +++ b/init.el @@ -34,10 +34,15 @@ "C-x 4 n" #'clone-buffer "C-c v" #'visible-mode "C-M-;" #'+lisp-comment-or-uncomment-sexp - "M-j" nil) + "M-j" nil + "C-x o" (lambda () (interactive) (switch-to-buffer nil)) + "C-x C-o" #'+open-paragraph + "C-w" #'+kill-word-backward-or-region) ;; 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-?) + ;; Hooks + ;; Advice ;; 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'." @@ -1141,7 +1146,9 @@ See also `crux-reopen-as-root-mode'." (setup (:straight paredit) (:bind "DEL" #'paredit-backward-delete - "C-" #'paredit-backward-kill-word) + "C-" #'paredit-backward-kill-word + "C-w" (lambda (r) (interactive "P") + (+kill-word-backward-or-region r #'paredit-backward-kill-word))) (dolist (hook '(emacs-lisp-mode-hook eval-expression-minibuffer-setup-hook ielm-mode-hook diff --git a/lisp/+emacs.el b/lisp/+emacs.el index 7453913..ecdfeaa 100644 --- a/lisp/+emacs.el +++ b/lisp/+emacs.el @@ -220,6 +220,15 @@ kill without asking." (save-buffers-kill-emacs)) (delete-frame nil :force))) +(defun +kill-word-backward-or-region (&optional arg backward-kill-word-fn) + "Kill active region or ARG words backward. +BACKWARD-KILL-WORD-FN is the function to call to kill a word +backward. It defaults to `backward-kill-word'." + (interactive "P") + (call-interactively (if (region-active-p) + #'kill-region + (or backward-kill-word-fn #'backward-kill-word)))) + ;; ... and advice ;; Indent the region after a yank. -- cgit 1.4.1-21-gabe81