Fuco1 / smartparens

Minor mode for Emacs that deals with parens pairs and tries to be smart about it.
GNU General Public License v3.0
1.82k stars 195 forks source link

Ability to Keep a major mode's binding #1173

Open pcompassion opened 1 year ago

pcompassion commented 1 year ago

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.


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'sC-M-a keybinding is a relatively huge deal it seems.

pcompassion commented 1 year ago

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?