Sams Teach Yourself Emacs in 24 Hours |  | ContentsIndex
Hour 3: Getting Started with Emacs |  | Previous HourNext Hour
Sections in this Hour: |  |

## Point, Mark, and Region

The location in a buffer where text is inserted when you type is called the point. The point is located between two characters and is indicated by highlighting the subsequent character in inverse video. In Figure 3.9, point is located between the two fs in buffer. Note how the second f is in inverse video. If the window does not have focus, point will be shown only as a border around the character.

Figure 3.9
The point.

Caution - Hey, stop here! What was it the point was? From now on the point will be referred to as point, not the insertion cursor, the cursor, or anything else--simply point. So please be sure that you are familiar with this name.

To cut or copy something from a window, you need to mark the text which you want to cut or copy. This marked part is called a region. A region has two ends, one at the location of point, the other at a location called the mark. Thus, without using the mouse, you mark a region by going to one of its boundaries, setting the mark at this location and then go to the other end (point will then be there). (Using the mouse to mark the region works a bit differently.) The mark is set by pressing either C-SPC or C-@ (set-mark- command). In Figure 3.10, you can see the point, the mark, and the region (you can, in fact, see the mark only because you can see the boundary of the region).

Figure 3.10
Point, mark, and region.

Please note that point is a characteristic for a window, whereas the mark is a characteristic for the buffer. This means that you can't have two different regions for one buffer shown in two different windows, because they share the mark, which is one end of the region. (See Hour 15, "Getting an Overview of a File," for a workaround for this.)

There will always be exactly one point and one mark in a buffer, thus there will always be a region. (Technically, this is not 100% true; there is in fact a whole set of marks, but that is beyond the scope of this book.) If the region should always be highlighted, as can be seen in Figure 3.10, some part of the buffer would be in inverse video. There are two ways to avoid this:

- Never highlight the region.

- Highlight the region only when it is active.

The region is active when the mark has been set, and no commands other than movements have been invoked.

The drawback of the first solution is that you can never see the region (you can, however, ask Emacs to show you the mark). The drawback of the second solution is that you have to activate the region when you need to use it.

You can exchange the location of point and mark by pressing C-x C-x (exchange-point-and-mark). As a side effect, this activates the region. This might, therefore, be a solution to the drawbacks in the preceding methods. If the region is never shown, you can exchange the location of mark and point to see where point is and, in method two, you can use this command to activate the region.

GNU Emacs chose the first method as the default, whereas XEmacs chose the second one. One thing is for sure: Regardless of which of the two methods you prefer, it is irritating that there is a difference between GNU Emacs and XEmacs. Therefore you should decide which of these methods you like the best and insert one of the lines shown in the following sections into your .emacs file. (If you use both GNU Emacs and XEmacs, you should remember to insert a test around the appropriate lines to ensure that they are executing only in the appropriate Emacs. See Hour 1, "Introducing Emacs," for a discussion of this.)

### Highlighted Regions in GNU Emacs

To obtain a region that is highlighted in GNU Emacs when it is active, insert the following lines into your .emacs file:

    (transient-mark-mode)

### Always Active Regions in XEmacs

To obtain the GNU Emacs default for regions in XEmacs (that is, that regions are never highlighted but always active) insert the following into your .emacs file:

    (setq zmacs-regions nil)

Sams Teach Yourself Emacs in 24 Hours |  | ContentsIndex
Hour 3: Getting Started with Emacs |  | Previous HourNext Hour
Sections in this Hour: |  |