Emacs editing environment, Part 5: Shape your Emacs view ?· Emacs editing environment, Part 5: Shape…

  • Published on
    04-Jun-2018

  • View
    213

  • Download
    0

Embed Size (px)

Transcript

<ul><li><p>Emacs editing environment, Part 5: Shape yourEmacs viewGet going with this famous open source editor</p><p>Skill Level: Intermediate</p><p>Michael Stutz (stutz@dsl.org)AuthorConsultant</p><p>07 Aug 2007</p><p>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.</p><p>Section 1. Before you start</p><p>Learn what to expect from this tutorial, and how to get the most out of it.</p><p>About this series</p><p>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.</p><p>After completing this series (see Resources), you'll be able to comfortably use</p><p>Shape your Emacs view Copyright IBM Corporation 1994, 2008. All rights reserved. Page 1 of 32</p><p>mailto:stutz@dsl.orghttp://www.ibm.com/legal/copytrade.shtml</p></li><li><p>Emacs for everyday editing, be well on your way to Emacs proficiency, and have agood feel for many of the advanced capabilities of Emacs.</p><p>About this tutorial</p><p>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.</p><p>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.</p><p>Objectives</p><p>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.</p><p>After working through this tutorial, you'll know how to manipulate frames and thewindows they contain, including using mouse techniques to do so.</p><p>Prerequisites</p><p>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).</p><p>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."</p><p>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:</p><p> Files</p><p> Directories</p><p> Permissions</p><p> File system hierarchy</p><p>developerWorks ibm.com/developerWorks</p><p>Shape your Emacs viewPage 2 of 32 Copyright IBM Corporation 1994, 2008. All rights reserved.</p><p>http://www.ibm.com/legal/copytrade.shtml</p></li><li><p>System requirements</p><p>This tutorial requires a user account on any UNIX-based system that has a recentcopy of Emacs installed.</p><p>There are several varieties of Emacs; the original and most popular is GNU Emacs,which is published online by the GNU Project (see Resources).</p><p>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.</p><p>To know what version of Emacs you have running, use the GNU-style --versionflag:</p><p>$ 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.$</p><p>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.</p><p>This tutorial uses a two-file sample data set, which is available as a single archivefile (see the Downloads section for the link).</p><p>Section 2. Split and partition your Emacs session</p><p>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.</p><p>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.</p><p>ibm.com/developerWorks developerWorks</p><p>Shape your Emacs view Copyright IBM Corporation 1994, 2008. All rights reserved. Page 3 of 32</p><p>http://www.ibm.com/legal/copytrade.shtml</p></li><li><p>To get started, extract these two files into your own examples directory.</p><p>Split a window vertically</p><p>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.</p><p>To make such a split, run the split-window-vertically function, which isbound to the C-x 2 keystroke.</p><p>Try it with the sample files:</p><p>1. Start Emacs by typing emacs in the directory containing your copies ofthe two sample files.</p><p>2. Open the files:</p><p>C-x C-f innocence Enter C-x C-f experience Enter</p><p>3. Split the window:</p><p>C-x 2</p><p>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:</p><p>C-x b Enter</p><p>Your Emacs session should look like Figure 1.</p><p>Figure 1. Splitting an Emacs window vertically</p><p>developerWorks ibm.com/developerWorks</p><p>Shape your Emacs viewPage 4 of 32 Copyright IBM Corporation 1994, 2008. All rights reserved.</p><p>http://www.ibm.com/legal/copytrade.shtml</p></li><li><p>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:</p><p>$ emacs innocence experience</p><p>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.</p><p>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.</p><p>For example, the bottom window of the two is now active; type C-x 2 to split justthis one lower window.</p><p>ibm.com/developerWorks developerWorks</p><p>Shape your Emacs view Copyright IBM Corporation 1994, 2008. All rights reserved. Page 5 of 32</p><p>http://www.ibm.com/legal/copytrade.shtml</p></li><li><p>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.</p><p>Figure 2. Multiple Emacs vertical splits</p><p>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.</p><p>Try it now:</p><p>developerWorks ibm.com/developerWorks</p><p>Shape your Emacs viewPage 6 of 32 Copyright IBM Corporation 1994, 2008. All rights reserved.</p><p>http://www.ibm.com/legal/copytrade.shtml</p></li><li><p>1. Exit Emacs by typing C-x C-c, and then start it up with a single file:</p><p>$ emacs experience</p><p>2. Type M-&gt; to move to the end of the buffer.</p><p>3. Type C-x 2 to split the window vertically, with the same buffer in bothwindows.</p><p>4. Move to the top of the buffer in the active window: Type M-</p></li><li><p>2. Type M-- M-4 C-x 2 to split the buffer, with four lines in the bottombuffer.</p><p>C-x 2 makes a vertical split, but a number of important key bindings for splittingwindows begin with the C-x 4 prefix.</p><p>To open a new file in a new buffer and in a new window, use thefind-file-other-window function, which is bound to C-x 4 f. Then, give thename of the file. To open the read-only file, usefind-file-read-only-other-window instead and give the filename. It's boundto C-x 4 r.</p><p>Try opening the innocence file in a new buffer in the other window: Type C-x 4 finnocence Enter .</p><p>Although the other window already existed when you specified a four-line window,notice how this command resizes it so that the active window and the new windoware about the same size.</p><p>The switch-to-buffer-other-window function, which is bound to C-x 4 b,splits the window vertically and lets you choose which buffer to display in the newother window, which also becomes the active window.</p><p>Try switching the buffer in the other window to the innocence buffer with thiscommand: Type C-x 4 b innocence Enter and notice that it doesn't changethe window you typed it init, too, now displays the innocence buffer.</p><p>To display a new buffer in another vertical window but keep the active cursor in thecurrent window, run the display-buffer function, which is bound to C-x 4 C-o.It prompts for the name of the buffer to display in the other window, but the currentwindow remains active. If the display has only a single window, this function splits itand creates a new windowbut if the display already has two or more windows, anew split isn't made.</p><p>Try switching the buffer in the bottom window to the experience buffer with thiscommand: Type C-x 4 C-o experience Enter .</p><p>Move inside a window</p><p>When you have multiple windows in your Emacs session, cursor motion isn'taffectedyou move normally in the current, active window just as if there were onlyone window in your session. And when you scroll this window, using either thescrollbar or the various keys for scrolling, the other window or windows don'tscrolleven if those windows show a copy of the same buffer.</p><p>To scroll the other window, not the window the cursor is in, use thescroll-other-window function, which is bound to C-M-v. (Emacs keeps all your</p><p>developerWorks ibm.com/developerWorks</p><p>Shape your Emacs viewPage 8 of 32 Copyright IBM Corporation 1994, 2008. All rights reserved.</p><p>http://www.ibm.com/legal/copytrade.shtml</p></li><li><p>windows in an ordered list, so if you have more than two windows open, thiscommand scrolls the window that is next on the list.)</p><p>Try typing C-M-v now to scroll through the lower window with the experience bufferin it until the title of "A Little Boy Lost" comes into view.</p><p>You can scroll all windows that are open to the same buffer at once by enablingscroll-all mode. This function is a toggle and, when it's active, the mode line shows*SL*. It moves all the windows of the same buffer together, even if the windowsshow completely different portions of the bufferthe scroll commands you type areapplied to all windows containing that buffer.</p><p>Try it now:</p><p>1. Type C-x b experience Enter to switch to the experience buffer inthe top window.</p><p>2. Turn on scroll-all mode by typing M-x scroll-all-mode.</p><p>3. Scroll through both windows at once by typing PgDn while the top windowis still active.</p><p>4. Move the cursor up in both windows by pressing the up arrow key; pressit enough times so that the top of the buffer appears in the top window,and keep pressing to see the cursor move in the bottom window but notthe top.</p><p>5. Move the cursor down in both buffers by pressing the down arrow keyseveral times.</p><p>Move to another window</p><p>To move between the windows, run the other-window function, C-x o, whichmoves to the next window. It cycles through all windows when you run it repeatedly.When you move to another window, the cursor is drawn at the current point in thatbuffer.</p><p>You can also move the cursor to other windows by specifying them directionally withthe windmove commands, as described by Table 1.</p><p>Table 1. Summary of Emacs windmove commandsFunction Description</p><p>windmove-up Move to the window directly above the currentwindow, if it exists.</p><p>ibm.com/developerWorks developerWorks</p><p>Shape your Emacs view Copyright IBM Corporation 1994, 2008. All rights reserved. Page 9 of 32</p><p>http://www.ibm.com/legal/copytrade.shtml</p></li><li><p>windmove-down Move to the window directly below the currentwindow, if it exists.</p><p>windmove-left Move to the window directly to the left of thecurrent window, if it exists.</p><p>windmove-right Move to the window directly to the right of thecurrent window, if it exists.</p><p>Try it now:</p><p>1. Type C-x o to move to the bottom window.</p><p>2. Turn off scroll-all mode: Type M-x scroll-all-mode, and then scrolldown to "A Little Boy Lost" again, noticing that the top window no longerscrolls.</p><p>3. Move back to the top window by typing C-x o.</p><p>4. Split this window with C-x 2.</p><p>5. Move down to the window you just split by typing M-x windmove-down.</p><p>Delete a window</p><p>There are a few ways to delete Emacs windows.</p><p>To delete the current windowthat is, the one where the active cursor currentlyisrun the delete-window function, which is bound to C-x 0.</p><p>Try i...</p></li></ul>

Recommended

View more >