Custom macros and keyboard shortcuts

Hey, I have been trying to find this information on my own, but I did not succeed.

I want to do multiple things:

  1. Add a review command in Texmacs, which I can later modify to either display everything that was tagged as “review” in red or not display those places.
  2. Have a shortcut to trigger the review command.

For now I tried adding a shortcut to display things in red via

(kbd-map . ("C-r" (make-with "color" "red")))

in my my-init-texmacs.scm, which unfortunately does not work.

Also, on a different note, is there any document which maybe walks you through simple modifications as above, which are probably relatively common? Unfortunately, the online documentation seems to be broken and has dead links (for example “master the keyboard”). Opening the full documentation inside texmacs takes a while and crashed the editor once for me, but also only told me


which did not help me.

You can give a look here for some more detailed instructions: How to modify the arrow keys?

(I’ve searched ‘kbd-map’ in the forum).

1 Like

I think the dot in the syntax (help file, the image you posted as well) means “followed by a variable number of arguments”, it does not mean that you have to write the dot when you add your shortcut. I’ll try and keep this in mind when I write the tutorial.

Writing the command without the dot works.

1 Like

A small explanation about the scheme language is in order: the notation (a . b) denotes a pair (of values). A list is a pair of values of which the second is another pair or the null value, denoted (). The problem is that, if you write

(kbd-map . ("C-r" (make-with "color" "red")))

this is the same as the list

(kbd-map "C-r" (make-with "color" "red"))

Indeed the form (a b c) is a shortcut for (a . (b . (c . ())))) i.e. a list of pairs chained via their second argument and ending in null.
While what you needed was

(kbd-map ("C-r" (make-with "color" "red")))

which is a list of two elements and can be represented as the pair

(kbd-map . ( ("C-r" (make-with "color" "red")) . ()))

You can check this entering this last form in a scheme session and see that it has the indended behaviour.
In this case the list is used to represent a call to the procedure kbd-map which accepts as argument a list of pairs of the form

( (key1 . command1) (key2 . command2) )

and binds the commands to the respective key combinations. Do not make confusions between a list as a chaining of pairs and a list of pairs (as above). The list above is a sequence of pairs whose first argument is a pair and the second another list of pairs or ().
That is it could be written also as

(  (key1 . command1) . ( (key2 . command2) . () ) )
2 Likes