[main]Notes on TeXmacs

Keyboard shortcuts for menu items

How to write a keyboard shortcut for a menu item—and searching for text in TeXmacs Scheme files.

Strategy

Following up from this forum post, let us see how to write a keyboard shortcut for a command available from a menu item.

The forum post asks how to define a keyboard shortcut for inserting a footnote, which can be done through the menu item InsertNoteFootnote.

To do so, we need to find out which Scheme command is associated to the menu item and then write a keyboard shortcut for that command in my-init-texmacs.scm (see Section 12.4 of the TeXmacs manual for the definition of personal keyboard shortcuts).

I don't think a list of commands associated to menu items exists and I am not aware of an automatic way for generating it (id est, if one wants such an automatic way, one needs to write a program that does that :-)).

Listing these commands by hand takes time and patience and if the files where the menus are defined change from release to release the list becomes outdated when there are new releases.

Here is what I do: I do a search on the TeXmacs GitHub repository using as search key the menu item name (in this case “footnote”), in the search results I select only the Scheme files and I go through them looking for the menu item.

For “footnote” I found in the file progs/generic/insert-menu.scm, within a menu-bind form—the menu-defining and modifying form, the Scheme list ("Footnote" (make 'footnote)) and by placing

(kbd-map ("A-e f" 
(make 'footnote)))

in my-init-texmacs.scm I obtained a shortcut for footnotes.

Searching for text in TeXmacs Scheme files

Forum member @jeroen uses ack for searching through the TeXmacs Scheme files on the local disk, perhaps you like that more than the GitHub search I do. Here are the advantages and disadvantages of the two search methods as I see them.

Searching on GitHub is intuitive; enter the search term into the search box when at the repository one wants to search in, one is offered the option to search “In this repository” and clicking on the option starts the search. One can then filter the search results by file type, for example one can choose only Scheme files.

One can also limit the search to a path by means of the path: option; here is how one searches for “footnote” within the progs directory of TeXmacs:

footnote path:texmacs/progs

On the other search is not case sensitive and “(a)t most, search results can show two fragments from the same file, but there may be more results within the file” (from GitHub code search online manual, and here is the main page for the GitHub search as well); if one does not see the code lines they are looking for in the search results, they have to open each file GitHub has found and repeat the search in there (maybe with the browser's search facility).

With ack one types

ack Footnote

(case sensitive: it helps, because the menu item we are looking for is uppercase) from the terminal when in the progs directory of the TeXmacs installation and gets all the matching lines classified according to the file they are in. In the short tests I did, I got the impression that ack can match more precisely what the user wants: I was able to match (make 'footnote) with ack but not with the GitHub search, where I got results for the consecutive words make footnote within a string as well. On the other hand, with ack one does not have the immediacy of a search box.