emacs editing environment, part 5: shape your emacs view .emacs editing environment, part 5: shape

Download Emacs editing environment, Part 5: Shape your Emacs view .Emacs editing environment, Part 5: Shape

Post on 04-Jun-2018

213 views

Category:

Documents

0 download

Embed Size (px)

TRANSCRIPT

  • Emacs editing environment, Part 5: Shape yourEmacs viewGet going with this famous open source editor

    Skill Level: Intermediate

    Michael Stutz (stutz@dsl.org)AuthorConsultant

    07 Aug 2007

    This tutorial, the fifth in a series, shows you how to manage and manipulate theshape your Emacs sessionexamine how to partition the Emacs screen, createmultiple X client windows for a single Emacs session, and display multiple buffers ineach window, dividing the screen with horizontal and vertical divisions. You also learnabout 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.

    Section 1. Before you start

    Learn what to expect from this tutorial, and how to get the most out of it.

    About this series

    The Emacs editing environment is a favorite of UNIX developers. It's known aroundthe world as the king of editors, but many users find it has a bit of a learning curve.The Emacs environment doesn't seem intuitive at first glance, and it doesn't worklike other editors and word processors. But learning Emacs doesn't have to bedifficult. Once you get going, you'll see how intuitive it is and become morecomfortable with it after each use. This tutorial series (see Resources) shows youthe way, taking you from the basics of Emacs, such as its features, philosophy,key-command layout, and methods for editing text, through many of its powerfulediting features.

    After completing this series (see Resources), you'll be able to comfortably use

    Shape your Emacs view Copyright IBM Corporation 1994, 2008. All rights reserved. Page 1 of 32

    mailto:stutz@dsl.orghttp://www.ibm.com/legal/copytrade.shtml

  • Emacs for everyday editing, be well on your way to Emacs proficiency, and have agood feel for many of the advanced capabilities of Emacs.

    About this tutorial

    This intermediate-level, hands-on tutorial builds on what you learned in previousinstallments, and shows you how to customize and tool the system for your specificneeds.

    In this tutorial, you learn how to manage and manipulate the viewport of your Emacssessionthe main Emacs X client window and the space inside it that displaysbuffers and other information. You find out the best way to partition this area for youruse, including creating multiple X client windows for a single Emacs session anddisplaying multiple buffers in each window by dividing the screen with horizontal andvertical divisions. You also examine how to use the mouse to manipulate thesedivisions.

    Objectives

    This tutorial illustrates how to manipulate your view into Emacs: how to partition anddivide an Emacs window and how to make more Emacs windows that attach to asingle Emacs session.

    After working through this tutorial, you'll know how to manipulate frames and thewindows they contain, including using mouse techniques to do so.

    Prerequisites

    Before working through this tutorial, you should complete the previous tutorials inthis series. They lay down the basic foundation and explain many of the Emacsconcepts you use in this tutorial (see Resources).

    The special Emacs notation for representing keystrokes, which is used in this tutorialand throughout the series, is described in the introduction of the first tutorial of theseries, "Learning the Emacs editing environment, Part 1: The basics of Emacs."

    Although this tutorial is written for all levels of UNIX expertise, it's helpful if you haveat least a rudimentary understanding of the UNIX file system:

    Files

    Directories

    Permissions

    File system hierarchy

    developerWorks ibm.com/developerWorks

    Shape your Emacs viewPage 2 of 32 Copyright IBM Corporation 1994, 2008. All rights reserved.

    http://www.ibm.com/legal/copytrade.shtml

  • System requirements

    This tutorial requires a user account on any UNIX-based system that has a recentcopy of Emacs installed.

    There are several varieties of Emacs; the original and most popular is GNU Emacs,which is published online by the GNU Project (see Resources).

    You should have a recent copy of GNU Emacsone that is at version 20 or greater.Versions 20 and 21 are the most commonly available, and development snapshotsof version 22 are also available. This tutorial works with any of these versions forEmacs. If your system is running something older, it's time to upgrade.

    To know what version of Emacs you have running, use the GNU-style --versionflag:

    $ emacs --versionGNU Emacs 22.0.91.1Copyright (C) 2006 Free Software Foundation, Inc.GNU Emacs comes with ABSOLUTELY NO WARRANTY.You may redistribute copies of Emacsunder the terms of the GNU General Public License.For more information about these matters, see the file named COPYING.$

    Because this tutorial deals exclusively with graphical elements of Emacs operation inthe X Window System environment, you should also have an X server up andrunning.

    This tutorial uses a two-file sample data set, which is available as a single archivefile (see the Downloads section for the link).

    Section 2. Split and partition your Emacs session

    You can use a number of commands to control an Emacs window, which is the viewof a buffer that you see framed in an Emacs X client window containing the bufferitself and its mode line beneath it. These commands let you view multiple buffers atonce by partitioning your window in various ways. Practically speaking, these are themost commonly used of all the commands for manipulation of Emacs clientwindows.

    The examples in this tutorial use a sample data set, which is available in acompressed archive file (see Downloads). This archive file contains a tar archivecontaining two plain text files, innocence and experience, whose contents are thecomplete text of William Blake's The Songs of Innocence and The Songs ofExperience, respectivelyyou'll recognize some of the text from previous tutorials.

    ibm.com/developerWorks developerWorks

    Shape your Emacs view Copyright IBM Corporation 1994, 2008. All rights reserved. Page 3 of 32

    http://www.ibm.com/legal/copytrade.shtml

  • To get started, extract these two files into your own examples directory.

    Split a window vertically

    Probably the most common way to partition an Emacs window is to slice it in halfacross the middle of the screen. This action makes two new windows, each with itsown mode line and each approximately half the height of the original. You cuthorizontally across the Emacs screen, so the two new windows are stacked on topof each other in a vertical column; thus, this kind of window operation is called avertical split.

    To make such a split, run the split-window-vertically function, which isbound to the C-x 2 keystroke.

    Try it with the sample files:

    1. Start Emacs by typing emacs in the directory containing your copies ofthe two sample files.

    2. Open the files:

    C-x C-f innocence Enter C-x C-f experience Enter

    3. Split the window:

    C-x 2

    4. Notice that the active buffer (named experience, which was the last bufferyou opened) appears in both windows when the window splits. The bufferin the top window is now the active buffer and contains an active cursor.Switch to the innocence buffer in this top window:

    C-x b Enter

    Your Emacs session should look like Figure 1.

    Figure 1. Splitting an Emacs window vertically

    developerWorks ibm.com/developerWorks

    Shape your Emacs viewPage 4 of 32 Copyright IBM Corporation 1994, 2008. All rights reserved.

    http://www.ibm.com/legal/copytrade.shtml

  • Incidentally, this is the same two-buffer vertical split that Emacs does automaticallywhen you start it with two files as arguments, as described in the last tutorial in thisseries, "Emacs options, registers, and bookmarks." Type C-x C-c to exit Emacs,and then try it on the sample files:

    $ emacs innocence experience

    Notice the one difference: When you specify two files as command-line arguments,the bottom window (whose contents are the second argument) becomes the activewindow.

    You're not limited to two windows at onceEmacs can show as many windows aswill fit on the screen. But remember that when you make a split, Emacs splits thecurrent window, and all other windows remain untouched.

    For example, the bottom window of the two is now active; type C-x 2 to split justthis one lower window.

    ibm.com/developerWorks developerWorks

    Shape your Emacs view Copyright IBM Corporation 1994, 2008. All rights reserved. Page 5 of 32

    http://www.ibm.com/legal/copytrade.shtml

  • Your Emacs screen is now divided into three windows, and the middle window isactive. Type C-x 2 to split that middle window again, making a total of four windowsin the Emacs screenand then type C-x 2 again to try to split the second, tinywindow. Depending on the size of your main Emacs X client window, this recursivesplitting of split windows comes to an end sooner or later, at the point when any newwindow would be too small to display at least two lines of text and a mode line; then,Emacs beeps and reports in the minibuffer that the given window can't be splitfurther. Your session should look like Figure 2.

    Figure 2. Multiple Emacs vertical splits

    You can use split windows to view multiple buffers at once, but it's also helpful toview the same buffer in multiple windowsspecifically, to view different parts of abuffer in different windows. This ability to edit one part of the buffer while you'relooking at another part of the buffer is one of the most useful tricks in power editing.It's a tremendous aid.

    Try it now:

    developerWorks ibm.com/developerWorks

    Shape your Emacs viewPage 6 of 32 Copyright IBM Corporation 1994, 2008. All rights reserved.