File: interface-tab.en.tm

package info (click to toggle)
texmacs 1%3A2.1.4%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 145,076 kB
  • sloc: cpp: 227,393; lisp: 197,386; ansic: 5,395; python: 1,939; makefile: 1,065; sh: 781; perl: 339; xml: 100; awk: 36
file content (167 lines) | stat: -rw-r--r-- 4,952 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<TeXmacs|1.0.7.14>

<style|tmdoc>

<\body>
  <tmdoc-title|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

  <\scm-code>
    (:tab-completion #t)
  </scm-code>

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

  <\quotation>
    <\framed-fragment>
      <\verbatim>
        <render-key|DATA_COMMAND>(complete <em|input-string>
        <em|cursor-position>)<shortcut|(kbd-return)>
      </verbatim>
    </framed-fragment>
  </quotation>

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

  <\quotation>
    <\framed-fragment>
      <verbatim|<render-key|DATA_BEGIN>scheme:(tuple <em|root>
      <em|completion-1> ><math|\<cdots\>><verbatim|
      <em|completion-n>)><render-key|DATA_END>
    </framed-fragment>
  </quotation>

  Here <verbatim|<em|root>> corresponds to a substring before the cursor for
  which completions could be found. The strings <verbatim|<em|completion-1>>
  until <verbatim|<em|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>
    In principle, the tab-completion mechanism should still work in
    mathematical input mode. In that case, the <verbatim|<em|input-string>>
    will correspond to the serialization of the <TeXmacs> input.
  </remark>

  <\remark>
    The way <TeXmacs> sends commands to your application can be customized in
    a similar way as for the input: we provide a <scm|:commander>
    configuration option for this, which works in a similar way as the
    <scm|:serializer> option.
  </remark>

  <paragraph*|The <verbatim|complete> plug-in>

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

  <\verbatim>
    \ \ \ \ <example-plugin-link|complete/Makefile>

    \ \ \ \ <example-plugin-link|complete/progs/init-complete.scm>

    \ \ \ \ <example-plugin-link|complete/src/complete.cpp>
  </verbatim>

  The startup banner in <verbatim|complete.cpp> takes care of part of the
  configuration:

  <\cpp-code>
    cout \<less\>\<less\> DATA_BEGIN \<less\>\<less\> "verbatim:";

    format_plugin ();

    cout \<less\>\<less\> "We know how to complete 'h'";

    cout \<less\>\<less\> DATA_END;

    fflush (stdout);
  </cpp-code>

  Here <cpp|format_plugin> is given by

  <\cpp-code>
    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 \<less\>\<less\> DATA_BEGIN \<less\>\<less\> "command:";

    \ \ cout \<less\>\<less\> "(plugin-configure complete (:tab-completion
    #t))";

    \ \ cout \<less\>\<less\> DATA_END;

    }
  </cpp-code>

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

  <\cpp-code>
    char buffer[100];

    cin.getline (buffer, 100, '\\n');

    if (buffer[0] != DATA_COMMAND) {

    \ \ cout \<less\>\<less\> DATA_BEGIN \<less\>\<less\> "verbatim:";

    \ \ cout \<less\>\<less\> "You typed " \<less\>\<less\> buffer;

    \ \ cout \<less\>\<less\> DATA_END;

    }
  </cpp-code>

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

  <\cpp-code>
    else {

    \ \ cout \<less\>\<less\> DATA_BEGIN \<less\>\<less\> "scheme:";

    \ \ cout \<less\>\<less\> "(tuple \\"h\\" \\"ello\\" \\"i there\\"
    \\"ola\\" \\"opsakee\\")";

    \ \ cout \<less\>\<less\> DATA_END;

    }

    cout.flush ();
  </cpp-code>

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

  <tmdoc-copyright|1998--2002|Joris van der Hoeven>

  <tmdoc-license|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".>
</body>

<\initial>
  <\collection>
    <associate|language|english>
  </collection>
</initial>