medit/doc/help/Storing-tools-in-files.html
2010-09-06 16:36:50 -07:00

123 lines
8.0 KiB
HTML

<html lang="en">
<head>
<title>Storing tools in files - medit 0.99.0-unstable manual</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="medit 0.99.0-unstable manual">
<meta name="generator" content="makeinfo 4.13">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="User_002ddefined-tools.html#User_002ddefined-tools" title="User-defined tools">
<link rel="prev" href="Managing-tools.html#Managing-tools" title="Managing tools">
<link rel="next" href="Shell-scripts.html#Shell-scripts" title="Shell scripts">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
pre.display { font-family:inherit }
pre.format { font-family:inherit }
pre.smalldisplay { font-family:inherit; font-size:smaller }
pre.smallformat { font-family:inherit; font-size:smaller }
pre.smallexample { font-size:smaller }
pre.smalllisp { font-size:smaller }
span.sc { font-variant:small-caps }
span.roman { font-family:serif; font-weight:normal; }
span.sansserif { font-family:sans-serif; font-weight:normal; }
--></style>
</head>
<body>
<div class="node">
<a name="Storing-tools-in-files"></a>
<p>
Next:&nbsp;<a rel="next" accesskey="n" href="Shell-scripts.html#Shell-scripts">Shell scripts</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="Managing-tools.html#Managing-tools">Managing tools</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="User_002ddefined-tools.html#User_002ddefined-tools">User-defined tools</a>
<hr>
</div>
<h3 class="section">4.2 Storing tools in files</h3>
<p><!-- moo-help-section: USER_TOOLS_FILES -->
<p>It is possible to create tools without using the <em>Preferences</em> dialog,
they can be stored in files in <samp><span class="file">tools</span></samp> subfolder of the medit data
folders (or <samp><span class="file">tools-context</span></samp> for tools which appear in the document context
menu). In particular, on Unix systems you can place files into
<samp><span class="file">$HOME/.local/share/medit/tools/</span></samp> folder.
<p>Names of the files in the <samp><span class="file">tools</span></samp> folder are used as their menu item
labels, after stripping first three characters, so you can use trhee-character
prefix to affect the order of the menu items, e.g. you can have <samp><span class="file">00-Do Something</span></samp>,
<samp><span class="file">01-Another tool</span></samp> files to have them in that order in the menu. The files
may be of three types: files with extension "<samp><span class="file">.py</span></samp>", they will be used
as Python scripts; files with extension "<samp><span class="file">.lua</span></samp>", they will be used
as Lua scripts; and executable files, they will be executed in the same way
as shell commands.
<p>To set parameters for a tool, place them on the first or the second line of the file in
the following format:
<pre class="example"> !! <var>key</var>=<var>value</var>; <var>key</var>=<var>value</var>; ... !!
</pre>
<p><var>key</var> may be one of the following:
<dl>
<dt><var>position</var><dd>it can be &ldquo;start&ldquo; or &ldquo;end&ldquo;, and defines whether the menu item will be located at the start or at the end of the menu.
<br><dt><var>id</var><dd>the tool identificator.
<br><dt><var>name</var><dd>the tool name, i.e. the label used in the menu item. Overrides the file name.
<br><dt><var>accel</var><dd>default keyboard accelerator used to invoke this tool.
<br><dt><var>menu</var><dd>the menu to place this tool into. By default the tools are located in the Tools menu, but they can be as well put into any other menu.
<br><dt><var>langs</var><dd>comma-separated list of languages for which this tool will be enabled.
<br><dt><var>file-filter</var><dd>defines for which files this tool will be enabled. The value has the same format as in the <em>Preferences</em> dialog.
<br><dt><var>options</var><dd>same as the <em>Options</em> entry content in the <em>Preferences</em> dialog.
</dl>
<p>In addition to these, you can set input and output options for executable files:
<dl>
<dt><var>input</var><dd>can be <code>none</code>, <code>lines</code>, <code>selection</code>, or <code>doc</code>.
<br><dt><var>output</var><dd>can be <code>none</code>, <code>async</code>, <code>pane</code>, <code>insert</code>, or <code>new-doc</code>.
<br><dt><var>filter</var><dd>the output filter name.
</dl>
<!-- @node Lua scripts -->
<!-- @section Lua scripts -->
<!-- Lua scripts can use the standard Lua library, ``lfs`` library, and ``medit`` package -->
<!-- which provides some text editor API. Lua scripts have the following variables and functions available. -->
<!-- ``doc``: a table with the following fields: -->
<!-- | ``file`` | the document file path. | -->
<!-- | ``name`` | the document file basename. -->
<!-- | ``dir`` | the document file directory. -->
<!-- | ``ext`` | the document filename extension including the period. -->
<!-- | ``base`` | the document filename without the extension: the basename is always ``base..ext``. -->
<!-- ``Cut()``, ``Copy()``, ``Paste()``: clipboard operations. -->
<!-- ``Backspace()``, ``Delete()``: corresponding key actions. -->
<!-- ``Up()``, ``Down()``, ``Left()``, ``Right()``: move cursor as the arrow keys do. -->
<!-- ``Selection()``: returns selected text as a string. Returns ``nil`` when no text is selected. -->
<!-- ``Select(n)``: selects ``n`` characters to the right if ``n`` is positive, and ``-n`` characters to the left if it is negative. -->
<!-- ``Insert(...)``: inserts text at cursor. Namely, it converts each argument to a string and inserts the result into the document. -->
<!-- ``NewLine()``: inserts new line character. -->
<!-- The following functions are provided for more advanced text manipulation. Position in the -->
<!-- document is denoted by the character offset from the beginning of the document, starting -->
<!-- from 1, so the first character is at position 1. Functions which take or return ranges use pairs of -->
<!-- offsets, a pair ``start``, ``end`` denotes range of text from -->
<!-- ``start`` to ``end``, **not** including the character at offset ``end``. For instance, the -->
<!-- single-character range consisting of the first character in the document corresponds to the -->
<!-- pair ``1, 2``. Non-positive offset denotes the end of the document. -->
<!-- ``InsertText(pos, ...)``: inserts text at the position ``pos``. -->
<!-- ``DeleteText(start, end)``: deletes text in the range ``[start..end)``. -->
<!-- ``GetInsert()``: returns position of the cursor in the document. -->
<!-- ``GetSelectionBounds()``: returns positions of the selection start and end. If no text is -->
<!-- selected, returns pair ``pos, pos`` where ``pos`` is the cursor position. -->
<!-- ``GetLine([pos])``: returns line number of the character at the position ``pos``. If ``pos`` -->
<!-- is not specified, it defaults to the cursor position. -->
<!-- ``GetPosAtLine(n)``: returns position at the beginning of the ``n``-th line. -->
<!-- ``LineStart([pos])``: returns the position of the beginning of the line which contains character at ``pos``. -->
<!-- If ``pos`` is not specified, it defaults to the cursor position. -->
<!-- ``LineEnd([pos])``: returns the position of the end of the line which contains character at ``pos``. -->
<!-- If ``pos`` is not specified, it defaults to the cursor position. -->
<!-- ``ForwardLine([pos, [n]])``: returns the position of the beginning of the next line (or -->
<!-- ``n``-th line if ``n`` is specified). ``pos`` defaults to the cursor position if not -->
<!-- specified. -->
<!-- ``BackwardLine([pos, [n]])``: returns the position of the beginning of the previous line -->
<!-- (or ``n``-th line backwards if ``n`` is specified). ``pos`` defaults to the cursor position -->
<!-- if not specified. -->
<!-- ``GetText(start, end)``: returns the text in the ``[start..end)``. If ``start == end``, it -->
<!-- returns an empty string, not ``nil``. -->
</body></html>