diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2023-03-04 12:31:22 -0700 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2023-03-04 14:02:14 -0700 |
commit | 6d5becbbacfc7b0f47ab70a97dcc59d7ab72c0e7 (patch) | |
tree | 6c8f7bcf7565ac46cad9fd449f01fd4391f80500 | |
parent | adb981b224cd40af029d6adadd5de6286534651e (diff) | |
download | dotfiles-6d5becbbacfc7b0f47ab70a97dcc59d7ab72c0e7.tar.gz |
refactor
-rw-r--r-- | .emacs.d/init.el | 98 |
1 files changed, 48 insertions, 50 deletions
diff --git a/.emacs.d/init.el b/.emacs.d/init.el index e30bf5eb..6977be4f 100644 --- a/.emacs.d/init.el +++ b/.emacs.d/init.el @@ -4594,56 +4594,54 @@ likely to keep parentheses balanced." ;; This must come after I've made all my modifications to `paredit-mode-map'. (defvar spw/scratch-paredit-mode-map - (cl-labels - ((define-keys (keymap into prefix) - (map-keymap - (lambda (event paredit-binding) - ;; `paredit-mode-map' has no parents; otherwise, we should - ;; conditionalise on (eq (lookup-key keymap key) paredit-binding). - (let* ((key (vector event)) - (prefixed (vconcat prefix key))) - (cond - ((keymapp paredit-binding) - (let ((map (make-sparse-keymap))) - (define-key into key map) - (define-keys paredit-binding map prefixed))) - ((commandp paredit-binding) - (when-let* ((normal-binding (key-binding prefixed)) - (new-binding - (intern (format "spw/scratch-%s" - (if (symbolp paredit-binding) - paredit-binding - (gensym)))))) - (defalias new-binding (lambda () - (interactive) - (call-interactively - (if (spw/scratch-paredit-in-lisp-p) - paredit-binding - normal-binding))) - (format "Like `%s' but for `spw/scratch-paredit-mode'." - paredit-binding)) - (define-key into key new-binding)))))) - keymap) - into)) - (with-current-buffer (get-buffer-create "*scratch*") - (let (;; Bind `minor-mode-map-alist' such that our call to `key-binding' - ;; ignores the bindings of minor modes that have priority over us. - ;; This avoids an infinite loop if one of those minor modes wants - ;; to defer to our binding, e.g. in the way `orgtbl-mode' does. - (minor-mode-map-alist - (or (cdr - (cl-member 'spw/scratch-paredit-mode minor-mode-map-alist - :key #'car)) - minor-mode-map-alist)) - ;; Also ensure that `key-binding' ignores `paredit-mode-map'. - ;; We don't need to turn the mode off because we know we are - ;; earlier in `minor-mode-map-alist' as we require the `paredit' - ;; feature, and `paredit-mode-map' is our parent, so lookup can't - ;; ever fail in our map but then succeed in `paredit-mode-map'. - paredit-mode) - (let ((map (define-keys paredit-mode-map (make-sparse-keymap) []))) - (set-keymap-parent map paredit-mode-map) - map)))) + (with-current-buffer (get-buffer-create "*scratch*") + (let (;; Bind `minor-mode-map-alist' such that our call to `key-binding' + ;; ignores the bindings of minor modes that have priority over us. + ;; This avoids an infinite loop if one of those minor modes wants to + ;; defer to our binding, e.g. in the way `orgtbl-mode' does. + (minor-mode-map-alist + (or (cdr (cl-member 'spw/scratch-paredit-mode minor-mode-map-alist + :key #'car)) + minor-mode-map-alist)) + ;; Also ensure that `key-binding' ignores `paredit-mode-map'. + ;; We don't need to turn the mode off because we know we are earlier + ;; in `minor-mode-map-alist' as we require the `paredit' feature, + ;; and `paredit-mode-map' is our parent, so lookup can't ever fail + ;; in our map but then succeed in `paredit-mode-map'. + paredit-mode + (map (make-sparse-keymap))) + (set-keymap-parent map paredit-mode-map) + (named-let define-keys ((from paredit-mode-map) (into map) (prefix [])) + (map-keymap + (lambda (event paredit-binding) + ;; `paredit-mode-map' has no parents; otherwise, we should + ;; conditionalise on (eq (lookup-key keymap key) paredit-binding). + (let* ((key (vector event)) + (prefixed (vconcat prefix key))) + (cond + ((keymapp paredit-binding) + (let ((map (make-sparse-keymap))) + (define-key into key map) + (define-keys paredit-binding map prefixed))) + ((commandp paredit-binding) + (when-let* ((normal-binding (key-binding prefixed)) + (new-binding + (intern (format "spw/scratch-%s" + (if (symbolp paredit-binding) + paredit-binding + (gensym)))))) + (defalias new-binding + (lambda () + (interactive) + (call-interactively + (if (spw/scratch-paredit-in-lisp-p) + paredit-binding + normal-binding))) + (format "Like `%s' but for `spw/scratch-paredit-mode'." + paredit-binding)) + (define-key into key new-binding)))))) + from)) + map)) "Keymap for `spw/scratch-paredit-mode'.") (define-minor-mode spw/scratch-paredit-mode |