I'm trying to learn how to:
- Define a kbd-macro, (here I'm using kbd-macros, because I'm bad at elisp currently).
- Letting that to be executed when yas-snippet to expand. (here I'm struggling with)
My current state:
I want to make following in latex equation. First write a_x /
then press Tab to get \frac{a_x}{}
(in here /
as yas-snippet key).
# -*- mode: snippet -*-
# name: 1slash-frac_one_word
# key: /
# type: command
# --
(fset 'gry-test-frac-kbdmacro
(kmacro-lambda-form [C-left ?\\ ?f ?r ?a ?c ?\{ C-right ?\} ?\{ ?\} left return return up tab] 0 "%d"))
(gry-test-frac-kbdmacro)
Basically, I first defined kbd-macro, and then inserted it's definition to the snippet, and then running it. This works.
My concerns/tries: Every time this snippet expands, gry-test-frac-kbdmacro
gets defined again and again. Which seems to me inefficient. Also I don't want to write it's definition in other places like init.el
. So tried following:
# -*- mode: snippet -*-
# name: 1slash-frac_one_word
# key: /
# type: command
# --
(kmacro-lambda-form [C-left ?\\ ?f ?r ?a ?c ?\{ C-right ?\} ?\{ ?\} left return return up tab] 0 "%d")
Basically, I tried to run the things inside of the macro definition (without defining it). However this doesn't work.
- Could you explain me why 2-nd snippet doesn't work?
- And Is there any way to run what's inside of macro without defining it first?