Keyboard shortcuts with a scheme function

Hello,
I created the ext-perso function and it returns me a code scheme to create a keyboard shortcut
in order to use the cube function in texmacs. (or other functions)

(define (ext-perso a b)`(kbd-map (,a (begin (insert '(with “info-flag” “detailed” (flag ,b “red”)))(make-script-input* “scheme” “default”) (insert (string-append “(” ,b " )"))(go-to-previous)))))

(ext-perso “’ z c” “cube”)

(kbd-map ("’ z c" (begin (insert (quote (with “info-flag” “detailed” (flag “cube” “red”)))) (make-script-input* “scheme” “default”) (insert (string-append “(” “cube” " )")) (go-to-previous))))

(delayed (lazy-keyboard-force)`(ext-perso “’ a a” “cube”))


My problem is that this code would have to be executed directly to be able to use the shortcut.
If I execute this code in a scheme session then the result is what I want: the keyboard shortcut works well.
Do you have an idea for this?

Thank you very much for any answers.

Try to change the define in define-macro, then should work. The problem is that your function evaluate in list which is the representation of a statement, in this case the invocation of the kbd-map procedure, while you need to execute this list, not only obtain it as a result. This is the task of a macro which has value a form which is then evaluated. If you want still to use define then you need to write (eval (ext-perso “’ z c” “cube”)) to run it.

I would suggest you to read an introduction to scheme programming, it will save you a lot of time later and it is a beautiful language.

1 Like