Tải bản đầy đủ - 0 (trang)
Chapter 4. Using Buffers, Windows, and Frames

Chapter 4. Using Buffers, Windows, and Frames

Tải bản đầy đủ - 0trang

4.1.UnderstandingBuffers,Windows,and

Frames

Conceptually,Emacsisdifferentfrommostapplicationsintwo

importantways.First,itswindowterminologyisdifferent.

Second,Emacsbuffersarenottiedtowindowsorframes,

unlikemostapplications.



4.1.1WindowsVersusFrames

Let'sgetourtermsstraightfirst.GUIwindowsarenotEmacs

windows.EmacscallsGUIwindowsframes.Inpart,this

terminologyisnecessarybecauseEmacspredatesGUIsandis

stilloftenusedonterminalswithoutGUIwindows.Emacs

windowsaresplitscreens.We'veseenthemalready;for

example,whenyouaskforkeyboardhelp,youseeitdisplayed

ina*Help*bufferatthebottomofyourscreen.FiguresFigure

4-1andFigure4-2showEmacsframesandEmacswindows.In

Figure4-1,weseeourdickensandodysseybuffersintwo

separateframes.Figure4-2showsasingleframedisplaying

twoEmacswindows,oneontopoftheother,showingthesetwo

files.



Figure4-1.EditingdickensandodysseyinEmacs

frames



Figure4-2.EditingdickensandodysseyinEmacs

windows



Fromnowon,whenwesayframe,wemeanaseparateGUI

window.Whenwesaywindow,wemeanaportionofthe

currentEmacsdisplay.Andfromapracticalstandpoint,we

emphasizethatthisisnotaneither-orproposition.Evenifyou



prefermultipleframes,youwillstilluseEmacs-stylewindows

sometimes.Emacsitselfwillseetothat.



4.1.2Buffers:IndependentofWindowsand

Frames

Nowwhataboutbuffers?Essentially,bothwindowsandframes

arewaystodisplayabuffer,which,asdefinedinChapter1,

maycontainacopyofafileornot.Buffersmaycontainfiles.

TheymaybeEmacs-generatedbuffers,like*Messages*,

*scratch*,or*Help*.Ortheymaybebuffersthatyoucreate

buthaven'twrittentoafile.

MostGUIapplicationstiecertainfilestocertainGUIwindowsor,

inEmacspeak,frames.Emacs'sdetachmentofbuffersfrom

theirdisplay(whetherasplitdisplayoraseparateframe)is

morepowerfulandflexible.Tobehonest,mostofthetimewe

preferusingasingleEmacsframeandswitchingbetween

buffersusingC-xb.It'smucheasierthanmousingbetween

framesordealingwithasplitscreen,thougheachhasits

advantagesinsomesituations.



4.1.3MoreAboutBuffers

HowdoyouknowhowmanybuffersareactiveinEmacsand

whattheyare?Therearethreeways:thebufferlist(which

appearsinawindowwhenyoutypeC-xC-b),theBuffersmenu

(whichlistsactivebuffersandcommandsfornavigatingthem),

andtheBufferpop-upmenu(accessedbyholdingdownCtrl

andclickingtheleftmousebutton,whichlistsbuffersbymode).

Emacscreatesitsownspecializedbuffers.Thenamesforthese

internalbuffersgenerallyhavetheformat*buffername*.

*Help*,*scratch*,and*BufferList*arejustafewofthe



buffersthatEmacscreates.

WhenyoustartEmacs,itgeneratestwobuffers:

*Messages*

*scratch*

*Messages*isabufferwhereEmacsaccumulatesmessages

fromitsstartupandfromtheminibuffer.*scratch*isjustwhat

itsoundslike:atemporaryscratchpadwhereyoucantype.It

won'tbesavedunlessyouexplicitlywriteittoafileusingC-x

C-w.

Ofcourse,typicallyyoueditfileswithEmacs.Thesefilesare

thencopiedintobuffersofthesamename.Ifyouaskforhelp,

you'llalsohavea*Help*buffer.

Thenumberofbuffersyoucanhavereallyhasnolimit.Mostof

thetime,onlyoneortwobuffersaredisplayed,butevenifyou

can'tseethem,allthebuffersyoucreateinanEmacssession

arestillactive.Youcanthinkofthemasastackofpages,with

theonebeingdisplayedasthetoppage.Atanytime,youcan

turntoanotherpage(anotherbuffer),oryoucancreateanew

page.

Eachbufferhasanassociatedmajormodethatdetermines

muchabouthowEmacsbehavesinthatbuffer.Forexample,

textmode,designedforwritingtext,behavesdifferentlyfrom

Lispmode,whichisdesignedforwritingLispprograms.

Youcandisplaymultiplebuffersinseparatewindowsorframes

orboth.Theimportantthingtorememberisthatallthebuffers

youcreateareactiveeveniftheyarenotcurrentlydisplayed.



4.2.WorkingwithMultipleBuffers

Ifyouwanttocreateabufferthatcontainsafile,simplytype

C-xC-ftofindthefile.Emacsautomaticallycreatesasecond

bufferandmovesyouthere.Ifyoualreadyhaveacopyofthe

fileinabuffer,C-xC-fjustmovesyoutotheexistingbuffer.

Thismoveissensibleandprobablyreallywhatyouwant

anyhow;ifC-xC-freadthefilefromdiskeverytime,youcould

endupwithmanyversionsofthesamefilethatwereeach

slightlydifferent.IfthefilenameyougiveC-xC-fdoesn'texist,

Emacsassumesyouwanttocreateanewfilebythatnameand

movesyoutoablankbuffer.



4.2.1SwitchingBuffers

C-xC-fisalwaysfollowedbyafilename.Thecommandfor

movingbetweenbuffers,C-xb,isfollowedbyabuffername.

Didyourealizethatthemodelinedoesn'tdisplayfilenamesbut

onlybuffernames?SomeversionsofEmacsshowboth,but

GNUEmacsshowsonlythebuffername.Thebuffernameand

thefilename,ifany,arethesameunlessyouchangethem(see

thesection"RenamingBuffers,"laterinthischapter).

Tomovebetweenthebuffers,typeC-xb.Emacsshowsyoua

defaultbuffername.PressEnterifthat'sthebufferyouwant,

ortypethefirstfewcharactersofthecorrectbuffernameand

pressTab.Emacsfillsintherestofthename.NowpressEnter

tomovetothebuffer.

YoucandothefollowingwithC-xb:

IfyoutypeC-xb

followedby:



Emacs:



Anewbuffername



Createsanewbufferthatisn'tconnectedwithafileandmoves

there.



Thenameofan

existingbuffer



Movesyoutothebuffer(itdoesn'tmatterwhetherthebufferis

connectedwithafileornot).



Ifyouwanttocreateasecond(orthirdorfourth,etc.)empty

buffer,typeC-xb.Emacsasksforabuffername.Youcanuse

anyname,forexample,practice,andpressEnter.Emacs

createsthebufferandmovesyouthere.Forexample,assume

you'vebeenworkingonyourtried-and-truedickensbuffer.But

you'dlikesomethingnew,soyoustartanewbuffertoplaywith

someprosefromJamesJoyce.

Type:C-xbjoyce



Youtypedanewbuffername.



Type:Enter



Nowyouhaveanewbuffernamedjoycetotypein.



Thisprocedureisn'tallthatdifferentfromusingC-xC-f;about

theonlydifferenceisthatthenewbuffer,joyce,isn'tyet

associatedwithafile.Therefore,ifyouquitEmacs,theeditor

won'taskyouwhetherornotyouwanttosaveit.

C-xbisespeciallyusefulifyoudon'tknowthenameofthefile

youareworkingwith.Assumeyou'reworkingwithsome

obscurefilewithanunusualnamesuchas.saves-5175pcp832913pcs.nrockv01.ky.roadrunner.com.Nowassumethat

youaccidentallydosomethingthatmakesthisbufferdisappear

fromyourscreen.Howdoyouget.saves-5175pcp832913pcs.nrockv01.ky.roadrunner.combackontothe

screen?Doyouneedtoremembertheentirenameorevena

partofit?No.Beforedoinganythingelse,justtypeC-xb.The

defaultbufferisthebufferthatmostrecentlydisappeared;type

Enterandyou'llseeitagain.

Alternatively,theBufferMenupopuplistsbuffersbymajor

mode,andyoucanchooseone.HolddownCtrlandclickthe

leftmousebuttontoseeapop-upmenuofyourcurrentbuffers.

(TheBuffersmenuatthetopofthescreenalsoshowsall

currentbuffers.)

HolddownCtrlandclicktheleftmousebutton.



Emacsdisplaysapop-upmenuofcurrentbuffersbymode(MacOSX).



Tocyclethroughallthebuffersyouhave,typeC-x togoto

thenextbuffer(inthebufferlist)orC-xtogototheprevious

buffer.(Don'tholddownCtrlwhileyoupressthearrowkeyor

Emacsbeepsunhappily.)



4.2.2DeletingBuffers

It'seasytocreatebuffers,andjustaseasytodeletethem

whenyouwantto.Youmaywanttodeletebuffersifyoufeel

yourEmacssessionisgettingclutteredwithtoomanybuffers.

Perhapsyoustartedoutworkingonasetoffivebuffersand

nowwanttodosomethingwithanotherfive.Gettingridofthe

firstsetofbuffersmakesitabiteasiertokeepthingsstraight.

Deletingabuffercanalsobeausefulemergencyescape.For

example,somereplacementoperationmayhavehaddisastrous

results.Youcankillthebufferandchoosenottosavethe

changes,thenreadthefileagain.



Deletingabufferdoesn'tdeletetheunderlyingfilenorisitthe

sameasnotdisplayingabuffer.Buffersthatarenotdisplayed

arestillactivewhereasdeletedbuffersarenolongerpartof

yourEmacssession.Usingtheanalogyofastackofpages,

deletingabufferisliketakingapageoutofthecurrentstackof

buffersyouareeditingandfilingitaway.

Deletingbuffersdoesn'tputyouatriskoflosingchanges,

either.Ifyou'vechangedthebuffer(andthebufferisassociated

withafile),Emacsasksifyouwanttosaveyourchangesbefore

thebufferisdeleted.Youwilllosechangestoanybuffersthat

aren'tconnectedtofiles,butyouprobablydon'tcareabout

thesebuffers.

Deletingabufferissuchabasicoperationthatitisonthe

Emacstoolbar,theXsymbol.Nowlet'slearnhowtodoitfrom

thekeyboardtoincreaseyourfluencyinEmacs.

Todeleteabuffer,typeC-xk(forkill-buffer).Emacsshows

thenameofthebuffercurrentlydisplayed;pressEnterto

deleteitortypeanotherbuffernameiftheonebeingdisplayed

isnottheoneyouwanttodelete,thenpressEnter.Ifyou've

madechangesthatyouhaven'tyetsaved,Emacsdisplaysthe

followingmessage:

Bufferbuffernamemodified.Killanyway?(yesorno).



Toditchyourchanges,typeyes,andEmacskillsthebuffer.To

stopthebufferdeletionprocess,typeno.YoucanthentypeCxC-stosavethebuffer,followedbyC-xktokillit.

YoucanalsohaveEmacsaskyouaboutdeletingeachbuffer,

andyoucandecidewhethertokilleachoneindividually.Type

M-xkill-some-bufferstoweedoutunneededbuffersthisway.

Emacsdisplaysthenameofeachbufferandwhetherornotit

wasmodified,thenaskswhetheryouwanttokillit.Emacs



offerstokilleachandeverybuffer,includingthebuffersit

createsautomatically,like*scratch*and*Messages*.Ifyou

killallthebuffersinyoursession,Emacscreatesanew

*scratch*buffer;afterall,somethinghastodisplayonthe

screen!



4.3.WorkingwithWindows

WindowsareareasonthescreeninwhichEmacsdisplaysthe

buffersthatyouareediting.Youcanhavemultiplewindowson

thescreenatonetime,eachdisplayingadifferentbufferor

differentpartsofthesamebuffer.Granted,themorewindows

youhave,thesmallereachoneis;unlikeGUIwindows,Emacs

windowscan'toverlap,soasyouaddmorewindows,theolder

onesshrink.Thescreenislikeapie;youcancutitintomany

pieces,butthemorepiecesyoucut,thesmallertheyhaveto

be.Youcanplacewindowsside-by-side,oneontopofthe

other,ormixthem.Eachwindowhasitsownmodelinethat

identifiesthebuffername,themodesyou'rerunning,andyour

positioninthebuffer.Tomakeitclearwhereonewindowbegins

andanotherends,modelinesareusuallyshaded.

Aswe'vesaid,windowsarenotbuffers.Infact,youcanhave

morethanonewindowonthesamebuffer.Doingsoisoften

helpfulifyouwanttolookatdifferentpartsofalargefile

simultaneously.Youcanevenhavethesamepartofthebuffer

displayedintwowindows,andanychangeyoumakeinone

windowisreflectedintheother.

Thedifferencebetweenbuffersandwindowsbecomes

importantwhenyouthinkaboutmarking,cutting,andpasting

text.Marksareassociatedwithbuffers,notwithwindows,and

eachbuffercanhaveonlyonemark.Ifyougotoanother

windowonthesamebufferandsetthemark,Emacsmovesthe

marktothenewlocation,forgettingtheplaceyousetitlast.

Asforcursors,youhaveonlyonecursor,andthecursor's

locationdeterminestheactivewindow.However,althoughthere

isonlyonecursoratatime,eachwindowdoeskeeptrackof

yourcurrenteditinglocationseparatelythatis,youcanmove

thecursorfromonewindowtoanother,dosomeediting,jump

backtothefirstwindow,andbeinthesameplace.Awindow's



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Chapter 4. Using Buffers, Windows, and Frames

Tải bản đầy đủ ngay(0 tr)

×