## 10 Basic Editing

Editing with jed is pretty easy— most keys simply insert themselves. Movement around the buffer is usually done using the arrow keys or page up and page down keys. If `edt.sl` is loaded, the keypads on VTxxx terminals function as well. Here, only the highlights are touched upon (cut/paste operations are not considered “highlights”). In the following, any character prefixed by the `^` character denotes a Control character. On keyboards without an explicit Escape key, Ctrl-[ will most likely generate and Escape character.

A “prefix argument” to a command may be generated by first hitting the Esc key, then entering the number followed by pressing the desired key. Normally, the prefix argument is used simply for repetition. For example, to move to the right 40 characters, one would press Esc 4 0 followed immediately by the right arrow key. This illustrates the use of the repeat argument for repetition. However, the prefix argument may be used in other ways as well. For example, to begin defining a region, one would press the Ctrl-@ key. This sets the mark and begins highlighting. Pressing the Ctrl-@ key with a prefix argument will abort the act of defining the region and to pop the mark.

The following list of useful keybindings assumes that `emacs.sl` has been loaded.

Ctrl-L
Redraw screen.

Ctrl-_
Undo (Control-underscore, also Ctrl-X u).

Esc q
Reformat paragraph (wrap mode). Used with a prefix argument. will justify the paragraph as well.

Esc n
narrow paragraph (wrap mode). Used with a prefix argument will justify the paragraph as well.

Esc ;
Make Language comment (Fortran and C)

Esc `\`
Trim whitespace around point

Esc !
Execute shell command

Esc $
Ispell word (unix)

Ctrl-X ?
Show line/column information.

‘
`quoted_insert` — insert next char as is (backquote key)

Esc s
Center line.

Esc u
Upcase word.

Esc d
Downcase word.

Esc c
Capitalize word.

Esc x
Get M-x minibuffer prompt with command completion

Ctrl-X Ctrl-B
pop up a list of buffers

Ctrl-X Ctrl-C
exit jed

Ctrl-X 0
Delete Current Window

Ctrl-X 1
One Window.

Ctrl-X 2
Split Window.

Ctrl-X o
Other window.

Ctrl-X b
switch to buffer

Ctrl-X k
kill buffer

Ctrl-X s
save some buffers

Ctrl-X Esc
Get S-Lang> prompt for interface to the S-Lang interpreter.

Esc .
Find tag (unix ctags compatible)

Ctrl-@
Set Mark (Begin defining a region). Used with a prefix argument aborts the act of defining the region and pops the Mark.

### 10.1 Undo

One of jed’s nicest features is the ability to undo nearly any change that occurs within a buffer at the touch of a key. If you delete a word, you can undo it. If you delete 10 words in the middle of the buffer, move to the top of the buffer and randomly make changes, you can undo all of that too.

By default, the `undo` function is bound to the key Ctrl-_ (Ascii 31). Since some terminals are not capable of generating this character, it is also bound to the key sequence Ctrl-X u.

Due to the lack of virtual memory support on IBMPC systems, the `undo` function is not enabled on every buffer. In particular, it is not enabled for the `*scratch*` buffer. However, it is enabled for any buffer which is associated with a file. A “plus” character on the left hand side of the status line indicates that undo is enabled for the buffer. It is possible to enable undo for any buffer by using the `toggle_undo` function.

### 10.2 Marking Text (Point and Mark)

Many commands work on certain regions of text. A region is defined by the `Point` and the `Mark` The `Point` is the location of the current editing point or cursor position. The `Mark` is the location of a mark. The mark is set using the `set_mark_cmd` which is bound to Ctrl-@ (Control-2 or Control-Space on some keyboards). When the mark is set, the m mark indicator will appear on the status line. This indicates that a region is being defined. Moving the cursor (`Point`) defines the other end of a region. If the variable HIGHLIGHT is non-zero, jed will highlight the region as it is defined.

Even without highlighting, it is easy to see where the location of the mark is by using the `exchange` command which is bound to Ctrl-X Ctrl-X. This simply exchanges the `Point` and the `Mark`. The region is still intact since it is defined only by the `Point` and `Mark`. Pressing Ctrl-X Ctrl-X again restores the mark and Point back to their original locations. Try it.

### 10.3 Tab Issues.

Strictly speaking, jed uses only fixed column tabs whose size is determined by the value of the `TAB` variable. Setting the `TAB` variable to 0 causes jed to not use tabs as whitespace and to display tabs as Ctrl-I. Please note that changing the tab settings on the terminal will have no effect as far as jed is concerned. The `TAB` variable is local to each buffer allowing every buffer to have its own tab setting. The variable `TAB_DEFAULT` is the tab setting that is given to all newly created buffers. The default value for this variable is 8 which corresponds to eight column tabs.

jed is also able to “simulate” arbitrary tabs as well through the use of user defined tab stops. Calling the function `edit_tab_stops` allows the user to interactively set the tab stops. That is, one simply presses Esc X to get the `M-x` prompt and enters `edit_tab_stops`. A window will pop open displaying the current tab settings. To add a tab stop, simply place a T in the appropriate column. Use the space bar to remove a tab stop.

Here an argument is presented in favor of simulated tabs over real tab stops. First, consider what a “tab” really is. A “tab” in a file is nothing more than a character whose ASCII value is 9. For this reason, one also denotes a tab as `^I` (Ctrl-I). Unlike most other ASCII characters, the effect of the tab character is device dependent and is controlled through the device tab settings. Hence, a file which displays one way on one device may look totally different on another device if the tab settings do not correspond. For this reason, many people avoid tabs altogether and others the adopt “standard” of eight column tabs. Even though people always argue about what the correct tab settings should be, it must be kept in mind that this is primarily a human issue and not a machine issue.

On a device employing tab stops, a tab will cause the cursor to jump to the position of the next tab stop. Now consider the effect of changing the tab settings. Assume that in one part of a document, text was entered using the first setting and in another part, the second setting was used. When moving from the part of the document where the current tab setting is appropriate to the part where the other tab setting was used will cause the document to look unformatted unless the appropriate tab settings are restored. Wordprocessors store the tab settings in the file with the text so that the tabs may be dynamically changed to eliminate such unwanted behavior. However, text editors such as jed, vi, Emacs, EDT, EVE (TPU), etc, do not store this information in the file. jed avoids this problem by using simulated tabs. When using simulated tabs, tabs are not really used at all. Rather jed inserts the appropriate number of spaces to achieve the desired effect. This also has the advantage of one being able to cut and paste from the part of a document using one tab setting to another part with a different tab setting. This simple operation may lead to unwanted results on some wordprocessors as well as those text editors using real tab stops.

### 10.4 Searching

jed currently has two kinds of searches: ordinary searches and incremental searches. Both types of searches have forward and backward versions. The actual functions for binding purposes are:

          search_forward
          search_backward
          isearch_forward
          isearch_backward

There is also the `occur` function which finds all occurrences of a single word (string). This function has no backwards version. By default it is not bound to any keys, so to use it, `occur` must be entered at the `M-x` prompt (Esc X) or one is always free to bind it to a key.

In the following only the incremental search is discussed.

The default type of search in Emacs in the incremental search. However, since this type of search is confusing to the uninitiated, the ordinary type of search has been made the default in jed’s Emacs emulation. For the traditional emacs keybinding, it is up to the user to provide the keybinding.

As the name suggests, an incremental search performs a search incrementally. That is, as you enter the search string, the editor begins searching right away. For example, suppose you wish to search for the string apple. As soon as the letter a is entered into the incremental search prompt, jed will search for the first occurrence of a. Then as soon as the p is entered, jed will search from the current point for the string ap, etc. This way, one is able to quickly locate the desired string with only a minimal amount of information.

Unlike the “ordinary” search, the incremental search is not terminated with the Enter key. Hitting the Enter key causes jed to search for the next occurrence of the string based on the data currently entered at the prompt. The search is terminated with the Esc key.

Finally, the DEL key (Ctrl-?) is used to erase the last character entered at the search prompt. In addition to erasing the last character of the search string, jed will return back to the location of the previous match. Erasing all characters will cause the editor to return to the place where the search began. Like many things, this is one of those that is easier to do than explain. Feel free to play around with it.

### 10.5 Rectangles

jed has built-in support for the editing of rectangular regions of text. One corner of rectangle is defined by setting the mark somewhere in the text. The Point (cursor location) defines the opposite corner of the rectangle.

Once a rectangle is defined, one may use the following functions:

`kill_rect`
Delete text inside the rectangle saving the rectangle in the internal rectangle buffer.

`n_rect`
Push all text in the rectangle to the right outside the rectangle.

`copy_rect`
Copy text inside the rectangle to the internal rectangle buffer.

`blank_rect`
Replace all text inside the rectangle by spaces.

The function `insert_rect` inserts a previously killed or copied rectangle into the text at the Point.

These functions have no default binding and must be entered into the MiniBuffer by pressing Esc X to produce the `M-x` prompt.

### 10.6 Sorting

jed is capable of sorting a region of lines using the heapsort algorithm. The region is sorted alphabetically based upon the ASCII values of the characters located within a user defined rectangle in the region. That is, the rectangle simply defines the characters upon what the sort is based. Simply move to the top line of the region and set the mark on the top left corner of the rectangle. Move to the bottom line and place the point at the position which defines the lower right corner of the rectangle. Press Esc X to get the `M-x` prompt and enter `sort` As as example, consider the following data:

          Fruit:             Quantity:
          lemons                3
          pears                37
          peaches             175
          apples              200
          oranges              56

To sort the data based upon the name, move the Point to the top left corner of the sorting rectangle. In this case, the Point should be moved to the l in the word lemons. Set the mark. Now move to the lower right corner of the rectangle which is immediately after the s in oranges. Pressing Esc X and entering `sort` yields:

          Fruit:             Quantity:
          apples              200
          lemons                3
          oranges              56
          peaches             175
          pears                37

Suppose that it is desired to sort by quantity instead. Looking at the original (unsorted) data, move the Point to two spaces before the 3 on the line containing lemons. The cursor should be right under the u in Quantity. Set the mark. Now move the Point to immediately after 56 on the oranges line and again press Esc X and enter `sort`. This yields the desired sort:

          Fruit:             Quantity:
          lemons                3
          pears                37
          oranges              56
          peaches             175
          apples              200