/plugins/TextAutocomplete/tags/RELEASE-0_9_5/TextAutocomplete.html

# · HTML · 454 lines · 391 code · 63 blank · 0 comment · 0 complexity · 264dc4cfaec03407cfa579d5574d96c3 MD5 · raw file

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  2. "http://www.w3.org/TR/html4/loose.dtd">
  3. <html>
  4. <head>
  5. <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  6. <title>Plugin: TextAutocomplete - Docs</title>
  7. <meta name="generator" content="amaya 9.51, see http://www.w3.org/Amaya/">
  8. </head>
  9. <body lang="en">
  10. <h1>TextAutocomplete Plugin</h1>
  11. <p><strong>by Jakub Holý</strong></p>
  12. <hr>
  13. <h2>Table of Contents</h2>
  14. <div class="toc">
  15. <ul>
  16. <li><a href="#About">About</a></li>
  17. <li><a href="#Words">Words, completions</a> and how does it work</li>
  18. <li><a href="#Control">Control keys</a> of the completions pop-up
  19. window</li>
  20. <li><a href="#Menu">Menu</a></li>
  21. <li><a href="#Options">Options</a></li>
  22. <li><a href="#Accessing">Accessing the plugin from BeanShell</a></li>
  23. <li><a href="#Development">Development</a>
  24. <ul>
  25. <li><a href="#Feedback">Feedback</a></li>
  26. <li><a href="#Wish">Wish list</a></li>
  27. <li><a href="#Change">Change Log</a></li>
  28. <li><a href="#Overview">Overview of the Classes</a></li>
  29. <li><a href="#Working">How does it work?</a></li>
  30. </ul>
  31. </li>
  32. <li><a href="#License">License</a></li>
  33. </ul>
  34. </div>
  35. <h2><a name="About">About</a></h2>
  36. <p>TextAutocomplete collects "words" in the current buffer and those that you
  37. type and offers you automatically a list of possible completions. It's pretty
  38. similar to the jEdit's function "Complete Word" but it's automatic, you don't
  39. need to press any key to invoke the list of completions. Contrary to
  40. "Complete Word" it doesn't search the buffer every time for possible
  41. completions. Instead of that it keeps a list of remembered words (i.e.
  42. possible completions) that is created by parsing the buffer at startup and is
  43. updated with new words that you type. You can export (save), import and
  44. modify the list of remembered words. The plugin was inspired by a similar
  45. functionality in OpenOffice.org.</p>
  46. <p>The plugin is configurable, you can define what is a "word", what words
  47. (not) to remember etc. - see below. It's also possible to modify manually the
  48. list of remembered words.</p>
  49. <p>You must enable the autocompletion manually for every buffer where you
  50. want it (Plugins - TextAutocomplete - Start for buffer). Alternatively, you
  51. can enable the autocompletion for all buffers (Plugins - TextAutocomplete -
  52. Start for all buffers) or set the plugin to start automatically for every new
  53. buffer that you open (Plugins - Plugin Options... - TextAutocomplete - check
  54. "Start autom. for new buffers").</p>
  55. <h2><a name="Words" id="Words">Words, completions and how does it
  56. work</a></h2>
  57. <p>As described above, the plugin parses the buffer and what you type to find
  58. and remember the words to offer as completions later on. But what is a word
  59. and when/how is the list of completions offered?</p>
  60. <p>To consider a string as a word it must pass some tests - see the options
  61. "Belongs to word?" and "Is word to remember?". The first one determines
  62. whether the character typed may start/extend a word or whether it ends one,
  63. i.e. whether it is a word separator or a word constituent. By default only
  64. letters are regarded as constituting a word. The second option may be used to
  65. limit what words are remembered as possible completions - by default we
  66. ignore words shorter than determined by the option "Remember words long at
  67. least".</p>
  68. <p>The pop-up window with completions appears when you type the beginning of
  69. a word long enough (assuming there are some completions for that prefix). The
  70. length is given by the option "Minimal prefix length". So, with the default
  71. setting, you must type at least two letters before the completions may be
  72. offered.</p>
  73. <p><a name="L590" id="L590"></a>The important thing to note is that even
  74. though you can add arbitrary string to the list of remembered words (by
  75. importing them from a file or by adding the string by means of the
  76. "Remembered words" dialog), it will <em>never be offered as a completion</em>
  77. unless it satisfies the condition for the pop-up completions window to turn
  78. up, in other words it must start with a word that is at least as long as the
  79. "Minimal prefix length" - under the default setting it must start with two
  80. letters.</p>
  81. <p>Please be aware that the words are <em>case sensitive</em>, so
  82. "Something", "something" and "someTHING" are three different words.</p>
  83. <h2><a name="Control">Control keys of the completions pop-up window</a></h2>
  84. <p>By default, the following keys may be used to control the completion
  85. pop-up window:</p>
  86. <ul>
  87. <li><kbd>Escape</kbd> - Cancel (dispose) the window.</li>
  88. <li><kbd>Enter</kbd>, <kbd>Tab</kbd> - Accept and insert the selected
  89. completion.</li>
  90. <li><kbd>Up arrow</kbd> - Select the completion above the currently
  91. selected one. It cycles through the list, so pressing Up on the first
  92. entry gets you to the last one.</li>
  93. <li><kbd>Down arrow</kbd> - Select the completion below the currently
  94. selected one. It cycles through the list.</li>
  95. <li>Numbers <kbd>0-9</kbd> - Accept and insert the completion with the
  96. given number. You may disable it if you want numbers to be treated as
  97. regular characters or you may set it so that &lt;a modifier key&gt; +
  98. number inserts a completion while number without the modifier is just
  99. appended to the current word.</li>
  100. </ul>
  101. <h2><a name="Menu">Menu</a></h2>
  102. <dl>
  103. <dt><strong>Start for buffer</strong></dt>
  104. <dd>Enable autocompletion for the current buffer. The buffer is parsed to
  105. collect the words that already exist in it.</dd>
  106. <dt><strong>Stop for buffer</strong></dt>
  107. <dd>Disable autocompletion for the current buffer and forget all
  108. remembered words.</dd>
  109. <dt><strong>Parse buffer</strong></dt>
  110. <dd>Scan the current buffer for words to remember and add them to the
  111. list of remembered words.</dd>
  112. <dt><strong>Show remembered words</strong></dt>
  113. <dd>Display the list of remember words that you can edit: <br>
  114. <ol>
  115. <li><em>Add a word</em> typed in the text field; the string is
  116. remembered as is, even if normally it wouldn't be considered to be
  117. a word - but it should start as a word, see the <a
  118. href="#L590">explanation</a> above.</li>
  119. <li><em>Delete selected</em> - forgets the words you've selected in
  120. the list. To select multiple entries use Control+click.</li>
  121. <li><em>Delete all</em> - forget all remembered words. You can Parse
  122. buffer to get them back.<br>
  123. </li>
  124. </ol>
  125. </dd>
  126. <dd>Additionally, you can:
  127. <ol>
  128. <li><em>Import words</em> - read a file with previously saved words
  129. and add them to the list. One line is considered as one word and is
  130. added to the list "as is" even if it wouldn't normally be
  131. considered as a word - but it should start as a word, see the <a
  132. href="#L590">explanation</a> above.</li>
  133. <li><em>Export words</em> - save the remembered words into a file,
  134. one per line.</li>
  135. </ol>
  136. </dd>
  137. <dt><strong>Start for all buffers</strong></dt>
  138. <dd>Enable autocompletion for all currently opened buffers. (To detach
  139. from all buffers, open the Plugin Manager and under Manage uncheck and
  140. re-check the TextAutocomplete plugin.)</dd>
  141. <dt><strong>Stop for all buffers</strong></dt>
  142. <dd>Disable autocompletion for all buffers that have it enabled and
  143. forget all remembered words.</dd>
  144. </dl>
  145. <h2 id="Options"><a name="Options">Options</a></h2>
  146. <p>It's possible to set some options that will apply to autocompletion in all
  147. buffers.</p>
  148. <p>When you put the mouse pointer above some of the text field on the option
  149. page and wait for a while, a tool tip with more detailed description will
  150. show up.</p>
  151. <dl>
  152. <dt>Start autom. for new buffers</dt>
  153. <dd>Enable autocompletion for every new buffer that you will open from
  154. that moment on.<br>
  155. Default: Off</dd>
  156. <dt>Filename filters</dt>
  157. <dd>Specify filename glob patterns to be included or excluded from
  158. autocompletion.<br>
  159. Default: Include all files</dd>
  160. </dl>
  161. <p>The following options influence words and completions.</p>
  162. <dl>
  163. <dt>Remember at max. words</dt>
  164. <dd>The maximal number of words that should be remembered as potential
  165. completions. Notice, that completions are only offered based on the
  166. list of remembered words.<br>
  167. Default: 1000</dd>
  168. <dt>Minimal prefix length</dt>
  169. <dd>Don't offer possible completions until at least the given number of
  170. characters have been typed.</dd>
  171. <dd>Default: 2.</dd>
  172. <dt>Remember words long at least</dt>
  173. <dd>Don't remember words shorter than the given value.</dd>
  174. <dd>Default: 5.</dd>
  175. </dl>
  176. <p>Value of the following properties is a beanshell expression that evaluates
  177. to either true or false. It can make use of special variables - see below. If
  178. the code isn't correct, BeanShell will throw an exception when it is first
  179. executed so you should make sure that it is all right; than it reverts to the
  180. default setting to prevent repetitions of the same error. The description of
  181. such an exception will mention either PreferencesManager.precompileCode or
  182. PreferencesManager.executeCachedCode and either the method accept (for
  183. "Belongs to word?") or isWordToRemember. The expression must be valid Java
  184. expression, so it should end with a semicolon.</p>
  185. <dl>
  186. <dt>Is word to remember? [code]</dt>
  187. <dd>Return true if the word that has just been typed should be
  188. remembered. In addition to that, the word must also be at least as long
  189. as required by "Remember words long at least". The variable
  190. <code>word</code> (String) holds the word in question.</dd>
  191. <dd>Example: <code>! word.startsWith("X");</code></dd>
  192. <dd>Default: always true</dd>
  193. <dt>Belongs to word? [code]</dt>
  194. <dd>Return true when the insertion (the typed character) doesn't end the
  195. word being typed, in other words, it must return false for word
  196. separators. The available variables are <var>prefix</var> (String; the
  197. word that has been typed so far) and <var>insertion</var> (char; the
  198. newly typed character). This determines what is considered as a word
  199. while the previous option determines whether something, that is already
  200. considered to be a word, should be remembered or not.</dd>
  201. <dd>Example: <code>Character.isLetterOrDigit(insertion) || insertion ==
  202. '_' || (prefix.startsWith("&lt;") &amp;&amp; prefix.indexOf("&gt;") ==
  203. -1);</code> // alphanumeric string or anything between &lt; and
  204. &gt;</dd>
  205. <dd>Default: <code>Character.isLetter(insertion);</code></dd>
  206. </dl>
  207. <p>Use the following properties to change the <a href="#Control">default
  208. control keys</a> (see above). All of them take a list of keys separated by a
  209. single space or by a comma. A key is represented by the name of one of the
  210. constants of the class <a
  211. href="http://java.sun.com/j2se/1.4.2/docs/api/index.html">java.awt.event.KeyEvent</a>
  212. that start with the prefix "VK_". You can only use special keys, that means
  213. keys that don't produce a character. It includes VK_ENTER, VK_ESCAPE,
  214. VK_BACK_SPACE, VK_DELETE, VK_F1 etc., VK_TAB, VK_UP, VK_DOWN and others.</p>
  215. <dl>
  216. <dt>Accept with key</dt>
  217. <dd>Accept and insert the currently selected completion.</dd>
  218. <dd>Default: VK_ENTER,VK_TAB</dd>
  219. <dt>Dispose with key</dt>
  220. <dd>Hide the window with completions.</dd>
  221. <dd>Default: VK_ESCAPE</dd>
  222. <dt>Up in completions key</dt>
  223. <dd>Select the completion above.</dd>
  224. <dd>Default: VK_UP</dd>
  225. <dt>Down in completions key</dt>
  226. <dd>Select the completion below.</dd>
  227. <dd>Default: VK_DOWN</dd>
  228. <dt>Select compl. by number</dt>
  229. <dd>If checked, pressing a number inserts the completion with that index.
  230. If unchecked, the number is just inserted as an ordinary character.<br>
  231. Default: Checked (i.e. enabled)</dd>
  232. <dt>Select by number modifier</dt>
  233. <dd>If you press the selected modifier key + a number, the completion
  234. with that index is inserted. If you press only the number, it's
  235. inserted into the buffer. Note: Some of the modifiers may not work for
  236. you. There are reports of problems with AltGr.<br>
  237. Default: None (no modifier key, pressing the number inserts the
  238. completion)</dd>
  239. </dl>
  240. <p>The button <var>Reset options</var> resets them to the default values.</p>
  241. <h2><a name="Accessing" id="Accessing">Accessing the plugin from
  242. BeanShell</a></h2>
  243. <p>If you know Java programming, you can access and control the plugin via
  244. BeanShell - either by means of the Console plugin or from a macro.</p>
  245. <p>You can see the current options by calling the methods of
  246. PreferencesManager, for example<br>
  247. <code>net.jakubholy.jedit.autocomplete.PreferencesManager.getPreferencesManager().getMaxCountOfWords()</code><br>
  248. To modify the options you'd need to set some properties (jEdit.setProperty) -
  249. see the file TextAutocomplete.props within the plugin's .jar archive.</p>
  250. <p>You could also invoke the actions that are usually run from the menu - for
  251. example
  252. <code>net.jakubholy.jedit.autocomplete.AutoComplete.attachAction(buffer)</code>.</p>
  253. <p>To get the AutoComplete associated with the buffer, call
  254. <code>net.jakubholy.jedit.autocomplete.getAutoCompleteOfBuffer(buffer)</code>.
  255. If it returns null, you must attach one first.</p>
  256. <p>See the JavaDoc for <a
  257. href="docs/javadocs/net/jakubholy/jedit/autocomplete/AutoComplete.html">AutoComplete</a>,
  258. <a
  259. href="docs/javadocs/net/jakubholy/jedit/autocomplete/PreferencesManager.html">PreferencesManager</a>,
  260. <a
  261. href="docs/javadocs/net/jakubholy/jedit/autocomplete/WordList.html">WordList</a>,
  262. <a
  263. href="docs/javadocs/net/jakubholy/jedit/autocomplete/Completion.html">Completion</a>
  264. and <a
  265. href="docs/javadocs/net/jakubholy/jedit/autocomplete/TextAutocompletePlugin.html">TextAutocompletePlugin</a>
  266. included with this plugin or download the plugins's source with the full API
  267. JavaDoc. You can also browse the plugin's source files via Source Forge's web
  268. interface to the <a
  269. href="http://cvs.sourceforge.net/viewcvs.py/jedit/plugins/TextAutocomplete/net/jakubholy/jedit/autocomplete/">CVS</a>
  270. repository.</p>
  271. <h2><a name="Development">Development</a></h2>
  272. <h3><a name="Feedback">Feedback</a></h3>
  273. <p>The preferred way to send bug reports is to use the Sourceforge Bug
  274. Tracker at <a
  275. href="http://sourceforge.net/bugs/?group_id=588">http://sourceforge.net/bugs/?group_id=588</a>
  276. and also notify me by e-mail.</p>
  277. <p>You can also write to:</p>
  278. <p>Jakub Holý alias MalyVelky &lt;malyvelky@users.sourceforge.net&gt;;</p>
  279. <p>If you find a bug, help to discover it by switching on verbose logging for
  280. the plugin - execute the following BeanShell code (paste it into a new
  281. buffer, select it and execute it via Utilities &gt; BeanShell &gt; Evaluate
  282. Selection):</p>
  283. <code>jEdit.setIntegerProperty("plugin.net.jakubholy.jedit.autocomplete.TextAutocompletePlugin.logLevel",2)</code>
  284. <p>You will need to either reload the plugin or restart jEdit to activate the
  285. change. (WordTypedListener reads the log level only upon its creation.) Look
  286. for the logs starting with "TextAutocompletePlugin:" in Utilities &gt;
  287. Troubleshooting &gt; Activity Log. To disable the logging again, execute:</p>
  288. <code>jEdit.setIntegerProperty("plugin.net.jakubholy.jedit.autocomplete.TextAutocompletePlugin.logLevel",0)</code>
  289. <p>And reload/restart.</p>
  290. <h3><a name="Wish">Wish list</a></h3>
  291. <ul>
  292. <li>Make it possible to start with a default word list (read from a file, same for all buffers)</li>
  293. <li>Options - check that the beanshell expressions are ok before the
  294. preferences are saved</li>
  295. <li>Allow for the insertion of longer texts after a prefix (so far only 1
  296. character can be inserted/typed)</li>
  297. <li>Support the insertion of the "longest common suffix" of two or more
  298. completions (typed: "co", possible completions: community, communist
  299. =&gt; insert (co)mmuni)</li>
  300. <li>Option to show the completion popup only after a period of inactivity
  301. (e.g. when the user stops typing for 2 seconds).</li>
  302. </ul>
  303. <h3><a name="Change">Change Log</a></h3>
  304. <h4>Version 0.9.4, October 2006</h4>
  305. <p>Added the possibility to disable selection of a completion by number or to
  306. require a modifier key together with the number.</p>
  307. <h4>Version 0.9.3, May 2006</h4>
  308. <p>Added handling of backspace.</p>
  309. <p>Development: added unit tests, corrections of the code (thanks to
  310. JUnit!).</p>
  311. <h4>Version 0.9.2, April 2006</h4>
  312. <p>This is a bug fixes and enhancement release. Additionally, the plugin has
  313. been updated for jEdit 4.3pre3.</p>
  314. <p>Bug fixes:</p>
  315. <ul>
  316. <li>Prevent the cursor from switching buffer/view: When you edited one or
  317. two file(s) in a split view, it sometimes happened that you started
  318. writing in one and suddenly the cursor jumped into the another. This
  319. should be now fixed (We prefer jEdit.getActiveView over the remembered
  320. view). I'd like to thank Jeremias, who discovered the bug.</li>
  321. </ul>
  322. <p>New features:</p>
  323. <ul>
  324. <li>Start for all opened buffers and Stop for all opened buffers</li>
  325. <li>Start automatically for new buffers</li>
  326. <li>The number of remembered words is now limited to 1000, the limit may be
  327. changed.</li>
  328. <li>It's now possible to export/import (append) the list of remembered
  329. words.</li>
  330. </ul>
  331. <h4 id="Version">Version 0.9, May 2006</h4>
  332. <p>Initial release.</p>
  333. <h3><a name="Overview">Overview of the Classes</a></h3>
  334. <p>Core classes:</p>
  335. <ul>
  336. <li>AutoComplete - ties together all the core classes: registers a
  337. WordTypedListener for the buffer, stores the words into a WordList and
  338. displays a CompletionPopup window with the possible completions. It keeps
  339. the map (buffer to its autocompletion instance).</li>
  340. <li>PreferencesManager - handles options; other classes use its methods and
  341. do not access the preferences directly. Only one instance exists.</li>
  342. <li>CompletionPopup - Pop-up window with completions of the word being
  343. typed. It intercepts keys and handles the control keys.</li>
  344. <li>WordList [interface] - structure for storage of the words (more exactly
  345. completions) to remember.</li>
  346. <li>WordListTreeSet - a concrete implementation of the WordList.</li>
  347. <li>WordTypedListener - it listens to what keys are typed in the buffer and
  348. notifies others (the AutoComplete) about such events as a character being
  349. appended to a word and the end of a word.</li>
  350. </ul>
  351. <p>GUI classes:</p>
  352. <ul>
  353. <li>TextAutocompletePlugin - implements jEdit plugin.</li>
  354. <li>TextAutocompletePane - the Option pane.</li>
  355. <li>WordListEditorUI - the editor of remembered words.</li>
  356. </ul>
  357. <p>Helper classes</p>
  358. <ul>
  359. <li>Completion - the structure used to keep a word to remember. Using it
  360. instead of a string enables us to add later on additional information to
  361. each word and, for instance, offer completions order with respect to the
  362. frequency of their occurrence.</li>
  363. <li>WordTypedEvent - produced by WordTypedListener to carry information
  364. about what's going on in the buffer.</li>
  365. <li>ActionException - thrown when some of the actions invoked via menu
  366. fails.</li>
  367. </ul>
  368. <p>For more info see <a
  369. href="http://jakubholy.net/comp/jedit.html">http://jakubholy.net/comp/jedit.html</a>.</p>
  370. <h3><a name="Working">How does it work?</a></h3>
  371. <p>A BufferListener (implemented by my WordTypedListener) is attached to the
  372. buffer. When it detects an important event (a letter appended to a word, a
  373. word ended...), it notifies the main class AutoComplete via the
  374. Observer/Observable mechanism. It may then display (or dispose) a list of
  375. completions. When the list of completions is displayed, it intercepts special
  376. keys being pressed (such as Enter, Escape...) and reacts according to its
  377. setting (hide itself, insert the selected completion...).</p>
  378. <h2><a name="License">License</a></h2>
  379. <p>This plugin is released under the GNU General Public License version 2
  380. (GPL). Please see <a
  381. href="http://www.fsf.org/copyleft/gpl.html">http://www.fsf.org/copyleft/gpl.html</a>.</p>
  382. <p>Moreover, permission is granted to copy, distribute and/or modify this
  383. document under the terms of the GNU Free Documentation License, Version 1.1
  384. or any later version published by the Free Software Foundation; with no
  385. "Invariant Sections", "Front-Cover Texts" or "Back-Cover Texts", each as
  386. defined in the license. A copy of the license can be found in the file
  387. COPYING.DOC.txt included with jEdit.</p>
  388. <hr>
  389. <p style="text-align:center">Jakub Holý 2006</p>
  390. </body>
  391. </html>