summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2021-06-18 20:36:24 -0700
committerSean Whitton <spwhitton@spwhitton.name>2021-06-18 20:36:24 -0700
commitcdb96806910cb660d8f710ce90a7c5949d4fb492 (patch)
tree0f7472bea56c30174d4eda8e2d29a6edafd2b43f
parentaaf282e3588fc832cb804da3913519d61c0cca46 (diff)
downloaddotfiles-cdb96806910cb660d8f710ce90a7c5949d4fb492.tar.gz
drop electric-pair-mode
-rw-r--r--.emacs.d/init-spw.el80
1 files changed, 24 insertions, 56 deletions
diff --git a/.emacs.d/init-spw.el b/.emacs.d/init-spw.el
index 82ecbd82..168ca436 100644
--- a/.emacs.d/init-spw.el
+++ b/.emacs.d/init-spw.el
@@ -1005,61 +1005,22 @@ whole thing."
`(,(regexp-quote "/ssh:") "direct-async-process" t)))
-;;;; Electric pairs
-
-;; This mode sometimes gets thing wrong, and I've considered turning it off
-;; and just doing things manually, but it does mean that non-paredit buffers
-;; are a bit more like paredit buffers, and on balance I think that
-;; consistency is the least surprising way to have things (not going to give
-;; up paredit!)
+;;;; Electric pairs when the region is active
+
+;; I used to have `electric-pair-mode' switched on, based on the idea that it
+;; makes non-paredit buffers a bit more like paredit buffers, and that's the
+;; least surprising way to have things, given that I'm not going to give up
+;; paredit. However, even with `electric-pair-conservative-inhibit', I still
+;; frequently found myself with unwanted insertion. It also makes C-w much
+;; less effective for correcting mistakes, because you end up with junk to the
+;; right of point as well as to the left.
;;
-;; I think using this mode frees up M-( for rebinding as can just use C-M-SPC
-;; (, but it does not free up M-), which remains useful for tapping repeatedly
-;; when editing Lisp (using ) RET is less convenient for repeating). We might
-;; globally bind M-( to a paredit manipulation command, or bind it
-;; mode-specifically; for example, `paredit-wrap-sexp' (different from
-;; `paredit-wrap-round') might be on M-( in Lisp modes
-
-(electric-pair-mode 1)
-
-;; disable when paredit, cperl active as those modes are also trying to keep
-;; things paired; better not to have two of them at it. note that this will
-;; be ignored for characters in `electric-pair-pairs' or
-;; `electric-pair-text-pairs' (as appropriate to the context) such that, for
-;; example, typing a backtick in a comment when editing Lisp will insert a
-;; corresponding apostrophe. possibly, then, I want to disable
-;; `electric-pair-mode' more aggressively, perhaps by locally removing its
-;; entry in `post-self-insert-hook'
-(defun spw/electric-pair-inhibit-predicate (char)
- (or (bound-and-true-p paredit-mode)
- (eq major-mode 'cperl-mode)
- (electric-pair-conservative-inhibit char)))
-(setq-default electric-pair-inhibit-predicate
- #'spw/electric-pair-inhibit-predicate)
-
-(defun spw/add-mode-electric-pairs (lib mode pairs)
- (let ((hook (intern (concat (symbol-name mode) "-hook")))
- (fn (intern (concat "spw/add-" (symbol-name mode) "-electric-pairs"))))
- (fset fn `(lambda ()
- ,(concat "Add my additional electric pairs for `"
- (symbol-name mode)
- "'.")
- (setq-local electric-pair-pairs
- (append electric-pair-pairs ,pairs)
- electric-pair-text-pairs
- (append electric-pair-text-pairs ,pairs))))
- (eval-after-load lib `(add-hook ,hook #',fn))))
-
-;; take care adding things here -- only if would *never* want to use the
-;; opening character on its own in that major mode (and then, should probably
-;; be in the mode's syntax table)
-(spw/add-mode-electric-pairs 'markdown-mode 'markdown-mode '((?` . ?`)))
-
-;; Following sets up keys to behave as if they are in
-;; `electric-pair-pairs'/`electric-pair-text-pairs' only when the region is
-;; active (useful after hitting M-@ and/or C-M-SPC a few times). Just for
-;; consistency with paredit, as I keep finding myself expecting things to work
-;; that way in other modes
+;; Add back a way to wrap the active region in paired delimiters; useful after
+;; hitting M-@ and/or C-M-SPC a few times. This is the main paredit feature
+;; that I find myself expecting to work in other modes.
+;;
+;; An alternative is to deactivate `electric-pair-mode' only in `text-mode'.
+
(defun spw/add-mode-wrapping-pairs (lib mode pairs)
(let ((map (intern (concat (symbol-name mode) "-map")))
(fn (intern (concat "spw/set-" (symbol-name mode) "-wrapping-keys"))))
@@ -1094,11 +1055,18 @@ whole thing."
(eval-after-load lib fn)))
(defvar spw/global-wrapping-pairs
- '((?' . ?'))
+ '((?( . ?))
+ (?[ . ?])
+ (?{ . ?})
+ (?< . ?>)
+ (?' . ?')
+ (?\" . ?\"))
"Like `spw/add-mode-wrapping-pairs' but for the global map.")
(spw/add-mode-wrapping-pairs 'elisp-mode 'emacs-lisp-mode '((?` . ?')))
-(spw/add-mode-wrapping-pairs 'org 'org-mode '((?* . ?*)
+;; add global pairs to Org-mode because it has its own self-inserting cmd
+(spw/add-mode-wrapping-pairs 'org 'org-mode `(,@spw/global-wrapping-pairs
+ (?* . ?*)
(?/ . ?/)
(?= . ?=)))