Tab-completion

By default, TeXmacs looks into your document for possible tab-completions. Inside sessions for your application, you might wish to customize this behaviour, so as to complete built-in commands. In order to do this, you have to specify the configuration option

(:tab-completion #t)

in your init-myplugin.scm file, so that TeXmacs will send special tab-completion requests to your application whenever you press tab inside a session. These commands are of the form

DATA_COMMAND(complete input-string cursor-position)return

Here DATA_COMMAND stands for the special character '\20' (ASCII 16). The input-string is the complete string in which the tab occurred and the cursor-position is an integer which specifies the position of the cursor when you pressed tab. TeXmacs expects your application to return a tuple with all possible tab-completions of the form

DATA_BEGINscheme:(tuple root completion-1 completion-n)DATA_END

Here root corresponds to a substring before the cursor for which completions could be found. The strings completion-1 until completion-n are the list of completions as they might be inserted at the current cursor position. If no completions could be found, then you may also return the empty string.

Remark 1. In principle, the tab-completion mechanism should still work in mathematical input mode. In that case, the input-string will correspond to the serialization of the TeXmacs input.

Remark 2. The way TeXmacs sends commands to your application can be customized in a similar way as for the input: we provide a :commander configuration option for this, which works in a similar way as the :serializer option.

The complete plug-in

A very rudimentary example of how the tab-completion mechanism works is given by the complete plug-in, which consists of the following files:

    complete/Makefile
    complete/progs/init-complete.scm
    complete/src/complete.cpp

The startup banner in complete.cpp takes care of part of the configuration:

cout << DATA_BEGIN << "verbatim:";
format_plugin ();
cout << "We know how to complete 'h'";
cout << DATA_END;
fflush (stdout);

Here format_plugin is given by

void
format_plugin () {
  // The configuration of a plugin can be completed at startup time.
  // This may be interesting for adding tab-completion a posteriori.
  cout << DATA_BEGIN << "command:";
  cout << "(plugin-configure complete (:tab-completion #t))";
  cout << DATA_END;
}

In the main loop, we first deal with regular input:

char buffer[100];
cin.getline (buffer, 100, '\n');
if (buffer[0] != DATA_COMMAND) {
  cout << DATA_BEGIN << "verbatim:";
  cout << "You typed " << buffer;
  cout << DATA_END;
}

We next treat the case when a tab-completion command is sent to the application:

else {
  cout << DATA_BEGIN << "scheme:";
  cout << "(tuple \"h\" \"ello\" \"i there\" \"ola\" \"opsakee\")";
  cout << DATA_END;
}
fflush (stdout);

As you notice, the actual command is ignored, so our example is really very rudimentary.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".