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:  23266 views
Comments:  

Use the Emacs Customize function

Customize is a special Emacs function that was designed to make it easy to customize all aspects of the editor's behavior. It allows you to interactively select, set, and save values and settings for many aspects of Emacs, including the various fonts, faces, and colors used to display text. Its purpose is to simplify and rein in the elaborate Emacs customization process, making it easier for Emacs users who aren't Emacs Lisp programmers to customize their setup.

The Customize function is especially useful for setting text colors and faces because you can see and make changes interactively, and you can test them in your current session without applying them to all future sessions. When you do save your changes for future sessions, they're automatically written to your .emacs file, so they apply to the current as well as all future Emacs sessions.

Start a customization buffer

To begin customizing your Emacs, run the customize function by typing M-x customize.

When you do this, a new customization buffer appears in your Emacs frame, as shown in Figure 6. Notice the buffer's name: *Customize Group: Emacs*.


Figure 6. The Emacs customize buffer
The Emacs customize buffer

Pick a customization group

All of the various aspects of Emacs that can be customized are divided into groups containing similar elements and aspects of the editor. The groups that are displayed depend on your system setup.

To open a group and view its individual members, either use the mouse to click B1 on the Go to Group text button for that group, or use the keyboard to move the cursor over that button and press Enter. Sometimes a group opens into a list of new subgroups, in which case the process for selecting is the same.

Try selecting the Editing group now. When you do, Emacs opens a new buffer named *Customize Group: Editing* that contains a new listing of groups, all pertaining to Emacs editing functions.

Select the Fill group in this menu so that a *Customize Group: Fill* buffer is opened. This buffer contains many individual options and additional subgroups—you have to scroll down to see them all. Your Emacs session should look like Figure 7.


Figure 7. The Emacs Fill customize group buffer
The Emacs Fill customize group buffer

Change a customization option

Each option in the group listing has a value that you can change. You see a number of buttons for each option, including More, which provides more information about the option. When you click this button, it's relabeled Hide; when you click it, the expansion is hidden again.

The State button describes the current state of that option: unchanged from its standard setting, hidden, changed but not saved, or changed and saved.

Try changing a value: Scroll down to the Fill Column entry, and notice that the value is set to 70, which you remember is the default for this variable. Move the cursor to the box with its value, and change it to 10. The State button for this value reports the following:

you have edited the value as text, but you have not set the option.

Move up to the top of the buffer, and click the Set for Current Session button; this puts your changes in effect, but they'll reset as soon as you exit Emacs. (If you want to make a change that affects this and all future sessions, click the Save for Future Sessions button instead).

Click the Finish button, which removes this buffer, and click the Finish button on all other Customize buffers.

Now you can test your customization:

  1. Type C-x C-f .emacs Enter to open a copy of your .emacs init file in a new buffer.

  2. Move the cursor to each comment line (they begin with ;; and are followed by a line of text), and type M-q on run the fill-paragraph function on them.

The paragraphs fill at the tenth character on each line, so your .emacs init file should look like Figure 8.


Figure 8. Wrap comment text in a .emacs file after customizing the fill column
Wrap comment text in a .emacs file after customizing the fill column

You can verify that the changes you made to default filling work only for this session: Save your reformatted .emacs file, exit Emacs with C-x C-c, and then restart it with your .emacs file:

$ emacs .emacs
                

Now, move to all the comment lines containing text, and type M-q on each of them to watch them move back to where they were before (filled at 70 columns).


Customize specific attributes

You don't have to go through the entire series of customization buffers every time you want to make a particular customization. Commands are available to take you directly to a particular group, and some of the Emacs customization menus have special Emacs functions of their own.

For example, the customize-group function opens a customization buffer for the given group.

Try opening a new Emacs customization buffer for the Fill group:

                    M-x customize-group
Customize group: (default emacs) fill
                

You get a *Customize Group: Fill* buffer just as before, as in Figure 7.

Know the Emacs customization functions

Table 3 lists and describes the various Emacs Customize functions.


Table 3. Summary of Emacs Customize functions
FunctionDescription
customize-changed-options Enter version Open a new customization buffer for all faces, options, or groups that have been changed since the version of Emacs given by version.
customize-customized Open a new customization buffer for all options and faces that have already been customized but haven't been saved to disk.
customize-face Enter regexp Open a new customization buffer for all the face, option, or groups relevant to the regular expression given by regexp.
customize-face Enter face Open a new customization buffer for the face name given by face.
customize-group Enter group Open a new customization buffer for the group name given by group.
customize-option Enter option Open a new customization buffer for the option name given by option.
customize-saved Open a new customization buffer for all faces and options that you've changed with the Customize function.

7 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