The `sh' Mode
The
sh mode of
jedit is intended for editing
Bourne shell scripts, or scripts in similar shells such as
ksh(1) or
bash(1). Among its major features are a `Funcs' menu that lets
you quickly jump to a particular function definition and rudimentary
support for automatic indentation.
This document describes the
sh mode available with version 4.1/4.4 of
jedit.
In
sh mode, by default, the
Space and
Return keys do not do abbreviation expansion (although you can do
it by hand with the commands on the `Abbrev' menu), lines do not
have newlines inserted automatically as you approach the right
margin, and when you type a closing parenthesis, bracket or brace,
the corresponding opening character briefly flashes (assuming
it's visible on the screen). Also, new lines start with the
same indentation as the preceeding line, except as modified by
sh mode's
automatic indentation, described below. Of course, you can change any of these settings
on the ModeSpecific Preferences panel.
The
sh mode provides a `Tcl' menu with commands for manipulating comments.
Comment with #
`Comment with #' prepends a hash mark and a space to each line
of the selected text. It's useful for commenting out sections
of code.
Comment with ###
`Comment with ###' functions identically to `Comment with #',
except that it uses three hash marks instead of one. I use
this to comment out sections of code that I want to call my attention
to later.
Uncomment
`Uncomment' removes any number of hash marks followed by a space
from the beginning of the selected lines. (Tip: You can
reformat commented prose by selecting it, choosing `Uncomment',
choosing `Format lines with ``fmt''' from the `Format' menu, and
choosing `Comment with #'.)
Make Border
`Make Border' inserts a line consisting of 70 hash marks, followed
by a newline. I use this as part of my block comments before
procedure definitions, and sometimes as a separator.
The `Hilight Comments' Checkbutton
The `sh' menu also has a checkbutton marked `Hilight Comments'.
This controls a modespecific preference for whether comments
will be highlighted as you type or when a file is loaded. This
preference is saved when you save modespecific preferences from
the ModeSpecific Preferences panel.
Currently, this causes comments to be displayed in a particular
hardcoded font and foreground colour. This is obviously not
ideal; and will be fixed in future versions. For now, this
feature is mainly included for demonstration purposes.
When you change the value of this preference, the existing text
is not automatically checked for comments, so you may need to
reload the current file in order for comments to display correctly.
As are functions, comments are parsed quite simplistically, and
it's easy for
sh mode to fail to identify legitimate comments or to identify
as comments things that aren't.
The Buttonbar
The
tclmode buttonbar has buttons which duplicate the functions of the
commands on the `Tcl' menu, and also a `Save' button which duplicates
the `Save' command on the `File' menu.
The `Funcs' menu provides a dynamic list of all the function definitions
in the current file. You can choose a function name from the
`Funcs' menu to jump quickly to the specified procedure definition.
The `Funcs' menu is generated by searching the text for lines
matching the Tcl regular expression `^[a-zA-Z0-9_]+ *\(\) *\{' (i.e., an alphanumeric word at the beginning of a line, followed
by empty parentheses, followed by an opening brace), so it may
not list functions defined in an unusual coding style.
Normally, as you type in
sh mode, each line gets the same indentation as the previous line
had. However,
sh mode increases the indentation after lines ending in an opening
brace and decreases it on lines consisting of a closing brace;
this is sufficient to indent the bodies of function definitions.
It also increases the indentation for a line following a line
that ends in a backslash; this handles continued lines. Its
parsing is not at all sophisticated and you should not assume
that it will indent code correctly.
The `code' Mode
- In addition to the limitations mentioned above under
Automatic Indentation, the main problem with
sh mode is that indentation is hardwired to two per level of nesting.
Future Directions
- There should be a set of preferences for things like indentation
depth and whether to highlight keywords or comments. This will
require changes to
jedit's mode and preferencehandling mechanisms.