Next: , Previous: , Up: Programming Tools   [Contents][Index]


5.24.1 Locating source code definitions

Many programming systems are organized as an integrated development environment (IDE) where the editor is the hub of the system, and allows building and running programs. If you want that, Gforth has it, too (see Emacs and Gforth).

However, several Forth systems have a different kind of IDE: The Forth command line is the hub of the environment; you can view the source from there in various ways, and call an editor if needed.

Gforth also implements such an IDE. It mostly follows the conventions of SwiftForth where they exist, but implements features beyond them.

An advantage of this approach is that it allows you to use your favourite editor: set the environment variable EDITOR to your favourite editor, and the editing commands will call that editor; Gforth invokes some GUI editors in the background (so you do not need to finish editing to continue with your Forth session), terminal editors in the foreground (default for editors not known to Gforth is foreground). If you have not set EDITOR, the default editor is vi.

locate       "name" –         gforth       “locate”

Show the source code of the word name and set the current location there.

The current location is set by a number of other words in addition to locate. Also, when an error happens while loading a file, the location of the error becomes the current location.

A number of words work with the current location:

l              unknown       “l”

Display source code lines at the current location.

n              gforth       “n”

Display lines behind the current location, or behind the last n or b output (whichever was later).

b              gforth       “b”

Display lines before the current location, or before the last n or b output (whichever was later).

g              gforth       “g”

Enter the editor at the current location, or at the start of the last n or b output (whichever was later).

You can control how many lines l, n and b show by changing the values:

before-locate       – u         gforth       “before-locate”

number of lines shown before current location (default 3).

after-locate       – u         gforth       “after-locate”

number of lines shown after current location (default 12).

Finally, you can directly go to the source code of a word in the editor with

edit       "name" –         gforth       “edit”

Enter the editor at the location of "name"


Next: , Previous: , Up: Programming Tools   [Contents][Index]