{The `sh' Mode

Introduction
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.

Preferences
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 Mode­Specific Preferences panel.

The `sh' Menu and the Buttonbar
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 mode­specific preference for whether comments will be highlighted as you type or when a file is loaded.  This preference is saved when you save mode­specific preferences from the Mode­Specific Preferences panel.

Currently, this causes comments to be displayed in a particular hard­coded 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 re­load 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 tcl­mode 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
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.

Automatic Indentation
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.

See Also
	The `code' Mode

Evolution
Bugs and Limitations
· 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 preference­handling mechanisms.
} {{{jdoc:anchor:anchorname {3.0 4.0 8.0 9.0 11.0 12.0 38.0 39.0 43.0 44.0 46.0 47.0 49.0 51.0}} {list:level:1 {51.0 52.0 54.0 55.0}} {sel {6.59 6.66}} {jdoc:xref:link {4.15 4.20 9.495 9.516 47.1 47.16 51.55 51.76 54.150 54.155}} {jdoc:xref:manpage {4.45 4.57 4.104 4.107 4.114 4.118}} {richtext:font:roman {2.0 3.0 4.0 4.4 4.6 4.15 4.20 4.45 4.57 4.104 4.107 4.114 4.118 6.28 6.30 6.70 6.75 8.0 9.0 9.3 9.5 9.28 9.33 9.38 9.44 9.485 9.487 11.0 12.0 12.4 12.6 14.0 15.0 17.0 18.0 20.0 21.0 23.0 24.0 26.0 27.0 33.78 33.80 35.0 36.0 36.4 36.7 38.0 39.0 41.100 41.124 43.0 44.0 44.25 44.27 44.106 44.108 46.0 47.0 47.1 47.16 49.0 51.0 51.55 51.76 51.100 51.102 53.0 54.0 54.150 54.155 55.0}} {richtext:font:bold {9.28 9.33 9.38 9.44}} {richtext:font:bolditalic {47.1 47.16 51.55 51.76}} {richtext:font:typewriter {4.4 4.6 4.15 4.20 4.45 4.57 4.104 4.107 4.114 4.118 6.28 6.30 6.70 6.75 9.3 9.5 9.485 9.487 12.4 12.6 33.78 33.80 36.4 36.7 41.100 41.124 44.25 44.27 44.106 44.108 51.100 51.102 54.150 54.155}} {richtext:font:heading0 {1.0 2.0}} {richtext:font:heading1 {3.0 4.0 8.0 9.0 11.0 12.0 38.0 39.0 43.0 44.0 46.0 47.0 49.0 50.0}} {richtext:font:heading2 {14.0 15.0 17.0 18.0 20.0 21.0 23.0 24.0 26.0 27.0 35.0 36.0 50.0 51.0 53.0 54.0}} {special:list_item:1 {51.0 51.1 54.0 54.1}} {jdoc:anchorname:Introduction {3.0 4.0}} {jdoc:link:jedit.jdoc {4.15 4.20 54.150 54.155}} {jdoc:anchorname:Preferences {8.0 9.0}} {jdoc:link:#Automatic_Indentation {9.495 9.516 51.55 51.76}} {jdoc:anchorname:Automatic_Indentation {43.0 44.0}} {jdoc:link:jeditmodes/code-mode.jdoc {47.1 47.16}} {jdoc:anchorname:See_Also {46.0 47.0}} {jdoc:anchorname:Bugs_and_Limitations {50.0 51.0}} {jdoc:anchorname:Evolution {49.0 50.0}} {jdoc:manpage:sh {4.45 4.57}} {jdoc:manpage:ksh {4.104 4.107}} {jdoc:manpage:bash {4.114 4.118}} {jdoc:anchorname:The_`sh'_Menu_and_the_Buttonbar {11.0 12.0}} {list:1:ul {51.0 52.0 54.0 55.0}} {jdoc:anchorname:The_`Funcs'_Menu {38.0 39.0}}} {{matchend 49.0} {abbrevstart 34.0} {abbrevend 34.0} {insert 6.66} {matchstart 49.0} {anchor 38.16} {current 6.46}}} {}