smartparens
smartparens copied to clipboard
Ability to Keep a major mode's binding
Expected behavior
want to keep python-mode's bindings because it's more python specific
Actual behavior
smartparens default bindings override python bindings
Steps to reproduce the problem
activate smartparens for python-mode
Backtraces if necessary (M-x toggle-debug-on-error
)
Environment & version information
The content of the buffer underneath the line was copied to your clipboard. You can also edit it in this buffer and then copy the results manually.
-
smartparens
version: 20230529.1017 - Active
major-mode
:python-mode
- Smartparens strict mode: t
- Emacs version (
M-x emacs-version
): GNU Emacs 29.1 (build 1, x86_64-apple-darwin18.7.0, NS appkit-1671.60 Version 10.14.6 (Build 18G9323)) of 2023-08-17 - Starterkit/Distribution: Spacemacs
- OS: darwin
in python-mode,
For instance, C-M-a
is bound to 'python-nav-beginning-of-defun
by (setq-local beginning-of-defun-function #'python-nav-beginning-of-defun)
I want to keep this binding in python mode, (and there are other keys too)
If I want to keep smartparens' default binding in other modes, but want to keep python binding, what should I do?
this is the code I use, it works, but I have to see what bindings are actually there in python-mode first.
(defun ek/override-minor-mode-key-for-major-mode (major-mode minor-mode key-fn-list)
"
example: override C-M-a for python-mode which was set by smartparens-mode
major-mode: python-mode
minor-mode: smartparens-mode
key: C-M-a
"
(let ((oldmap (cdr (assoc minor-mode minor-mode-map-alist)))
(newmap (make-sparse-keymap)))
(set-keymap-parent newmap oldmap)
(dolist (pair key-fn-list)
(let ((key (car pair) ) (fn (cdr pair)))
(define-key newmap (kbd key) fn)))
(push `(minor-mode . ,newmap) minor-mode-overriding-map-alist))
)
I wonder if it'd be possible to make a function that tells smartparens not to override a key if a major mode has defined one of the keys that smartparens is trying to define
Something like,
(sp-respect-major-mode-key 'python-mode)
I could create the function myself (although I'm relatively new to elisp programming), But was wondering if that functionality makese sense and if it's already implemented.
Because overriding python-mode's C-M-a
keybinding is a relatively huge deal it seems.
so smartparens-c.el has
(define-key smartparens-strict-mode-map [remap c-electric-delete-forward] 'sp-delete-char)
(define-key smartparens-strict-mode-map [remap c-electric-backspace] 'sp-backward-delete-char)
Does this not override other major mode map?