TransWikia.com

keybinding behavior and smartparens

Emacs Asked by Andi on January 30, 2021

I am using a german keyboard layout and because it is very annoying to type curly brackets I have remapped them to C-7 and C-0 in addition to the default binding AltGr-7 and AltGr-0. I also want to modify the behavior of smartparens for cpp-mode and there is already a code snippet in the smartparens documentation which does exactly what I want. When I type { and press Return it immediately creates and empty line between the curly brackets and moves the pointer to that empty line with an indent. But it does so only when I use AltGr-7 and press Return but not when I used C-7 and press Return (it just inserts a new line). Is it possible to make smartparens behave with C-7 like it would with AltGr-7?

Code snippets I am referring too:

(global-set-key (kbd "C-7") (kbd "{"))
(global-set-key (kbd "C-0") (kbd "}"))

(use-package smartparens
  :hook
  (prog-mode . smartparens-mode)
  (c++-mode . smartparens-mode)
  :config (require 'smartparens-config)
  )

;; From smartparens documentation  
(sp-local-pair 'c++-mode "{" nil :post-handlers '((my-create-newline-and-enter-sexp "RET")))

(defun my-create-newline-and-enter-sexp (&rest _ignored)
  "Open a new brace or bracket expression, with relevant newlines and indent. "
  (newline)
  (indent-according-to-mode)
  (forward-line -1)
  (indent-according-to-mode))

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP