Warning, /office/kile/doc/scripting.docbook is written in an unsupported language. File is not indexed.

0001 <chapter id="id_scripting">
0002 <title>Scripting</title>
0003 
0004 <sect1 id="id_scripting_kile">
0005 <title>Scripting in &kile;</title>
0006 
0007 <para>&kile;'s scripting feature allows the execution of <ulink url="http://en.wikipedia.org/wiki/ECMAScript">ECMAScript</ulink> code, widely known as &javascript;. You will find a lot of tutorials, which provide information about objects (variables), functions and properties supported by &javascript;.</para>
0008 
0009 <para>Scripting support can be enabled in the configuration dialog of &kile;: <menuchoice><guimenu>Settings</guimenu><guisubmenu>Configure Kile...</guisubmenu>
0010 <guimenuitem>Kile</guimenuitem><guilabel>Scripting</guilabel></menuchoice>.
0011 <screenshot>
0012         <screeninfo>Enable or disable scripting support</screeninfo>
0013         <mediaobject>
0014         <imageobject>
0015         <imagedata fileref="scripting-support.png" format="PNG" />
0016         </imageobject>
0017         <textobject>
0018                 <phrase>Enable or disable scripting support</phrase>
0019         </textobject>
0020         </mediaobject>
0021 </screenshot>
0022 </para>
0023 
0024 <para> If scripting is enabled, an additional scripting panel is visible in the sidebar, where scripts can be managed:
0025 <screenshot>
0026         <screeninfo>Scripting panel in the sidebar</screeninfo>
0027         <mediaobject>
0028         <imageobject>
0029         <imagedata fileref="scripting-panel.png" format="PNG" />
0030         </imageobject>
0031         <textobject>
0032                 <phrase>Scripting panel in the sidebar</phrase>
0033         </textobject>
0034         </mediaobject>
0035 </screenshot>
0036 </para>
0037 
0038 <para>
0039 This widget contains six icons, which offer different tasks:
0040 <itemizedlist>
0041 <listitem><para>Run the selected script.</para></listitem>
0042 <listitem><para>Create a new script.</para></listitem>
0043 <listitem><para>Open the selected script in the editor.</para></listitem>
0044 <listitem><para>Configure a key sequence for the selected script.</para></listitem>
0045 <listitem><para>Remove an assigned key sequence.</para></listitem>
0046 <listitem><para>Refresh the list of available scripts, which are all found in <filename>$<envar>KDEDIR</envar>/share/apps/kile/scripts/</filename>.</para></listitem>
0047 </itemizedlist>
0048 </para>
0049 
0050 </sect1>
0051 
0052 <sect1 id="id_execute_script">
0053 <title>Executing a Script</title>
0054 
0055 <para>You can execute a script in three different ways:</para>
0056 
0057 <procedure>
0058 <step><para>Select the desired script and click on the <guilabel>Execute</guilabel> button on the left side of the script management widget.</para>
0059 <screenshot>
0060         <screeninfo>Scripting: execute button</screeninfo>
0061         <mediaobject>
0062         <imageobject>
0063         <imagedata fileref="scripting-execbutton.png" format="PNG" />
0064         </imageobject>
0065         <textobject>
0066                 <phrase>Scripting: execute button</phrase>
0067         </textobject>
0068         </mediaobject>
0069 </screenshot>
0070 </step>
0071 
0072 <step><para>Use a keyboard shortcut.</para>
0073 <screenshot>
0074         <screeninfo>Scripting: keyboard shortcut</screeninfo>
0075         <mediaobject>
0076         <imageobject>
0077         <imagedata fileref="scripting-shortcut.png" format="PNG" />
0078         </imageobject>
0079         <textobject>
0080                 <phrase>Scripting: keyboard shortcut</phrase>
0081         </textobject>
0082         </mediaobject>
0083 </screenshot>
0084 <para>You can assign a keyboard shortcut to a script using the <guilabel>Configure</guilabel> button in the script management widget.</para>
0085 <screenshot>
0086         <screeninfo>Scripting: configure sequence dialog</screeninfo>
0087         <mediaobject>
0088         <imageobject>
0089         <imagedata fileref="scripting-configure.png" format="PNG" />
0090         </imageobject>
0091         <textobject>
0092                 <phrase>Scripting: configure sequence dialog</phrase>
0093         </textobject>
0094         </mediaobject>
0095 </screenshot>
0096 </step>
0097 
0098 <step><para>Use an editor key sequence. The script will be executed, if you type the assigned key sequence in the editor.</para>
0099 <screenshot>
0100         <screeninfo>Scripting: editor key sequence</screeninfo>
0101         <mediaobject>
0102         <imageobject>
0103         <imagedata fileref="scripting-keysequence1.png" format="PNG" />
0104         </imageobject>
0105         <textobject>
0106                 <phrase>Scripting: editor key sequence</phrase>
0107         </textobject>
0108         </mediaobject>
0109 </screenshot>
0110 <para>This method can be extended to a rather sophisticated kind of code completion. Let us assume that you have a written a script, which simply inserts the &latex; command <userinput>\textbf{}</userinput> into the current document.</para>
0111 
0112 <programlisting>
0113 document.insertText("\\textbf{%C}");
0114 </programlisting>
0115 
0116 <para>If you now type the assigned key sequence <userinput>bfx</userinput> in your text document, this key sequence will be removed and the script will be executed. It will insert <userinput>\textbf{}</userinput> and the cursor is placed between the braces.</para>
0117 <screenshot>
0118         <screeninfo>Scripting: typing an editor key sequence</screeninfo>
0119         <mediaobject>
0120         <imageobject>
0121         <imagedata fileref="scripting-keysequence2.png" format="PNG" />
0122         </imageobject>
0123         <textobject>
0124                 <phrase>Scripting: typing an editor key sequence</phrase>
0125         </textobject>
0126         </mediaobject>
0127 </screenshot>
0128 <para>What a comfortable and powerful method of code completion.</para>
0129 </step>
0130 </procedure>
0131 
0132 </sect1>
0133 
0134 <sect1 id="id_scripting_api">
0135 <title>API Reference</title>
0136 
0137 <para>The scripting API presented here is available in all scripts. Before the contents of a script is loaded, &kile; first adds several prototypes and functions to the scripting context. This convenience API contains prototypes like text cursors and text ranges and is located in the folder <filename>KILE_APP_DIR/script-plugins/</filename>.</para>
0138 
0139 <para>&kile; scripts differ slightly from <ulink url="http://kate-editor.org">&kate;</ulink> scripts, which use another design, as they also can be started from the command line. But all functions of the &kate; scripting API are also available in &kile;'s scripting API, so porting &javascript; code from &kate; to &kile; should be very easy. But as &kile; is a very rich featured &latex; editor, its own scripting API offers many more possibilities than &kate;'s one.</para>
0140 
0141 <para><emphasis>Remark: </emphasis>Description of API calls, which are also available in &kate; scripting, have been taken from &kate;'s documentation.</para>
0142 
0143 
0144 <sect2 id="id_scripting_api_global">
0145 <title>Global Functions</title>
0146 
0147 <para>This section lists global functions.</para>
0148 
0149 <variablelist><varlistentry>
0150 <term><synopsis>
0151 void debug(<parameter>String <replaceable>text</replaceable></parameter>);
0152 </synopsis></term>
0153 <listitem><para>
0154 Prints <parameter>text</parameter> to <literal>stdout</literal> in the console. The printed text is colored to distinguish it from other debug output.
0155 </para></listitem>
0156 </varlistentry></variablelist>
0157 
0158 </sect2>
0159 
0160 
0161 <sect2 id="id_scripting_api_cursor">
0162 <title>The Cursor Prototype</title>
0163 
0164 <para>As &kile; is a text editor, all the scripting API is based on cursors and ranges whenever possible. A Cursor is a simple <literal>(line, column)</literal> tuple representing a text position in the document.</para>
0165 
0166 <variablelist><varlistentry>
0167 <term><synopsis>
0168 Cursor();
0169 </synopsis></term>
0170 <listitem><para>
0171 Constructor: Returns a Cursor at position <literal>(0,0)</literal>.
0172 </para><para>
0173 Example: <function>var cursor = new Cursor();</function></para>
0174 </listitem>
0175 </varlistentry></variablelist>
0176 
0177 <variablelist><varlistentry>
0178 <term><synopsis>
0179 Cursor(<parameter>int <replaceable>line</replaceable></parameter>, <parameter>int <replaceable>column</replaceable></parameter>);
0180 </synopsis></term>
0181 <listitem><para>
0182 Constructor: Returns a Cursor at position (line,column).
0183 </para><para>
0184 Example: <function>var cursor = new Cursor(3,42);</function>
0185 </para></listitem>
0186 </varlistentry></variablelist>
0187 
0188 <variablelist><varlistentry>
0189 <term><synopsis>
0190 Cursor(<parameter>Cursor <replaceable>other</replaceable></parameter>);
0191 </synopsis></term>
0192 <listitem><para>
0193 Copy constructor: Returns a copy of the cursor <parameter>other</parameter>.
0194 </para><para>
0195         Example: <function>var copy = new Cursor(other);</function>
0196 </para></listitem>
0197 </varlistentry></variablelist>
0198 
0199 <variablelist><varlistentry>
0200 <term><synopsis>
0201 Cursor Cursor.clone();
0202 </synopsis></term>
0203 <listitem><para>
0204 Returns a clone of the cursor.
0205 </para><para>
0206         Example: <function>var clone = cursor.clone();</function>
0207 </para></listitem>
0208 </varlistentry></variablelist>
0209 
0210 <variablelist><varlistentry>
0211 <term><synopsis>
0212 bool Cursor.isValid();
0213 </synopsis></term>
0214 <listitem><para>
0215 Check whether the cursor is valid. The cursor is invalid if line and/or
0216 column are set to <literal>-1</literal>.
0217 </para><para>
0218 Example: <function>var valid = cursor.isValid();</function>
0219 </para></listitem>
0220 </varlistentry></variablelist>
0221 
0222 <variablelist><varlistentry>
0223 <term><synopsis>
0224 Cursor Cursor.invalid();
0225 </synopsis></term>
0226 <listitem><para>
0227 Returns a new invalid cursor located at <literal>(-1,-1)</literal>.
0228 </para><para>
0229 Example: <function>var invalidCursor = cursor.invalid();</function>
0230 </para></listitem>
0231 </varlistentry></variablelist>
0232 
0233 <variablelist><varlistentry>
0234 <term><synopsis>
0235 int Cursor.compareTo(<parameter>Cursor <replaceable>other</replaceable></parameter>);
0236 </synopsis></term>
0237 <listitem><para>
0238 Compares this cursor to the cursor <parameter>other</parameter>. Returns
0239 <itemizedlist>
0240 <listitem><para><literal>-1</literal>, if this cursor is located before the cursor <parameter>other</parameter>,</para></listitem>
0241 <listitem><para><literal>0</literal>, if both cursors equal and</para></listitem>
0242 <listitem><para><literal>+1</literal>, if this cursor is located after the cursor <parameter>other</parameter>.</para></listitem>
0243 </itemizedlist>
0244 </para></listitem>
0245 </varlistentry></variablelist>
0246 
0247 <variablelist><varlistentry>
0248 <term><synopsis>
0249 bool Cursor.equals(<parameter>Cursor <replaceable>other</replaceable></parameter>);
0250 </synopsis></term>
0251 <listitem><para>
0252 Returns <literal>true</literal>, if this cursor and the cursor <parameter>other</parameter> are equal, otherwise <literal>false</literal>.
0253 </para></listitem>
0254 </varlistentry></variablelist>
0255 
0256 <variablelist><varlistentry>
0257 <term><synopsis>
0258 String Cursor.toString();
0259 </synopsis></term>
0260 <listitem><para>
0261 Returns the cursor as a string of the form <literal>Cursor(line,column)</literal>.
0262 </para></listitem>
0263 </varlistentry></variablelist>
0264 
0265 </sect2>
0266 
0267 
0268 <sect2 id="id_scripting_api_range">
0269 <title>The Range Prototype</title>
0270 
0271 <para>As &kile; is a text editor, all the scripting API is based on cursors and ranges whenever possible. As Cursor is a simple <literal>(line, column)</literal> tuple representing a text position in the document, a Range spans text from a starting cursor position to an ending cursor position.</para>
0272 
0273 <variablelist><varlistentry>
0274 <term><synopsis>
0275 Range();
0276 </synopsis></term>
0277 <listitem><para>
0278 Constructor: Calling <literal>new Range()</literal> returns a Range at <literal>(0,0) - (0,0)</literal>.
0279 </para></listitem>
0280 </varlistentry></variablelist>
0281 
0282 <variablelist><varlistentry>
0283 <term><synopsis>
0284 Range(<parameter>Cursor <replaceable>start</replaceable></parameter>, <parameter>Cursor <replaceable>end</replaceable></parameter>);
0285 </synopsis></term>
0286 <listitem><para>
0287 Constructor: Calling <literal>new Range(<replaceable>start</replaceable>, <replaceable>end</replaceable>)</literal> returns the range from cursor <parameter>start</parameter> to cursor <parameter>end</parameter>.
0288 </para></listitem>
0289 </varlistentry></variablelist>
0290 
0291 <variablelist><varlistentry>
0292 <term><synopsis>
0293 Range(<parameter>int <replaceable>startLine</replaceable></parameter>, <parameter>int <replaceable>startColumn</replaceable></parameter>, <parameter>int <replaceable>endLine</replaceable></parameter>, <parameter>int <replaceable>endColumn</replaceable></parameter>);
0294 </synopsis></term>
0295 <listitem><para>
0296 Constructor: Calling <literal>new Range(<replaceable>startLine</replaceable>,<replaceable>startColumn</replaceable>,<replaceable>endLine</replaceable>, <replaceable>endColumn</replaceable>)</literal>
0297 returns the Range from (<literal>startLine</literal>, <literal>startColumn</literal>) to (<literal>endLine</literal>, <literal>endColumn</literal>).
0298 </para></listitem>
0299 </varlistentry></variablelist>
0300 
0301 <variablelist><varlistentry>
0302 <term><synopsis>
0303 Range(<parameter>Range <replaceable>other</replaceable></parameter>);
0304 </synopsis></term>
0305 <listitem><para>
0306 Copy constructor: Returns a copy of Range <literal>other</literal>.
0307 </para></listitem>
0308 </varlistentry></variablelist>
0309 
0310 <variablelist><varlistentry>
0311 <term><synopsis>
0312 Range Range.clone();
0313 </synopsis></term>
0314 <listitem><para>
0315 Returns a clone of the range.
0316 </para><para>
0317 Example: <function>var clone = range.clone();</function>
0318 </para></listitem>
0319 </varlistentry></variablelist>
0320 
0321 <variablelist><varlistentry>
0322 <term><synopsis>
0323 bool Range.isValid();
0324 </synopsis></term>
0325 <listitem><para>
0326 Returns <literal>true</literal>, if both start and end cursor are valid, otherwise <literal>false</literal>.
0327 </para><para>
0328 Example: <function>var valid = range.isValid();</function>
0329 </para></listitem>
0330 </varlistentry></variablelist>
0331 
0332 <variablelist><varlistentry>
0333 <term><synopsis>
0334 bool Range.invalid();
0335 </synopsis></term>
0336 <listitem><para>
0337 Returns the Range from (-1,-1) to (-1,-1).
0338 </para></listitem>
0339 </varlistentry></variablelist>
0340 
0341 <variablelist><varlistentry>
0342 <term><synopsis>
0343 bool Range.contains(<parameter>Cursor <replaceable>cursor</replaceable></parameter>);
0344 </synopsis></term>
0345 <listitem><para>
0346 Returns <literal>true</literal>, if this range contains the cursor position, otherwise <literal>false</literal>.
0347 </para></listitem>
0348 </varlistentry></variablelist>
0349 
0350 <variablelist><varlistentry>
0351 <term><synopsis>
0352 bool Range.contains(<parameter>Range <replaceable>other</replaceable></parameter>);
0353 </synopsis></term>
0354 <listitem><para>
0355 Returns <literal>true</literal>, if this range contains the Range <parameter>other</parameter>, otherwise <literal>false</literal>.
0356 </para></listitem>
0357 </varlistentry></variablelist>
0358 
0359 <variablelist><varlistentry>
0360 <term><synopsis>
0361 bool Range.containsColumn(<parameter>int <replaceable>column</replaceable></parameter>);
0362 </synopsis></term>
0363 <listitem><para>
0364 Returns <literal>true</literal>, if <parameter>column</parameter> is in the half open interval <literal>[start.column, end.column]</literal>, otherwise <literal>false</literal>.
0365 </para></listitem>
0366 </varlistentry></variablelist>
0367 
0368 <variablelist><varlistentry>
0369 <term><synopsis>
0370 bool Range.containsLine(<parameter>int <replaceable>line</replaceable></parameter>);
0371 </synopsis></term>
0372 <listitem><para>
0373 Returns <literal>true</literal>, if <parameter>line</parameter> is in the half open interval <literal>[start.line, end.line]</literal>, otherwise <literal>false</literal>.
0374 </para></listitem>
0375 </varlistentry></variablelist>
0376 
0377 <variablelist><varlistentry>
0378 <term><synopsis>
0379 bool Range.overlaps(<parameter>Range <replaceable>other</replaceable></parameter>);
0380 </synopsis></term>
0381 <listitem><para>
0382 Returns <literal>true</literal>, if this range and the range <parameter>other</parameter> share a common region, otherwise <literal>false</literal>.
0383 </para></listitem>
0384 </varlistentry></variablelist>
0385 
0386 <variablelist><varlistentry>
0387 <term><synopsis>
0388 bool Range.overlapsLine(<parameter>int <replaceable>line</replaceable></parameter>);
0389 </synopsis></term>
0390 <listitem><para>
0391 Returns <literal>true</literal>, if <parameter>line</parameter> is in the interval <literal>[start.line, end.line]</literal>, otherwise <literal>false</literal>.
0392 </para></listitem>
0393 </varlistentry></variablelist>
0394 
0395 <variablelist><varlistentry>
0396 <term><synopsis>
0397 bool Range.overlapsColumn(<parameter>int <replaceable>column</replaceable></parameter>);
0398 </synopsis></term>
0399 <listitem><para>
0400 Returns <literal>true</literal>, if <parameter>column</parameter> is in the interval <literal>[start.column, end.column]</literal>, otherwise <literal>false</literal>.
0401 </para></listitem>
0402 </varlistentry></variablelist>
0403 
0404 <variablelist><varlistentry>
0405 <term><synopsis>
0406 bool Range.equals(<parameter>Range <replaceable>other</replaceable></parameter>);
0407 </synopsis></term>
0408 <listitem><para>
0409 Returns <literal>true</literal>, if this range and the Range <parameter>other</parameter> are equal, otherwise <literal>false</literal>.
0410 </para></listitem>
0411 </varlistentry></variablelist>
0412 
0413 <variablelist><varlistentry>
0414 <term><synopsis>
0415 String Range.toString();
0416 </synopsis></term>
0417 <listitem><para>
0418 Returns the range as a string of the form <literal>Range(Cursor(line,column) - Cursor(line,column))</literal>.
0419 </para></listitem>
0420 </varlistentry></variablelist>
0421 
0422 </sect2>
0423 
0424 
0425 <sect2 id="id_scripting_api_view">
0426 <title>The View API</title>
0427 
0428 <para>Whenever a script is being executed, there is a global object (variable) <userinput>view</userinput> representing the current active editor view. All functions of <literal>view</literal> work with cursor positions or selected text. The following is a list of all available <userinput>view</userinput> functions.</para>
0429 
0430 <variablelist><varlistentry>
0431 <term><synopsis>
0432 void view.backspace();
0433 </synopsis></term>
0434 <listitem><para>
0435 Programmatically performs the equivalent of pressing the backspace key.
0436 </para></listitem>
0437 </varlistentry></variablelist>
0438 
0439 <variablelist><varlistentry>
0440 <term><synopsis>
0441 Cursor view.cursorPosition();
0442 </synopsis></term>
0443 <listitem><para>
0444 Returns the current cursor position in the view.
0445 </para></listitem>
0446 </varlistentry></variablelist>
0447 
0448 <variablelist><varlistentry>
0449 <term><synopsis>
0450 void view.setCursorPosition(<parameter>int <replaceable>line</replaceable></parameter>, <parameter>int <replaceable>column</replaceable></parameter>);
0451 void view.setCursorPosition(<parameter>Cursor <replaceable>cursor</replaceable></parameter>);
0452 </synopsis></term>
0453 <listitem><para>
0454         Set the current cursor position to either <parameter>line</parameter>, <parameter>column</parameter> or to the given <parameter>cursor</parameter>.
0455 </para></listitem>
0456 </varlistentry></variablelist>
0457 
0458 <variablelist><varlistentry>
0459 <term><synopsis>
0460 void view.cursorLeft();
0461 </synopsis></term>
0462 <listitem><para>
0463 Moves the cursor one position backward in the text.
0464 </para></listitem>
0465 </varlistentry></variablelist>
0466 
0467 <variablelist><varlistentry>
0468 <term><synopsis>
0469 void view.cursorRight();
0470 </synopsis></term>
0471 <listitem><para>
0472 Moves the cursor one position forward in the text.
0473 </para></listitem>
0474 </varlistentry></variablelist>
0475 
0476 <variablelist><varlistentry>
0477 <term><synopsis>
0478 void view.cursorUp();
0479 </synopsis></term>
0480 <listitem><para>
0481 Moves the cursor one line up in the document.
0482 </para></listitem>
0483 </varlistentry></variablelist>
0484 
0485 <variablelist><varlistentry>
0486 <term><synopsis>
0487 void view.cursorDown();
0488 </synopsis></term>
0489 <listitem><para>
0490 Moves the cursor one line down in the document.
0491 </para></listitem>
0492 </varlistentry></variablelist>
0493 
0494 <variablelist><varlistentry>
0495 <term><synopsis>
0496 int view.cursorLine();
0497 </synopsis></term>
0498 <listitem><para>
0499 Returns the line which the cursor is currently located at.
0500 </para></listitem>
0501 </varlistentry></variablelist>
0502 
0503 <variablelist><varlistentry>
0504 <term><synopsis>
0505 int view.cursorColumn();
0506 </synopsis></term>
0507 <listitem><para>
0508 Returns the column which the cursor is currently located at.
0509 </para></listitem>
0510 </varlistentry></variablelist>
0511 
0512 <variablelist><varlistentry>
0513 <term><synopsis>
0514 void view.setCursorLine(<parameter>int <replaceable>line</replaceable></parameter>);
0515 </synopsis></term>
0516 <listitem><para>
0517 Set the cursor line to the given <parameter>line</parameter>.
0518 </para></listitem>
0519 </varlistentry></variablelist>
0520 
0521 <variablelist><varlistentry>
0522 <term><synopsis>
0523 void view.setCursorColumn(<parameter>int <replaceable>column</replaceable></parameter>);
0524 </synopsis></term>
0525 <listitem><para>
0526 Set the cursor column to the given <parameter>column</parameter>.
0527 </para></listitem>
0528 </varlistentry></variablelist>
0529 
0530 <variablelist><varlistentry>
0531 <term><synopsis>
0532 Cursor view.virtualCursorPosition();
0533 </synopsis></term>
0534 <listitem><para>
0535 Get the current <emphasis>virtual</emphasis> cursor position. <emphasis>Virtual</emphasis> means the tabulator character (TAB) counts <emphasis>multiple</emphasis> characters, as configured by the user (e.g. one TAB is 8 spaces). The virtual cursor position provides access to the user visible values of the current cursor position.
0536 </para></listitem>
0537 </varlistentry></variablelist>
0538 
0539 <variablelist><varlistentry>
0540 <term><synopsis>
0541 bool view.hasSelection();
0542 </synopsis></term>
0543 <listitem><para>
0544 Returns <literal>true</literal>, if the view has selected text, otherwise <literal>false</literal>.
0545 </para></listitem>
0546 </varlistentry></variablelist>
0547 
0548 <variablelist><varlistentry>
0549 <term><synopsis>
0550 String view.selectedText();
0551 </synopsis></term>
0552 <listitem><para>
0553 Returns the selected text. If no text is selected, the returned string is empty.
0554 </para></listitem>
0555 </varlistentry></variablelist>
0556 
0557 <variablelist><varlistentry>
0558 <term><synopsis>
0559 Range view.selectionRange();
0560 </synopsis></term>
0561 <listitem><para>
0562 Returns the selected text range. The returned range is invalid if there is no selected text.
0563 </para></listitem>
0564 </varlistentry></variablelist>
0565 
0566 <variablelist><varlistentry>
0567 <term><synopsis>
0568 void view.setSelection(<parameter>Range <replaceable>range</replaceable></parameter>);
0569 </synopsis></term>
0570 <listitem><para>
0571 Set the selected text to the given <parameter>range</parameter>.
0572 </para></listitem>
0573 </varlistentry></variablelist>
0574 
0575 <variablelist><varlistentry>
0576 <term><synopsis>
0577 void view.selectAll();
0578 </synopsis></term>
0579 <listitem><para>
0580 Selects the entire text in the document.
0581 </para></listitem>
0582 </varlistentry></variablelist>
0583 
0584 <variablelist><varlistentry>
0585 <term><synopsis>
0586 void view.clearSelection();
0587 </synopsis></term>
0588 <listitem><para>
0589 Clears the text selection without removing the text.
0590 </para></listitem>
0591 </varlistentry></variablelist>
0592 
0593 <variablelist><varlistentry>
0594 <term><synopsis>
0595 void view.removeSelectedText();
0596 </synopsis></term>
0597 <listitem><para>
0598 Remove the selected text. If the view does not have any selected text, this does nothing.
0599 </para></listitem>
0600 </varlistentry></variablelist>
0601 
0602 <variablelist><varlistentry>
0603 <term><synopsis>
0604 void view.selectLine();
0605 </synopsis></term>
0606 <listitem><para>
0607 Selects the text in the current line.
0608 </para></listitem>
0609 </varlistentry></variablelist>
0610 
0611 <variablelist><varlistentry>
0612 <term><synopsis>
0613 void view.selectLine(<parameter>int <replaceable>line</replaceable></parameter>);
0614 </synopsis></term>
0615 <listitem><para>
0616 Selects the text in the given <parameter>line</parameter>.
0617 </para></listitem>
0618 </varlistentry></variablelist>
0619 
0620 <variablelist><varlistentry>
0621 <term><synopsis>
0622 void view.selectLines(<parameter>int <replaceable>from</replaceable></parameter>, <parameter>int <replaceable>to</replaceable></parameter>);
0623 </synopsis></term>
0624 <listitem><para>
0625 Selects the entire text from line <parameter>from</parameter> to line <parameter>to</parameter>.
0626 </para></listitem>
0627 </varlistentry></variablelist>
0628 
0629 <variablelist><varlistentry>
0630 <term><synopsis>
0631 void view.selectWord();
0632 </synopsis></term>
0633 <listitem><para>
0634 Selects the current word. If no word is found at the current cursor position, nothing is done.
0635 </para></listitem>
0636 </varlistentry></variablelist>
0637 
0638 <variablelist><varlistentry>
0639 <term><synopsis>
0640 void view.selectLatexCommand();
0641 </synopsis></term>
0642 <listitem><para>
0643 Selects the current &latex; command. If no command is found at the current cursor position, nothing is done.
0644 </para></listitem>
0645 </varlistentry></variablelist>
0646 
0647 <variablelist><varlistentry>
0648 <term><synopsis>
0649 void view.selectEnvironment(<parameter>bool <replaceable>inside = false</replaceable></parameter>);
0650 </synopsis></term>
0651 <listitem><para>
0652 Selects the entire text of the current &latex; environment. If <parameter>inside</parameter> is <literal>false</literal>, the environment text including the surrounding &latex; tags <userinput>\begin{...}...\end{...}</userinput> will be selected, else without these tags. If no parameter is given, <parameter>inside</parameter> is set to <literal>false</literal>.
0653 </para></listitem>
0654 </varlistentry></variablelist>
0655 
0656 <variablelist><varlistentry>
0657 <term><synopsis>
0658 void view.selectTexgroup(<parameter>bool <replaceable>inside = true</replaceable></parameter>);
0659 </synopsis></term>
0660 <listitem><para>
0661 Selects the text of the current &latex; group. If <parameter>inside</parameter> is <literal>true</literal>, only the texgroup without the surrounding braces will be selected. If no parameter is given, <parameter>inside</parameter> is set to <literal>true</literal>.
0662 </para></listitem>
0663 </varlistentry></variablelist>
0664 
0665 <variablelist><varlistentry>
0666 <term><synopsis>
0667 void view.selectMathgroup();
0668 </synopsis></term>
0669 <listitem><para>
0670 Selects the text of the current math group.
0671 </para></listitem>
0672 </varlistentry></variablelist>
0673 
0674 <variablelist><varlistentry>
0675 <term><synopsis>
0676 void view.selectParagraph(bool wholeLines = true);
0677 </synopsis></term>
0678 <listitem><para>
0679 Selects the entire text of the current &latex; paragraph. If <parameter>wholeLines</parameter> is <literal>true</literal>, the first and the last lines of the paragraph will be included in the selection entirely (including the end-of-line character); otherwise, the selection will only contain non-whitespace characters.
0680 </para></listitem>
0681 </varlistentry></variablelist>
0682 
0683 </sect2>
0684 
0685 
0686 <sect2 id="id_scripting_api_document">
0687 <title>The Document API</title>
0688 
0689 <para>Whenever a script is being executed, there is a global object (variable) <userinput>document</userinput> representing the current active document. The following is a list of all available <userinput>document</userinput> functions.</para>
0690 
0691 <variablelist><varlistentry>
0692 <term><synopsis>
0693 void document.insertText(<parameter>String <replaceable>text</replaceable></parameter>);
0694 </synopsis></term>
0695 <listitem><para>
0696 Inserts the <parameter>text</parameter> at the current cursor position.
0697 </para></listitem>
0698 </varlistentry></variablelist>
0699 
0700 <variablelist><varlistentry>
0701 <term><synopsis>
0702 void document.insertText(<parameter>int <replaceable>line</replaceable></parameter>, <parameter>int <replaceable>column</replaceable></parameter>, <parameter>String <replaceable>text</replaceable></parameter>);
0703 void document.insertText(<parameter>Cursor <replaceable>cursor</replaceable></parameter>, <parameter>String <replaceable>text</replaceable></parameter>);
0704 </synopsis></term>
0705 <listitem><para>
0706 Inserts the <parameter>text</parameter> at the given cursor position.
0707 </para></listitem>
0708 </varlistentry></variablelist>
0709 
0710 <variablelist><varlistentry>
0711 <term><synopsis>
0712 bool document.removeText(<parameter>int <replaceable>fromLine</replaceable></parameter>, <parameter>int <replaceable>fromColumn</replaceable></parameter>, <parameter>int <replaceable>toLine</replaceable></parameter>, <parameter>int <replaceable>toColumn</replaceable></parameter>);
0713 bool document.removeText(<parameter>Cursor <replaceable>from</replaceable></parameter>, <parameter>Cursor <replaceable>to</replaceable></parameter>);
0714 bool document.removeText(<parameter>Range <replaceable>range</replaceable></parameter>);
0715 </synopsis></term>
0716 <listitem><para>
0717 Removes the text in the given range. Returns <literal>true</literal> on success, or <literal>false</literal>, if the document is in read-only mode.
0718 </para></listitem>
0719 </varlistentry></variablelist>
0720 
0721 <variablelist><varlistentry>
0722 <term><synopsis>
0723 bool document.replaceText(<parameter>Range <replaceable>range</replaceable></parameter>, <parameter>String <replaceable>text</replaceable></parameter>);
0724 </synopsis></term>
0725 <listitem><para>
0726 Replace the text of the given range with the specified text.
0727 </para></listitem>
0728 </varlistentry></variablelist>
0729 
0730 <variablelist><varlistentry>
0731 <term><synopsis>
0732 int document.lines();
0733 </synopsis></term>
0734 <listitem><para>
0735 Returns the number of lines in the document.
0736 </para></listitem>
0737 </varlistentry></variablelist>
0738 
0739 <variablelist><varlistentry>
0740 <term><synopsis>
0741 int document.length();
0742 </synopsis></term>
0743 <listitem><para>
0744 Returns the number of characters in the document.
0745 </para></listitem>
0746 </varlistentry></variablelist>
0747 
0748 <variablelist><varlistentry>
0749 <term><synopsis>
0750 Range document.documentRange();
0751 </synopsis></term>
0752 <listitem><para>
0753 Returns a range which encompasses the whole document.
0754 </para></listitem>
0755 </varlistentry></variablelist>
0756 
0757 <variablelist><varlistentry>
0758 <term><synopsis>
0759 Cursor document.documentEnd();
0760 </synopsis></term>
0761 <listitem><para>
0762 Returns the current cursor position of the document's end.
0763 </para></listitem>
0764 </varlistentry></variablelist>
0765 
0766 <variablelist><varlistentry>
0767 <term><synopsis>
0768 String document.text();
0769 </synopsis></term>
0770 <listitem><para>
0771 Returns the entire content of the document in a single text string. Newlines
0772 are marked with the newline character <literal>\n</literal>.
0773 </para></listitem>
0774 </varlistentry></variablelist>
0775 
0776 <variablelist><varlistentry>
0777 <term><synopsis>
0778 String document.text(<parameter>int <replaceable>fromLine</replaceable></parameter>, <parameter>int <replaceable>fromColumn</replaceable></parameter>, <parameter>int <replaceable>toLine</replaceable></parameter>, <parameter>int <replaceable>toColumn</replaceable></parameter>);
0779 String document.text(<parameter>Cursor <replaceable>from</replaceable></parameter>, <parameter>Cursor <replaceable>to</replaceable></parameter>);
0780 String document.text(<parameter>Range <replaceable>range</replaceable></parameter>);
0781 </synopsis></term>
0782 <listitem><para>
0783 Returns the text in the given range. It is recommended to use the cursor and range based version for better readability of the source code.
0784 </para></listitem>
0785 </varlistentry></variablelist>
0786 
0787 <variablelist><varlistentry>
0788 <term><synopsis>
0789 bool document.setText(<parameter>String <replaceable>text</replaceable></parameter>);
0790 </synopsis></term>
0791 <listitem><para>
0792 Sets the entire document text.
0793 </para></listitem>
0794 </varlistentry></variablelist>
0795 
0796 <variablelist><varlistentry>
0797 <term><synopsis>
0798 bool document.clear();
0799 </synopsis></term>
0800 <listitem><para>
0801 Removes the entire text in the document.
0802 </para></listitem>
0803 </varlistentry></variablelist>
0804 
0805 <variablelist><varlistentry>
0806 <term><synopsis>
0807 String document.line();
0808 </synopsis></term>
0809 <listitem><para>
0810 Returns the current text line as string.
0811 </para></listitem>
0812 </varlistentry></variablelist>
0813 
0814 <variablelist><varlistentry>
0815 <term><synopsis>
0816 String document.line(<parameter>int <replaceable>line</replaceable></parameter>);
0817 </synopsis></term>
0818 <listitem><para>
0819 Returns the given text line as string. The string is empty if the requested line is out of range.
0820 </para></listitem>
0821 </varlistentry></variablelist>
0822 
0823 <variablelist><varlistentry>
0824 <term><synopsis>
0825 int document.lineLength();
0826 </synopsis></term>
0827 <listitem><para>
0828 Returns the length of the current line.
0829 </para></listitem>
0830 </varlistentry></variablelist>
0831 
0832 <variablelist><varlistentry>
0833 <term><synopsis>
0834 int document.lineLength(<parameter>int <replaceable>line</replaceable></parameter>);
0835 </synopsis></term>
0836 <listitem><para>
0837 Returns the <parameter>line</parameter>'s length.
0838 </para></listitem>
0839 </varlistentry></variablelist>
0840 
0841 <variablelist><varlistentry>
0842 <term><synopsis>
0843 bool document.insertLine(<parameter>String <replaceable>s</replaceable></parameter>);
0844 </synopsis></term>
0845 <listitem><para>
0846 Inserts text in the current line. Returns <literal>true</literal> on success, or <literal>false</literal>, if the document is in read-only mode or the line is not in the document range.
0847 </para></listitem>
0848 </varlistentry></variablelist>
0849 
0850 <variablelist><varlistentry>
0851 <term><synopsis>
0852 bool document.insertLine(<parameter>int <replaceable>line</replaceable></parameter>, <parameter>String <replaceable>s</replaceable></parameter>);
0853 </synopsis></term>
0854 <listitem><para>
0855 Inserts text in the given line. Returns <literal>true</literal> on success, or <literal>false</literal>, if the document is in read-only mode or the line is not in the document range.
0856 </para></listitem>
0857 </varlistentry></variablelist>
0858 
0859 <variablelist><varlistentry>
0860 <term><synopsis>
0861 bool document.removeLine();
0862 </synopsis></term>
0863 <listitem><para>
0864 Removes the current text line. Returns <literal>true</literal> on success, or <literal>false</literal>, if the document is in read-only mode.
0865 </para></listitem>
0866 </varlistentry></variablelist>
0867 
0868 <variablelist><varlistentry>
0869 <term><synopsis>
0870 bool document.removeLine(<parameter>int <replaceable>line</replaceable></parameter>);
0871 </synopsis></term>
0872 <listitem><para>
0873 Removes the given text line. Returns <literal>true</literal> on success, or <literal>false</literal>, if the document is in read-only mode or the line is not in the document range.
0874 </para></listitem>
0875 </varlistentry></variablelist>
0876 
0877 <variablelist><varlistentry>
0878 <term><synopsis>
0879 bool document.replaceLine(<parameter>String <replaceable>text</replaceable></parameter>);
0880 </synopsis></term>
0881 <listitem><para>
0882 Replace the text of the current line with the specified text.
0883 </para></listitem>
0884 </varlistentry></variablelist>
0885 
0886 <variablelist><varlistentry>
0887 <term><synopsis>
0888 bool document.replaceLine(<parameter>int <replaceable>line</replaceable></parameter>, <parameter>String <replaceable>text</replaceable></parameter>);
0889 </synopsis></term>
0890 <listitem><para>
0891 Replace the text of the given line with the specified text.
0892 </para></listitem>
0893 </varlistentry></variablelist>
0894 
0895 <variablelist><varlistentry>
0896 <term><synopsis>
0897 bool document.truncateLine();
0898 </synopsis></term>
0899 <listitem><para>
0900 Truncate the current line at the given column or cursor position. Returns <literal>true</literal> on success, or <literal>false</literal> if the given line is not part of the document range.
0901 </para></listitem>
0902 </varlistentry></variablelist>
0903 
0904 <variablelist><varlistentry>
0905 <term><synopsis>
0906 bool document.truncate(<parameter>int <replaceable>line</replaceable></parameter>, <parameter>int <replaceable>column</replaceable></parameter>);
0907 bool document.truncate(<parameter>Cursor <replaceable>cursor</replaceable></parameter>);
0908 </synopsis></term>
0909 <listitem><para>
0910 Truncate the given line at the given column or cursor position. Returns <literal>true</literal> on success, or <literal>false</literal> if the given line is not part of the document range.
0911 </para></listitem>
0912 </varlistentry></variablelist>
0913 
0914 <variablelist><varlistentry>
0915 <term><synopsis>
0916 String document.word();
0917 </synopsis></term>
0918 <listitem><para>
0919 Returns the word at the current cursor position. If no word is found at this cursor position, the returned string is empty.
0920 </para></listitem>
0921 </varlistentry></variablelist>
0922 
0923 <variablelist><varlistentry>
0924 <term><synopsis>
0925 String document.wordAt(<parameter>int <replaceable>line</replaceable></parameter>, <parameter>int <replaceable>column</replaceable></parameter>);
0926 String document.wordAt(<parameter>Cursor <replaceable>cursor</replaceable></parameter>);
0927 </synopsis></term>
0928 <listitem><para>
0929 Returns the word at the given cursor position. If no word is found at this cursor position, the returned string is empty.
0930 </para></listitem>
0931 </varlistentry></variablelist>
0932 
0933 <variablelist><varlistentry>
0934 <term><synopsis>
0935 Range document.wordRange();
0936 </synopsis></term>
0937 <listitem><para>
0938 Returns the range of the word at the given cursor position. If no word is found, <literal>Range.invalid()</literal> is returned, which can be tested with <literal>Range.isValid()</literal>.
0939 </para></listitem>
0940 </varlistentry></variablelist>
0941 
0942 <variablelist><varlistentry>
0943 <term><synopsis>
0944 String document.latexCommand();
0945 </synopsis></term>
0946 <listitem><para>
0947 Returns the &latex; command at the current cursor position. If no command is found at this cursor position, the returned string is empty.
0948 </para></listitem>
0949 </varlistentry></variablelist>
0950 
0951 <variablelist><varlistentry>
0952 <term><synopsis>
0953 String document.latexCommandAt(<parameter>int <replaceable>line</replaceable></parameter>, <parameter>int <replaceable>column</replaceable></parameter>);
0954 String document.latexCommandAt(<parameter>Cursor <replaceable>cursor</replaceable></parameter>);
0955 </synopsis></term>
0956 <listitem><para>
0957 Returns the &latex; command at the given cursor position. If no command is found at this cursor position, the returned string is empty.
0958 </para></listitem>
0959 </varlistentry></variablelist>
0960 
0961 <variablelist><varlistentry>
0962 <term><synopsis>
0963 Range document.latexCommandRange();
0964 </synopsis></term>
0965 <listitem><para>
0966 Returns the range of the &latex; command at the given cursor position. If no &latex; command is found, <literal>Range.invalid()</literal> is returned, which can be tested with <literal>Range.isValid()</literal>.
0967 </para></listitem>
0968 </varlistentry></variablelist>
0969 
0970 <variablelist><varlistentry>
0971 <term><synopsis>
0972 String document.charAt(<parameter>int <replaceable>line</replaceable></parameter>, <parameter>int <replaceable>column</replaceable></parameter>);
0973 String document.charAt(<parameter>Cursor <replaceable>cursor</replaceable></parameter>);
0974 </synopsis></term>
0975 <listitem><para>
0976 Returns the character at the given cursor position.
0977 </para></listitem>
0978 </varlistentry></variablelist>
0979 
0980 <variablelist><varlistentry>
0981 <term><synopsis>
0982 String document.firstChar(<parameter>int <replaceable>line</replaceable></parameter>);
0983 </synopsis></term>
0984 <listitem><para>
0985 Returns the first character in the given <parameter>line</parameter> that is not a whitespace. The first character is at column 0. If the line is empty or only contains whitespace characters, the returned string is empty.
0986 </para></listitem>
0987 </varlistentry></variablelist>
0988 
0989 <variablelist><varlistentry>
0990 <term><synopsis>
0991 String document.lastChar(<parameter>int <replaceable>line</replaceable></parameter>);
0992 </synopsis></term>
0993 <listitem><para>
0994 Returns the last character in the given <parameter>line</parameter> that is not a whitespace. If the line is empty or only contains whitespace characters, the returned string is empty.
0995 </para></listitem>
0996 </varlistentry></variablelist>
0997 
0998 <variablelist><varlistentry>
0999 <term><synopsis>
1000 bool document.isSpace(<parameter>int <replaceable>line</replaceable></parameter>, <parameter>int <replaceable>column</replaceable></parameter>);
1001 bool document.isSpace(<parameter>Cursor <replaceable>cursor</replaceable></parameter>);
1002 </synopsis></term>
1003 <listitem><para>
1004 Returns <literal>true</literal>, if the character at the given cursor position is a whitespace, otherwise <literal>false</literal>.
1005 </para></listitem>
1006 </varlistentry></variablelist>
1007 
1008 <variablelist><varlistentry>
1009 <term><synopsis>
1010 void document.insertBullet();
1011 </synopsis></term>
1012 <listitem><para>
1013         Insert a &kile; <emphasis>bullet</emphasis>. Remember that you can easily jump to the next or previous bullet. This will also highlight this bullet so that it will be deleted automatically, when you enter your first letter.
1014 </para></listitem>
1015 </varlistentry></variablelist>
1016 
1017 <variablelist><varlistentry>
1018 <term><synopsis>
1019 void document.nextBullet();
1020 </synopsis></term>
1021 <listitem><para>
1022 Jump to the next bullet in the text if there is one.
1023 </para></listitem>
1024 </varlistentry></variablelist>
1025 
1026 <variablelist><varlistentry>
1027 <term><synopsis>
1028 void document.previousBullet();
1029 </synopsis></term>
1030 <listitem><para>
1031 Jump to the previous bullet in the text if there is one.
1032 </para></listitem>
1033 </varlistentry></variablelist>
1034 
1035 <variablelist><varlistentry>
1036 <term><synopsis>
1037 bool document.hasEnvironment();
1038 </synopsis></term>
1039 <listitem><para>
1040 Returns  <literal>true</literal> if a surrounding &latex; environment is found, else <literal>false</literal>.
1041 </para></listitem>
1042 </varlistentry></variablelist>
1043 
1044 <variablelist><varlistentry>
1045 <term><synopsis>
1046 String document.environment(<parameter>bool <replaceable>inside = false</replaceable></parameter>);
1047 </synopsis></term>
1048 <listitem><para>
1049 Returns the entire text of the surrounding &latex; environment. If <parameter>inside</parameter> is <literal>false</literal>, the environment text including the surrounding &latex; tags <userinput>\begin{...}...\end{...}</userinput> will be returned, else without these tags. If no parameter is given, <parameter>inside</parameter> is set to <literal>false</literal>. If no environment is found, the returned string is empty.
1050 </para></listitem>
1051 </varlistentry></variablelist>
1052 
1053 <variablelist><varlistentry>
1054 <term><synopsis>
1055 Range document.environmentRange(<parameter>bool <replaceable>inside = false</replaceable></parameter>);
1056 </synopsis></term>
1057 <listitem><para>
1058 Returns the range of the surrounding &latex; environment. If <parameter>inside</parameter> is <literal>false</literal>, the range including the surrounding &latex; tags <userinput>\begin{...}...\end{...}</userinput> will be returned, else without these tags. If no parameter is given, <parameter>inside</parameter> is set to <literal>false</literal>. If no environment is found, <literal>Range.invalid()</literal> is returned, which can be tested with <literal>Range.isValid()</literal>.
1059 </para></listitem>
1060 </varlistentry></variablelist>
1061 
1062 <variablelist><varlistentry>
1063 <term><synopsis>
1064 String document.environmentName();
1065 </synopsis></term>
1066 <listitem><para>
1067 Returns the name of the surrounding &latex; environment or an empty string.
1068 </para></listitem>
1069 </varlistentry></variablelist>
1070 
1071 <variablelist><varlistentry>
1072 <term><synopsis>
1073 void document.removeEnvironment(<parameter>bool <replaceable>inside = false</replaceable></parameter>);
1074 </synopsis></term>
1075 <listitem><para>
1076 Removes the text of the surrounding &latex; environment. If <parameter>inside</parameter> is <literal>false</literal>, the environment text including the surrounding &latex; tags <userinput>\begin{...}...\end{...}</userinput> will be removed, else without these tags. If no parameter is given, <parameter>inside</parameter> is set to <literal>false</literal>.
1077 </para></listitem>
1078 </varlistentry></variablelist>
1079 
1080 <variablelist><varlistentry>
1081 <term><synopsis>
1082 void document.closeEnvironment();
1083 </synopsis></term>
1084 <listitem><para>
1085 Insert a closing environment tag, if an opened &latex; environment is found at the current cursor position.
1086 </para></listitem>
1087 </varlistentry></variablelist>
1088 
1089 <variablelist><varlistentry>
1090 <term><synopsis>
1091 void document.closeAllEnvironments();
1092 </synopsis></term>
1093 <listitem><para>
1094 Insert closing environment tags for all opened &latex; environments, which were found at the current cursor position.
1095 </para></listitem>
1096 </varlistentry></variablelist>
1097 
1098 <variablelist><varlistentry>
1099 <term><synopsis>
1100 bool document.hasTexgroup();
1101 </synopsis></term>
1102 <listitem><para>
1103 Returns  <literal>true</literal> if a surrounding &latex; group is found at the current cursor position, else <literal>false</literal>.
1104 </para></listitem>
1105 </varlistentry></variablelist>
1106 
1107 <variablelist><varlistentry>
1108 <term><synopsis>
1109 String document.texgroup(<parameter>bool <replaceable>inside = true</replaceable></parameter>);
1110 </synopsis></term>
1111 <listitem><para>
1112 Returns the text of the surrounding &latex; group. If <parameter>inside</parameter> is <literal>false</literal>, the text of this &latex; group including the surrounding braces <userinput>{...}</userinput> will be returned, else without them. If no parameter is given, <parameter>inside</parameter> is set to <literal>false</literal>. The returned string is empty, if no surrounding &latex; group is found at the current cursor position.
1113 </para></listitem>
1114 </varlistentry></variablelist>
1115 
1116 <variablelist><varlistentry>
1117 <term><synopsis>
1118 Range document.texgroupRange(<parameter>bool <replaceable>inside = true</replaceable></parameter>);
1119 </synopsis></term>
1120 <listitem><para>
1121 Returns the range of the surrounding &latex; group. If <parameter>inside</parameter> is <literal>false</literal>, the range including the surrounding braces <userinput>{...}</userinput> will be returned, else without them. If no parameter is given, <parameter>inside</parameter> is set to <literal>false</literal>. If no group is found, <literal>Range.invalid()</literal> is returned, which can be tested with <literal>Range.isValid()</literal>.
1122 </para></listitem>
1123 </varlistentry></variablelist>
1124 
1125 <variablelist><varlistentry>
1126 <term><synopsis>
1127 void document.removeTexgroup(<parameter>bool <replaceable>inside = true</replaceable></parameter>);
1128 </synopsis></term>
1129 <listitem><para>
1130 Removes the text of the surrounding &latex; group. If <parameter>inside</parameter> is <literal>false</literal>, the text of this &latex; group including the surrounding braces <userinput>{...}</userinput> will be removed, else without them. If no parameter is given, <parameter>inside</parameter> is set to <literal>false</literal>.
1131 </para></listitem>
1132 </varlistentry></variablelist>
1133 
1134 <variablelist><varlistentry>
1135 <term><synopsis>
1136 bool document.hasMathgroup();
1137 </synopsis></term>
1138 <listitem><para>
1139 Returns  <literal>true</literal> if a surrounding &latex; mathgroup is found at the current cursor position, else <literal>false</literal>.
1140 </para></listitem>
1141 </varlistentry></variablelist>
1142 
1143 <variablelist><varlistentry>
1144 <term><synopsis>
1145 String document.mathgroup();
1146 </synopsis></term>
1147 <listitem><para>
1148 Returns the text of the surrounding &latex; mathgroup. The returned string is empty, if no surrounding &latex; mathgroup is found at the current cursor position.
1149 </para></listitem>
1150 </varlistentry></variablelist>
1151 
1152 <variablelist><varlistentry>
1153 <term><synopsis>
1154 Range document.mathgroupRange();
1155 </synopsis></term>
1156 <listitem><para>
1157 Returns the range of the surrounding &latex; mathgroup. If there is no surrounding mathgroup, <literal>Range.invalid()</literal> is returned, which can be tested with <literal>Range.isValid()</literal>.
1158 </para></listitem>
1159 </varlistentry></variablelist>
1160 
1161 <variablelist><varlistentry>
1162 <term><synopsis>
1163 void document.removeMathgroup();
1164 </synopsis></term>
1165 <listitem><para>
1166 Removes the text of the surrounding &latex; mathgroup.
1167 </para></listitem>
1168 </varlistentry></variablelist>
1169 
1170 <variablelist><varlistentry>
1171 <term><synopsis>
1172 String document.paragraph();
1173 </synopsis></term>
1174 <listitem><para>
1175 Returns the text of the current &latex; paragraph.
1176 </para></listitem>
1177 </varlistentry></variablelist>
1178 
1179 <variablelist><varlistentry>
1180 <term><synopsis>
1181 Range document.paragraphRange();
1182 </synopsis></term>
1183 <listitem><para>
1184 Returns the range of the surrounding &latex; paragraph.
1185 </para></listitem>
1186 </varlistentry></variablelist>
1187 
1188 <variablelist><varlistentry>
1189 <term><synopsis>
1190 void document.removeParagraph();
1191 </synopsis></term>
1192 <listitem><para>
1193 Removes the text of the current &latex; paragraph.
1194 </para></listitem>
1195 </varlistentry></variablelist>
1196 
1197 <variablelist><varlistentry>
1198 <term><synopsis>
1199 bool document.matchesAt(<parameter>int <replaceable>line</replaceable></parameter>, <parameter>int <replaceable>column</replaceable></parameter>, <parameter>String <replaceable>text</replaceable></parameter>);
1200 bool document.matchesAt(<parameter>Cursor <replaceable>cursor</replaceable></parameter>, <parameter>String <replaceable>text</replaceable></parameter>);
1201 </synopsis></term>
1202 <listitem><para>
1203 Returns <literal>true</literal>, if the given <parameter>text</parameter> matches at the corresponding cursor position, otherwise <literal>false</literal>.
1204 </para></listitem>
1205 </varlistentry></variablelist>
1206 
1207 <variablelist><varlistentry>
1208 <term><synopsis>
1209 bool document.startsWith(<parameter>int <replaceable>line</replaceable></parameter>, <parameter>String <replaceable>pattern</replaceable></parameter>, <parameter>bool <replaceable>skipWhiteSpaces = true</replaceable></parameter>);
1210 </synopsis></term>
1211 <listitem><para>
1212 Returns <literal>true</literal>, if the line starts with <parameter>pattern</parameter>, otherwise <literal>false</literal>. The argument <parameter>skipWhiteSpaces</parameter> controls whether leading whitespaces are ignored.
1213 </para></listitem>
1214 </varlistentry></variablelist>
1215 
1216 <variablelist><varlistentry>
1217 <term><synopsis>
1218 bool document.endsWith(<parameter>int <replaceable>line</replaceable></parameter>, <parameter>String <replaceable>pattern</replaceable></parameter>, <parameter>bool <replaceable>skipWhiteSpaces = true</replaceable></parameter>);
1219 </synopsis></term>
1220 <listitem><para>
1221 Returns <literal>true</literal>, if the line ends with <parameter>pattern</parameter>, otherwise <literal>false</literal>. The argument <parameter>skipWhiteSpaces</parameter> controls whether trailing whitespaces are ignored.
1222 </para></listitem>
1223 </varlistentry></variablelist>
1224 
1225 <variablelist><varlistentry>
1226 <term><synopsis>
1227 int document.firstColumn(<parameter>int <replaceable>line</replaceable></parameter>);
1228 </synopsis></term>
1229 <listitem><para>
1230 Returns the first non-whitespace column in the given <parameter>line</parameter>. If there are only whitespaces in the line, the return value is <literal>-1</literal>.
1231 </para></listitem>
1232 </varlistentry></variablelist>
1233 
1234 <variablelist><varlistentry>
1235 <term><synopsis>
1236 int document.lastColumn(<parameter>int <replaceable>line</replaceable></parameter>);
1237 </synopsis></term>
1238 <listitem><para>
1239 Returns the last non-whitespace column in the given <parameter>line</parameter>. If there are only whitespaces in the line, the return value is <literal>-1</literal>.
1240 </para></listitem>
1241 </varlistentry></variablelist>
1242 
1243 <variablelist><varlistentry>
1244 <term><synopsis>
1245 int document.prevNonSpaceColumn(<parameter>int <replaceable>line</replaceable></parameter>, <parameter>int <replaceable>column</replaceable></parameter>);
1246 int document.prevNonSpaceColumn(<parameter>Cursor <replaceable>cursor</replaceable></parameter>);
1247 </synopsis></term>
1248 <listitem><para>
1249 Returns the column with a non-whitespace character starting at the given cursor position and searching backwards.
1250 </para></listitem>
1251 </varlistentry></variablelist>
1252 
1253 <variablelist><varlistentry>
1254 <term><synopsis>
1255 int document.nextNonSpaceColumn(<parameter>int <replaceable>line</replaceable></parameter>, <parameter>int <replaceable>column</replaceable></parameter>);
1256 int document.nextNonSpaceColumn(<parameter>Cursor <replaceable>cursor</replaceable></parameter>);
1257 </synopsis></term>
1258 <listitem><para>
1259 Returns the column with a non-whitespace character starting at the given cursor position and searching forwards.
1260 </para></listitem>
1261 </varlistentry></variablelist>
1262 
1263 <variablelist><varlistentry>
1264 <term><synopsis>
1265 int document.prevNonEmptyLine(<parameter>int <replaceable>line</replaceable></parameter>);
1266 </synopsis></term>
1267 <listitem><para>
1268 Returns the next non-empty line containing non-whitespace characters searching backwards.
1269 </para></listitem>
1270 </varlistentry></variablelist>
1271 
1272 <variablelist><varlistentry>
1273 <term><synopsis>
1274 int document.nextNonEmptyLine(<parameter>int <replaceable>line</replaceable></parameter>);
1275 </synopsis></term>
1276 <listitem><para>
1277 Returns the next non-empty line containing non-whitespace characters searching forwards.
1278 </para></listitem>
1279 </varlistentry></variablelist>
1280 
1281 <variablelist><varlistentry>
1282 <term><synopsis>
1283 void document.gotoBeginEnv();
1284 </synopsis></term>
1285 <listitem><para>
1286 Go to the start of a surrounding &latex; environment.
1287 </para></listitem>
1288 </varlistentry></variablelist>
1289 
1290 <variablelist><varlistentry>
1291 <term><synopsis>
1292 void document.gotoEndEnv();
1293 </synopsis></term>
1294 <listitem><para>
1295 Go to the end of a surrounding &latex; environment.
1296 </para></listitem>
1297 </varlistentry></variablelist>
1298 
1299 <variablelist><varlistentry>
1300 <term><synopsis>
1301 void document.gotoBeginTexgroup();
1302 </synopsis></term>
1303 <listitem><para>
1304 Go to the start of a surrounding &latex; group.
1305 </para></listitem>
1306 </varlistentry></variablelist>
1307 
1308 <variablelist><varlistentry>
1309 <term><synopsis>
1310 void document.gotoEndTexgroup();
1311 </synopsis></term>
1312 <listitem><para>
1313 Go to the end of a surrounding &latex; group.
1314 </para></listitem>
1315 </varlistentry></variablelist>
1316 
1317 <variablelist><varlistentry>
1318 <term><synopsis>
1319 void document.gotoNextParagraph();
1320 </synopsis></term>
1321 <listitem><para>
1322 Go to the next &latex; paragraph.
1323 </para></listitem>
1324 </varlistentry></variablelist>
1325 
1326 <variablelist><varlistentry>
1327 <term><synopsis>
1328 void document.gotoPrevParagraph();
1329 </synopsis></term>
1330 <listitem><para>
1331 Go to the previous &latex; paragraph.
1332 </para></listitem>
1333 </varlistentry></variablelist>
1334 
1335 <variablelist><varlistentry>
1336 <term><synopsis>
1337 void document.gotoNextSectioning();
1338 </synopsis></term>
1339 <listitem><para>
1340 Go to the next &latex; section.
1341 </para></listitem>
1342 </varlistentry></variablelist>
1343 
1344 <variablelist><varlistentry>
1345 <term><synopsis>
1346 void document.gotoPrevSectioning();
1347 </synopsis></term>
1348 <listitem><para>
1349 Go to the previous &latex; section.
1350 </para></listitem>
1351 </varlistentry></variablelist>
1352 
1353 <variablelist><varlistentry>
1354 <term><synopsis>
1355 void document.gotoLine(<parameter>int <replaceable>line</replaceable></parameter>);
1356 </synopsis></term>
1357 <listitem><para>
1358         Go to the given <literal>line</literal>.
1359 </para></listitem>
1360 </varlistentry></variablelist>
1361 
1362 <variablelist><varlistentry>
1363 <term><synopsis>
1364 void document.insertChapter();
1365 </synopsis></term>
1366 <listitem><para>
1367 Insert a <userinput>\chapter</userinput> command (see also <literal>document.insertSection()</literal>).
1368 </para></listitem>
1369 </varlistentry></variablelist>
1370 
1371 <variablelist><varlistentry>
1372 <term><synopsis>
1373 void document.insertSection();
1374 </synopsis></term>
1375 <listitem><para>
1376 Insert a <userinput>\section</userinput> command. As with choosing the menu entry <menuchoice><guimenu>LaTeX</guimenu><guisubmenu>Sectioning</guisubmenu><guimenuitem>section</guimenuitem></menuchoice> a dialog will appear, where you can choose the title and an optional label for this sectioning command.
1377 <screenshot>
1378         <screeninfo>Dialog: insert chapter command</screeninfo>
1379         <mediaobject>
1380         <imageobject>
1381         <imagedata fileref="dialog-insertsection.png" format="PNG" />
1382         </imageobject>
1383         <textobject>
1384                 <phrase>Dialog: insert chapter command</phrase>
1385         </textobject>
1386         </mediaobject>
1387 </screenshot>
1388 </para></listitem>
1389 </varlistentry></variablelist>
1390 
1391 <variablelist><varlistentry>
1392 <term><synopsis>
1393 void document.insertSubsection();
1394 </synopsis></term>
1395 <listitem><para>
1396 Insert a <userinput>\subsection</userinput> command (see also <literal>document.insertSection()</literal>).
1397 </para></listitem>
1398 </varlistentry></variablelist>
1399 
1400 <variablelist><varlistentry>
1401 <term><synopsis>
1402 void document.insertSubsubsection();
1403 </synopsis></term>
1404 <listitem><para>
1405 Insert a <userinput>\subsubsection</userinput> command (see also <literal>document.insertSection()</literal>).
1406 </para></listitem>
1407 </varlistentry></variablelist>
1408 
1409 <variablelist><varlistentry>
1410 <term><synopsis>
1411 void document.insertParagraph();
1412 </synopsis></term>
1413 <listitem><para>
1414 Insert a <userinput>\paragraph</userinput> command (see also <literal>document.insertSection()</literal>).
1415 </para></listitem>
1416 </varlistentry></variablelist>
1417 
1418 <variablelist><varlistentry>
1419 <term><synopsis>
1420 void document.insertSubparagraph();
1421 </synopsis></term>
1422 <listitem><para>
1423 Insert a <userinput>\subparagraph</userinput> command (see also <literal>document.insertSection()</literal>).
1424 </para></listitem>
1425 </varlistentry></variablelist>
1426 
1427 <variablelist><varlistentry>
1428 <term><synopsis>
1429 void document.insertLabel();
1430 </synopsis></term>
1431 <listitem><para>
1432 Insert a <userinput>\label</userinput> command.
1433 </para></listitem>
1434 </varlistentry></variablelist>
1435 
1436 <variablelist><varlistentry>
1437 <term><synopsis>
1438 void document.insertReference();
1439 </synopsis></term>
1440 <listitem><para>
1441 Insert a <userinput>\ref</userinput> command. As with choosing the menu entry <menuchoice><guimenu>&latex;</guimenu><guisubmenu>References</guisubmenu><guimenuitem>ref</guimenuitem></menuchoice> a dialog will appear, where you can choose from already defined labels, which are listed in a combobox.
1442 <screenshot>
1443         <screeninfo>Dialog: insert a reference command</screeninfo>
1444         <mediaobject>
1445         <imageobject>
1446         <imagedata fileref="dialog-insertreference.png" format="PNG" />
1447         </imageobject>
1448         <textobject>
1449                 <phrase>Dialog: insert a reference command</phrase>
1450         </textobject>
1451         </mediaobject>
1452 </screenshot>
1453 </para></listitem>
1454 </varlistentry></variablelist>
1455 
1456 <variablelist><varlistentry>
1457 <term><synopsis>
1458 void document.insertPageref();
1459 </synopsis></term>
1460 <listitem><para>
1461 Insert a <userinput>\pageref</userinput> command (see also <literal>document.insertReference()</literal>).
1462 </para></listitem>
1463 </varlistentry></variablelist>
1464 
1465 
1466 <variablelist><varlistentry>
1467 <term><synopsis>
1468 void document.insertCitation();
1469 </synopsis></term>
1470 <listitem><para>
1471 Insert a <userinput>\cite</userinput> command.
1472 </para></listitem>
1473 </varlistentry></variablelist>
1474 
1475 <variablelist><varlistentry>
1476 <term><synopsis>
1477 void document.insertIndex();
1478 </synopsis></term>
1479 <listitem><para>
1480 Insert a <userinput>\index</userinput> command.
1481 </para></listitem>
1482 </varlistentry></variablelist>
1483 
1484 <variablelist><varlistentry>
1485 <term><synopsis>
1486 void document.insertFootnote();
1487 </synopsis></term>
1488 <listitem><para>
1489 Insert a <userinput>\footnote</userinput> command.
1490 </para></listitem>
1491 </varlistentry></variablelist>
1492 
1493 <variablelist><varlistentry>
1494 <term><synopsis>
1495 void document.comment();
1496 </synopsis></term>
1497 <listitem><para>
1498 Inserts comment markers to make the selection or current line a comment.
1499 </para></listitem>
1500 </varlistentry></variablelist>
1501 
1502 <variablelist><varlistentry>
1503 <term><synopsis>
1504 void document.uncomment();
1505 </synopsis></term>
1506 <listitem><para>
1507 Removes comment markers from the selection or current line.
1508 </para></listitem>
1509 </varlistentry></variablelist>
1510 
1511 <variablelist><varlistentry>
1512 <term><synopsis>
1513 void document.uppercase();
1514 </synopsis></term>
1515 <listitem><para>
1516 Put the selected text or the letter after the cursor in uppercase.
1517 </para></listitem>
1518 </varlistentry></variablelist>
1519 
1520 <variablelist><varlistentry>
1521 <term><synopsis>
1522 void document.lowercase();
1523 </synopsis></term>
1524 <listitem><para>
1525 Put the selected text or the letter after the cursor in lowercase.
1526 </para></listitem>
1527 </varlistentry></variablelist>
1528 
1529 <variablelist><varlistentry>
1530 <term><synopsis>
1531 void document.capitalize();
1532 </synopsis></term>
1533 <listitem><para>
1534 Capitalize the selected text or the current word.
1535 </para></listitem>
1536 </varlistentry></variablelist>
1537 
1538 <variablelist><varlistentry>
1539 <term><synopsis>
1540 void document.joinLines();
1541 </synopsis></term>
1542 <listitem><para>
1543 Joins the lines of the current selection. Two succeeding text lines are always separated with a single space.
1544 </para></listitem>
1545 </varlistentry></variablelist>
1546 
1547 <variablelist><varlistentry>
1548 <term><synopsis>
1549 void document.insertIntelligentNewline();
1550 </synopsis></term>
1551 <listitem><para>
1552 Insert a smart newline (see <xref linkend="editing_smartnewline" role="select: title pageabbrv"/>).
1553 </para></listitem>
1554 </varlistentry></variablelist>
1555 
1556 <variablelist><varlistentry>
1557 <term><synopsis>
1558 void document.insertIntelligentTabulator();
1559 </synopsis></term>
1560 <listitem><para>
1561 Insert a smart tabulator (see <xref linkend="editing_tabulator" role="select: title pageabbrv"/>).
1562 </para></listitem>
1563 </varlistentry></variablelist>
1564 
1565 <variablelist><varlistentry>
1566 <term><synopsis>
1567 void document.editBegin();
1568 </synopsis></term>
1569 <listitem><para>
1570 Starts an edit group for undo/redo grouping. Make sure to always call <function>editEnd()</function> as often as you call <function>editBegin()</function>. Calling <function>editBegin()</function> internally uses a reference counter, i.e., this call can be nested.
1571 </para></listitem>
1572 </varlistentry></variablelist>
1573 
1574 <variablelist><varlistentry>
1575 <term><synopsis>
1576 void document.editEnd();
1577 </synopsis></term>
1578 <listitem><para>
1579 Ends an edit group. The last call of <function>editEnd()</function> (i.e. the one for the first call of <function>editBegin()</function>) finishes the edit step.
1580 </para></listitem>
1581 </varlistentry></variablelist>
1582 
1583 <variablelist><varlistentry>
1584 <term><synopsis>
1585 StringList document.labelList();
1586 </synopsis></term>
1587 <listitem><para>
1588 Returns all defined labels as a <literal>StringList</literal>, which can be used in &javascript; as an array of strings.
1589 </para></listitem>
1590 </varlistentry></variablelist>
1591 
1592 <variablelist><varlistentry>
1593 <term><synopsis>
1594 StringList document.bibitemList();
1595 </synopsis></term>
1596 <listitem><para>
1597 Returns all defined bibitems as a <literal>StringList</literal>, which can be used in &javascript; as an array of strings.
1598 </para></listitem>
1599 </varlistentry></variablelist>
1600 
1601 <variablelist><varlistentry>
1602 <term><synopsis>
1603 void document.refreshStructure();
1604 </synopsis></term>
1605 <listitem><para>
1606 Refresh the structure view (see <xref linkend="navigating" role="select: title pageabbrv"/>).
1607 </para></listitem>
1608 </varlistentry></variablelist>
1609 
1610 </sect2>
1611 
1612 
1613 <sect2 id="id_scripting_api_kile">
1614 <title>The &kile; API</title>
1615 
1616 <para>The global object (variable) <userinput>kile</userinput> is used to handle top level interactions with the outside world, input message and dialog interfaces. These API calls are divided into subobjects to structure this part of the scripting API. Conceptually <userinput>kile</userinput> is a bit like <userinput>window</userinput> in a browser API.
1617 <itemizedlist>
1618 <listitem><para><literal>kile.alert</literal>: &nbsp; message boxes</para></listitem>
1619 <listitem><para><literal>kile.input</literal>: &nbsp; get user input</para></listitem>
1620 <listitem><para><literal>kile.wizard</literal>: &nbsp; call one of &kile;'s wizards</para></listitem>
1621 <listitem><para><literal>kile.script</literal>: &nbsp; get info about a running script</para></listitem>
1622 <listitem><para><literal>kile.file</literal>: &nbsp; file operations like read and write.</para></listitem>
1623 </itemizedlist>
1624 </para>
1625 
1626 
1627 <sect3 id="id_scripting_api_kile_alert">
1628 <title>Alert</title>
1629 
1630 <variablelist><varlistentry>
1631 <term><synopsis>
1632 void kile.alert.information(<parameter>String <replaceable>text</replaceable></parameter>, <parameter>String <replaceable>caption</replaceable></parameter>);
1633 </synopsis></term>
1634 <listitem><para>
1635 Display an <emphasis>Information</emphasis> dialog. <parameter>text</parameter> is the message string and <parameter>caption</parameter> the title of the message box. The default title is the script name.
1636 </para></listitem>
1637 </varlistentry></variablelist>
1638 
1639 <variablelist><varlistentry>
1640 <term><synopsis>
1641 void kile.alert.sorry(<parameter>String <replaceable>text</replaceable></parameter>, <parameter>String <replaceable>caption</replaceable></parameter>);
1642 </synopsis></term>
1643 <listitem><para>
1644 Display a <emphasis>Sorry</emphasis> dialog. <parameter>text</parameter> is the message string and <parameter>caption</parameter> the title of the message box. The default title is the script name.
1645 </para></listitem>
1646 </varlistentry></variablelist>
1647 
1648 <variablelist><varlistentry>
1649 <term><synopsis>
1650 void kile.alert.error(<parameter>String <replaceable>text</replaceable></parameter>, <parameter>String <replaceable>caption</replaceable></parameter>);
1651 </synopsis></term>
1652 <listitem><para>
1653 Display an <emphasis>Error</emphasis> dialog. <parameter>text</parameter> is the message string and <parameter>caption</parameter> the title of the message box. The default title is the script name.
1654 </para></listitem>
1655 </varlistentry></variablelist>
1656 
1657 <variablelist><varlistentry>
1658 <term><synopsis>
1659 String kile.alert.question(<parameter>String <replaceable>text</replaceable></parameter>, <parameter>String <replaceable>caption</replaceable></parameter>);
1660 </synopsis></term>
1661 <listitem><para>
1662 Display a simple <emphasis>question</emphasis> dialog. <parameter>text</parameter> is the message string and <parameter>caption</parameter> the title of the message box. The default title is the script name. The returned string is either <literal>yes</literal> or <literal>no</literal>.
1663 </para></listitem>
1664 </varlistentry></variablelist>
1665 
1666 <variablelist><varlistentry>
1667 <term><synopsis>
1668 String kile.alert.warning(<parameter>String <replaceable>text</replaceable></parameter>, <parameter>String <replaceable>caption</replaceable></parameter>);
1669 </synopsis></term>
1670 <listitem><para>
1671 Display a simple <emphasis>warning</emphasis> dialog. <parameter>text</parameter> is the message string and <parameter>caption</parameter> the title of the message box. The default title is the script name. The returned string is either <literal>continue</literal> or <literal>cancel</literal>.
1672 </para></listitem>
1673 </varlistentry></variablelist>
1674 </sect3>
1675 
1676 
1677 <sect3 id="id_scripting_api_kile_input">
1678 <title>Input</title>
1679 
1680 <variablelist><varlistentry>
1681 <term><synopsis>
1682 String kile.input.getListboxItem(<parameter>String <replaceable>caption</replaceable></parameter>, <parameter>String <replaceable>label</replaceable></parameter>, <parameter>StringList <replaceable>list</replaceable></parameter>);
1683 </synopsis></term>
1684 <listitem><para>
1685 Function to let the user select an item from a list, which is shown as a listbox. <parameter>caption</parameter> is the text that is displayed in the title bar, <parameter>label</parameter> is the text that appears as the label for the list and <parameter>list</parameter> is the string list which is inserted into the list.
1686 </para></listitem>
1687 </varlistentry></variablelist>
1688 
1689 <variablelist><varlistentry>
1690 <term><synopsis>
1691 String kile.input.getComboboxItem(<parameter>String <replaceable>caption</replaceable></parameter>, <parameter>String <replaceable>label</replaceable></parameter>, <parameter>StringList <replaceable>list</replaceable></parameter>);
1692 </synopsis></term>
1693 <listitem><para>
1694 Function to let the user select an item from a list, which is shown as a combobox. <parameter>caption</parameter> is the text that is displayed in the title bar, <parameter>label</parameter> is the text that appears as the label for the list and <parameter>list</parameter> is the string list which is inserted into the list.
1695 </para></listitem>
1696 </varlistentry></variablelist>
1697 
1698 <variablelist><varlistentry>
1699 <term><synopsis>
1700 String kile.input.getText(<parameter>String <replaceable>caption</replaceable></parameter>, <parameter>String <replaceable>label</replaceable></parameter>);
1701 </synopsis></term>
1702 <listitem><para>
1703 Function to get a string from the user. <parameter>caption</parameter> is the text that is displayed in the title bar and <parameter>label</parameter> the text that appears as a label for the line edit.
1704 </para></listitem>
1705 </varlistentry></variablelist>
1706 
1707 <variablelist><varlistentry>
1708 <term><synopsis>
1709 String kile.input.getLatexCommand(<parameter>String <replaceable>caption</replaceable></parameter>, <parameter>String <replaceable>label</replaceable></parameter>);
1710 </synopsis></term>
1711 <listitem><para>
1712 Function to get a &latex; command from the user. This means that only lower- and uppercase letters are allowed. <parameter>caption</parameter> is the text that is displayed in the title bar and <parameter>label</parameter> the text that appears as a label for the line edit.
1713 </para></listitem>
1714 </varlistentry></variablelist>
1715 
1716 <variablelist><varlistentry>
1717 <term><synopsis>
1718 int kile.input.getInteger(<parameter>String <replaceable>caption</replaceable></parameter>, <parameter>String <replaceable>label</replaceable></parameter>, <parameter>int <replaceable>min = INT_MIN</replaceable></parameter>, <parameter>int <replaceable>max = INT_MAX</replaceable></parameter>);
1719 </synopsis></term>
1720 <listitem><para>
1721 Function to get an integer from the user. <parameter>caption</parameter> is the text that is displayed in the title bar. <parameter>label</parameter> is the text that appears as the label for the spin box. <parameter>min</parameter> and <parameter>max</parameter> are the minimum and maximum allowable values the user may choose. Default values are <literal>INT_MIN</literal> and <literal>INT_MAX</literal>.
1722 </para></listitem>
1723 </varlistentry></variablelist>
1724 
1725 <variablelist><varlistentry>
1726 <term><synopsis>
1727 int kile.input.getPosInteger(<parameter>String <replaceable>caption</replaceable></parameter>, <parameter>String <replaceable>label</replaceable></parameter>, <parameter>int <replaceable>min = 1</replaceable></parameter>, <parameter>int <replaceable>max = INT_MAX</replaceable></parameter>);
1728 </synopsis></term>
1729 <listitem><para>
1730 Function to get a positive integer from the user. <parameter>caption</parameter> is the text that is displayed in the title bar. <parameter>label</parameter> is the text that appears as the label for the spin box. <parameter>min</parameter> and <parameter>max</parameter> are the minimum and maximum allowable values the user may choose. Default values are <literal>1</literal> and <literal>INT_MAX</literal>.
1731 </para></listitem>
1732 </varlistentry></variablelist>
1733 </sect3>
1734 
1735 
1736 <sect3 id="id_scripting_api_kile_wizard">
1737 <title>Wizard</title>
1738 
1739 <variablelist><varlistentry>
1740 <term><synopsis>
1741 void kile.wizard.tabular();
1742 </synopsis></term>
1743 <listitem><para>
1744 Calls the <emphasis>Tabular wizard</emphasis>, which helps to write a tabular environment (see <xref linkend="wizard_array" role="select: title pageabbrv"/>).
1745 </para></listitem>
1746 </varlistentry></variablelist>
1747 
1748 <variablelist><varlistentry>
1749 <term><synopsis>
1750 void kile.wizard.array();
1751 </synopsis></term>
1752 <listitem><para>
1753 Calls the <emphasis>Array wizard</emphasis>, which helps to write an array environment (see <xref linkend="wizard_array" role="select: title pageabbrv"/>).
1754 </para></listitem>
1755 </varlistentry></variablelist>
1756 
1757 <variablelist><varlistentry>
1758 <term><synopsis>
1759 void kile.wizard.tabbing();
1760 </synopsis></term>
1761 <listitem><para>
1762 Calls the <emphasis>Tabbing wizard</emphasis>, which helps to write a tabbing environment (see <xref linkend="wizard_array" role="select: title pageabbrv"/>).
1763 </para></listitem>
1764 </varlistentry></variablelist>
1765 
1766 <variablelist><varlistentry>
1767 <term><synopsis>
1768 void kile.wizard.floatEnvironment();
1769 </synopsis></term>
1770 <listitem><para>
1771 Calls the <emphasis>Floats wizard</emphasis>, which helps to insert floating elements (see <xref linkend="wizard_float" role="select: title pageabbrv"/>).
1772 </para></listitem>
1773 </varlistentry></variablelist>
1774 
1775 <variablelist><varlistentry>
1776 <term><synopsis>
1777 void kile.wizard.mathEnvironment();
1778 </synopsis></term>
1779 <listitem><para>
1780 Calls the <emphasis>Math wizard</emphasis>, which helps to insert math environments (see <xref linkend="wizard_math" role="select: title pageabbrv"/>).
1781 </para></listitem>
1782 </varlistentry></variablelist>
1783 
1784 <variablelist><varlistentry>
1785 <term><synopsis>
1786 void kile.wizard.postscript();
1787 </synopsis></term>
1788 <listitem><para>
1789 Calls the <emphasis>Postscript Tools wizard</emphasis>, which may help to manipulate or rearrange Postscript documents (see <xref linkend="wizard_postscript" role="select: title pageabbrv"/>).
1790 </para></listitem>
1791 </varlistentry></variablelist>
1792 </sect3>
1793 
1794 
1795 <sect3 id="id_scripting_api_kile_script">
1796 <title>Script</title>
1797 
1798 <variablelist><varlistentry>
1799 <term><synopsis>
1800 String kile.script.name();
1801 </synopsis></term>
1802 <listitem><para>
1803 Returns the basename of a running script (without path and extension).
1804 </para></listitem>
1805 </varlistentry></variablelist>
1806 
1807 <variablelist><varlistentry>
1808 <term><synopsis>
1809 String kile.script.caption();
1810 </synopsis></term>
1811 <listitem><para>
1812 Returns a string, which can be used as a caption of alert boxes. It looks like <userinput>Script: scriptname.js</userinput>.
1813 </para></listitem>
1814 </varlistentry></variablelist>
1815 </sect3>
1816 
1817 
1818 <sect3 id="id_scripting_api_kile_file">
1819 <title>File</title>
1820 
1821 <variablelist><varlistentry>
1822 <term><synopsis>
1823 Object kile.file.read(<parameter>String <replaceable>filename</replaceable></parameter>);
1824 </synopsis></term>
1825 <listitem><para>
1826 Read the contents of a text file. It is used like
1827 </para><para>
1828 Example: <function>var res = kile.file.read("path/to/file.txt");</function>
1829 </para><para>
1830 The return value <userinput>res</userinput> is an object (better: a map) with three properties:
1831 </para><para>
1832 <itemizedlist>
1833 <listitem><para><guilabel>status:</guilabel>&nbsp; Gives the status code of the operation, which can be 0 (no error), 1 (access failed) or 2 (access denied). So, if no error occurred, the value of <userinput>res.status</userinput> or <userinput>res["status"]</userinput> will be 0.</para></listitem>
1834 <listitem><para><guilabel>result:</guilabel>&nbsp; Contains the text of the given file.</para></listitem>
1835 <listitem><para><guilabel>message:</guilabel>&nbsp; Contains an error message, if an error occurred.</para></listitem>
1836 </itemizedlist>
1837 </para></listitem>
1838 </varlistentry></variablelist>
1839 
1840 <variablelist><varlistentry>
1841 <term><synopsis>
1842 Object kile.file.read();
1843 </synopsis></term>
1844 <listitem><para>
1845 The same as <literal>read(filename)</literal>, but no filename is given. A dialog will appear to select the file to read.
1846 </para></listitem>
1847 </varlistentry></variablelist>
1848 
1849 <variablelist><varlistentry>
1850 <term><synopsis>
1851 Object kile.file.write(<parameter>String <replaceable>filename</replaceable></parameter>, <parameter>String <replaceable>text</replaceable></parameter>);
1852 </synopsis></term>
1853 <listitem><para>
1854 Write the given text into a file. It is used like
1855 </para><para>
1856 Example: <function>var res = kile.file.write("path/to/file.txt","Some text...");</function>
1857 </para><para>
1858 The return value <userinput>res</userinput> is an object (better: a map) with two properties: <literal>status</literal> and <literal>message</literal> (see <literal>read()</literal> for more information).
1859 </para></listitem>
1860 </varlistentry></variablelist>
1861 
1862 <variablelist><varlistentry>
1863 <term><synopsis>
1864 Object kile.file.write(<parameter>String <replaceable>text</replaceable></parameter>);
1865 </synopsis></term>
1866 <listitem><para>
1867 The same as <literal>write(filename,text)</literal>, but no filename is given. A dialog will appear to choose a filename.
1868 </para></listitem>
1869 </varlistentry></variablelist>
1870 
1871 <variablelist><varlistentry>
1872 <term><synopsis>
1873 String kile.file.getOpenFileName(<parameter>String <replaceable>startDir</replaceable></parameter>, <parameter>String <replaceable>filter</replaceable></parameter>);
1874 </synopsis></term>
1875 <listitem><para>
1876 Creates a modal file dialog and return the selected filename or an empty string if none is chosen. Note that with this method the user must select an existing filename.
1877 </para><para>
1878 Parameters:
1879 </para><para>
1880 <itemizedlist>
1881 <listitem><para><guilabel>startDir:</guilabel>&nbsp; Starting directory of the open dialog.</para></listitem>
1882 <listitem><para><guilabel>filter:</guilabel>&nbsp; A shell glob or a mime-type-filter that specifies which files to display. Refer to the KFileDialog documentation for more information on this parameter.</para></listitem>
1883 </itemizedlist>
1884 </para><para>
1885 Both parameters are optional. If you omit <literal>filter</literal>, all files will be displayed. If additionally <literal>startDir</literal> is omitted, the dialog will take the current document directory as starting point.
1886 </para></listitem>
1887 </varlistentry></variablelist>
1888 
1889 <variablelist><varlistentry>
1890 <term><synopsis>
1891 String kile.file.getSaveFileName(<parameter>String <replaceable>startDir</replaceable></parameter>, <parameter>String <replaceable>filter</replaceable></parameter>);
1892 </synopsis></term>
1893 <listitem><para>
1894 Creates a modal file dialog and returns the selected filename or an empty string if none is chosen. Note that with this method the user need not select an existing filename.
1895 See <literal>getOpenFileName()</literal> for an explanation of the parameters.
1896 </para></listitem>
1897 </varlistentry></variablelist>
1898 
1899 </sect3>
1900 
1901 </sect2>
1902 
1903 </sect1>
1904 
1905 
1906 <sect1 id="id_scripting_examples">
1907 <title>Examples</title>
1908 
1909 <para>Some examples may help you to understand how to use the scripting API. These examples and some more are found in the scripting directory of &kile;: <filename>KILE_APP_DIR/scripts/</filename>. Each script contains a short description.</para>
1910 
1911 <sect2 id="id_scripting_example1">
1912 <title>Example 1: replace environment name</title>
1913 
1914 <para>Replace a surrounding &latex; environment with another, where the relative cursor position will not be changed. <userinput>\begin{abc}...\end{abc}</userinput> for example can be changed to <userinput>\begin{xyz}...\end{xyz}</userinput>.</para>
1915 
1916 <programlisting>
1917 var range = document.environmentRange(false);
1918 if ( range.isValid() ) {
1919         var envname = kile.input.getLatexCommand("Enter Environment","New environment name:");
1920         if ( envname != '' ) {
1921                 replaceEnvCommand(envname,range);
1922         }
1923 }
1924 else {
1925         kile.alert.sorry("No surrounding LaTeX environment found.");
1926 }
1927 
1928 function replaceEnvCommand(newEnv,r)
1929 {
1930         var c = view.cursorPosition();
1931 
1932         var envname = document.environmentName();
1933 
1934         if ( envname != "" ) {
1935                 var beginRange = new Range(r.start,new Cursor(r.start.line,r.start.column+8+envname.length));
1936                 var endRange = new Range(new Cursor(r.end.line,r.end.column-6-envname.length),r.end);
1937 
1938                 document.editBegin();
1939                 document.replaceText(endRange,"\\end{"+newEnv+"}");
1940                 document.replaceText(beginRange,"\\begin{"+newEnv+"}");
1941                 document.editEnd();
1942         }
1943 }
1944 </programlisting>
1945 </sect2>
1946 
1947 <sect2 id="id_scripting_example2">
1948 <title>Example 2: replace a &latex; font command</title>
1949 
1950 <para>Replace a surrounding &latex; font command with another font command, when the cursor is placed inside the texgroup. The relative cursor position will not be changed. <userinput>\textbf{abc}</userinput> for example can be changed to <userinput>\textit{abc}</userinput>.</para>
1951 
1952 <programlisting>
1953 var fontCommands = new Array("\\textbf","\\textit","\\textsl","\\texttt",
1954                              "\\textsc","\\textrm","\\textsf","\\emph");
1955 
1956 var range = document.texgroupRange(false);
1957 if ( range.isValid() ) {
1958         replaceFontCommand(range);
1959 }
1960 else {
1961         kile.alert.sorry("No surrounding TeX group found.");
1962 }
1963 
1964 function replaceFontCommand(r)
1965 {
1966         var c = view.cursorPosition();
1967 
1968         document.editBegin();
1969         view.setCursorPosition(r.start);
1970         var cmd = document.latexCommand();
1971         var index = fontCommands.indexOf(cmd);
1972         if ( index >= 0 ) {
1973                 var cmdRange = document.latexCommandRange();
1974                 if ( cmdRange.isValid() ) {
1975                         var newcommand = kile.input.getListboxItem("Choose",
1976                                                     "Choose font command:",buildCmdList(cmd));
1977                         if ( newcommand != "" ) {
1978                                 document.replaceText(cmdRange,newcommand);
1979                                 c.column = c.column - (cmd.length - newcommand.length);
1980                         }
1981                 }
1982 /               view.setCursorPosition(c);
1983         }
1984         else {
1985                 kile.alert.sorry("No surrounding font command found.");
1986         }
1987         document.editEnd();
1988 }
1989 
1990 function buildCmdList(current)
1991 {
1992         var result = new Array();
1993         for ( i=0; i&lt;fontCommands.length; ++i ) {
1994                 if ( fontCommands[i] != current ) {
1995                         result.push(fontCommands[i]);
1996                 }
1997         }
1998         return result;
1999 }
2000 </programlisting>
2001 
2002 </sect2>
2003 
2004 <sect2 id="id_scripting_example3">
2005 <title>Example 3: surround selected text</title>
2006 
2007 <para>Surround selected text with a TeX command, where the relative cursor position will not be changed. <userinput>abc</userinput> for example can be changed to <userinput>\texcommand{abc}</userinput>.</para>
2008 
2009 <programlisting>
2010 var range = view.selectionRange();
2011 
2012 if ( range.isValid() ) {
2013         var cmd = kile.input.getLatexCommand("Choose","Choose surrounding LaTeX command:");
2014         if ( cmd != "" ) {
2015                 surroundTexCommand("\\"+cmd,range);
2016         }
2017 }
2018 else {
2019         kile.alert.sorry("No selection found.");
2020 }
2021 
2022 function surroundTexCommand(cmd,r)
2023 {
2024         var c = view.cursorPosition();
2025 
2026         document.editBegin();
2027         view.clearSelection();
2028         document.insertText(r.end,"}");
2029         document.insertText(r.start,cmd+"{");
2030 
2031         c.column = c.column + cmd.length + 2;
2032         view.setCursorPosition(c);
2033         document.editEnd();
2034 }
2035 </programlisting>
2036 </sect2>
2037 
2038 </sect1>
2039 
2040 </chapter>