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
  (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. "
  (forward-line -1)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.