In general, you can use call-interactively
to invoke an interactive command from Lisp code, drawing the required arguments from whatever sources are specified in the (interactive)
declaration at the top of the command's function definition. It's as though you invoked the same command with M-x
or a keybinding.
# name: math-modify
# key: mod
# type: command
# --
(call-interactively #'cdlatex-math-modify)
This even handles prefix arguments correctly. If you want to pass a prefix arg to cdlatex-math-modify
when calling it this way, just type C-u [arg]
immediately before invoking yas/expand
. For instance, after you've entered the template key ("mod" here), type C-u 2 TAB
to make cdlatex-math-modify
operate on the last two words before point. It will percolate down.
Now, I don't know if this is the function you actually intend to create a snippet for, or if you just picked it as an example. But in this particular case, there's a problem with using a snippet triggered by a character sequence. Specifically, cdlatex-math-modify
operates on the character before point, but yasnippet only recognizes template key sequences when it sees them as whole words – that is, when they're preceded by a word separator or at the beginning of a buffer. As a result, this snippet only works to modify word-boundary characters, because that's the only kind of preceding character that can be there when it gets expanded. (You can do C-u 1 TAB
as described above, but then it grabs the whole last word and the word boundary following it.) I'd just use a regular keybinding for this purpose.
Thanks for bringing cdlatex-mode
to my attention; I wasn't aware of it.