0

I'm currently extending the tempo.el template insertion system to be sensitive to C styles. Specifically, I want to insert braces using c-electric-brace. How programmatically insertion of braces as either (c-electric-brace "{")) or (c-electric-brace "}")) only results in insertion of a newline but not the brace character itself.

I've also tried (self-insert-command 1 "{") and (progn (self-insert-command 1) (insert "{")) but no one does what I want.

What am I missing?

I have activated the electric behavior via c-toggle-auto-newline otherwise I wouldn't have gotten the newline inserted.

Nordlöw
  • 487
  • 3
  • 12
  • Could you show the effect you're looking for? Are you just asking how to insert a brace character? I suppose not... – Drew Aug 30 '22 at 15:01
  • I'm expecting the `{` to occur aswell. – Nordlöw Aug 30 '22 at 21:54
  • Sorry, but I don't understand what you're saying or trying to do. Hopefully someone does. I guess you're trying to insert a `{` char and is not inserting. Did you try with `emacs -Q` (no init file), and with just `(insert "{")`? – Drew Aug 31 '22 at 03:10
  • I want programmatic calls to insertion of "{" and "}" behave exact like interactive inserts when pressing the corresponding keys when `electric-indent-mode` is active in C-like modes. – Nordlöw Aug 31 '22 at 08:54

1 Answers1

1

Your problem is that c-electric-brace is not designed to accept the character to be inserted as a function argument; instead, it just invokes self-insert-command which uses the variable last-command-event to decide which character to insert. And of course just calling self-insert-command doesn't involve the C electric behavior at all.

You might try binding last-command-event explicitly, something like this:

(let ((last-command-event ?{)) (c-electric-brace nil))

Have a look at the "Command Loop Info" Info node in the Emacs Lisp Reference Manual for discussion of last-command-event.

user98761
  • 180
  • 3