wiki:HemlockUser/EditingPrograms

7 Editing Programs

7.1 Comment Manipulation

Hemlock has commenting commands which can be used in almost any language. The behavior of these commands is determined by several Hemlock variables which language modes should define appropriately.

Indent for Comment (bound to M-;) [Command]

This is the most basic commenting command. If there is already a comment on the current line, then this moves the point to the start of the comment. If there no comment, this creates an empty one.

This command normally indents the comment to start at Comment Column. The comment indents differently in the following cases:

  1. If the comment currently starts at the beginning of the line, or if the last character in the Comment Start appears three times, then the comment remains unmoved.
  1. If the last character in the Comment Start appears two times, then the comment is indented like a line of code.
  1. If text on the line prevents the comment occurring in the desired position, this places the comment at the end of the line, separated from the text by a space.

Although the rules about replication in the comment start are oriented toward Lisp commenting styles, you can exploit these properties in other languages.

When given a prefix argument, this command indents any existing comment on that many consecutive lines. This is useful for fixing up the indentation of a group of comments.

Indent New Comment Line (bound to M-j, M-Linefeed) [Command]

This commend ends the current comment and starts a new comment on a blank line, indenting the comment the same way that Indent for Comment does. When not in a comment, this command is the same as Indent New Line.

Up Comment Line (bound to M-p) [Command]

Down Comment Line (bound to M-n) [Command]

These commands are similar to Previous Line or Next Line followed by Indent for Comment. Any empty comment on the current line is deleted before moving to the new line.

Kill Comment (bound to C-M-;) [Command]

This command kills any comment on the current line. When given a prefix argument, it kills comments on that many consecutive lines. Undo will restore the unmodified text.

Set Comment Column (bound to C-x ;) [Command]

This command sets the comment column to its prefix argument. If used without a prefix argument, it sets the comment column to the column the point is at.

Comment Start (initial value nil) [Variable]

Comment End (initial value nil) [Variable]

Comment Begin (initial value nil) [Variable]

Comment Column (initial value 0) [Variable]

These variables determine the behavior of the comment commands.

Comment Start
The string which indicates the start of a comment. If this is nil, then there is no defined comment syntax.
Comment End
The string which ends a comment. If this is nil, then the comment is terminated by the end of the line.
Comment Begin
The string inserted to begin a new comment.
Comment Column
The column that normal comments start at.

7.2 Indentation

Nearly all programming languages have conventions for indentation or leading whitespace at the beginning of lines. The Hemlock indentation facility is integrated into the command set so that it interacts well with other features such as filling and commenting.

Indent (bound to Tab, C-i) [Command]

This command indents the current line. With a prefix argument, indents that many lines and moves down. Exactly what constitutes indentation depends on the current mode (see Indent Function).

Indent New Line (bound to Linefeed) [Command]

This command starts a new indented line. Deletes any whitespace before the point and inserts indentation on a blank line. The effect of this is similar to Return followed by Tab. The prefix argument is passed to New Line, which is used to insert the blank line.

Indent Region (bound to C-M-\) [Command]

This command indents every line in the region. It may be undone with Undo.

Back to Indentation (bound to M-m, C-M-m) [Command]

This command moves point to the first non-whitespace character on the current line.

Delete Indentation (bound to M-, C-M-) [Command]

Delete Indentation joins the current line with the previous one, deleting excess whitespace. This operation is the inverse of the Linefeed command in most modes. Usually this leaves one space between the two joined lines, but there are several exceptions.

The non-whitespace immediately surrounding the deleted line break determine the amount of space inserted.

If the preceding character is an "(" or the following character is a ")", then this inserts no space. If the preceding character is a newline, then this inserts no space. This will happen if the previous line was blank. If the preceding character is a sentence terminator, then this inserts two spaces. When given a prefix argument, this command joins the current and next lines, rather than the previous and current lines.

Quote Tab (bound to M-Tab) [Command]

This command inserts a tab character.

Indent Rigidly (bound to C-x Tab, C-x C-i) [Command]

This command changes the indentation of all the lines in the region. Each line is moved to the right by the number of spaces specified by the prefix argument, which defaults to eight. A negative prefix argument moves lines left.

Center Line [Command]

This indents the current line so that it is centered between the left margin and Fill Column. If a prefix argument is supplied, then it is used as the width instead of Fill Column.

Indent Function (initial value tab-to-tab-stop) [Variable]

The value of this variable determines how indentation is done, and it is a function which is passed a mark as its argument. The function should indent the line which the mark points to. The function may move the mark around on the line. The mark will be :left-inserting. The default simply inserts a tab character at the mark.

Indent with Tabs (initial value indent-using-tabs) [Variable]

Spaces per Tab (initial value 8) [Variable]

Indent with Tabs holds a function that takes a mark and a number of spaces. The function will insert a maximum number of tabs and a minimum number of spaces at mark to move the specified number of columns. The default definition uses Spaces per Tab to determine the size of a tab. Note, Spaces per Tab is not used everywhere in Hemlock yet, so changing this variable could have unexpected results.

7.3 Language Modes

Hemlock's language modes are currently fairly crude, but probably provide better programming support than most non-extensible editors.

Pascal Mode [Command]

This command sets the current buffer's major mode to Pascal. Pascal mode borrows parenthesis matching from Scribe mode and indents lines under the previous line.