From 710dfe7cd5620d6bec2ddc7b776cddacf2c640a1 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Wed, 5 Jan 2022 11:23:26 -0600 Subject: [PATCH] Add wrap-region and modify expand-region to match --- init.el | 18 +++++++++++++++++- lisp/+expand-region.el | 24 ++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 lisp/+expand-region.el diff --git a/init.el b/init.el index 13284d1..49e549e 100644 --- a/init.el +++ b/init.el @@ -944,7 +944,10 @@ See also `crux-reopen-as-root-mode'." (exec-path-from-shell-initialize)) (setup (:straight expand-region) - (:+key "C-=" #'er/expand-region)) + (:also-load +expand-region) + (:option expand-region-fast-keys-enabled nil) + (:+key "C-=" #'er/expand-region + "C--" #'+er/contract-or-negative-argument)) (setup (:straight (fill-sentences-correctly :host github @@ -1303,6 +1306,19 @@ See also `crux-reopen-as-root-mode'." whitespace-cleanup-mode-only-if-initially-clean nil) (global-whitespace-cleanup-mode +1)) +(setup (:straight wrap-region) + (:require wrap-region) + (wrap-region-add-wrappers + '(("*" "*" nil org-mode) + ("~" "~" nil org-mode) + ("/" "/" nil org-mode) + ("=" "=" nil org-mode) + ("+" "+" nil org-mode) + ("_" "_" nil org-mode) + ("$" "$" nil (org-mode latex-mode)))) + (:hook-into org-mode + latex-mode)) + (setup (:straight zoom-frm)) (setup (:straight zzz-to-char) diff --git a/lisp/+expand-region.el b/lisp/+expand-region.el new file mode 100644 index 0000000..8aac3ce --- /dev/null +++ b/lisp/+expand-region.el @@ -0,0 +1,24 @@ +;;; +expand-region.el -*- lexical-binding: t; -*- + +;;; Commentary: + +;; + +;;; Code: + +;; Because of `wrap-region', I can't use `expand-region-fast-keys-enabled'. So +;; instead of that, I'm adding this to the binding to C--, but I also want to be +;; able to use the negative argument. So there's this. +(defun +er/contract-or-negative-argument (arg) + "Contract the region if the last command expanded it. +Otherwise, pass the ARG as a negative argument." + (interactive "p") + (cond ((memq last-command '(er/expand-region + er/contract-region + +er/contract-or-negative-argument)) + + (er/contract-region arg)) + (t (call-interactively #'negative-argument)))) + +(provide '+expand-region) +;;; +expand-region.el ends here