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]

Emacs editing environment, Part 6: Customize your Emacs world

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 sixth in a series, walks you through some of the useful ways you can customize and configure the Emacs environment. Learn how to change everything about the Emacs environment to your liking, from the behavior of minor modes to the default key bindings. Along the way, figure out how to set variables, make all your customizations automatic with a startup file, save and recall any window and frame customizations that you make, and use the easy customizer that comes built into Emacs.

View more content in this series

Date:  02 Oct 2007
Level:  Intermediate

Activity:  23241 views
Comments:  

Remember Emacs window and frame customizations

In the fifth installment of this series (see Resources), you learned how to manipulate Emacs frames and split them into multiple windows, both horizontally and vertically. You can also save your window customizations and recall them later in your session, even after you've made many changes to the layout of the screen; you do this with Winner mode.

Winner mode is a minor mode that records and remembers your changes to windows and frames. Each time you change the window configuration, it's remembered; you can undo your change to revert to the last configuration. You can also redo your changes to go back to the way you had them. It's especially handy if you're trying an unusual or complex configuration, or if you tend to do different kinds of tasks involving different window setups.

Two functions work in Winner mode: C-x <- (which you type by pressing and holding Ctrl, pressing X, releasing both keys, and then pressing the left arrow key) runs the winner-undo function and undoes the last change to the windows. Its counterpart is C-x ->, which runs winner-redo, returning the last change to the windows that you previously undid.

Enable Winner mode

To get started with Winner mode, set up a custom Emacs frame:

  1. Exit Emacs (if it's currently running), and then restart it with no arguments:

    $ emacs
                            

  2. Type C-x 2 to split the Emacs window vertically, and then type C-x o C-x C-f .emacs Enter to open your .emacs file in the lower window.

  3. Type M-x winner-mode to turn on Winner mode.

When you do this, notice that Win is added to the mode listing given in parentheses on the mode lines of both visible buffers. This means that Winner mode is on and that it works in all buffers. (It even works in other Emacs frames, should you create them.)

Your Emacs session should now look like Figure 4. Notice that the Emacs frame no longer has a menu bar or toolbar—these were turned off in the .emacs file.


Figure 4. Winner mode enabled in an Emacs session
Winner mode enabled in an Emacs session

Cycle through your window configurations

Now, make some new window configurations:

  1. Use the mouse to click B1 in the top window so that it becomes the active window, and then type C-x 3 to split the window horizontally once.

  2. Split the upper-left window vertically by typing C-x 2, and then split the new, upper-left window horizontally again by typing C-x. Type C-x b .emacs Enter to switch to the .emacs buffer in this new window.

Your Emacs frame should now look like Figure 5. Notice that Win appears in the mode line of every window in the frame.


Figure 5. Reconfigure an Emacs frame with Winner mode enabled
Reconfigure an Emacs frame with Winner mode enabled.

Now you can go back to your old configurations and cycle through them—type C-x <- to undo your last window change.

Type C-x <- again to undo another change. Keep going until the minibuffer reports that no further undoes are possible. At this point, your Emacs frame should look like Figure 4, which was how it looked when you first enabled Winner mode.

Type C-x -> to run the winner-redo function and undo your last change. You can cycle between C-x <- and C-x -> to move through all your window changes.

The winner-mode function is a toggle: Type M-x winner-mode again to turn it off. When you do, the winner-redo and winner-undo functions no longer work, and window changes aren't remembered—but once it's enabled again, you can undo and redo any changes you've made to the windows.

6 of 10 | Previous | Next

Comments



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