Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your profile (name, country/region, and company) is displayed to the public and will accompany any content you post. You may update your IBM account at any time.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

developerWorks Community:

  • Close [x]

Emacs editing environment, Part 5: Shape your Emacs view

Get going with this famous open source editor

Michael Stutz, Author, Consultant
Photo of Michael Stutz
Michael Stutz is author of The Linux Cookbook, which he also designed and typeset using only open source software. His research interests include digital publishing and the future of the book. He has used various UNIX operating systems for 20 years.

Summary:  This tutorial, the fifth in a series, shows you how to manage and manipulate the shape your Emacs session—examine how to partition the Emacs screen, create multiple X client windows for a single Emacs session, and display multiple buffers in each window, dividing the screen with horizontal and vertical divisions. You also learn about mouse window control and characteristics so that by the time you're through, you can make your Emacs session look and work the way you want it to.

View more content in this series

Date:  07 Aug 2007
Level:  Intermediate PDF:  A4 and Letter (1247 KB | 26 pages)Get Adobe® Reader®

Activity:  22894 views
Comments:  

Emacs windows and the mouse

Several useful techniques are available for using the mouse with Emacs windows.

The mouse on the mode line

You can use the mouse to perform many of the functions described in the Split and partition your Emacs session section. These window actions are done on the mode line.

In new versions of Emacs, special areas of the mode line have their own mouse bindings. For instance, if your mode line displays whether you have mail (it does so by writing the word Mail), then clicking that word on the mode line in certain ways with the mouse starts a new buffer for your mail; clicking the buffer name in the mode line switches the buffer in that window to the next buffer in your buffer list. These are called tooltips and are shown with a pop-up box that appears when you mouse over the particular area of the mode line. Aside from these special tooltips, the following commands work anywhere on the mode line.

Split windows with the mouse

The C-B2 combination clicked on the mode line splits the window horizontally at the place you click. If you're too close to either end of the window, the split is the minimal amount possible. (You make this combination by pressing and holding the Ctrl key and then clicking the middle mouse button.)

The C-B2 combination on the scrollbar splits the window vertically at the place you click. If you're too close to either end of the window, the split is the minimal amount. (Note that this currently doesn't work with some of the X toolkits that implement the scrollbar.)

Try splitting the window with the mouse:

  1. Exit Emacs, if it's running, by typing C-x C-c. Start it up again with one of the sample files:

    $ emacs innocence
                            

  2. Open the second sample file in a new vertical window: Type C-x 4 f experience Enter .

  3. Your Emacs session should look like Figure 1. Try the C-B2 mouse combination in the middle of the top mode line (somewhere just after the word Top) to split the top window horizontally at that point.

  4. Split the bottom window horizontally at about the same point with a C-B2 mouse combination on its mode line—again, somewhere just after the word Top.

  5. Click and drag B1 on the small vertical bar beneath the scrollbars of the two new windows you just created to adjust them so that all four windows are approximately the same size. If your Emacs frame is too small to display the text in all four windows, you can adjust the size of its X client frame using your window manager controls.

Move to other windows with the mouse

You can move to any Emacs window with the mouse by clicking B1 (the first mouse button) on a blank area of the mode line of the window you want to move to. (In new versions of Emacs, clicking the buffer name changes the visible buffer in that window to the next buffer in the buffer list.) The window whose mode line you click becomes the active window, and the active cursor is moved to the current point in that window.

You can also use the mouse to move anywhere in the visible portion of another window: To do so, click B1 in the window. Point moves to the place where you click.

Try moving between the four windows you just created:

  1. Move to the upper-right window by clicking B1 in a blank area of its mode line, and then type C-u 349 C-n to move down in the file.

  2. Move back to the upper-left window by clicking B1 on any character in the visible buffer window, and then type C-s Till C-s C-s C-a to refocus the display elsewhere in the buffer.

  3. Take a break from the mouse, and move to the lower-left window by typing C-x o C-x o, as you learned in the Move to another window section. Type C-u 286 C-n to move down in the buffer.

  4. Click B1 somewhere just after the buffer name of the mode line on the lower-right window to make it the active window. Type C-s jour C-l to shift the view in this window to elsewhere in the buffer.

Resize windows with the mouse

You can also use the mouse on the mode line to resize windows. This is an alternative to what you learned previously in the Resize a window section.

To make a window taller or shorter, click and drag the mode line with B1. To make a window thinner or wider, click and drag the tiny vertical bar beneath its scrollbar.

Try adjusting the size of your windows with the mouse:

  1. Click and drag B1 and the tiny vertical bar beneath the scrollbar of the upper-right window just a bit, so the width of the upper-right window shrinks by a few characters and the upper-left window grows enough that all the characters on each line appear in the window of both buffers. (You might also have to grow the Emacs frame using your window manager's controls.)

  2. Make the two bottom windows smaller by clicking and dragging B1 on the mode line, so the bottom windows shrink by a few lines.

If you've followed all the steps in this section, your Emacs session should look something like Figure 7.


Figure 7. Making and resizing Emacs windows with the mouse
Making and resizing Emacs windows with the mouse

Delete windows with the mouse

To delete a window, click B3 on its mode line. Click B2 on a blank area of the mode line to kill all the other windows and make that window enlarge to fill the entire frame.

Get rid of some windows:

  1. Click B3 on the mode line of the upper-left window to delete the window. The upper-right window expands over to the left to fill the space; now this window is the active window.

  2. Click B2 on its mode line to delete the two windows beneath it and make this upper window fill the entire Emacs frame.

Mouse avoidance mode

Sometimes the mouse pointer in X gets in the way of your Emacs session—you select an Emacs frame and begin editing, and the mouse pointer is hovering somewhere over your text.

If you find this annoying, you can use mouse-avoidance-mode to change the behavior of the mouse pointer. This mode offers several techniques, as described in Table 4.


Table 4. Styles of Emacs mouse-pointer avoidance
ModeDescription
animate Make the mouse pointer move quickly away to a random position in the frame whenever the cursor gets close to it.
banish Banish the mouse pointer to the upper-right corner of the window as soon as you start typing.
cat-and-mouse Synonym for animate.
exile Move the mouse pointer to the upper-right corner of the window (like banish) only if the pointer gets too close to the cursor. Once the cursor moves away, bring the pointer back to its original position.
jump Make the mouse pointer instantly jump to a random position in the frame whenever the cursor gets close to it.
none No mouse avoidance (the default).
proteus Move the mouse pointer as in animate, but like Proteus of Greek mythology, change the mouse pointer's shape (a random image character is used).

It's best with a demonstration. Try it now:

  1. Type M-x mouse-avoidance-mode Enter cat-and-mouse Enter to turn on mouse-avoidance mode.

  2. Move to the scratch buffer: Type C-x b *scratch* Enter .

  3. Move the mouse pointer so that it's just a few inches to the left of the cursor, and start typing a line of text: "When the cat wants to play the mouse runs away." The mouse pointer should scoot off as soon as the cursor gets near it.

4 of 8 | Previous | Next

Comments



static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=AIX and UNIX, Open source
ArticleID=245702
TutorialTitle=Emacs editing environment, Part 5: Shape your Emacs view
publish-date=08072007
author1-email=stutz@dsl.org
author1-email-cc=mmccrary@us.ibm.com