4 Editing Documents

Although Hemlock is not dedicated to editing documents as word processing systems are, it provides a number of commands for this purpose. If Hemlock is used in conjunction with a text-formatting program, then its lack of complex formatting commands is no liability.

Text Mode [Command]

This commands puts the current buffer into "Text" mode.

4.1 Sentence Commands

A sentence is defined as a sequence of characters ending with a period, question mark or exclamation point, followed by either two spaces or a newline. A sentence may also be terminated by the end of a paragraph. Any number of closing delimiters, such as brackets or quotes, may be between the punctuation and the whitespace. This somewhat complex definition of a sentence is used so that periods in abbreviations are not misinterpreted as sentence ends.

Forward Sentence (bound to M-a) [Command]

Backward Sentence (bound to M-e) [Command]

Forward Sentence moves the point forward past the next sentence end. Backward Sentence moves to the beginning of the current sentence. A prefix argument may be used as a repeat count.

Forward Kill Sentence (bound to M-k) [Command]

Backward Kill Sentence (bound to C-x Delete, C-x Backspace) [Command]

Forward Kill Sentence kills text from the point through to the end of the current sentence. Backward Kill Sentence kills from the point to the beginning of the current sentence. A prefix argument may be used as a repeat count.

Mark Sentence [Command]

This command puts the point at the beginning and the mark at the end of the next or current sentence.

4.2 Paragraph Commands

A paragraph may be delimited by a blank line or a line beginning with "'" or ".", in which case the delimiting line is not part of the paragraph. Other characters may be paragraph delimiters in some modes. A line with at least one leading whitespace character may also introduce a paragraph and is considered to be part of the paragraph. Any fill-prefix which is present on a line is disregarded for the purpose of locating a paragraph boundary.

Forward Paragraph (bound to M-]) [Command]

Backward Paragraph (bound to M-[) [Command]

Forward Paragraph moves to the end of the current or next paragraph. Backward Paragraph moves to the beginning of the current or previous paragraph. A prefix argument may be used as a repeat count.

Mark Paragraph (bound to M-h) [Command]

This command puts the point at the beginning and the mark at the end of the current paragraph.

Paragraph Delimiter Function (initial value default-para-delim-function) [Variable]

This variable holds a function that takes a mark as its argument and returns true when the line it points to should break the paragraph.

4.3 Filling

Filling is a coarse text-formatting process which attempts to make all the lines roughly the same length, but doesn't vary the amount of space between words. Editing text may leave lines with all sorts of strange lengths; filling this text will return it to a moderately aesthetic form.

Set Fill Column (bound to C-x f) [Command]

This command sets the fill column to the column that the point is currently at, or the one specified by the absolute value of prefix argument, if it is supplied. The fill column is the column past which no text is permitted to extend.

Set Fill Prefix (bound to C-x .) [Command]

This command sets the fill prefix to the text from the beginning of the current line to the point. The fill-prefix is a string which filling commands leave at the beginning of every line filled. This feature is useful for filling indented text or comments.

Fill Column (initial value 75) [Variable] Fill Prefix (initial value nil) [Variable]

These variables hold the value of the fill prefix and fill column, thus setting these variables will change the way filling is done. If Fill Prefix is nil, then there is no fill prefix.

Fill Paragraph (bound to M-q) [Command]

This command fills the text in the current or next paragraph. The point is not moved.

Fill Region (bound to M-g) [Command]

This command fills the text in the region. Since filling can mangle a large quantity of text, this command asks for confirmation before filling a large region (see Region Query Size.)

Auto Fill Mode [Command]

This command turns on or off the Fill minor mode in the current buffer. When in Fill mode, Space, Return and Linefeed are rebound to commands that check whether the point is past the fill column and fill the current line if it is. This enables typing text without having to break the lines manually.

If a prefix argument is supplied, then instead of toggling, the sign determines whether Fill mode is turned off; a positive argument argument turns in on, and a negative one turns it off.

Auto Fill Linefeed [Command]

Auto Fill Return [Command]

Auto Fill Linefeed fills the current line if it needs it and then goes to a new line and inserts the fill prefix. Auto Fill Return is similar, but does not insert the fill prefix on the new line.

Auto Fill Space [Command]

If no prefix argument is supplied, this command inserts a space and fills the current line if it extends past the fill column. If the argument is zero, then it fills the line if needed, but does not insert a space. If the argument is positive, then that many spaces are inserted without filling.

Auto Fill Space Indent (initial value nil) [Variable]

This variable determines how lines are broken by the auto fill commands. If it is true, new lines are created using the Indent New Comment Line command, otherwise the New Line command is used. Language modes should define this variable to be true so that auto fill mode can be used on code.

4.4 Scribe Mode

Scribe mode provides a number of facilities useful for editing Scribe documents. It is also sufficiently parameterizable to be adapted to other similar syntaxes.

Scribe Mode [Command]

This command puts the current buffer in Scribe mode. Except for special Scribe commands, the only difference between Scribe mode and Text mode is that the rules for determining paragraph breaks are different. In Scribe mode, paragraphs delimited by Scribe commands are normally placed on their own line, in addition to the normal paragraph breaks. The main reason for doing this is that it prevents Fill Paragraph from mashing these commands into the body of a paragraph.

Insert Scribe Directive [Command]

This command prompts for a key-event to determine which Scribe directive to insert. Directives are inserted differently depending on their kind:

The current or next paragraph is enclosed in a begin-end pair: @begin[directive] paragraph @end[directive]. If the current region is active, then this command encloses the region instead of the paragraph it would otherwise chose.
The previous word is enclosed by @directive[word]. If the previous word is already enclosed by a use of the same command, then the beginning of the command is extended backward by one word.

Typing Home or C-_ to this command's prompt will display a list of all the defined key-events on which it dispatches.

Add Scribe Directive [Command]

This command adds to the database of directives recognized by the Insert Scribe Directive command. It prompts for the directive's name, the kind of directive (environment or command) and the key-event on which to dispatch.

Add Scribe Paragraph Delimiter [Command]

List Scribe Paragraph Delimiters [Command]

Add Scribe Paragraph Delimiter prompts for a string to add to the list of formatting commands that delimit paragraphs in Scribe mode. If the user supplies a prefix argument, then this command removes the string as a delimiter.

List Scribe Paragraph Delimiters displays in a pop-up window the Scribe commands that delimit paragraphs.

Escape Character (initial value #\@) [Variable]

Close Paren Character (initial value #\]) [Variable]

Open Paren Character (initial value #\[) [Variable]

These variables determine the characters used when a Scribe directive is inserted.

Scribe Insert Bracket [Command]

Scribe Bracket Table (initial value ) [Variable]

Scribe Insert Bracket inserts a bracket (>, }, ), or ]), that caused its invocation, and then shows the matching bracket.

Scribe Bracket Table holds a simple-vector indexed by character codes. If a character is a bracket, then the entry for its char-code should be the opposite bracket. If a character is not a bracket, then the entry should be nil.

4.5 Spelling Correction

Hemlock has a spelling correction facility based on the dictionary for the ITS spell program. This dictionary is fairly small, having only 45,000 word or so, which means it fits on your disk, but it also means that many reasonably common words are not in the dictionary. A correct spelling for a misspelled word will be found if the word is in the dictionary and is only erroneous in that it has a wrong character, a missing character, an extra character or a transposition of two characters.

Check Word Spelling (bound to M-$) [Command]

This command looks up the previous or current word in the dictionary and attempts to correct the spelling if it is misspelled. There are four possible results of invoking this command:

This command displays the message "Found it." in the echo area. This means it found the word in the dictionary exactly as given.

This command displays the message "Found it because of word.", where word is some other word with the same root but a different ending. The word is no less correct than if the first message is given, but an additional piece of useless information is supplied to make you feel like you are using a computer.

The command prompts with "Correction choice:" in the echo area and lists possible correct spellings associated with numbers in a pop-up display. Typing a number selects the corresponding correction, and the command replaces the erroneous word, preserving case as though by Query Replace. Typing anything else rejects all the choices.

This commands displays the message "Word not found.". The word is not in the dictionary and possibly spelled correctly anyway. Furthermore, no similarly spelled words were found to offer as possible corrections. If this happens, it is worth trying some alternate spellings since one of them might be close enough to some known words that this command could display.

Correct Buffer Spelling [Command]

This command scans the entire buffer looking for misspelled words and offers to correct them. It creates a window into the Spell Corrections buffer, and in this buffer it maintains a log of any actions taken by the user. When this finds an unknown word, it prompts for a key-event. The user has the following options:

Ignore this word. If the command finds the word again, it will prompt again.
Insert this word in the dictionary.
Choose one of the corrections displayed in the Spell Corrections window by specifying the correction number. If the same misspelling is encountered again, then the command will make the same correction automatically, leaving a note in the log window.
Prompt for a word to use instead of the misspelled one, remembering the correction as with c.
Go into a recursive edit at the current position, and resume checking when the recursive edit is exited.

After this command completes, it deletes the log window leaving the buffer around for future reference.

Spell Ignore Uppercase (initial value nil) [Variable]

If this variable is true, then Auto Check Word Spelling and Correct Buffer Spelling will ignore unknown words that are all uppercase. This is useful for acronyms and cryptic formatter directives.

Add Word to Spelling Dictionary (bound to C-x $) [Command]

This command adds the previous or current word to the spelling dictionary.

Remove Word from Spelling Dictionary [Command]

This command prompts for a word to remove from the spelling dictionary. Due to the dictionary representation, removal of a word in the initial spelling dictionary will remove all words with the same root. The user is asked for confirmation before removing a root word with valid suffix flags.

List Incremental Spelling Insertions [Command]

This command displays the incremental spelling insertions for the current buffer's associated spelling dictionary file.

Read Spelling Dictionary [Command]

This command adds some words from a file to the spelling dictionary. The format of the file is a list of words, one on each line.

Save Incremental Spelling Insertions [Command]

This command appends incremental dictionary insertions to a file. Any words added to the dictionary since the last time this was done will be appended to the file. Except for Augment Spelling Dictionary, all the commands that add words to the dictionary put their insertions in this list. The file is prompted for unless Set Buffer Spelling Dictionary has been executed in the buffer.

Set Buffer Spelling Dictionary [Command]

This command Prompts for the dictionary file to associate with the current buffer. If the specified dictionary file has not been read for any other buffer, then it is read. Incremental spelling insertions from this buffer can be appended to this file with Save Incremental Spelling Insertions. If a buffer has an associated spelling dictionary, then saving the buffer's associated file also saves any incremental dictionary insertions. The "Dictionary: file" file option may also be used to specify the dictionary for a buffer (see section 3.3.3).

Default User Spelling Dictionary (initial value nil) [Variable]

This variable holds the pathname of a dictionary to read the first time Spell mode is entered in a given editing session. When Set Buffer Spelling Dictionary or the "dictionary" file option is used to specify a dictionary, this default one is read also. It defaults to nil.

4.5.1 Auto Spell Mode

Auto Spell Mode checks the spelling of each word as it is typed. When an unknown word is typed the user is notified and allowed to take a number of actions to correct the word.

Auto Spell Mode [Command]

This command turns Spell mode on or off in the current buffer.

Auto Check Word Spelling [Command]

Check Word Spelling Beep (initial value t) [Variable]

Correct Unique Spelling Immediately (initial value t) [Variable]

This command checks the spelling of the word before the point, doing nothing if the word is in the dictionary. If the word is misspelled but has a known correction previously supplied by the user, then this command corrects the spelling. If there is no correction, then this displays a message in the echo area indicating the word is unknown. An unknown word detected by this command may be corrected using the Correct Last Misspelled Word command. This command executes in addition to others bound to the same key; for example, if Fill mode is on, any of its commands bound to the same keys as this command also run.

If Check Word Spelling Beep is true, then this command will beep when an unknown word is found. If Correct Unique Spelling Immediately is true, then this command will immediately attempt to correct any unknown word, automatically making the correction if there is only one possible.

Undo Last Spelling Correction (bound to C-x a) [Command]

Spelling Un-Correct Prompt for Insert (initial value nil) [Variable]

Undo Last Spelling Correction undoes the last incremental spelling correction. The "correction" is replaced with the old word, and the old word is inserted in the dictionary. Any automatic replacement for the old word is eliminated. When Spelling Un-Correct Prompt for Insert is true, the user is asked to confirm the insertion into the dictionary.

Correct Last Misspelled Word (bound to M-:) [Command]

This command places the cursor after the last misspelled word detected by the Auto Check Word Spelling command and then prompts for a key-event on which it dispatches:

Display possible corrections in a pop-up window, and prompt for the one to make according to the corresponding displayed digit or letter.
any digit
Similar to c digit, but immediately makes the correction, dispensing with display of the possible corrections. This is shorter, but only works when there are less than ten corrections.
Insert the word in the dictionary.
Replace the word with another.
Backspace, Delete, n
Skip this word and try again on the next most recently misspelled word.
Enter a recursive edit at the word, exiting the command when the recursive edit is exited.
Exit and forget about this word.

As in Correct Buffer Spelling, the c and r commands add the correction to the known corrections.