From 9774587564b8f758eb1680ce7a181777011a16ea Mon Sep 17 00:00:00 2001 From: Uko Kokņevičs Date: Mon, 27 Oct 2025 12:51:19 +0200 Subject: emacs: smartparens keybinds This is basically the result of customizing sp-base-key-bindings with 'sp, but with two exceptions: 1. C- and C- binds are replaced with M- and M- because I use C- for normal navigation. 2. Selecting text and pressing backspace deletes it all :) --- emacs/.config/emacs/init.el | 49 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/emacs/.config/emacs/init.el b/emacs/.config/emacs/init.el index 4e407fc..c8aab0a 100644 --- a/emacs/.config/emacs/init.el +++ b/emacs/.config/emacs/init.el @@ -445,12 +445,59 @@ (use-package smartparens :straight t - ;; See: (sp-cheat-sheet) and make some cool keybinds :) :init (defun arkta/disable-sp-strictness () (smartparens-strict-mode -1) (smartparens-mode +1)) + + (defun arkta/delete-region-or-backchar (&optional arg) + "Delete the previous character as per `sp-backward-delete-char'. If +Transient Mark mode is enabled, the mark is active, delete the text in +the region and deactivate the mark instead. To disable this set option +`delete-active-region' to nil. Essentially like a weird mix of +`delete-backward-char' and `sp-backward-delete-char'." + (interactive "*P") + (if (and (use-region-p) delete-active-region) + (if (eq delete-active-region 'kill) + (sp-kill-region (region-beginning) (region-end)) + (sp-delete-region (region-beginning) (region-end))) + (sp-backward-delete-char arg))) + :bind (:map smartparens-mode-map + ("C-M-f" . sp-forward-sexp) + ("C-M-b" . sp-backward-sexp) + ("C-M-d" . sp-down-sexp) + ("C-M-a" . sp-backward-down-sexp) + ("C-S-d" . sp-beginning-of-sexp) + ("C-S-a" . sp-end-of-sexp) + ("C-M-e" . sp-up-sexp) + ("C-M-u" . sp-backward-up-sexp) + ("C-M-n" . sp-next-sexp) + ("C-M-p" . sp-previous-sexp) + ("C-M-k" . sp-kill-sexp) + ("C-M-w" . sp-copy-sexp) + ("M-" . sp-unwrap-sexp) + ("M-" . sp-backward-unwrap-sexp) + ("M-" . sp-forward-slurp-sexp) + ("M-" . sp-forward-barf-sexp) + ("C-M-" . sp-backward-slurp-sexp) + ("C-M-" . sp-backward-barf-sexp) + ("M-D" . sp-splice-sexp) + ("C-M-" . sp-splice-sexp-killing-forward) + ("C-M-" . sp-splice-sexp-killing-backward) + ("C-S-" . sp-splice-sexp-killing-around) + ("C-]" . sp-select-next-thing-exchange) + ("C-M-]" . sp-select-next-thing) + ("C-M-SPC" . sp-mark-sexp) + ("M-F" . sp-forward-symbol) + ("M-B" . sp-backward-symbol) + :map smartparens-strict-mode-map + ("" . arkta/delete-region-or-backchar) + ([remap backward-delete-char-untabify] . arkta/delete-region-or-backchar) + ([remap backward-delete-char] . arkta/delete-region-or-backchar) + ([remap delete-backward-char] . arkta/delete-region-or-backchar)) :hook (prog-mode . smartparens-strict-mode) + :custom + (sp-base-key-bindings nil) :config (require 'smartparens-config)) -- cgit v1.2.3