Using TurtleEdit
The TurtleEdit window is divided into two panes. The upper pane is the editor, where you write and edit programs or other text. The lower pane displays compiler messages and program output. You cannot edit the contents of the lower pane. The illustration below shows the main window. You can open only one file at a time.
TurtleEdit provides only basic text-editing features, so it is straightforward to use. One distinctive feature is that Japanese (full-width) characters are always outlined in orange to help you distinguish them from half-width characters.
Setting up external programs
TurtleEdit lets you launch external programs, such as compilers, using buttons or menu commands. Before using this feature, you need to configure the commands. Choose Settings from the Run menu to open the window shown below.
In the Compile command field, enter the command to run when you click Compile. You can use the following placeholders in a command:
%f: the name of the file you are editing.%b: the file name without its extension; for example,fooforfoo.c.%d: the directory where the file is saved.%c: the directory containing the running TurtleEdit application.%h: your home directory.
If an argument contains spaces, enclose it in single quotes or replace each
space with %s.
The directory where the file is saved is used as the command's working directory.
For example, to compile a C program, enter the following in Compile command:
cc %f -lm
In the Command for execution field, enter the command to run when you click Run.
In the Additional exec PATH field, enter any directories to add to the
PATH environment variable when an external command runs. Separate
entries with colons (:), or with semicolons (;) on Windows.
You can also choose common compilation and execution settings from the Preset values drop-down list.
The Path to TurtleField and Auto launch settings are useful when working with turtle graphics using the TurtleField server. You do not need to configure them for other programming exercises.
Set Character code to the encoding used in your environment. An incorrect setting may cause text to appear garbled.
Under Preferred font, choose a font that supports Japanese, such as MS Gothic. A font intended only for Western languages may not display Japanese text correctly.
Click OK to save your settings. They will also be used the next time you start TurtleEdit.
TurtleEdit can be used for more than programming: it can also run tools that
process source text and display the results. For example, if LaTeX is installed
in /opt/local/bin, you could use these settings:
Compile command: /opt/local/bin/platex %f Command for execution: /opt/local/bin/xdvi %b Additional exec PATH: /opt/local/bin
In this example, you must keep /opt/local/bin/ in the execution
command /opt/local/bin/xdvi, even though that directory is listed in
Additional exec PATH. The modified PATH environment variable
is used when xdvi itself launches other programs.
Tips
On Windows, separate the parts of a path with backslashes, as in
C:\Users\daresore. On a Japanese keyboard, use the yen-sign
(¥) key to enter a backslash (\).
To run a command in an external terminal instead of TurtleEdit's lower pane (its basic terminal), set Command for execution as follows:
macOS: open -a Terminal command_name Linux running KDE: Konsole -e command_name Windows: CMD command_name
Learning to program with TurtleEdit
Once you have configured the commands, you can carry out your programming exercises within TurtleEdit:
- Write your program in the editor (the upper pane).
- Save it by choosing Save from the File menu.
- Click Compile. If there are errors, messages appear in the lower pane. Use those messages to help you correct the program.
- Once compilation succeeds, click Run. If the program does not stop as expected, click Break to terminate it.
After opening a file, you must compile it successfully at least once before
you can run it. For a language that does not require compilation, you can assign
either an execution command or a syntax-checking command to the Compile
button. For example, ruby -cw %f checks the syntax of a Ruby program.
When writing a program that asks for input, you need to be aware of output buffering. Consider this C program:
#include <stdio.h>
main(){
int x ;
printf("x? ") ;
scanf("%d",&x) ;
printf("x=%d\n",x) ;
}
The prompt x? may not appear in the lower pane when you expect
it to, because the program's output is buffered. To display the prompt before
waiting for input, flush the output after printing it:
printf("x? ") ;
fflush(stdout) ;
scanf("%d",&x) ;
Alternatively, disable buffering by calling setbuf() before
printf():
setbuf(stdout,NULL) ;
printf("x? ") ;
scanf("%d",&x) ;
If you prefer not to modify your program this way, another approach is
available. For details, see
https://daifukujs.org/coda/tedit/simple-launcher.html.
Notes
To send keyboard input to a running program, first click the lower pane. When the red cursor (caret) appears, type your input.
The amount of output an external program can display in the lower pane is limited to approximately 1 MB. This helps protect against runaway output, for example from an unintended infinite loop.
Learning regular expressions
Choose RegEx Filter from the Filter menu to open a window with a field for a regular expression. Enter an expression and click OK. Matches found in the editor's text are displayed in the lower pane. For details of regular expression syntax, consult the Java documentation.
Select Matched string to output the text that matches the expression.
Note that a dot (.) does not match a newline character.
Select Matched line to output only lines that match the entire expression.
Select Lines containing pattern to output each line that contains a match.
Select Line number to include the corresponding line numbers in the output.
Choose RegEx Replace from the Filter menu to replace all matches
and display the result in the lower pane. The text in the editor (the upper pane)
is left unchanged. In the replacement text, use $n, where
n is 1 through 9, to refer to the text matched by the corresponding
parenthesized group in the expression.
You can also filter the editor's text using external commands such as
sort, uniq, wc, and awk.
Choose External command from the Filter menu and make sure
Plunge text is selected to use the editor's text as input. The result
appears in the lower pane.
The last item in the Filter menu, Swap buffers, exchanges the contents of the upper and lower panes. Using it twice restores the original contents. This is useful when you want to apply a regular expression to the editor's text, move the result back to the editor, then apply another expression, and repeat.