0
  1. Within c-mode it is possible to configure a style and with c-hanging-braces-alist it is possible to relocate braces like { and } to separate lines, inserting whitespace and so on. Th function which triggers this is c-electric-brace.

  2. With smartparens it is possible to insert/delete/wrap/navigate over complete pairs of braces.

How could I use all above mentioned features, at the same time, from within c-mode?

remarks, and what I tried:

  • when smartparens-mode is enabled, then both pairs are inserted and navigation works, but no relocation (1.) of braces is happening.
  • both involved functions are too complex to rewrite them.
  • experimenting with (sp-local-pair 'c-mode "{" "}" :pre-handlers '(c-electric-brace) :post-handlers '(c-electric-brace)) did not do anything. I guess because of the call to self-insert-command from within c-electric-brace
  • currently I'm using (sp-local-pair 'c-mode "{" "}" :actions '(:rem insert)) which delivers most of the wanted functionality, but automatic inserting of whole pairs of { } does not work. Could another package like electric-pair-mode deliver the missing autopairing and so enable the whole feature set?

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.