CoCoA:User Interface Guide Word Completion (4.4)

From ApCoCoAWiki
Revision as of 00:33, 20 July 2005 by Mabshoff (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Description

When you are editing CoCoA documents with CoCoA you can make use of its word completion mode. You can enter word completion mode either manually or automatically.

If you want to enter it manually, just press Ctrl + Down or Ctrl + Up. All text between the current cursor position and the last whitespace character (i.e. spaces, tabs, ...) in the current line is then taken as the word completion base. Now, CoCoA checks its wordlist for any words starting with the word completion base. It then displays the first available completion (if you pressed Ctrl + Down), the last available completion (if you pressed Ctrl + Up) or nothing (if there is no completion available).

If you want to enter it automatically whenever you type more than 3 non-whitespace characters check the entry Autocompleting in the Settings menu or press Ctrl + Insert to toggle autocompletion mode. The entry AC in the status bar indicates whether autocompletion mode is active or not.

After you entered word completion mode you have the following options:

  1. Browse through all available completions of the current word completion base using the keys Down or Up
  2. Leave the word completion mode accepting the completion using Right
  3. Leave the word completion mode accepting the completion and appending function parenthesis' using Left
  4. Leave the word completion mode rejecting the completion by pressing Esc, Del or simply by continuing to type normally.

Word completion mode is configurable, i. e. apart from the system wordlist you can create and load your own wordlists. For this, go to the Settings menu and select Word completion. This will open the following dialog:

FIXME: Upload image of dialog

Whenever you add a new file it will automatically be loaded. If you want to disable the completions contained in that file temporarily, simply unload it. It will remain in the list of wordfiles but will be marked not to be loaded until you load it again in the dialog. When a file is marked for loading and cannot be loaded, the reason for this will show up in the column labeled Load state.

In the current version of CoCoA, wordfiles have the format

some_word
some_other_word
...

so it's quite easy to create them by hand. To create a wordfile for a package you wrote you can also use the following functions:

 Define WriteWordList(PackageName, PackageAlias, FileName)
     D := OpenOFile(FileName);
     Functions := Functions(PackageName);
     For I := 1 To Len(Functions) Do
         S := Sprint(Functions[I]) + '(';
         EndPos := Min([I | I In 1..Len(S) And S[I] = '(']);
         FunctionName := Sum(First(S, EndPos - 1));
         If PackageAlias <>  Then
             Print PackageAlias, '.' On D;
         EndIf;
         Println FunctionName On D;
     EndFor;
 EndDefine;

For example, you can use

WriteWordList('$cocoa/io', 'IO', 'iopkg_wordlist.txt');

to write the names of all functions contained in the IO package to the file iopkg_wordlist.txt which can then be used directly by CoCoA Word Completion. Of course the package must be loaded into CoCoA beforehand.

Shortcuts

  • CTRL-Down: Enter word completion mode manually and show the first possible completion.
  • CTRL-Up: Enter word completion mode manually and show the last possible completion.
  • Down: When in word completion mode, this will show the next possible completion.
  • Up: When in word completion mode, this will show the previous possible completion.
  • Right: When in word completion mode, this will exit word completion mode accepting the last completion shown.
  • Left: When in word completion mode, this will exit word completion mode accepting the last completion shown. Furthermore, this will append () to the completed word. This is very useful for completions that represent function names.
  • CTRL-Insert: Activates/Deactivates autocompletion mode. The current status is shown in the status bar (AC).
  • Esc Delete: When in word completion mode, this will exit word completion mode rejecting the completion. You can also exit word completion mode by resuming normal typing.