by Jakub Holý
TextAutocomplete collects "words" in the current buffer and those that you type and offers you automatically a list of possible completions. It's pretty similar to the jEdit's function "Complete Word" but it's automatic, you don't need to press any key to invoke the list of completions. Contrary to "Complete Word" it doesn't search the buffer every time for possible completions. Instead of that it keeps a list of remembered words (i.e. possible completions) that is created by parsing the buffer at startup and is updated with new words that you type. You can export (save), import and modify the list of remembered words. It's also possible to import a default list of words for new buffers, see below. The plugin was inspired by a similar functionality in OpenOffice.org.
The plugin is configurable, you can define what is a "word", what words (not) to remember etc. - see below. It's also possible to modify manually the list of remembered words.
You must enable the autocompletion manually for every buffer where you want it (Plugins - TextAutocomplete - Start for buffer). Alternatively, you can enable the autocompletion for all buffers (Plugins - TextAutocomplete - Start for all buffers) or set the plugin to start automatically for every new buffer that you open (Plugins - Plugin Options... - TextAutocomplete - check "Start autom. for new buffers").
Since: 0.9.8
You can create a list of words that will be loaded by default for any buffer or for any buffer with a particular extension provided that TextAutocomplete is enabled for that buffer. Every line of the file is taken as a 'word' - but see notes on the import word list function above. Currently this isn't yet configurable but it's planned for the future.
If you want some words to be readily available in any buffer using the TextAutocomplete plugin then store them into the file named autocompleteDefaultWordList
under the jEdit settings directory (see Utilities - Settings Directory; for me it's /home/jholy/.jedit).
If you want some words to be loaded only for a buffer (file) with a particular extension then
store them into a file with the name autocompleteDefaultWordList
and
the appropriate extension under the settings directory. So to load some words by default only
for PHP files, create the file autocompleteDefaultWordList.php
. The word list
file's extension must be in lower-case (i.e. not Php). If there is an extension-specific
word list file then the common word list described above is not loaded.
Since: 0.9.9
In jEdit each buffer has a particular edit mode, which may define special keywords that should be highlighted in a special way such as programming language's reserved words or function names. To help people using Text Autocomplete when writing code, it does load the list of keywords from the buffer's edit mode and adds it to the list of completions. In addition to that it also takes into account what characters are considered to be part of words by the edit mode (such as '@' in PHP).
Beware that some edit modes may define a large number of keywords (e.g. over 25.000 for PHP) and thus you may need to adjust the max. words to remember. With multiple buffers open this can also consume considerable memory.
By default this functionality is off and must be enabled in Options.
As described above, the plugin parses the buffer and what you type to find and remember the words to offer as completions later on. But what is a word and when/how is the list of completions offered?
To consider a string as a word it must pass some tests - see the options "Belongs to word?" and "Is word to remember?". The first one determines whether the character typed may start/extend a word or whether it ends one, i.e. whether it is a word separator or a word constituent. By default only letters are regarded as constituting a word. The second option may be used to limit what words are remembered as possible completions - by default we ignore words shorter than determined by the option "Remember words long at least".
The pop-up window with completions appears when you type the beginning of a word long enough (assuming there are some completions for that prefix). The length is given by the option "Minimal prefix length". So, with the default setting, you must type at least two letters before the completions may be offered.
The important thing to note is that even though you can add arbitrary string to the list of remembered words (by importing them from a file or by adding the string by means of the "Remembered words" dialog), it will never be offered as a completion unless it satisfies the condition for the pop-up completions window to turn up, in other words it must start with a word that is at least as long as the "Minimal prefix length" - under the default setting it must start with two letters.
Please be aware that the words are case sensitive, so "Something", "something" and "someTHING" are three different words.
By default, the following keys may be used to control the completion pop-up window:
It's possible to set some options that will apply to autocompletion in all buffers.
When you put the mouse pointer above some of the text field on the option page and wait for a while, a tool tip with more detailed description will show up.
The following options influence words and completions.
Value of the following properties is a beanshell expression that evaluates to either true or false. It can make use of special variables - see below. If the code isn't correct, BeanShell will throw an exception when it is first executed so you should make sure that it is all right; than it reverts to the default setting to prevent repetitions of the same error. The description of such an exception will mention either PreferencesManager.precompileCode or PreferencesManager.executeCachedCode and either the method accept (for "Belongs to word?") or isWordToRemember. The expression must be valid Java expression, so it should end with a semicolon.
word
(String) holds the word in question.! word.startsWith("X");
Character.isLetterOrDigit(insertion) || insertion ==
'_' || (prefix.startsWith("<") && prefix.indexOf(">") ==
-1);
// alphanumeric string or anything between < and
>Character.isLetterOrDigit( insertion ) || noWordSeparators.indexOf( insertion ) >= 0;
Use the following properties to change the default control keys (see above). All of them take a list of keys separated by a single space or by a comma. A key is represented by the name of one of the constants of the class java.awt.event.KeyEvent that start with the prefix "VK_". You can only use special keys, that means keys that don't produce a character. It includes VK_ENTER, VK_ESCAPE, VK_BACK_SPACE, VK_DELETE, VK_F1 etc., VK_TAB, VK_UP, VK_DOWN and others.
The button Reset options resets them to the default values.
If you know Java programming, you can access and control the plugin via BeanShell - either by means of the Console plugin or from a macro.
You can see the current options by calling the methods of
PreferencesManager, for example
net.jakubholy.jedit.autocomplete.PreferencesManager.getPreferencesManager().getMaxCountOfWords()
To modify the options you'd need to set some properties (jEdit.setProperty) -
see the file TextAutocomplete.props within the plugin's .jar archive.
You could also invoke the actions that are usually run from the menu - for
example
net.jakubholy.jedit.autocomplete.AutoComplete.attachAction(buffer)
.
To get the AutoComplete associated with the buffer, call
net.jakubholy.jedit.autocomplete.AutoComplete.getAutoCompleteOfBuffer(buffer)
.
If it returns null, you must attach one first.
See the JavaDoc for AutoComplete, PreferencesManager, WordList, Completion and TextAutocompletePlugin included with this plugin or download the plugins's source with the full API JavaDoc. You can also browse the plugin's source files via Source Forge's web interface to the SVN repository.
The preferred way to send bug reports is to use the Sourceforge Bug Tracker at http://sourceforge.net/bugs/?group_id=588 and also notify me by e-mail.
You can also write to:
Jakub Holý alias MalyVelky <malyvelky@users.sourceforge.net>;
If you find a bug, help to discover it by switching on verbose logging for the plugin - execute the following BeanShell code (paste it into a new buffer, select it and execute it via Utilities > BeanShell > Evaluate Selection):
jEdit.setIntegerProperty("plugin.net.jakubholy.jedit.autocomplete.TextAutocompletePlugin.logLevel",2)
You will need to either reload the plugin or restart jEdit to activate the change. (WordTypedListener reads the log level only upon its creation.) Look for the logs starting with "TextAutocompletePlugin:" in Utilities > Troubleshooting > Activity Log. To disable the logging again, execute:
jEdit.setIntegerProperty("plugin.net.jakubholy.jedit.autocomplete.TextAutocompletePlugin.logLevel",0)
And reload/restart.
This is a minor enhancement release.
New features:
This is a bug fixes and enhancement release. Additionally, the plugin has been updated for jEdit 4.3pre15.
Bug fixes:
New features:
Added the possibility to disable selection of a completion by number or to require a modifier key together with the number.
Added handling of backspace.
Development: added unit tests, corrections of the code (thanks to JUnit!).
This is a bug fixes and enhancement release. Additionally, the plugin has been updated for jEdit 4.3pre3.
Bug fixes:
New features:
Initial release.
Core classes:
GUI classes:
Helper classes
For more info see http://jakubholy.net/comp/jedit.html.
A BufferListener (implemented by my WordTypedListener) is attached to the buffer. When it detects an important event (a letter appended to a word, a word ended...), it notifies the main class AutoComplete via the Observer/Observable mechanism. It may then display (or dispose) a list of completions. When the list of completions is displayed, it intercepts special keys being pressed (such as Enter, Escape...) and reacts according to its setting (hide itself, insert the selected completion...).
svn co https://jedit.svn.sourceforge.net/svnroot/jedit/plugins/TextAutocomplete/trunk TextAutocomplete
See readme-development.md
in the plugin's directory for more information.
This plugin is released under the GNU General Public License version 2 (GPL). Please see http://www.fsf.org/copyleft/gpl.html.
Moreover, permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no "Invariant Sections", "Front-Cover Texts" or "Back-Cover Texts", each as defined in the license. A copy of the license can be found in the file COPYING.DOC.txt included with jEdit.
Jakub Holý 2006