From 6ba4dbea44a17dd25a39a6a7788c7125f7577bf1 Mon Sep 17 00:00:00 2001 From: Vedang Manerikar <ved.manerikar@gmail.com> Date: Sun, 17 Nov 2024 12:29:17 +0530 Subject: [PATCH] Bring in backward-kill-word-or-kill-region from my config This experience is still not as good as just using helm is. (Because the C-l feature of helm-ff is killer) (not to mention a properly working helm-resume) --- unravel-emacs.org | 28 +++++++++++++++++++++++++++ unravel-modules/unravel-essentials.el | 21 ++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/unravel-emacs.org b/unravel-emacs.org index 8155f31..ff5c1b3 100644 --- a/unravel-emacs.org +++ b/unravel-emacs.org @@ -1185,6 +1185,34 @@ These are modifications to basic configuration I use on my Mac OSX machine. (setq find-function-C-source-directory (expand-file-name "~/src/emacs/src/")))) #+end_src +** The =unravel-essentials.el= section for ~simple.el~ changes +:PROPERTIES: +:CUSTOM_ID: h:6B18F988-DBAD-458C-97BE-129D1FF988F4 +:END: + +#+begin_src emacs-lisp :tangle "unravel-modules/unravel-essentials.el" + (defun vedang/backward-kill-word-or-kill-region (&optional arg) + "Rebind `C-w' to work differently based on whether a region is active. + + If the region is selected, retain the original behaviour, otherwise call + `backward-kill-word' instead. ARG is passed to `backward-kill-word'." + (interactive "p") + (if (region-active-p) + (kill-region (region-beginning) (region-end)) + (backward-kill-word arg))) + + (use-package simple + :ensure nil + :after vertico ; so that we can bind to vertico-map + :bind + ;; Rebind `C-w' to work differently based on whether a region is + ;; active. + ( :map global-map + ("C-w" . vedang/backward-kill-word-or-kill-region) + :map vertico-map + ("C-l" . vedang/backward-kill-word-or-kill-region))) +#+end_src + ** Finally, we provide the =unravel-essentials.el= module :PROPERTIES: :CUSTOM_ID: h:c8b2f021-fe5a-4f6b-944c-20340f764fb2 diff --git a/unravel-modules/unravel-essentials.el b/unravel-modules/unravel-essentials.el index 27a988f..20bedbc 100644 --- a/unravel-modules/unravel-essentials.el +++ b/unravel-modules/unravel-essentials.el @@ -152,4 +152,25 @@ word. Fall back to regular `expreg-expand'." (setq source-directory (expand-file-name "~/src/emacs/src/")) (setq find-function-C-source-directory (expand-file-name "~/src/emacs/src/")))) +(defun vedang/backward-kill-word-or-kill-region (&optional arg) + "Rebind `C-w' to work differently based on whether a region is active. + +If the region is selected, retain the original behaviour, otherwise call +`backward-kill-word' instead. ARG is passed to `backward-kill-word'." + (interactive "p") + (if (region-active-p) + (kill-region (region-beginning) (region-end)) + (backward-kill-word arg))) + +(use-package simple + :ensure nil + :after vertico ; so that we can bind to vertico-map + :bind + ;; Rebind `C-w' to work differently based on whether a region is + ;; active. + ( :map global-map + ("C-w" . vedang/backward-kill-word-or-kill-region) + :map vertico-map + ("C-l" . vedang/backward-kill-word-or-kill-region))) + (provide 'unravel-essentials)