windows.texi 189 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453
  1. @c -*-texinfo-*-
  2. @c This is part of the GNU Emacs Lisp Reference Manual.
  3. @c Copyright (C) 1990-1995, 1998-1999, 2001-2016 Free Software
  4. @c Foundation, Inc.
  5. @c See the file elisp.texi for copying conditions.
  6. @node Windows
  7. @chapter Windows
  8. This chapter describes the functions and variables related to Emacs
  9. windows. @xref{Frames}, for how windows are assigned an area of screen
  10. available for Emacs to use. @xref{Display}, for information on how text
  11. is displayed in windows.
  12. @menu
  13. * Basic Windows:: Basic information on using windows.
  14. * Windows and Frames:: Relating windows to the frame they appear on.
  15. * Window Sizes:: Accessing a window's size.
  16. * Resizing Windows:: Changing the sizes of windows.
  17. * Preserving Window Sizes:: Preserving the size of windows.
  18. * Splitting Windows:: Creating a new window.
  19. * Deleting Windows:: Removing a window from its frame.
  20. * Recombining Windows:: Preserving the frame layout when splitting and
  21. deleting windows.
  22. * Selecting Windows:: The selected window is the one that you edit in.
  23. * Cyclic Window Ordering:: Moving around the existing windows.
  24. * Buffers and Windows:: Each window displays the contents of a buffer.
  25. * Switching Buffers:: Higher-level functions for switching to a buffer.
  26. * Choosing Window:: How to choose a window for displaying a buffer.
  27. * Display Action Functions:: Subroutines for @code{display-buffer}.
  28. * Choosing Window Options:: Extra options affecting how buffers are displayed.
  29. * Window History:: Each window remembers the buffers displayed in it.
  30. * Dedicated Windows:: How to avoid displaying another buffer in
  31. a specific window.
  32. * Quitting Windows:: How to restore the state prior to displaying a
  33. buffer.
  34. * Window Point:: Each window has its own location of point.
  35. * Window Start and End:: Buffer positions indicating which text is
  36. on-screen in a window.
  37. * Textual Scrolling:: Moving text up and down through the window.
  38. * Vertical Scrolling:: Moving the contents up and down on the window.
  39. * Horizontal Scrolling:: Moving the contents sideways on the window.
  40. * Coordinates and Windows:: Converting coordinates to windows.
  41. * Window Configurations:: Saving and restoring the state of the screen.
  42. * Window Parameters:: Associating additional information with windows.
  43. * Window Hooks:: Hooks for scrolling, window size changes,
  44. redisplay going past a certain point,
  45. or window configuration changes.
  46. @end menu
  47. @node Basic Windows
  48. @section Basic Concepts of Emacs Windows
  49. @cindex window
  50. A @dfn{window} is an area of the screen that is used to display a buffer
  51. (@pxref{Buffers}). In Emacs Lisp, windows are represented by a special
  52. Lisp object type.
  53. @cindex multiple windows
  54. Windows are grouped into frames (@pxref{Frames}). Each frame
  55. contains at least one window; the user can subdivide it into multiple,
  56. non-overlapping windows to view several buffers at once. Lisp
  57. programs can use multiple windows for a variety of purposes. In
  58. Rmail, for example, you can view a summary of message titles in one
  59. window, and the contents of the selected message in another window.
  60. @cindex terminal screen
  61. @cindex screen of terminal
  62. Emacs uses the word ``window'' with a different meaning than in
  63. graphical desktop environments and window systems, such as the X
  64. Window System. When Emacs is run on X, each of its graphical X
  65. windows is an Emacs frame (containing one or more Emacs windows).
  66. When Emacs is run on a text terminal, the frame fills the entire
  67. terminal screen.
  68. @cindex tiled windows
  69. Unlike X windows, Emacs windows are @dfn{tiled}; they never overlap
  70. within the area of the frame. When a window is created, resized, or
  71. deleted, the change in window space is taken from or given to the
  72. adjacent windows, so that the total area of the frame is unchanged.
  73. @defun windowp object
  74. This function returns @code{t} if @var{object} is a window (whether or
  75. not it displays a buffer). Otherwise, it returns @code{nil}.
  76. @end defun
  77. @cindex live windows
  78. A @dfn{live window} is one that is actually displaying a buffer in a
  79. frame.
  80. @defun window-live-p object
  81. This function returns @code{t} if @var{object} is a live window and
  82. @code{nil} otherwise. A live window is one that displays a buffer.
  83. @end defun
  84. @cindex internal windows
  85. The windows in each frame are organized into a @dfn{window tree}.
  86. @xref{Windows and Frames}. The leaf nodes of each window tree are live
  87. windows---the ones actually displaying buffers. The internal nodes of
  88. the window tree are @dfn{internal windows}, which are not live.
  89. @cindex valid windows
  90. A @dfn{valid window} is one that is either live or internal. A valid
  91. window can be @dfn{deleted}, i.e., removed from its frame
  92. (@pxref{Deleting Windows}); then it is no longer valid, but the Lisp
  93. object representing it might be still referenced from other Lisp
  94. objects. A deleted window may be made valid again by restoring a saved
  95. window configuration (@pxref{Window Configurations}).
  96. You can distinguish valid windows from deleted windows with
  97. @code{window-valid-p}.
  98. @defun window-valid-p object
  99. This function returns @code{t} if @var{object} is a live window, or an
  100. internal window in a window tree. Otherwise, it returns @code{nil},
  101. including for the case where @var{object} is a deleted window.
  102. @end defun
  103. @cindex selected window
  104. @cindex window selected within a frame
  105. In each frame, at any time, exactly one Emacs window is designated
  106. as @dfn{selected within the frame}. For the selected frame, that
  107. window is called the @dfn{selected window}---the one in which most
  108. editing takes place, and in which the cursor for selected windows
  109. appears (@pxref{Cursor Parameters}). The selected window's buffer is
  110. usually also the current buffer, except when @code{set-buffer} has
  111. been used (@pxref{Current Buffer}). As for non-selected frames, the
  112. window selected within the frame becomes the selected window if the
  113. frame is ever selected. @xref{Selecting Windows}.
  114. @defun selected-window
  115. This function returns the selected window (which is always a live
  116. window).
  117. @end defun
  118. @anchor{Window Group}Sometimes several windows collectively and
  119. cooperatively display a buffer, for example, under the management of
  120. Follow Mode (@pxref{Follow Mode,,, emacs}), where the windows together
  121. display a bigger portion of the buffer than one window could alone.
  122. It is often useful to consider such a @dfn{window group} as a single
  123. entity. Several functions such as @code{window-group-start}
  124. (@pxref{Window Start and End}) allow you to do this by supplying, as
  125. an argument, one of the windows as a stand in for the whole group.
  126. @defun selected-window-group
  127. @vindex selected-window-group-function
  128. When the selected window is a member of a group of windows, this
  129. function returns a list of the windows in the group, ordered such that
  130. the first window in the list is displaying the earliest part of the
  131. buffer, and so on. Otherwise the function returns a list containing
  132. just the selected window.
  133. The selected window is considered part of a group when the buffer
  134. local variable @code{selected-window-group-function} is set to a
  135. function. In this case, @code{selected-window-group} calls it with no
  136. arguments and returns its result (which should be the list of windows
  137. in the group).
  138. @end defun
  139. @node Windows and Frames
  140. @section Windows and Frames
  141. Each window belongs to exactly one frame (@pxref{Frames}).
  142. @defun window-frame &optional window
  143. This function returns the frame that the window @var{window} belongs
  144. to. If @var{window} is @code{nil}, it defaults to the selected
  145. window.
  146. @end defun
  147. @defun window-list &optional frame minibuffer window
  148. This function returns a list of live windows belonging to the frame
  149. @var{frame}. If @var{frame} is omitted or @code{nil}, it defaults to
  150. the selected frame.
  151. The optional argument @var{minibuffer} specifies whether to include
  152. the minibuffer window in the returned list. If @var{minibuffer} is
  153. @code{t}, the minibuffer window is included. If @var{minibuffer} is
  154. @code{nil} or omitted, the minibuffer window is included only if it is
  155. active. If @var{minibuffer} is neither @code{nil} nor @code{t}, the
  156. minibuffer window is never included.
  157. The optional argument @var{window}, if non-@code{nil}, should be a live
  158. window on the specified frame; then @var{window} will be the first
  159. element in the returned list. If @var{window} is omitted or @code{nil},
  160. the window selected within the frame is the first element.
  161. @end defun
  162. @cindex window tree
  163. @cindex root window
  164. Windows in the same frame are organized into a @dfn{window tree},
  165. whose leaf nodes are the live windows. The internal nodes of a window
  166. tree are not live; they exist for the purpose of organizing the
  167. relationships between live windows. The root node of a window tree is
  168. called the @dfn{root window}. It can be either a live window (if the
  169. frame has just one window), or an internal window.
  170. A minibuffer window (@pxref{Minibuffer Windows}) is not part of its
  171. frame's window tree unless the frame is a minibuffer-only frame.
  172. Nonetheless, most of the functions in this section accept the
  173. minibuffer window as an argument. Also, the function
  174. @code{window-tree} described at the end of this section lists the
  175. minibuffer window alongside the actual window tree.
  176. @defun frame-root-window &optional frame-or-window
  177. This function returns the root window for @var{frame-or-window}. The
  178. argument @var{frame-or-window} should be either a window or a frame;
  179. if omitted or @code{nil}, it defaults to the selected frame. If
  180. @var{frame-or-window} is a window, the return value is the root window
  181. of that window's frame.
  182. @end defun
  183. @cindex parent window
  184. @cindex child window
  185. @cindex sibling window
  186. When a window is split, there are two live windows where previously
  187. there was one. One of these is represented by the same Lisp window
  188. object as the original window, and the other is represented by a
  189. newly-created Lisp window object. Both of these live windows become
  190. leaf nodes of the window tree, as @dfn{child windows} of a single
  191. internal window. If necessary, Emacs automatically creates this
  192. internal window, which is also called the @dfn{parent window}, and
  193. assigns it to the appropriate position in the window tree. A set of
  194. windows that share the same parent are called @dfn{siblings}.
  195. @cindex parent window
  196. @defun window-parent &optional window
  197. This function returns the parent window of @var{window}. If
  198. @var{window} is omitted or @code{nil}, it defaults to the selected
  199. window. The return value is @code{nil} if @var{window} has no parent
  200. (i.e., it is a minibuffer window or the root window of its frame).
  201. @end defun
  202. Each internal window always has at least two child windows. If this
  203. number falls to one as a result of window deletion, Emacs
  204. automatically deletes the internal window, and its sole remaining
  205. child window takes its place in the window tree.
  206. Each child window can be either a live window, or an internal window
  207. (which in turn would have its own child windows). Therefore, each
  208. internal window can be thought of as occupying a certain rectangular
  209. @dfn{screen area}---the union of the areas occupied by the live
  210. windows that are ultimately descended from it.
  211. @cindex window combination
  212. @cindex vertical combination
  213. @cindex horizontal combination
  214. For each internal window, the screen areas of the immediate children
  215. are arranged either vertically or horizontally (never both). If the
  216. child windows are arranged one above the other, they are said to form
  217. a @dfn{vertical combination}; if they are arranged side by side, they
  218. are said to form a @dfn{horizontal combination}. Consider the
  219. following example:
  220. @smallexample
  221. @group
  222. ______________________________________
  223. | ______ ____________________________ |
  224. || || __________________________ ||
  225. || ||| |||
  226. || ||| |||
  227. || ||| |||
  228. || |||____________W4____________|||
  229. || || __________________________ ||
  230. || ||| |||
  231. || ||| |||
  232. || |||____________W5____________|||
  233. ||__W2__||_____________W3_____________ |
  234. |__________________W1__________________|
  235. @end group
  236. @end smallexample
  237. @noindent
  238. The root window of this frame is an internal window, @var{W1}. Its
  239. child windows form a horizontal combination, consisting of the live
  240. window @var{W2} and the internal window @var{W3}. The child windows
  241. of @var{W3} form a vertical combination, consisting of the live
  242. windows @var{W4} and @var{W5}. Hence, the live windows in this
  243. window tree are @var{W2}, @var{W4}, and @var{W5}.
  244. The following functions can be used to retrieve a child window of an
  245. internal window, and the siblings of a child window.
  246. @defun window-top-child &optional window
  247. This function returns the topmost child window of @var{window}, if
  248. @var{window} is an internal window whose children form a vertical
  249. combination. For any other type of window, the return value is
  250. @code{nil}.
  251. @end defun
  252. @defun window-left-child &optional window
  253. This function returns the leftmost child window of @var{window}, if
  254. @var{window} is an internal window whose children form a horizontal
  255. combination. For any other type of window, the return value is
  256. @code{nil}.
  257. @end defun
  258. @defun window-child window
  259. This function returns the first child window of the internal window
  260. @var{window}---the topmost child window for a vertical combination, or
  261. the leftmost child window for a horizontal combination. If
  262. @var{window} is a live window, the return value is @code{nil}.
  263. @end defun
  264. @defun window-combined-p &optional window horizontal
  265. This function returns a non-@code{nil} value if and only if
  266. @var{window} is part of a vertical combination. If @var{window} is
  267. omitted or @code{nil}, it defaults to the selected one.
  268. If the optional argument @var{horizontal} is non-@code{nil}, this
  269. means to return non-@code{nil} if and only if @var{window} is part of
  270. a horizontal combination.
  271. @end defun
  272. @defun window-next-sibling &optional window
  273. This function returns the next sibling of the window @var{window}. If
  274. omitted or @code{nil}, @var{window} defaults to the selected window.
  275. The return value is @code{nil} if @var{window} is the last child of
  276. its parent.
  277. @end defun
  278. @defun window-prev-sibling &optional window
  279. This function returns the previous sibling of the window @var{window}.
  280. If omitted or @code{nil}, @var{window} defaults to the selected
  281. window. The return value is @code{nil} if @var{window} is the first
  282. child of its parent.
  283. @end defun
  284. The functions @code{window-next-sibling} and
  285. @code{window-prev-sibling} should not be confused with the functions
  286. @code{next-window} and @code{previous-window}, which return the next
  287. and previous window, respectively, in the cyclic ordering of windows
  288. (@pxref{Cyclic Window Ordering}).
  289. You can use the following functions to find the first live window on a
  290. frame and the window nearest to a given window.
  291. @defun frame-first-window &optional frame-or-window
  292. This function returns the live window at the upper left corner of the
  293. frame specified by @var{frame-or-window}. The argument
  294. @var{frame-or-window} must denote a window or a live frame and defaults
  295. to the selected frame. If @var{frame-or-window} specifies a window,
  296. this function returns the first window on that window's frame. Under
  297. the assumption that the frame from our canonical example is selected
  298. @code{(frame-first-window)} returns @var{W2}.
  299. @end defun
  300. @cindex window in direction
  301. @defun window-in-direction direction &optional window ignore sign wrap mini
  302. This function returns the nearest live window in direction
  303. @var{direction} as seen from the position of @code{window-point} in
  304. window @var{window}. The argument @var{direction} must be one of
  305. @code{above}, @code{below}, @code{left} or @code{right}. The optional
  306. argument @var{window} must denote a live window and defaults to the
  307. selected one.
  308. This function does not return a window whose @code{no-other-window}
  309. parameter is non-@code{nil} (@pxref{Window Parameters}). If the nearest
  310. window's @code{no-other-window} parameter is non-@code{nil}, this
  311. function tries to find another window in the indicated direction whose
  312. @code{no-other-window} parameter is @code{nil}. If the optional
  313. argument @var{ignore} is non-@code{nil}, a window may be returned even
  314. if its @code{no-other-window} parameter is non-@code{nil}.
  315. If the optional argument @var{sign} is a negative number, it means to
  316. use the right or bottom edge of @var{window} as reference position
  317. instead of @code{window-point}. If @var{sign} is a positive number, it
  318. means to use the left or top edge of @var{window} as reference position.
  319. If the optional argument @var{wrap} is non-@code{nil}, this means to
  320. wrap @var{direction} around frame borders. For example, if @var{window}
  321. is at the top of the frame and @var{direction} is @code{above}, then
  322. this function usually returns the frame's minibuffer window if it's
  323. active and a window at the bottom of the frame otherwise.
  324. If the optional argument @var{mini} is @code{nil}, this means to return
  325. the minibuffer window if and only if it is currently active. If
  326. @var{mini} is non-@code{nil}, this function may return the minibuffer
  327. window even when it's not active. However, if @var{wrap} is
  328. non-@code{nil}, it always acts as if @var{mini} were @code{nil}.
  329. If it doesn't find a suitable window, this function returns @code{nil}.
  330. @end defun
  331. The following function allows the entire window tree of a frame to be
  332. retrieved:
  333. @defun window-tree &optional frame
  334. This function returns a list representing the window tree for frame
  335. @var{frame}. If @var{frame} is omitted or @code{nil}, it defaults to
  336. the selected frame.
  337. The return value is a list of the form @code{(@var{root} @var{mini})},
  338. where @var{root} represents the window tree of the frame's root
  339. window, and @var{mini} is the frame's minibuffer window.
  340. If the root window is live, @var{root} is that window itself.
  341. Otherwise, @var{root} is a list @code{(@var{dir} @var{edges} @var{w1}
  342. @var{w2} ...)} where @var{dir} is @code{nil} for a horizontal
  343. combination and @code{t} for a vertical combination, @var{edges} gives
  344. the size and position of the combination, and the remaining elements
  345. are the child windows. Each child window may again be a window object
  346. (for a live window) or a list with the same format as above (for an
  347. internal window). The @var{edges} element is a list @code{(@var{left}
  348. @var{top} @var{right} @var{bottom})}, similar to the value returned by
  349. @code{window-edges} (@pxref{Coordinates and Windows}).
  350. @end defun
  351. @node Window Sizes
  352. @section Window Sizes
  353. @cindex window size
  354. @cindex size of window
  355. The following schematic shows the structure of a live window:
  356. @smallexample
  357. @group
  358. ____________________________________________
  359. |______________ Header Line ______________|RD| ^
  360. ^ |LS|LM|LF| |RF|RM|RS| | |
  361. | | | | | | | | | | |
  362. Window | | | | Text Area | | | | | Window
  363. Body | | | | | (Window Body) | | | | | Total
  364. Height | | | | | | | | | Height
  365. | | | | |<- Window Body Width ->| | | | | |
  366. v |__|__|__|_______________________|__|__|__| | |
  367. |_________ Horizontal Scroll Bar _________| | |
  368. |_______________ Mode Line _______________|__| |
  369. |_____________ Bottom Divider _______________| v
  370. <---------- Window Total Width ------------>
  371. @end group
  372. @end smallexample
  373. @cindex window body
  374. @cindex text area of a window
  375. @cindex body of a window
  376. At the center of the window is the @dfn{text area}, or @dfn{body},
  377. where the buffer text is displayed. The text area can be surrounded by
  378. a series of optional areas. On the left and right, from innermost to
  379. outermost, these are the left and right fringes, denoted by LF and RF
  380. (@pxref{Fringes}); the left and right margins, denoted by LM and RM in
  381. the schematic (@pxref{Display Margins}); the left or right vertical
  382. scroll bar, only one of which is present at any time, denoted by LS and
  383. RS (@pxref{Scroll Bars}); and the right divider, denoted by RD
  384. (@pxref{Window Dividers}). At the top of the window is the header line
  385. (@pxref{Header Lines}). At the bottom of the window are the horizontal
  386. scroll bar (@pxref{Scroll Bars}); the mode line (@pxref{Mode Line
  387. Format}); and the bottom divider (@pxref{Window Dividers}).
  388. Emacs provides miscellaneous functions for finding the height and
  389. width of a window. The return value of many of these functions can be
  390. specified either in units of pixels or in units of lines and columns.
  391. On a graphical display, the latter actually correspond to the height and
  392. width of a default character specified by the frame's default font
  393. as returned by @code{frame-char-height} and @code{frame-char-width}
  394. (@pxref{Frame Font}). Thus, if a window is displaying text with a
  395. different font or size, the reported line height and column width for
  396. that window may differ from the actual number of text lines or columns
  397. displayed within it.
  398. @cindex window height
  399. @cindex height of a window
  400. @cindex total height of a window
  401. The @dfn{total height} of a window is the number of lines comprising
  402. the window's body, the header line, the horizontal scroll bar, the mode
  403. line and the bottom divider (if any).
  404. @defun window-total-height &optional window round
  405. This function returns the total height, in lines, of the window
  406. @var{window}. If @var{window} is omitted or @code{nil}, it defaults to
  407. the selected window. If @var{window} is an internal window, the return
  408. value is the total height occupied by its descendant windows.
  409. If a window's pixel height is not an integral multiple of its frame's
  410. default character height, the number of lines occupied by the window is
  411. rounded internally. This is done in a way such that, if the window is a
  412. parent window, the sum of the total heights of all its child windows
  413. internally equals the total height of their parent. This means that
  414. although two windows have the same pixel height, their internal total
  415. heights may differ by one line. This means also, that if window is
  416. vertically combined and has a next sibling, the topmost row of that
  417. sibling can be calculated as the sum of this window's topmost row and
  418. total height (@pxref{Coordinates and Windows})
  419. If the optional argument @var{round} is @code{ceiling}, this
  420. function returns the smallest integer larger than @var{window}'s pixel
  421. height divided by the character height of its frame; if it is
  422. @code{floor}, it returns the largest integer smaller than said value;
  423. with any other @var{round} it returns the internal value of
  424. @var{windows}'s total height.
  425. @end defun
  426. @cindex window width
  427. @cindex width of a window
  428. @cindex total width of a window
  429. The @dfn{total width} of a window is the number of lines comprising the
  430. window's body, its margins, fringes, scroll bars and a right divider (if
  431. any).
  432. @defun window-total-width &optional window round
  433. This function returns the total width, in columns, of the window
  434. @var{window}. If @var{window} is omitted or @code{nil}, it defaults to
  435. the selected window. If @var{window} is internal, the return value is
  436. the total width occupied by its descendant windows.
  437. If a window's pixel width is not an integral multiple of its frame's
  438. character width, the number of lines occupied by the window is rounded
  439. internally. This is done in a way such that, if the window is a parent
  440. window, the sum of the total widths of all its children internally
  441. equals the total width of their parent. This means that although two
  442. windows have the same pixel width, their internal total widths may
  443. differ by one column. This means also, that if this window is
  444. horizontally combined and has a next sibling, the leftmost column of
  445. that sibling can be calculated as the sum of this window's leftmost
  446. column and total width (@pxref{Coordinates and Windows}). The optional
  447. argument @var{round} behaves as it does for @code{window-total-height}.
  448. @end defun
  449. @defun window-total-size &optional window horizontal round
  450. This function returns either the total height in lines or the total
  451. width in columns of the window @var{window}. If @var{horizontal} is
  452. omitted or @code{nil}, this is equivalent to calling
  453. @code{window-total-height} for @var{window}; otherwise it is equivalent
  454. to calling @code{window-total-width} for @var{window}. The optional
  455. argument @var{round} behaves as it does for @code{window-total-height}.
  456. @end defun
  457. The following two functions can be used to return the total size of a
  458. window in units of pixels.
  459. @cindex window pixel height
  460. @cindex pixel height of a window
  461. @cindex total pixel height of a window
  462. @defun window-pixel-height &optional window
  463. This function returns the total height of window @var{window} in pixels.
  464. @var{window} must be a valid window and defaults to the selected one.
  465. The return value includes mode and header line, a horizontal scroll bar
  466. and a bottom divider, if any. If @var{window} is an internal window,
  467. its pixel height is the pixel height of the screen areas spanned by its
  468. children.
  469. @end defun
  470. @defun window-pixel-height-before-size-change &optional Lisp_Object &optional window
  471. This function returns the height of window @var{window} in pixels at the
  472. time @code{window-size-change-functions} was run for the last time on
  473. @var{window}'s frame (@pxref{Window Hooks}).
  474. @end defun
  475. @cindex window pixel width
  476. @cindex pixel width of a window
  477. @cindex total pixel width of a window
  478. @defun window-pixel-width &optional Lisp_Object &optional window
  479. This function returns the width of window @var{window} in pixels.
  480. @var{window} must be a valid window and defaults to the selected one.
  481. The return value includes the fringes and margins of @var{window} as
  482. well as any vertical dividers or scroll bars belonging to @var{window}.
  483. If @var{window} is an internal window, its pixel width is the width of
  484. the screen areas spanned by its children.
  485. @end defun
  486. @defun window-pixel-width-before-size-change &optional Lisp_Object &optional window
  487. This function returns the width of window @var{window} in pixels at the
  488. time @code{window-size-change-functions} was run for the last time on
  489. @var{window}'s frame (@pxref{Window Hooks}).
  490. @end defun
  491. @cindex full-width window
  492. @cindex full-height window
  493. The following functions can be used to determine whether a given
  494. window has any adjacent windows.
  495. @defun window-full-height-p &optional window
  496. This function returns non-@code{nil} if @var{window} has no other window
  497. above or below it in its frame. More precisely, this means that the
  498. total height of @var{window} equals the total height of the root window
  499. on that frame. The minibuffer window does not count in this regard. If
  500. @var{window} is omitted or @code{nil}, it defaults to the selected
  501. window.
  502. @end defun
  503. @defun window-full-width-p &optional window
  504. This function returns non-@code{nil} if @var{window} has no other
  505. window to the left or right in its frame, i.e., its total width equals
  506. that of the root window on that frame. If @var{window} is omitted or
  507. @code{nil}, it defaults to the selected window.
  508. @end defun
  509. @cindex window body height
  510. @cindex body height of a window
  511. The @dfn{body height} of a window is the height of its text area, which
  512. does not include a mode or header line, a horizontal scroll bar, or a
  513. bottom divider.
  514. @defun window-body-height &optional window pixelwise
  515. This function returns the height, in lines, of the body of window
  516. @var{window}. If @var{window} is omitted or @code{nil}, it defaults to
  517. the selected window; otherwise it must be a live window.
  518. If the optional argument @var{pixelwise} is non-@code{nil}, this
  519. function returns the body height of @var{window} counted in pixels.
  520. If @var{pixelwise} is @code{nil}, the return value is rounded down to
  521. the nearest integer, if necessary. This means that if a line at the
  522. bottom of the text area is only partially visible, that line is not
  523. counted. It also means that the height of a window's body can never
  524. exceed its total height as returned by @code{window-total-height}.
  525. @end defun
  526. @cindex window body width
  527. @cindex body width of a window
  528. The @dfn{body width} of a window is the width of its text area, which
  529. does not include the scroll bar, fringes, margins or a right divider.
  530. @defun window-body-width &optional window pixelwise
  531. This function returns the width, in columns, of the body of window
  532. @var{window}. If @var{window} is omitted or @code{nil}, it defaults to
  533. the selected window; otherwise it must be a live window.
  534. If the optional argument @var{pixelwise} is non-@code{nil}, this
  535. function returns the body width of @var{window} in units of pixels.
  536. If @var{pixelwise} is @code{nil}, the return value is rounded down to
  537. the nearest integer, if necessary. This means that if a column on the
  538. right of the text area is only partially visible, that column is not
  539. counted. It also means that the width of a window's body can never
  540. exceed its total width as returned by @code{window-total-width}.
  541. @end defun
  542. @cindex window body size
  543. @cindex body size of a window
  544. @defun window-body-size &optional window horizontal pixelwise
  545. This function returns the body height or body width of @var{window}. If
  546. @var{horizontal} is omitted or @code{nil}, it is equivalent to calling
  547. @code{window-body-height} for @var{window}; otherwise it is equivalent
  548. to calling @code{window-body-width}. In either case, the optional
  549. argument @var{pixelwise} is passed to the function called.
  550. @end defun
  551. For compatibility with previous versions of Emacs,
  552. @code{window-height} is an alias for @code{window-total-height}, and
  553. @code{window-width} is an alias for @code{window-body-width}. These
  554. aliases are considered obsolete and will be removed in the future.
  555. The pixel heights of a window's mode and header line can be retrieved
  556. with the functions given below. Their return value is usually accurate
  557. unless the window has not been displayed before: In that case, the
  558. return value is based on an estimate of the font used for the window's
  559. frame.
  560. @defun window-mode-line-height &optional window
  561. This function returns the height in pixels of @var{window}'s mode line.
  562. @var{window} must be a live window and defaults to the selected one. If
  563. @var{window} has no mode line, the return value is zero.
  564. @end defun
  565. @defun window-header-line-height &optional window
  566. This function returns the height in pixels of @var{window}'s header
  567. line. @var{window} must be a live window and defaults to the selected
  568. one. If @var{window} has no header line, the return value is zero.
  569. @end defun
  570. Functions for retrieving the height and/or width of window dividers
  571. (@pxref{Window Dividers}), fringes (@pxref{Fringes}), scroll bars
  572. (@pxref{Scroll Bars}), and display margins (@pxref{Display Margins}) are
  573. described in the corresponding sections.
  574. If your Lisp program needs to make layout decisions, you will find the
  575. following function useful:
  576. @defun window-max-chars-per-line &optional window face
  577. This function returns the number of characters displayed in the
  578. specified face @var{face} in the specified window @var{window} (which
  579. must be a live window). If @var{face} was remapped (@pxref{Face
  580. Remapping}), the information is returned for the remapped face. If
  581. omitted or @code{nil}, @var{face} defaults to the default face, and
  582. @var{window} defaults to the selected window.
  583. Unlike @code{window-body-width}, this function accounts for the actual
  584. size of @var{face}'s font, instead of working in units of the canonical
  585. character width of @var{window}'s frame (@pxref{Frame Font}). It also
  586. accounts for space used by the continuation glyph, if @var{window} lacks
  587. one or both of its fringes.
  588. @end defun
  589. @cindex fixed-size window
  590. @vindex window-min-height
  591. @vindex window-min-width
  592. Commands that change the size of windows (@pxref{Resizing Windows}),
  593. or split them (@pxref{Splitting Windows}), obey the variables
  594. @code{window-min-height} and @code{window-min-width}, which specify the
  595. smallest allowable window height and width. They also obey the variable
  596. @code{window-size-fixed}, with which a window can be @dfn{fixed} in
  597. size (@pxref{Preserving Window Sizes}).
  598. @defopt window-min-height
  599. This option specifies the minimum total height, in lines, of any window.
  600. Its value has to accommodate at least one text line as well as a mode
  601. and header line, a horizontal scroll bar and a bottom divider, if
  602. present.
  603. @end defopt
  604. @defopt window-min-width
  605. This option specifies the minimum total width, in columns, of any
  606. window. Its value has to accommodate two text columns as well as
  607. margins, fringes, a scroll bar and a right divider, if present.
  608. @end defopt
  609. The following function tells how small a specific window can get taking
  610. into account the sizes of its areas and the values of
  611. @code{window-min-height}, @code{window-min-width} and
  612. @code{window-size-fixed} (@pxref{Preserving Window Sizes}).
  613. @defun window-min-size &optional window horizontal ignore pixelwise
  614. This function returns the minimum size of @var{window}. @var{window}
  615. must be a valid window and defaults to the selected one. The optional
  616. argument @var{horizontal} non-@code{nil} means to return the minimum
  617. number of columns of @var{window}; otherwise return the minimum number
  618. of @var{window}'s lines.
  619. The return value makes sure that all components of @var{window} remain
  620. fully visible if @var{window}'s size were actually set to it. With
  621. @var{horizontal} @code{nil} it includes the mode and header line, the
  622. horizontal scroll bar and the bottom divider, if present. With
  623. @var{horizontal} non-@code{nil} it includes the margins and fringes, the
  624. vertical scroll bar and the right divider, if present.
  625. The optional argument @var{ignore}, if non-@code{nil}, means ignore
  626. restrictions imposed by fixed size windows, @code{window-min-height} or
  627. @code{window-min-width} settings. If @var{ignore} equals @code{safe},
  628. live windows may get as small as @code{window-safe-min-height} lines and
  629. @code{window-safe-min-width} columns. If @var{ignore} is a window,
  630. ignore restrictions for that window only. Any other non-@code{nil}
  631. value means ignore all of the above restrictions for all windows.
  632. The optional argument @var{pixelwise} non-@code{nil} means to return the
  633. minimum size of @var{window} counted in pixels.
  634. @end defun
  635. @node Resizing Windows
  636. @section Resizing Windows
  637. @cindex window resizing
  638. @cindex resize window
  639. @cindex changing window size
  640. @cindex window size, changing
  641. This section describes functions for resizing a window without
  642. changing the size of its frame. Because live windows do not overlap,
  643. these functions are meaningful only on frames that contain two or more
  644. windows: resizing a window also changes the size of a neighboring
  645. window. If there is just one window on a frame, its size cannot be
  646. changed except by resizing the frame (@pxref{Size and Position}).
  647. Except where noted, these functions also accept internal windows as
  648. arguments. Resizing an internal window causes its child windows to be
  649. resized to fit the same space.
  650. @defun window-resizable window delta &optional horizontal ignore pixelwise
  651. This function returns @var{delta} if the size of @var{window} can be
  652. changed vertically by @var{delta} lines. If the optional argument
  653. @var{horizontal} is non-@code{nil}, it instead returns @var{delta} if
  654. @var{window} can be resized horizontally by @var{delta} columns. It
  655. does not actually change the window size.
  656. If @var{window} is @code{nil}, it defaults to the selected window.
  657. A positive value of @var{delta} means to check whether the window can be
  658. enlarged by that number of lines or columns; a negative value of
  659. @var{delta} means to check whether the window can be shrunk by that many
  660. lines or columns. If @var{delta} is non-zero, a return value of 0 means
  661. that the window cannot be resized.
  662. Normally, the variables @code{window-min-height} and
  663. @code{window-min-width} specify the smallest allowable window size
  664. (@pxref{Window Sizes}). However, if the optional argument @var{ignore}
  665. is non-@code{nil}, this function ignores @code{window-min-height} and
  666. @code{window-min-width}, as well as @code{window-size-fixed}. Instead,
  667. it considers the minimum-height window to be one consisting of a header
  668. and a mode line, a horizontal scrollbar and a bottom divider (if any),
  669. plus a text area one line tall; and a minimum-width window as one
  670. consisting of fringes, margins, a scroll bar and a right divider (if
  671. any), plus a text area two columns wide.
  672. If the optional argument @var{pixelwise} is non-@code{nil},
  673. @var{delta} is interpreted as pixels.
  674. @end defun
  675. @defun window-resize window delta &optional horizontal ignore pixelwise
  676. This function resizes @var{window} by @var{delta} increments. If
  677. @var{horizontal} is @code{nil}, it changes the height by @var{delta}
  678. lines; otherwise, it changes the width by @var{delta} columns. A
  679. positive @var{delta} means to enlarge the window, and a negative
  680. @var{delta} means to shrink it.
  681. If @var{window} is @code{nil}, it defaults to the selected window. If
  682. the window cannot be resized as demanded, an error is signaled.
  683. The optional argument @var{ignore} has the same meaning as for the
  684. function @code{window-resizable} above.
  685. If the optional argument @var{pixelwise} is non-@code{nil},
  686. @var{delta} will be interpreted as pixels.
  687. The choice of which window edges this function alters depends on the
  688. values of the option @code{window-combination-resize} and the
  689. combination limits of the involved windows; in some cases, it may alter
  690. both edges. @xref{Recombining Windows}. To resize by moving only the
  691. bottom or right edge of a window, use the function
  692. @code{adjust-window-trailing-edge}.
  693. @end defun
  694. @c The commands enlarge-window, enlarge-window-horizontally,
  695. @c shrink-window, and shrink-window-horizontally are documented in the
  696. @c Emacs manual. They are not preferred for calling from Lisp.
  697. @defun adjust-window-trailing-edge window delta &optional horizontal pixelwise
  698. This function moves @var{window}'s bottom edge by @var{delta} lines.
  699. If optional argument @var{horizontal} is non-@code{nil}, it instead
  700. moves the right edge by @var{delta} columns. If @var{window} is
  701. @code{nil}, it defaults to the selected window.
  702. If the optional argument @var{pixelwise} is non-@code{nil},
  703. @var{delta} is interpreted as pixels.
  704. A positive @var{delta} moves the edge downwards or to the right; a
  705. negative @var{delta} moves it upwards or to the left. If the edge
  706. cannot be moved as far as specified by @var{delta}, this function
  707. moves it as far as possible but does not signal a error.
  708. This function tries to resize windows adjacent to the edge that is
  709. moved. If this is not possible for some reason (e.g., if that adjacent
  710. window is fixed-size), it may resize other windows.
  711. @end defun
  712. @cindex pixelwise, resizing windows
  713. @defopt window-resize-pixelwise
  714. If the value of this option is non-@code{nil}, Emacs resizes windows in
  715. units of pixels. This currently affects functions like
  716. @code{split-window} (@pxref{Splitting Windows}), @code{maximize-window},
  717. @code{minimize-window}, @code{fit-window-to-buffer},
  718. @code{fit-frame-to-buffer} and
  719. @code{shrink-window-if-larger-than-buffer} (all listed below).
  720. Note that when a frame's pixel size is not a multiple of its character
  721. size, at least one window may get resized pixelwise even if this
  722. option is @code{nil}. The default value is @code{nil}.
  723. @end defopt
  724. The following commands resize windows in more specific ways. When
  725. called interactively, they act on the selected window.
  726. @deffn Command fit-window-to-buffer &optional window max-height min-height max-width min-width preserve-size
  727. This command adjusts the height or width of @var{window} to fit the text
  728. in it. It returns non-@code{nil} if it was able to resize @var{window},
  729. and @code{nil} otherwise. If @var{window} is omitted or @code{nil}, it
  730. defaults to the selected window. Otherwise, it should be a live window.
  731. If @var{window} is part of a vertical combination, this function adjusts
  732. @var{window}'s height. The new height is calculated from the actual
  733. height of the accessible portion of its buffer. The optional argument
  734. @var{max-height}, if non-@code{nil}, specifies the maximum total height
  735. that this function can give @var{window}. The optional argument
  736. @var{min-height}, if non-@code{nil}, specifies the minimum total height
  737. that it can give, which overrides the variable @code{window-min-height}.
  738. Both @var{max-height} and @var{min-height} are specified in lines and
  739. include mode and header line and a bottom divider, if any.
  740. If @var{window} is part of a horizontal combination and the value of the
  741. option @code{fit-window-to-buffer-horizontally} (see below) is
  742. non-@code{nil}, this function adjusts @var{window}'s height. The new
  743. width of @var{window} is calculated from the maximum length of its
  744. buffer's lines that follow the current start position of @var{window}.
  745. The optional argument @var{max-width} specifies a maximum width and
  746. defaults to the width of @var{window}'s frame. The optional argument
  747. @var{min-width} specifies a minimum width and defaults to
  748. @code{window-min-width}. Both @var{max-width} and @var{min-width} are
  749. specified in columns and include fringes, margins and scrollbars, if
  750. any.
  751. The optional argument @var{preserve-size}, if non-@code{nil}, will
  752. install a parameter to preserve the size of @var{window} during future
  753. resize operations (@pxref{Preserving Window Sizes}).
  754. If the option @code{fit-frame-to-buffer} (see below) is non-@code{nil},
  755. this function will try to resize the frame of @var{window} to fit its
  756. contents by calling @code{fit-frame-to-buffer} (see below).
  757. @end deffn
  758. @defopt fit-window-to-buffer-horizontally
  759. If this is non-@code{nil}, @code{fit-window-to-buffer} can resize
  760. windows horizontally. If this is @code{nil} (the default)
  761. @code{fit-window-to-buffer} never resizes windows horizontally. If this
  762. is @code{only}, it can resize windows horizontally only. Any other
  763. value means @code{fit-window-to-buffer} can resize windows in both
  764. dimensions.
  765. @end defopt
  766. @defopt fit-frame-to-buffer
  767. If this option is non-@code{nil}, @code{fit-window-to-buffer} can fit a
  768. frame to its buffer. A frame is fit if and only if its root window is a
  769. live window and this option is non-@code{nil}. If this is
  770. @code{horizontally}, frames are fit horizontally only. If this is
  771. @code{vertically}, frames are fit vertically only. Any other
  772. non-@code{nil} value means frames can be resized in both dimensions.
  773. @end defopt
  774. If you have a frame that displays only one window, you can fit that
  775. frame to its buffer using the command @code{fit-frame-to-buffer}.
  776. @deffn Command fit-frame-to-buffer &optional frame max-height min-height max-width min-width only
  777. This command adjusts the size of @var{frame} to display the contents of
  778. its buffer exactly. @var{frame} can be any live frame and defaults to
  779. the selected one. Fitting is done only if @var{frame}'s root window is
  780. live. The arguments @var{max-height}, @var{min-height}, @var{max-width}
  781. and @var{min-width} specify bounds on the new total size of
  782. @var{frame}'s root window. @var{min-height} and @var{min-width} default
  783. to the values of @code{window-min-height} and @code{window-min-width}
  784. respectively.
  785. If the optional argument @var{only} is @code{vertically}, this function
  786. may resize the frame vertically only. If @var{only} is
  787. @code{horizontally}, it may resize the frame horizontally only.
  788. @end deffn
  789. The behavior of @code{fit-frame-to-buffer} can be controlled with the
  790. help of the two options listed next.
  791. @defopt fit-frame-to-buffer-margins
  792. This option can be used to specify margins around frames to be fit by
  793. @code{fit-frame-to-buffer}. Such margins can be useful to avoid, for
  794. example, that such frames overlap the taskbar.
  795. It specifies the numbers of pixels to be left free on the left, above,
  796. the right, and below a frame that shall be fit. The default specifies
  797. @code{nil} for each which means to use no margins. The value specified
  798. here can be overridden for a specific frame by that frame's
  799. @code{fit-frame-to-buffer-margins} parameter, if present.
  800. @end defopt
  801. @defopt fit-frame-to-buffer-sizes
  802. This option specifies size boundaries for @code{fit-frame-to-buffer}.
  803. It specifies the total maximum and minimum lines and maximum and minimum
  804. columns of the root window of any frame that shall be fit to its buffer.
  805. If any of these values is non-@code{nil}, it overrides the corresponding
  806. argument of @code{fit-frame-to-buffer}.
  807. @end defopt
  808. @deffn Command shrink-window-if-larger-than-buffer &optional window
  809. This command attempts to reduce @var{window}'s height as much as
  810. possible while still showing its full buffer, but no less than
  811. @code{window-min-height} lines. The return value is non-@code{nil} if
  812. the window was resized, and @code{nil} otherwise. If @var{window} is
  813. omitted or @code{nil}, it defaults to the selected window. Otherwise,
  814. it should be a live window.
  815. This command does nothing if the window is already too short to
  816. display all of its buffer, or if any of the buffer is scrolled
  817. off-screen, or if the window is the only live window in its frame.
  818. This command calls @code{fit-window-to-buffer} (see above) to do its
  819. work.
  820. @end deffn
  821. @cindex balancing window sizes
  822. @deffn Command balance-windows &optional window-or-frame
  823. This function balances windows in a way that gives more space to
  824. full-width and/or full-height windows. If @var{window-or-frame}
  825. specifies a frame, it balances all windows on that frame. If
  826. @var{window-or-frame} specifies a window, it balances only that window
  827. and its siblings (@pxref{Windows and Frames}).
  828. @end deffn
  829. @deffn Command balance-windows-area
  830. This function attempts to give all windows on the selected frame
  831. approximately the same share of the screen area. Full-width or
  832. full-height windows are not given more space than other windows.
  833. @end deffn
  834. @cindex maximizing windows
  835. @deffn Command maximize-window &optional window
  836. This function attempts to make @var{window} as large as possible, in
  837. both dimensions, without resizing its frame or deleting other windows.
  838. If @var{window} is omitted or @code{nil}, it defaults to the selected
  839. window.
  840. @end deffn
  841. @cindex minimizing windows
  842. @deffn Command minimize-window &optional window
  843. This function attempts to make @var{window} as small as possible, in
  844. both dimensions, without deleting it or resizing its frame. If
  845. @var{window} is omitted or @code{nil}, it defaults to the selected
  846. window.
  847. @end deffn
  848. @node Preserving Window Sizes
  849. @section Preserving Window Sizes
  850. @cindex preserving window sizes
  851. A window can get resized explicitly by using one of the functions from
  852. the preceding section or implicitly, for example, when resizing an
  853. adjacent window, when splitting or deleting a window (@pxref{Splitting
  854. Windows}, @pxref{Deleting Windows}) or when resizing the window's frame
  855. (@pxref{Size and Position}).
  856. It is possible to avoid implicit resizing of a specific window when
  857. there are one or more other resizable windows on the same frame. For
  858. this purpose, Emacs must be advised to @dfn{preserve} the size of that
  859. window. There are two basic ways to do that.
  860. @defvar window-size-fixed
  861. If this buffer-local variable is non-@code{nil}, the size of any window
  862. displaying the buffer cannot normally be changed. Deleting a window or
  863. changing the frame's size may still change the window's size, if there
  864. is no choice.
  865. If the value is @code{height}, then only the window's height is fixed;
  866. if the value is @code{width}, then only the window's width is fixed.
  867. Any other non-@code{nil} value fixes both the width and the height.
  868. If this variable is @code{nil}, this does not necessarily mean that any
  869. window showing the buffer can be resized in the desired direction. To
  870. determine that, use the function @code{window-resizable}.
  871. @xref{Resizing Windows}.
  872. @end defvar
  873. Often @code{window-size-fixed} is overly aggressive because it inhibits
  874. any attempt to explicitly resize or split an affected window as well.
  875. This may even happen after the window has been resized implicitly, for
  876. example, when deleting an adjacent window or resizing the window's
  877. frame. The following function tries hard to never disallow resizing
  878. such a window explicitly:
  879. @defun window-preserve-size &optional window horizontal preserve
  880. This function (un-)marks the height of window @var{window} as preserved
  881. for future resize operations. @var{window} must be a live window and
  882. defaults to the selected one. If the optional argument @var{horizontal}
  883. is non-@code{nil}, it (un-)marks the width of @var{window} as preserved.
  884. If the optional argument @var{preserve} is @code{t}, this means to
  885. preserve the current height/width of @var{window}'s body. The
  886. height/width of @var{window} will change only if Emacs has no better
  887. choice. Resizing a window whose height/width is preserved by this
  888. function never throws an error.
  889. If @var{preserve} is @code{nil}, this means to stop preserving the
  890. height/width of @var{window}, lifting any respective restraint induced
  891. by a previous call of this function for @var{window}. Calling
  892. @code{enlarge-window}, @code{shrink-window} or
  893. @code{fit-window-to-buffer} with @var{window} as argument may also
  894. remove the respective restraint.
  895. @end defun
  896. @code{window-preserve-size} is currently invoked by the following
  897. functions:
  898. @table @code
  899. @item fit-window-to-buffer
  900. If the optional argument @var{preserve-size} of that function
  901. (@pxref{Resizing Windows}) is non-@code{nil}, the size established by
  902. that function is preserved.
  903. @item display-buffer
  904. If the @var{alist} argument of that function (@pxref{Choosing Window})
  905. contains a @code{preserve-size} entry, the size of the window produced
  906. by that function is preserved.
  907. @end table
  908. @code{window-preserve-size} installs a window parameter (@pxref{Window
  909. Parameters}) called @code{preserved-size} which is consulted by the
  910. window resizing functions. This parameter will not prevent resizing the
  911. window when the window shows another buffer than the one when
  912. @code{window-preserve-size} was invoked or if its size has changed since
  913. then.
  914. The following function can be used to check whether the height of a
  915. particular window is preserved:
  916. @defun window-preserved-size &optional window horizontal
  917. This function returns the preserved height of window @var{window} in
  918. pixels. @var{window} must be a live window and defaults to the selected
  919. one. If the optional argument @var{horizontal} is non-@code{nil}, it
  920. returns the preserved width of @var{window}. It returns @code{nil} if
  921. the size of @var{window} is not preserved.
  922. @end defun
  923. @node Splitting Windows
  924. @section Splitting Windows
  925. @cindex splitting windows
  926. @cindex window splitting
  927. This section describes functions for creating a new window by
  928. @dfn{splitting} an existing one.
  929. @defun split-window &optional window size side pixelwise
  930. This function creates a new live window next to the window
  931. @var{window}. If @var{window} is omitted or @code{nil}, it defaults
  932. to the selected window. That window is split, and reduced in
  933. size. The space is taken up by the new window, which is returned.
  934. The optional second argument @var{size} determines the sizes of
  935. @var{window} and/or the new window. If it is omitted or @code{nil},
  936. both windows are given equal sizes; if there is an odd line, it is
  937. allocated to the new window. If @var{size} is a positive number,
  938. @var{window} is given @var{size} lines (or columns, depending on the
  939. value of @var{side}). If @var{size} is a negative number, the new
  940. window is given @minus{}@var{size} lines (or columns).
  941. If @var{size} is @code{nil}, this function obeys the variables
  942. @code{window-min-height} and @code{window-min-width} (@pxref{Window
  943. Sizes}). Thus, it signals an error if splitting would result in making
  944. a window smaller than those variables specify. However, a
  945. non-@code{nil} value for @var{size} causes those variables to be
  946. ignored; in that case, the smallest allowable window is considered to be
  947. one that has space for a text area one line tall and/or two columns
  948. wide.
  949. Hence, if @var{size} is specified, it's the caller's responsibility to
  950. check whether the emanating windows are large enough to encompass all
  951. areas like a mode line or a scroll bar. The function
  952. @code{window-min-size} (@pxref{Window Sizes}) can be used to determine
  953. the minimum requirements of @var{window} in this regard. Since the new
  954. window usually inherits areas like the mode line or the scroll bar
  955. from @var{window}, that function is also a good guess for the minimum
  956. size of the new window. The caller should specify a smaller size only
  957. if it correspondingly removes an inherited area before the next
  958. redisplay.
  959. The optional third argument @var{side} determines the position of the
  960. new window relative to @var{window}. If it is @code{nil} or
  961. @code{below}, the new window is placed below @var{window}. If it is
  962. @code{above}, the new window is placed above @var{window}. In both
  963. these cases, @var{size} specifies a total window height, in lines.
  964. If @var{side} is @code{t} or @code{right}, the new window is placed on
  965. the right of @var{window}. If @var{side} is @code{left}, the new
  966. window is placed on the left of @var{window}. In both these cases,
  967. @var{size} specifies a total window width, in columns.
  968. The optional fourth argument @var{pixelwise}, if non-@code{nil}, means
  969. to interpret @var{size} in units of pixels, instead of lines and
  970. columns.
  971. If @var{window} is a live window, the new window inherits various
  972. properties from it, including margins and scroll bars. If
  973. @var{window} is an internal window, the new window inherits the
  974. properties of the window selected within @var{window}'s frame.
  975. The behavior of this function may be altered by the window parameters
  976. of @var{window}, so long as the variable
  977. @code{ignore-window-parameters} is @code{nil}. If the value of
  978. the @code{split-window} window parameter is @code{t}, this function
  979. ignores all other window parameters. Otherwise, if the value of the
  980. @code{split-window} window parameter is a function, that function is
  981. called with the arguments @var{window}, @var{size}, and @var{side}, in
  982. lieu of the usual action of @code{split-window}. Otherwise, this
  983. function obeys the @code{window-atom} or @code{window-side} window
  984. parameter, if any. @xref{Window Parameters}.
  985. @end defun
  986. As an example, here is a sequence of @code{split-window} calls that
  987. yields the window configuration discussed in @ref{Windows and Frames}.
  988. This example demonstrates splitting a live window as well as splitting
  989. an internal window. We begin with a frame containing a single window
  990. (a live root window), which we denote by @var{W4}. Calling
  991. @code{(split-window W4)} yields this window configuration:
  992. @smallexample
  993. @group
  994. ______________________________________
  995. | ____________________________________ |
  996. || ||
  997. || ||
  998. || ||
  999. ||_________________W4_________________||
  1000. | ____________________________________ |
  1001. || ||
  1002. || ||
  1003. || ||
  1004. ||_________________W5_________________||
  1005. |__________________W3__________________|
  1006. @end group
  1007. @end smallexample
  1008. @noindent
  1009. The @code{split-window} call has created a new live window, denoted by
  1010. @var{W5}. It has also created a new internal window, denoted by
  1011. @var{W3}, which becomes the root window and the parent of both
  1012. @var{W4} and @var{W5}.
  1013. Next, we call @code{(split-window W3 nil 'left)}, passing the
  1014. internal window @var{W3} as the argument. The result:
  1015. @smallexample
  1016. @group
  1017. ______________________________________
  1018. | ______ ____________________________ |
  1019. || || __________________________ ||
  1020. || ||| |||
  1021. || ||| |||
  1022. || ||| |||
  1023. || |||____________W4____________|||
  1024. || || __________________________ ||
  1025. || ||| |||
  1026. || ||| |||
  1027. || |||____________W5____________|||
  1028. ||__W2__||_____________W3_____________ |
  1029. |__________________W1__________________|
  1030. @end group
  1031. @end smallexample
  1032. @noindent
  1033. A new live window @var{W2} is created, to the left of the internal
  1034. window @var{W3}. A new internal window @var{W1} is created, becoming
  1035. the new root window.
  1036. For interactive use, Emacs provides two commands which always split
  1037. the selected window. These call @code{split-window} internally.
  1038. @deffn Command split-window-right &optional size
  1039. This function splits the selected window into two side-by-side
  1040. windows, putting the selected window on the left. If @var{size} is
  1041. positive, the left window gets @var{size} columns; if @var{size} is
  1042. negative, the right window gets @minus{}@var{size} columns.
  1043. @end deffn
  1044. @deffn Command split-window-below &optional size
  1045. This function splits the selected window into two windows, one above
  1046. the other, leaving the upper window selected. If @var{size} is
  1047. positive, the upper window gets @var{size} lines; if @var{size} is
  1048. negative, the lower window gets @minus{}@var{size} lines.
  1049. @end deffn
  1050. @defopt split-window-keep-point
  1051. If the value of this variable is non-@code{nil} (the default),
  1052. @code{split-window-below} behaves as described above.
  1053. If it is @code{nil}, @code{split-window-below} adjusts point in each
  1054. of the two windows to minimize redisplay. (This is useful on slow
  1055. terminals.) It selects whichever window contains the screen line that
  1056. point was previously on. Note that this only affects
  1057. @code{split-window-below}, not the lower-level @code{split-window}
  1058. function.
  1059. @end defopt
  1060. @node Deleting Windows
  1061. @section Deleting Windows
  1062. @cindex deleting windows
  1063. @dfn{Deleting} a window removes it from the frame's window tree. If
  1064. the window is a live window, it disappears from the screen. If the
  1065. window is an internal window, its child windows are deleted too.
  1066. Even after a window is deleted, it continues to exist as a Lisp
  1067. object, until there are no more references to it. Window deletion can
  1068. be reversed, by restoring a saved window configuration (@pxref{Window
  1069. Configurations}).
  1070. @deffn Command delete-window &optional window
  1071. This function removes @var{window} from display and returns
  1072. @code{nil}. If @var{window} is omitted or @code{nil}, it defaults to
  1073. the selected window. If deleting the window would leave no more
  1074. windows in the window tree (e.g., if it is the only live window in the
  1075. frame), an error is signaled.
  1076. By default, the space taken up by @var{window} is given to one of its
  1077. adjacent sibling windows, if any. However, if the variable
  1078. @code{window-combination-resize} is non-@code{nil}, the space is
  1079. proportionally distributed among any remaining windows in the same
  1080. window combination. @xref{Recombining Windows}.
  1081. The behavior of this function may be altered by the window parameters
  1082. of @var{window}, so long as the variable
  1083. @code{ignore-window-parameters} is @code{nil}. If the value of
  1084. the @code{delete-window} window parameter is @code{t}, this function
  1085. ignores all other window parameters. Otherwise, if the value of the
  1086. @code{delete-window} window parameter is a function, that function is
  1087. called with the argument @var{window}, in lieu of the usual action of
  1088. @code{delete-window}. Otherwise, this function obeys the
  1089. @code{window-atom} or @code{window-side} window parameter, if any.
  1090. @xref{Window Parameters}.
  1091. @end deffn
  1092. @deffn Command delete-other-windows &optional window
  1093. This function makes @var{window} fill its frame, by deleting other
  1094. windows as necessary. If @var{window} is omitted or @code{nil}, it
  1095. defaults to the selected window. The return value is @code{nil}.
  1096. The behavior of this function may be altered by the window parameters
  1097. of @var{window}, so long as the variable
  1098. @code{ignore-window-parameters} is @code{nil}. If the value of
  1099. the @code{delete-other-windows} window parameter is @code{t}, this
  1100. function ignores all other window parameters. Otherwise, if the value
  1101. of the @code{delete-other-windows} window parameter is a function,
  1102. that function is called with the argument @var{window}, in lieu of the
  1103. usual action of @code{delete-other-windows}. Otherwise, this function
  1104. obeys the @code{window-atom} or @code{window-side} window parameter,
  1105. if any. @xref{Window Parameters}.
  1106. @end deffn
  1107. @deffn Command delete-windows-on &optional buffer-or-name frame
  1108. This function deletes all windows showing @var{buffer-or-name}, by
  1109. calling @code{delete-window} on those windows. @var{buffer-or-name}
  1110. should be a buffer, or the name of a buffer; if omitted or @code{nil},
  1111. it defaults to the current buffer. If there are no windows showing
  1112. the specified buffer, this function does nothing. If the specified
  1113. buffer is a minibuffer, an error is signaled.
  1114. If there is a dedicated window showing the buffer, and that window is
  1115. the only one on its frame, this function also deletes that frame if it
  1116. is not the only frame on the terminal.
  1117. The optional argument @var{frame} specifies which frames to operate
  1118. on:
  1119. @itemize @bullet
  1120. @item @code{nil}
  1121. means operate on all frames.
  1122. @item @code{t}
  1123. means operate on the selected frame.
  1124. @item @code{visible}
  1125. means operate on all visible frames.
  1126. @item @code{0}
  1127. means operate on all visible or iconified frames.
  1128. @item A frame
  1129. means operate on that frame.
  1130. @end itemize
  1131. Note that this argument does not have the same meaning as in other
  1132. functions which scan all live windows (@pxref{Cyclic Window
  1133. Ordering}). Specifically, the meanings of @code{t} and @code{nil} here
  1134. are the opposite of what they are in those other functions.
  1135. @end deffn
  1136. @node Recombining Windows
  1137. @section Recombining Windows
  1138. @cindex recombining windows
  1139. @cindex windows, recombining
  1140. When deleting the last sibling of a window @var{W}, its parent window
  1141. is deleted too, with @var{W} replacing it in the window tree. This
  1142. means that @var{W} must be recombined with its parent's siblings to
  1143. form a new window combination (@pxref{Windows and Frames}). In some
  1144. occasions, deleting a live window may even entail the deletion of two
  1145. internal windows.
  1146. @smallexample
  1147. @group
  1148. ______________________________________
  1149. | ______ ____________________________ |
  1150. || || __________________________ ||
  1151. || ||| ___________ ___________ |||
  1152. || |||| || ||||
  1153. || ||||____W6_____||_____W7____||||
  1154. || |||____________W4____________|||
  1155. || || __________________________ ||
  1156. || ||| |||
  1157. || ||| |||
  1158. || |||____________W5____________|||
  1159. ||__W2__||_____________W3_____________ |
  1160. |__________________W1__________________|
  1161. @end group
  1162. @end smallexample
  1163. @noindent
  1164. Deleting @var{W5} in this configuration normally causes the deletion of
  1165. @var{W3} and @var{W4}. The remaining live windows @var{W2},
  1166. @var{W6} and @var{W7} are recombined to form a new horizontal
  1167. combination with parent @var{W1}.
  1168. Sometimes, however, it makes sense to not delete a parent window like
  1169. @var{W4}. In particular, a parent window should not be removed when it
  1170. was used to preserve a combination embedded in a combination of the same
  1171. type. Such embeddings make sense to assure that when you split a window
  1172. and subsequently delete the new window, Emacs reestablishes the layout
  1173. of the associated frame as it existed before the splitting.
  1174. Consider a scenario starting with two live windows @var{W2} and
  1175. @var{W3} and their parent @var{W1}.
  1176. @smallexample
  1177. @group
  1178. ______________________________________
  1179. | ____________________________________ |
  1180. || ||
  1181. || ||
  1182. || ||
  1183. || ||
  1184. || ||
  1185. || ||
  1186. ||_________________W2_________________||
  1187. | ____________________________________ |
  1188. || ||
  1189. || ||
  1190. ||_________________W3_________________||
  1191. |__________________W1__________________|
  1192. @end group
  1193. @end smallexample
  1194. @noindent
  1195. Split @var{W2} to make a new window @var{W4} as follows.
  1196. @smallexample
  1197. @group
  1198. ______________________________________
  1199. | ____________________________________ |
  1200. || ||
  1201. || ||
  1202. ||_________________W2_________________||
  1203. | ____________________________________ |
  1204. || ||
  1205. || ||
  1206. ||_________________W4_________________||
  1207. | ____________________________________ |
  1208. || ||
  1209. || ||
  1210. ||_________________W3_________________||
  1211. |__________________W1__________________|
  1212. @end group
  1213. @end smallexample
  1214. @noindent
  1215. Now, when enlarging a window vertically, Emacs tries to obtain the
  1216. corresponding space from its lower sibling, provided such a window
  1217. exists. In our scenario, enlarging @var{W4} will steal space from
  1218. @var{W3}.
  1219. @smallexample
  1220. @group
  1221. ______________________________________
  1222. | ____________________________________ |
  1223. || ||
  1224. || ||
  1225. ||_________________W2_________________||
  1226. | ____________________________________ |
  1227. || ||
  1228. || ||
  1229. || ||
  1230. || ||
  1231. ||_________________W4_________________||
  1232. | ____________________________________ |
  1233. ||_________________W3_________________||
  1234. |__________________W1__________________|
  1235. @end group
  1236. @end smallexample
  1237. @noindent
  1238. Deleting @var{W4} will now give its entire space to @var{W2},
  1239. including the space earlier stolen from @var{W3}.
  1240. @smallexample
  1241. @group
  1242. ______________________________________
  1243. | ____________________________________ |
  1244. || ||
  1245. || ||
  1246. || ||
  1247. || ||
  1248. || ||
  1249. || ||
  1250. || ||
  1251. || ||
  1252. ||_________________W2_________________||
  1253. | ____________________________________ |
  1254. ||_________________W3_________________||
  1255. |__________________W1__________________|
  1256. @end group
  1257. @end smallexample
  1258. @noindent
  1259. This can be counterintuitive, in particular if @var{W4} were used for
  1260. displaying a buffer only temporarily (@pxref{Temporary Displays}), and
  1261. you want to continue working with the initial layout.
  1262. The behavior can be fixed by making a new parent window when splitting
  1263. @var{W2}. The variable described next allows that to be done.
  1264. @defopt window-combination-limit
  1265. This variable controls whether splitting a window shall make a new
  1266. parent window. The following values are recognized:
  1267. @table @code
  1268. @item nil
  1269. This means that the new live window is allowed to share the existing
  1270. parent window, if one exists, provided the split occurs in the same
  1271. direction as the existing window combination (otherwise, a new internal
  1272. window is created anyway).
  1273. @item window-size
  1274. In this case @code{display-buffer} makes a new parent window if it is
  1275. passed a @code{window-height} or @code{window-width} entry in the
  1276. @var{alist} argument (@pxref{Display Action Functions}).
  1277. @item temp-buffer
  1278. This value causes the creation of a new parent window when a window is
  1279. split for showing a temporary buffer (@pxref{Temporary Displays}) only.
  1280. @item display-buffer
  1281. This means that when @code{display-buffer} (@pxref{Choosing Window})
  1282. splits a window it always makes a new parent window.
  1283. @item t
  1284. In this case a new parent window is always created when splitting a
  1285. window. Thus, if the value of this variable is at all times @code{t},
  1286. then at all times every window tree is a binary tree (a tree where each
  1287. window except the root window has exactly one sibling).
  1288. @end table
  1289. The default is @code{nil}. Other values are reserved for future use.
  1290. If, as a consequence of this variable's setting, @code{split-window}
  1291. makes a new parent window, it also calls
  1292. @code{set-window-combination-limit} (see below) on the newly-created
  1293. internal window. This affects how the window tree is rearranged when
  1294. the child windows are deleted (see below).
  1295. @end defopt
  1296. If @code{window-combination-limit} is @code{t}, splitting @var{W2} in
  1297. the initial configuration of our scenario would have produced this:
  1298. @smallexample
  1299. @group
  1300. ______________________________________
  1301. | ____________________________________ |
  1302. || __________________________________ ||
  1303. ||| |||
  1304. |||________________W2________________|||
  1305. || __________________________________ ||
  1306. ||| |||
  1307. |||________________W4________________|||
  1308. ||_________________W5_________________||
  1309. | ____________________________________ |
  1310. || ||
  1311. || ||
  1312. ||_________________W3_________________||
  1313. |__________________W1__________________|
  1314. @end group
  1315. @end smallexample
  1316. @noindent
  1317. A new internal window @var{W5} has been created; its children are
  1318. @var{W2} and the new live window @var{W4}. Now, @var{W2} is the only
  1319. sibling of @var{W4}, so enlarging @var{W4} will try to shrink
  1320. @var{W2}, leaving @var{W3} unaffected. Observe that @var{W5}
  1321. represents a vertical combination of two windows embedded in the
  1322. vertical combination @var{W1}.
  1323. @cindex window combination limit
  1324. @defun set-window-combination-limit window limit
  1325. This function sets the @dfn{combination limit} of the window
  1326. @var{window} to @var{limit}. This value can be retrieved via the
  1327. function @code{window-combination-limit}. See below for its effects;
  1328. note that it is only meaningful for internal windows. The
  1329. @code{split-window} function automatically calls this function, passing
  1330. it @code{t} as @var{limit}, provided the value of the variable
  1331. @code{window-combination-limit} is @code{t} when it is called.
  1332. @end defun
  1333. @defun window-combination-limit window
  1334. This function returns the combination limit for @var{window}.
  1335. The combination limit is meaningful only for an internal window. If it
  1336. is @code{nil}, then Emacs is allowed to automatically delete
  1337. @var{window}, in response to a window deletion, in order to group the
  1338. child windows of @var{window} with its sibling windows to form a new
  1339. window combination. If the combination limit is @code{t}, the child
  1340. windows of @var{window} are never automatically recombined with its
  1341. siblings.
  1342. If, in the configuration shown at the beginning of this section, the
  1343. combination limit of @var{W4} (the parent window of @var{W6} and
  1344. @var{W7}) is @code{t}, deleting @var{W5} will not implicitly delete
  1345. @var{W4} too.
  1346. @end defun
  1347. Alternatively, the problems sketched above can be avoided by always
  1348. resizing all windows in the same combination whenever one of its windows
  1349. is split or deleted. This also permits splitting windows that would be
  1350. otherwise too small for such an operation.
  1351. @defopt window-combination-resize
  1352. If this variable is @code{nil}, @code{split-window} can only split a
  1353. window (denoted by @var{window}) if @var{window}'s screen area is large
  1354. enough to accommodate both itself and the new window.
  1355. If this variable is @code{t}, @code{split-window} tries to resize all
  1356. windows that are part of the same combination as @var{window}, in order
  1357. to accommodate the new window. In particular, this may allow
  1358. @code{split-window} to succeed even if @var{window} is a fixed-size
  1359. window or too small to ordinarily split. Furthermore, subsequently
  1360. resizing or deleting @var{window} may resize all other windows in its
  1361. combination.
  1362. The default is @code{nil}. Other values are reserved for future use.
  1363. The value of this variable is ignored when
  1364. @code{window-combination-limit} is non-@code{nil}.
  1365. @end defopt
  1366. To illustrate the effect of @code{window-combination-resize}, consider
  1367. the following frame layout.
  1368. @smallexample
  1369. @group
  1370. ______________________________________
  1371. | ____________________________________ |
  1372. || ||
  1373. || ||
  1374. || ||
  1375. || ||
  1376. ||_________________W2_________________||
  1377. | ____________________________________ |
  1378. || ||
  1379. || ||
  1380. || ||
  1381. || ||
  1382. ||_________________W3_________________||
  1383. |__________________W1__________________|
  1384. @end group
  1385. @end smallexample
  1386. @noindent
  1387. If @code{window-combination-resize} is @code{nil}, splitting window
  1388. @var{W3} leaves the size of @var{W2} unchanged:
  1389. @smallexample
  1390. @group
  1391. ______________________________________
  1392. | ____________________________________ |
  1393. || ||
  1394. || ||
  1395. || ||
  1396. || ||
  1397. ||_________________W2_________________||
  1398. | ____________________________________ |
  1399. || ||
  1400. ||_________________W3_________________||
  1401. | ____________________________________ |
  1402. || ||
  1403. ||_________________W4_________________||
  1404. |__________________W1__________________|
  1405. @end group
  1406. @end smallexample
  1407. @noindent
  1408. If @code{window-combination-resize} is @code{t}, splitting @var{W3}
  1409. instead leaves all three live windows with approximately the same
  1410. height:
  1411. @smallexample
  1412. @group
  1413. ______________________________________
  1414. | ____________________________________ |
  1415. || ||
  1416. || ||
  1417. ||_________________W2_________________||
  1418. | ____________________________________ |
  1419. || ||
  1420. || ||
  1421. ||_________________W3_________________||
  1422. | ____________________________________ |
  1423. || ||
  1424. || ||
  1425. ||_________________W4_________________||
  1426. |__________________W1__________________|
  1427. @end group
  1428. @end smallexample
  1429. @noindent
  1430. Deleting any of the live windows @var{W2}, @var{W3} or @var{W4} will
  1431. distribute its space proportionally among the two remaining live
  1432. windows.
  1433. @node Selecting Windows
  1434. @section Selecting Windows
  1435. @cindex selecting a window
  1436. @defun select-window window &optional norecord
  1437. This function makes @var{window} the selected window and the window
  1438. selected within its frame (@pxref{Basic Windows}) and selects that
  1439. frame. It also makes @var{window}'s buffer (@pxref{Buffers and
  1440. Windows}) current and sets that buffer's value of @code{point} to the
  1441. value of @code{window-point} (@pxref{Window Point}) in @var{window}.
  1442. @var{window} must be a live window. The return value is @var{window}.
  1443. By default, this function also moves @var{window}'s buffer to the front
  1444. of the buffer list (@pxref{Buffer List}), and makes @var{window} the
  1445. most recently selected window. However, if the optional argument
  1446. @var{norecord} is non-@code{nil}, these additional actions are omitted.
  1447. This function runs @code{buffer-list-update-hook} (@pxref{Buffer List})
  1448. unless @var{norecord} is non-@code{nil}. Note that applications and
  1449. internal routines often temporarily select a window in order to simplify
  1450. coding. As a rule, such selections (including those made by the macros
  1451. @code{save-selected-window} and @code{with-selected-window} below) are
  1452. not recorded thus avoiding to pollute @code{buffer-list-update-hook}.
  1453. Selections that really count are those causing a visible change in
  1454. the next redisplay of @var{window}'s frame and should be always
  1455. recorded. This also means that to run a function each time a window
  1456. gets selected, putting it on @code{buffer-list-update-hook} should be
  1457. the right choice.
  1458. @end defun
  1459. @cindex most recently selected windows
  1460. The sequence of calls to @code{select-window} with a non-@code{nil}
  1461. @var{norecord} argument determines an ordering of windows by their
  1462. selection time. The function @code{get-lru-window} can be used to
  1463. retrieve the least recently selected live window (@pxref{Cyclic Window
  1464. Ordering}).
  1465. @defmac save-selected-window forms@dots{}
  1466. This macro records the selected frame, as well as the selected window
  1467. of each frame, executes @var{forms} in sequence, then restores the
  1468. earlier selected frame and windows. It also saves and restores the
  1469. current buffer. It returns the value of the last form in @var{forms}.
  1470. This macro does not save or restore anything about the sizes,
  1471. arrangement or contents of windows; therefore, if @var{forms} change
  1472. them, the change persists. If the previously selected window of some
  1473. frame is no longer live at the time of exit from @var{forms}, that
  1474. frame's selected window is left alone. If the previously selected
  1475. window is no longer live, then whatever window is selected at the end of
  1476. @var{forms} remains selected. The current buffer is restored if and
  1477. only if it is still live when exiting @var{forms}.
  1478. This macro changes neither the ordering of recently selected windows nor
  1479. the buffer list.
  1480. @end defmac
  1481. @defmac with-selected-window window forms@dots{}
  1482. This macro selects @var{window}, executes @var{forms} in sequence, then
  1483. restores the previously selected window and current buffer. The ordering
  1484. of recently selected windows and the buffer list remain unchanged unless
  1485. you deliberately change them within @var{forms}; for example, by calling
  1486. @code{select-window} with argument @var{norecord} @code{nil}.
  1487. This macro does not change the order of recently selected windows or
  1488. the buffer list.
  1489. @end defmac
  1490. @defun frame-selected-window &optional frame
  1491. This function returns the window on @var{frame} that is selected
  1492. within that frame. @var{frame} should be a live frame; if omitted or
  1493. @code{nil}, it defaults to the selected frame.
  1494. @end defun
  1495. @defun set-frame-selected-window frame window &optional norecord
  1496. This function makes @var{window} the window selected within the frame
  1497. @var{frame}. @var{frame} should be a live frame; if @code{nil}, it
  1498. defaults to the selected frame. @var{window} should be a live window;
  1499. if @code{nil}, it defaults to the selected window.
  1500. If @var{frame} is the selected frame, this makes @var{window} the
  1501. selected window.
  1502. If the optional argument @var{norecord} is non-@code{nil}, this
  1503. function does not alter the list of most recently selected windows,
  1504. nor the buffer list.
  1505. @end defun
  1506. @cindex window use time
  1507. @cindex use time of window
  1508. @cindex window order by time of last use
  1509. @defun window-use-time &optional window
  1510. This functions returns the use time of window @var{window}.
  1511. @var{window} must be a live window and defaults to the selected one.
  1512. The @dfn{use time} of a window is not really a time value, but an
  1513. integer that does increase monotonically with each call of
  1514. @code{select-window} with a @code{nil} @var{norecord} argument. The
  1515. window with the lowest use time is usually called the least recently
  1516. used window while the window with the highest use time is called the
  1517. most recently used one (@pxref{Cyclic Window Ordering}).
  1518. @end defun
  1519. @node Cyclic Window Ordering
  1520. @section Cyclic Ordering of Windows
  1521. @cindex cyclic ordering of windows
  1522. @cindex ordering of windows, cyclic
  1523. @cindex window ordering, cyclic
  1524. When you use the command @kbd{C-x o} (@code{other-window}) to select
  1525. some other window, it moves through live windows in a specific order.
  1526. For any given configuration of windows, this order never varies. It
  1527. is called the @dfn{cyclic ordering of windows}.
  1528. The ordering is determined by a depth-first traversal of each frame's
  1529. window tree, retrieving the live windows which are the leaf nodes of the
  1530. tree (@pxref{Windows and Frames}). If the minibuffer is active, the
  1531. minibuffer window is included too. The ordering is cyclic, so the last
  1532. window in the sequence is followed by the first one.
  1533. @defun next-window &optional window minibuf all-frames
  1534. @cindex minibuffer window, and @code{next-window}
  1535. This function returns a live window, the one following @var{window} in
  1536. the cyclic ordering of windows. @var{window} should be a live window;
  1537. if omitted or @code{nil}, it defaults to the selected window.
  1538. The optional argument @var{minibuf} specifies whether minibuffer windows
  1539. should be included in the cyclic ordering. Normally, when @var{minibuf}
  1540. is @code{nil}, a minibuffer window is included only if it is currently
  1541. active; this matches the behavior of @kbd{C-x o}. (Note that a
  1542. minibuffer window is active as long as its minibuffer is in use; see
  1543. @ref{Minibuffers}).
  1544. If @var{minibuf} is @code{t}, the cyclic ordering includes all
  1545. minibuffer windows. If @var{minibuf} is neither @code{t} nor
  1546. @code{nil}, minibuffer windows are not included even if they are active.
  1547. The optional argument @var{all-frames} specifies which frames to
  1548. consider:
  1549. @itemize @bullet
  1550. @item @code{nil}
  1551. means to consider windows on @var{window}'s frame. If the minibuffer
  1552. window is considered (as specified by the @var{minibuf} argument),
  1553. then frames that share the minibuffer window are considered too.
  1554. @item @code{t}
  1555. means to consider windows on all existing frames.
  1556. @item @code{visible}
  1557. means to consider windows on all visible frames.
  1558. @item 0
  1559. means to consider windows on all visible or iconified frames.
  1560. @item A frame
  1561. means to consider windows on that specific frame.
  1562. @item Anything else
  1563. means to consider windows on @var{window}'s frame, and no others.
  1564. @end itemize
  1565. If more than one frame is considered, the cyclic ordering is obtained
  1566. by appending the orderings for those frames, in the same order as the
  1567. list of all live frames (@pxref{Finding All Frames}).
  1568. @end defun
  1569. @defun previous-window &optional window minibuf all-frames
  1570. This function returns a live window, the one preceding @var{window} in
  1571. the cyclic ordering of windows. The other arguments are handled like
  1572. in @code{next-window}.
  1573. @end defun
  1574. @deffn Command other-window count &optional all-frames
  1575. This function selects a live window, one @var{count} places from the
  1576. selected window in the cyclic ordering of windows. If @var{count} is
  1577. a positive number, it skips @var{count} windows forwards; if
  1578. @var{count} is negative, it skips @minus{}@var{count} windows
  1579. backwards; if @var{count} is zero, that simply re-selects the selected
  1580. window. When called interactively, @var{count} is the numeric prefix
  1581. argument.
  1582. The optional argument @var{all-frames} has the same meaning as in
  1583. @code{next-window}, like a @code{nil} @var{minibuf} argument to
  1584. @code{next-window}.
  1585. This function does not select a window that has a non-@code{nil}
  1586. @code{no-other-window} window parameter (@pxref{Window Parameters}).
  1587. @end deffn
  1588. @defun walk-windows fun &optional minibuf all-frames
  1589. This function calls the function @var{fun} once for each live window,
  1590. with the window as the argument.
  1591. It follows the cyclic ordering of windows. The optional arguments
  1592. @var{minibuf} and @var{all-frames} specify the set of windows
  1593. included; these have the same arguments as in @code{next-window}. If
  1594. @var{all-frames} specifies a frame, the first window walked is the
  1595. first window on that frame (the one returned by
  1596. @code{frame-first-window}), not necessarily the selected window.
  1597. If @var{fun} changes the window configuration by splitting or deleting
  1598. windows, that does not alter the set of windows walked, which is
  1599. determined prior to calling @var{fun} for the first time.
  1600. @end defun
  1601. @defun one-window-p &optional no-mini all-frames
  1602. This function returns @code{t} if the selected window is the only live
  1603. window, and @code{nil} otherwise.
  1604. If the minibuffer window is active, it is normally considered (so that
  1605. this function returns @code{nil}). However, if the optional argument
  1606. @var{no-mini} is non-@code{nil}, the minibuffer window is ignored even
  1607. if active. The optional argument @var{all-frames} has the same
  1608. meaning as for @code{next-window}.
  1609. @end defun
  1610. @cindex finding windows
  1611. The following functions return a window which satisfies some
  1612. criterion, without selecting it:
  1613. @cindex least recently used window
  1614. @defun get-lru-window &optional all-frames dedicated not-selected
  1615. This function returns a live window which is heuristically the least
  1616. recently used. The optional argument @var{all-frames} has
  1617. the same meaning as in @code{next-window}.
  1618. If any full-width windows are present, only those windows are
  1619. considered. A minibuffer window is never a candidate. A dedicated
  1620. window (@pxref{Dedicated Windows}) is never a candidate unless the
  1621. optional argument @var{dedicated} is non-@code{nil}. The selected
  1622. window is never returned, unless it is the only candidate. However, if
  1623. the optional argument @var{not-selected} is non-@code{nil}, this
  1624. function returns @code{nil} in that case.
  1625. @end defun
  1626. @cindex most recently used window
  1627. @defun get-mru-window &optional all-frames dedicated not-selected
  1628. This function is like @code{get-lru-window}, but it returns the most
  1629. recently used window instead. The meaning of the arguments is the
  1630. same as described for @code{get-lru-window}.
  1631. @end defun
  1632. @cindex largest window
  1633. @defun get-largest-window &optional all-frames dedicated not-selected
  1634. This function returns the window with the largest area (height times
  1635. width). The optional argument @var{all-frames} specifies the windows to
  1636. search, and has the same meaning as in @code{next-window}.
  1637. A minibuffer window is never a candidate. A dedicated window
  1638. (@pxref{Dedicated Windows}) is never a candidate unless the optional
  1639. argument @var{dedicated} is non-@code{nil}. The selected window is not
  1640. a candidate if the optional argument @var{not-selected} is
  1641. non-@code{nil}. If the optional argument @var{not-selected} is
  1642. non-@code{nil} and the selected window is the only candidate, this
  1643. function returns @code{nil}.
  1644. If there are two candidate windows of the same size, this function
  1645. prefers the one that comes first in the cyclic ordering of windows,
  1646. starting from the selected window.
  1647. @end defun
  1648. @cindex window that satisfies a predicate
  1649. @cindex conditional selection of windows
  1650. @defun get-window-with-predicate predicate &optional minibuf all-frames default
  1651. This function calls the function @var{predicate} for each of the
  1652. windows in the cyclic order of windows in turn, passing it the window
  1653. as an argument. If the predicate returns non-@code{nil} for any
  1654. window, this function stops and returns that window. If no such
  1655. window is found, the return value is @var{default} (which defaults to
  1656. @code{nil}).
  1657. The optional arguments @var{minibuf} and @var{all-frames} specify the
  1658. windows to search, and have the same meanings as in
  1659. @code{next-window}.
  1660. @end defun
  1661. @node Buffers and Windows
  1662. @section Buffers and Windows
  1663. @cindex examining windows
  1664. @cindex windows, controlling precisely
  1665. @cindex buffers, controlled in windows
  1666. This section describes low-level functions for examining and setting
  1667. the contents of windows. @xref{Switching Buffers}, for higher-level
  1668. functions for displaying a specific buffer in a window.
  1669. @defun window-buffer &optional window
  1670. This function returns the buffer that @var{window} is displaying. If
  1671. @var{window} is omitted or @code{nil} it defaults to the selected
  1672. window. If @var{window} is an internal window, this function returns
  1673. @code{nil}.
  1674. @end defun
  1675. @defun set-window-buffer window buffer-or-name &optional keep-margins
  1676. This function makes @var{window} display @var{buffer-or-name}.
  1677. @var{window} should be a live window; if @code{nil}, it defaults to
  1678. the selected window. @var{buffer-or-name} should be a buffer, or the
  1679. name of an existing buffer. This function does not change which
  1680. window is selected, nor does it directly change which buffer is
  1681. current (@pxref{Current Buffer}). Its return value is @code{nil}.
  1682. If @var{window} is @dfn{strongly dedicated} to a buffer and
  1683. @var{buffer-or-name} does not specify that buffer, this function
  1684. signals an error. @xref{Dedicated Windows}.
  1685. By default, this function resets @var{window}'s position, display
  1686. margins, fringe widths, and scroll bar settings, based on the local
  1687. variables in the specified buffer. However, if the optional argument
  1688. @var{keep-margins} is non-@code{nil}, it leaves the display margins
  1689. and fringe widths unchanged.
  1690. When writing an application, you should normally use the higher-level
  1691. functions described in @ref{Switching Buffers}, instead of calling
  1692. @code{set-window-buffer} directly.
  1693. This runs @code{window-scroll-functions}, followed by
  1694. @code{window-configuration-change-hook}. @xref{Window Hooks}.
  1695. @end defun
  1696. @defvar buffer-display-count
  1697. This buffer-local variable records the number of times a buffer has been
  1698. displayed in a window. It is incremented each time
  1699. @code{set-window-buffer} is called for the buffer.
  1700. @end defvar
  1701. @defvar buffer-display-time
  1702. This buffer-local variable records the time at which a buffer was last
  1703. displayed in a window. The value is @code{nil} if the buffer has
  1704. never been displayed. It is updated each time
  1705. @code{set-window-buffer} is called for the buffer, with the value
  1706. returned by @code{current-time} (@pxref{Time of Day}).
  1707. @end defvar
  1708. @defun get-buffer-window &optional buffer-or-name all-frames
  1709. This function returns the first window displaying @var{buffer-or-name}
  1710. in the cyclic ordering of windows, starting from the selected window
  1711. (@pxref{Cyclic Window Ordering}). If no such window exists, the
  1712. return value is @code{nil}.
  1713. @var{buffer-or-name} should be a buffer or the name of a buffer; if
  1714. omitted or @code{nil}, it defaults to the current buffer. The
  1715. optional argument @var{all-frames} specifies which windows to
  1716. consider:
  1717. @itemize @bullet
  1718. @item
  1719. @code{t} means consider windows on all existing frames.
  1720. @item
  1721. @code{visible} means consider windows on all visible frames.
  1722. @item
  1723. 0 means consider windows on all visible or iconified frames.
  1724. @item
  1725. A frame means consider windows on that frame only.
  1726. @item
  1727. Any other value means consider windows on the selected frame.
  1728. @end itemize
  1729. Note that these meanings differ slightly from those of the
  1730. @var{all-frames} argument to @code{next-window} (@pxref{Cyclic Window
  1731. Ordering}). This function may be changed in a future version of Emacs
  1732. to eliminate this discrepancy.
  1733. @end defun
  1734. @defun get-buffer-window-list &optional buffer-or-name minibuf all-frames
  1735. This function returns a list of all windows currently displaying
  1736. @var{buffer-or-name}. @var{buffer-or-name} should be a buffer or the
  1737. name of an existing buffer. If omitted or @code{nil}, it defaults to
  1738. the current buffer. If the currently selected window displays
  1739. @var{buffer-or-name}, it will be the first in the list returned by
  1740. this function.
  1741. The arguments @var{minibuf} and @var{all-frames} have the same
  1742. meanings as in the function @code{next-window} (@pxref{Cyclic Window
  1743. Ordering}). Note that the @var{all-frames} argument does @emph{not}
  1744. behave exactly like in @code{get-buffer-window}.
  1745. @end defun
  1746. @deffn Command replace-buffer-in-windows &optional buffer-or-name
  1747. This command replaces @var{buffer-or-name} with some other buffer, in
  1748. all windows displaying it. @var{buffer-or-name} should be a buffer, or
  1749. the name of an existing buffer; if omitted or @code{nil}, it defaults to
  1750. the current buffer.
  1751. The replacement buffer in each window is chosen via
  1752. @code{switch-to-prev-buffer} (@pxref{Window History}). Any dedicated
  1753. window displaying @var{buffer-or-name} is deleted if possible
  1754. (@pxref{Dedicated Windows}). If such a window is the only window on its
  1755. frame and there are other frames on the same terminal, the frame is
  1756. deleted as well. If the dedicated window is the only window on the only
  1757. frame on its terminal, the buffer is replaced anyway.
  1758. @end deffn
  1759. @node Switching Buffers
  1760. @section Switching to a Buffer in a Window
  1761. @cindex switching to a buffer
  1762. @cindex displaying a buffer
  1763. This section describes high-level functions for switching to a specified
  1764. buffer in some window. In general, ``switching to a buffer'' means to
  1765. (1) show the buffer in some window, (2) make that window the selected
  1766. window (and its frame the selected frame), and (3) make the buffer the
  1767. current buffer.
  1768. Do @emph{not} use these functions to make a buffer temporarily
  1769. current just so a Lisp program can access or modify it. They have
  1770. side-effects, such as changing window histories (@pxref{Window
  1771. History}), which will surprise the user if used that way. If you want
  1772. to make a buffer current to modify it in Lisp, use
  1773. @code{with-current-buffer}, @code{save-current-buffer}, or
  1774. @code{set-buffer}. @xref{Current Buffer}.
  1775. @deffn Command switch-to-buffer buffer-or-name &optional norecord force-same-window
  1776. This command attempts to display @var{buffer-or-name} in the selected
  1777. window and make it the current buffer. It is often used interactively
  1778. (as the binding of @kbd{C-x b}), as well as in Lisp programs. The
  1779. return value is the buffer switched to.
  1780. If @var{buffer-or-name} is @code{nil}, it defaults to the buffer
  1781. returned by @code{other-buffer} (@pxref{Buffer List}). If
  1782. @var{buffer-or-name} is a string that is not the name of any existing
  1783. buffer, this function creates a new buffer with that name; the new
  1784. buffer's major mode is determined by the variable @code{major-mode}
  1785. (@pxref{Major Modes}).
  1786. Normally, the specified buffer is put at the front of the buffer
  1787. list---both the global buffer list and the selected frame's buffer
  1788. list (@pxref{Buffer List}). However, this is not done if the
  1789. optional argument @var{norecord} is non-@code{nil}.
  1790. Sometimes, the selected window may not be suitable for displaying the
  1791. buffer. This happens if the selected window is a minibuffer window, or
  1792. if the selected window is strongly dedicated to its buffer
  1793. (@pxref{Dedicated Windows}). In such cases, the command normally tries
  1794. to display the buffer in some other window, by invoking
  1795. @code{pop-to-buffer} (see below).
  1796. If the optional argument @var{force-same-window} is non-@code{nil} and
  1797. the selected window is not suitable for displaying the buffer, this
  1798. function always signals an error when called non-interactively. In
  1799. interactive use, if the selected window is a minibuffer window, this
  1800. function will try to use some other window instead. If the selected
  1801. window is strongly dedicated to its buffer, the option
  1802. @code{switch-to-buffer-in-dedicated-window} described next can be used
  1803. to proceed.
  1804. @end deffn
  1805. @defopt switch-to-buffer-in-dedicated-window
  1806. This option, if non-@code{nil}, allows @code{switch-to-buffer} to
  1807. proceed when called interactively and the selected window is strongly
  1808. dedicated to its buffer.
  1809. The following values are respected:
  1810. @table @code
  1811. @item nil
  1812. Disallows switching and signals an error as in non-interactive use.
  1813. @item prompt
  1814. Prompts the user whether to allow switching.
  1815. @item pop
  1816. Invokes @code{pop-to-buffer} to proceed.
  1817. @item t
  1818. Marks the selected window as non-dedicated and proceeds.
  1819. @end table
  1820. This option does not affect non-interactive calls of
  1821. @code{switch-to-buffer}.
  1822. @end defopt
  1823. By default, @code{switch-to-buffer} shows the buffer at its position of
  1824. @code{point}. This behavior can be tuned using the following option.
  1825. @defopt switch-to-buffer-preserve-window-point
  1826. If this variable is @code{nil}, @code{switch-to-buffer} displays the
  1827. buffer specified by @var{buffer-or-name} at the position of that
  1828. buffer's @code{point}. If this variable is @code{already-displayed}, it
  1829. tries to display the buffer at its previous position in the selected
  1830. window, provided the buffer is currently displayed in some other window
  1831. on any visible or iconified frame. If this variable is @code{t},
  1832. @code{switch-to-buffer} unconditionally tries to display the buffer at
  1833. its previous position in the selected window.
  1834. This variable is ignored if the buffer is already displayed in the
  1835. selected window or never appeared in it before, or if
  1836. @code{switch-to-buffer} calls @code{pop-to-buffer} to display the
  1837. buffer.
  1838. @end defopt
  1839. The next two commands are similar to @code{switch-to-buffer}, except for
  1840. the described features.
  1841. @deffn Command switch-to-buffer-other-window buffer-or-name &optional norecord
  1842. This function displays the buffer specified by @var{buffer-or-name} in
  1843. some window other than the selected window. It uses the function
  1844. @code{pop-to-buffer} internally (see below).
  1845. If the selected window already displays the specified buffer, it
  1846. continues to do so, but another window is nonetheless found to display
  1847. it as well.
  1848. The @var{buffer-or-name} and @var{norecord} arguments have the same
  1849. meanings as in @code{switch-to-buffer}.
  1850. @end deffn
  1851. @deffn Command switch-to-buffer-other-frame buffer-or-name &optional norecord
  1852. This function displays the buffer specified by @var{buffer-or-name} in a
  1853. new frame. It uses the function @code{pop-to-buffer} internally (see
  1854. below).
  1855. If the specified buffer is already displayed in another window, in any
  1856. frame on the current terminal, this switches to that window instead of
  1857. creating a new frame. However, the selected window is never used for
  1858. this.
  1859. The @var{buffer-or-name} and @var{norecord} arguments have the same
  1860. meanings as in @code{switch-to-buffer}.
  1861. @end deffn
  1862. The above commands use the function @code{pop-to-buffer}, which
  1863. flexibly displays a buffer in some window and selects that window for
  1864. editing. In turn, @code{pop-to-buffer} uses @code{display-buffer} for
  1865. displaying the buffer. Hence, all the variables affecting
  1866. @code{display-buffer} will affect it as well. @xref{Choosing Window},
  1867. for the documentation of @code{display-buffer}.
  1868. @deffn Command pop-to-buffer buffer-or-name &optional action norecord
  1869. This function makes @var{buffer-or-name} the current buffer and
  1870. displays it in some window, preferably not the window currently
  1871. selected. It then selects the displaying window. If that window is
  1872. on a different graphical frame, that frame is given input focus if
  1873. possible (@pxref{Input Focus}). The return value is the buffer that
  1874. was switched to.
  1875. If @var{buffer-or-name} is @code{nil}, it defaults to the buffer
  1876. returned by @code{other-buffer} (@pxref{Buffer List}). If
  1877. @var{buffer-or-name} is a string that is not the name of any existing
  1878. buffer, this function creates a new buffer with that name; the new
  1879. buffer's major mode is determined by the variable @code{major-mode}
  1880. (@pxref{Major Modes}).
  1881. If @var{action} is non-@code{nil}, it should be a display action to
  1882. pass to @code{display-buffer} (@pxref{Choosing Window}).
  1883. Alternatively, a non-@code{nil}, non-list value means to pop to a
  1884. window other than the selected one---even if the buffer is already
  1885. displayed in the selected window.
  1886. Like @code{switch-to-buffer}, this function updates the buffer list
  1887. unless @var{norecord} is non-@code{nil}.
  1888. @end deffn
  1889. @node Choosing Window
  1890. @section Choosing a Window for Display
  1891. The command @code{display-buffer} flexibly chooses a window for
  1892. display, and displays a specified buffer in that window. It can be
  1893. called interactively, via the key binding @kbd{C-x 4 C-o}. It is also
  1894. used as a subroutine by many functions and commands, including
  1895. @code{switch-to-buffer} and @code{pop-to-buffer} (@pxref{Switching
  1896. Buffers}).
  1897. @cindex display action
  1898. @cindex action function, for @code{display-buffer}
  1899. @cindex action alist, for @code{display-buffer}
  1900. This command performs several complex steps to find a window to
  1901. display in. These steps are described by means of @dfn{display
  1902. actions}, which have the form @code{(@var{function} . @var{alist})}.
  1903. Here, @var{function} is either a function or a list of functions,
  1904. which we refer to as @dfn{action functions}; @var{alist} is an
  1905. association list, which we refer to as @dfn{action alists}.
  1906. An action function accepts two arguments: the buffer to display and
  1907. an action alist. It attempts to display the buffer in some window,
  1908. picking or creating a window according to its own criteria. If
  1909. successful, it returns the window; otherwise, it returns @code{nil}.
  1910. @xref{Display Action Functions}, for a list of predefined action
  1911. functions.
  1912. @code{display-buffer} works by combining display actions from
  1913. several sources, and calling the action functions in turn, until one
  1914. of them manages to display the buffer and returns a non-@code{nil}
  1915. value.
  1916. @deffn Command display-buffer buffer-or-name &optional action frame
  1917. This command makes @var{buffer-or-name} appear in some window, without
  1918. selecting the window or making the buffer current. The argument
  1919. @var{buffer-or-name} must be a buffer or the name of an existing
  1920. buffer. The return value is the window chosen to display the buffer.
  1921. The optional argument @var{action}, if non-@code{nil}, should normally
  1922. be a display action (described above). @code{display-buffer} builds a
  1923. list of action functions and an action alist, by consolidating display
  1924. actions from the following sources (in order):
  1925. @itemize
  1926. @item
  1927. The variable @code{display-buffer-overriding-action}.
  1928. @item
  1929. The user option @code{display-buffer-alist}.
  1930. @item
  1931. The @var{action} argument.
  1932. @item
  1933. The user option @code{display-buffer-base-action}.
  1934. @item
  1935. The constant @code{display-buffer-fallback-action}.
  1936. @end itemize
  1937. @noindent
  1938. Each action function is called in turn, passing the buffer as the
  1939. first argument and the combined action alist as the second argument,
  1940. until one of the functions returns non-@code{nil}. The caller can
  1941. pass @code{(allow-no-window . t)} as an element of the action alist to
  1942. indicate its readiness to handle the case of not displaying the
  1943. buffer in a window.
  1944. The argument @var{action} can also have a non-@code{nil}, non-list
  1945. value. This has the special meaning that the buffer should be
  1946. displayed in a window other than the selected one, even if the
  1947. selected window is already displaying it. If called interactively
  1948. with a prefix argument, @var{action} is @code{t}.
  1949. The optional argument @var{frame}, if non-@code{nil}, specifies which
  1950. frames to check when deciding whether the buffer is already displayed.
  1951. It is equivalent to adding an element @code{(reusable-frames
  1952. . @var{frame})} to the action alist of @var{action}. @xref{Display
  1953. Action Functions}.
  1954. @end deffn
  1955. @defvar display-buffer-overriding-action
  1956. The value of this variable should be a display action, which is
  1957. treated with the highest priority by @code{display-buffer}. The
  1958. default value is empty, i.e., @code{(nil . nil)}.
  1959. @end defvar
  1960. @defopt display-buffer-alist
  1961. The value of this option is an alist mapping conditions to display
  1962. actions. Each condition may be either a regular expression matching a
  1963. buffer name or a function that takes two arguments: a buffer name and
  1964. the @var{action} argument passed to @code{display-buffer}. If the name
  1965. of the buffer passed to @code{display-buffer} either matches a regular
  1966. expression in this alist or the function specified by a condition
  1967. returns non-@code{nil}, then @code{display-buffer} uses the
  1968. corresponding display action to display the buffer.
  1969. @end defopt
  1970. @defopt display-buffer-base-action
  1971. The value of this option should be a display action. This option can
  1972. be used to define a standard display action for calls to
  1973. @code{display-buffer}.
  1974. @end defopt
  1975. @defvr Constant display-buffer-fallback-action
  1976. This display action specifies the fallback behavior for
  1977. @code{display-buffer} if no other display actions are given.
  1978. @end defvr
  1979. @node Display Action Functions
  1980. @section Action Functions for @code{display-buffer}
  1981. The following basic action functions are defined in Emacs. Each of
  1982. these functions takes two arguments: @var{buffer}, the buffer to
  1983. display, and @var{alist}, an action alist. Each action function
  1984. returns the window if it succeeds, and @code{nil} if it fails.
  1985. @defun display-buffer-same-window buffer alist
  1986. This function tries to display @var{buffer} in the selected window.
  1987. It fails if the selected window is a minibuffer window or is dedicated
  1988. to another buffer (@pxref{Dedicated Windows}). It also fails if
  1989. @var{alist} has a non-@code{nil} @code{inhibit-same-window} entry.
  1990. @end defun
  1991. @defun display-buffer-reuse-window buffer alist
  1992. This function tries to display @var{buffer} by finding a window
  1993. that is already displaying it.
  1994. If @var{alist} has a non-@code{nil} @code{inhibit-same-window} entry,
  1995. the selected window is not eligible for reuse. If @var{alist}
  1996. contains a @code{reusable-frames} entry, its value determines which
  1997. frames to search for a reusable window:
  1998. @itemize @bullet
  1999. @item
  2000. @code{nil} means consider windows on the selected frame.
  2001. (Actually, the last non-minibuffer frame.)
  2002. @item
  2003. @code{t} means consider windows on all frames.
  2004. @item
  2005. @code{visible} means consider windows on all visible frames.
  2006. @item
  2007. 0 means consider windows on all visible or iconified frames.
  2008. @item
  2009. A frame means consider windows on that frame only.
  2010. @end itemize
  2011. Note that these meanings differ slightly from those of the
  2012. @var{all-frames} argument to @code{next-window} (@pxref{Cyclic Window
  2013. Ordering}).
  2014. If @var{alist} contains no @code{reusable-frames} entry, this function
  2015. normally searches just the selected frame; however, if the variable
  2016. @code{pop-up-frames} is non-@code{nil}, it searches all frames on the
  2017. current terminal. @xref{Choosing Window Options}.
  2018. If this function chooses a window on another frame, it makes that frame
  2019. visible and, unless @var{alist} contains an @code{inhibit-switch-frame}
  2020. entry (@pxref{Choosing Window Options}), raises that frame if necessary.
  2021. @end defun
  2022. @defun display-buffer-reuse-mode-window buffer alist
  2023. This function tries to display @var{buffer} by finding a window
  2024. that is displaying a buffer in a given mode.
  2025. If @var{alist} contains a @code{mode} entry, its value is a major mode
  2026. (a symbol) or a list of major modes. If @var{alist} contains no
  2027. @code{mode} entry, the current major mode of @var{buffer} is used. A
  2028. window is a candidate if it displays a buffer that derives from one of
  2029. the given modes.
  2030. The behaviour is also controlled by entries for
  2031. @code{inhibit-same-window}, @code{reusable-frames} and
  2032. @code{inhibit-switch-frame} as is done in the function
  2033. @code{display-buffer-reuse-window}.
  2034. @end defun
  2035. @defun display-buffer-pop-up-frame buffer alist
  2036. This function creates a new frame, and displays the buffer in that
  2037. frame's window. It actually performs the frame creation by calling
  2038. the function specified in @code{pop-up-frame-function}
  2039. (@pxref{Choosing Window Options}). If @var{alist} contains a
  2040. @code{pop-up-frame-parameters} entry, the associated value
  2041. is added to the newly created frame's parameters.
  2042. @end defun
  2043. @defun display-buffer-use-some-frame buffer alist
  2044. This function tries to display @var{buffer} by trying to find a
  2045. frame that meets a predicate (by default any frame other than the
  2046. current frame).
  2047. If this function chooses a window on another frame, it makes that frame
  2048. visible and, unless @var{alist} contains an @code{inhibit-switch-frame}
  2049. entry (@pxref{Choosing Window Options}), raises that frame if necessary.
  2050. If @var{alist} has a non-@code{nil} @code{frame-predicate} entry, its
  2051. value is a function taking one argument (a frame), returning
  2052. non-@code{nil} if the frame is a candidate; this function replaces the
  2053. default predicate.
  2054. If @var{alist} has a non-@code{nil} @code{inhibit-same-window} entry,
  2055. the selected window is used; thus if the selected frame has a single
  2056. window, it is not used.
  2057. @end defun
  2058. @defun display-buffer-pop-up-window buffer alist
  2059. This function tries to display @var{buffer} by splitting the largest
  2060. or least recently-used window (typically one on the selected frame).
  2061. It actually performs the split by calling the function specified in
  2062. @code{split-window-preferred-function} (@pxref{Choosing Window
  2063. Options}).
  2064. The size of the new window can be adjusted by supplying
  2065. @code{window-height} and @code{window-width} entries in @var{alist}. To
  2066. adjust the window's height, use an entry whose @sc{car} is
  2067. @code{window-height} and whose @sc{cdr} is one of:
  2068. @itemize @bullet
  2069. @item
  2070. @code{nil} means to leave the height of the new window alone.
  2071. @item
  2072. A number specifies the desired height of the new window. An integer
  2073. specifies the number of lines of the window. A floating-point
  2074. number gives the fraction of the window's height with respect to the
  2075. height of the frame's root window.
  2076. @item
  2077. If the @sc{cdr} specifies a function, that function is called with one
  2078. argument: the new window. The function is supposed to adjust the
  2079. height of the window; its return value is ignored. Suitable functions
  2080. are @code{shrink-window-if-larger-than-buffer} and
  2081. @code{fit-window-to-buffer}, see @ref{Resizing Windows}.
  2082. @end itemize
  2083. To adjust the window's width, use an entry whose @sc{car} is
  2084. @code{window-width} and whose @sc{cdr} is one of:
  2085. @itemize @bullet
  2086. @item
  2087. @code{nil} means to leave the width of the new window alone.
  2088. @item
  2089. A number specifies the desired width of the new window. An integer
  2090. specifies the number of columns of the window. A floating-point
  2091. number gives the fraction of the window's width with respect to the
  2092. width of the frame's root window.
  2093. @item
  2094. If the @sc{cdr} specifies a function, that function is called with one
  2095. argument: the new window. The function is supposed to adjust the width
  2096. of the window; its return value is ignored.
  2097. @end itemize
  2098. If @var{alist} contains a @code{preserve-size} entry, Emacs will try to
  2099. preserve the size of the new window during future resize operations
  2100. (@pxref{Preserving Window Sizes}). The @sc{cdr} of that entry must be a
  2101. cons cell whose @sc{car}, if non-@code{nil}, means to preserve the width
  2102. of the window and whose @sc{cdr}, if non-@code{nil}, means to preserve
  2103. the height of the window.
  2104. This function can fail if no window splitting can be performed for some
  2105. reason (e.g., if the selected frame has an @code{unsplittable} frame
  2106. parameter; @pxref{Buffer Parameters}).
  2107. @end defun
  2108. @defun display-buffer-below-selected buffer alist
  2109. This function tries to display @var{buffer} in a window below the
  2110. selected window. This means to either split the selected window or use
  2111. the window below the selected one. If it does create a new window, it
  2112. will also adjust its size provided @var{alist} contains a suitable
  2113. @code{window-height} or @code{window-width} entry, see above.
  2114. @end defun
  2115. @defun display-buffer-in-previous-window buffer alist
  2116. This function tries to display @var{buffer} in a window previously
  2117. showing it. If @var{alist} has a non-@code{nil}
  2118. @code{inhibit-same-window} entry, the selected window is not eligible
  2119. for reuse. If @var{alist} contains a @code{reusable-frames} entry, its
  2120. value determines which frames to search for a suitable window as with
  2121. @code{display-buffer-reuse-window}.
  2122. If @var{alist} has a @code{previous-window} entry, the window
  2123. specified by that entry will override any other window found by the
  2124. methods above, even if that window never showed @var{buffer} before.
  2125. @end defun
  2126. @defun display-buffer-at-bottom buffer alist
  2127. This function tries to display @var{buffer} in a window at the bottom
  2128. of the selected frame.
  2129. This either splits the window at the bottom of the frame or the
  2130. frame's root window, or reuses an existing window at the bottom of the
  2131. selected frame.
  2132. @end defun
  2133. @defun display-buffer-use-some-window buffer alist
  2134. This function tries to display @var{buffer} by choosing an existing
  2135. window and displaying the buffer in that window. It can fail if all
  2136. windows are dedicated to another buffer (@pxref{Dedicated Windows}).
  2137. @end defun
  2138. @defun display-buffer-no-window buffer alist
  2139. If @var{alist} has a non-@code{nil} @code{allow-no-window} entry, then
  2140. this function does not display @code{buffer}. This allows you to
  2141. override the default action and avoid displaying the buffer. It is
  2142. assumed that when the caller specifies a non-@code{nil}
  2143. @code{allow-no-window} value it can handle a @code{nil} value returned
  2144. from @code{display-buffer} in this case.
  2145. @end defun
  2146. To illustrate the use of action functions, consider the following
  2147. example.
  2148. @example
  2149. @group
  2150. (display-buffer
  2151. (get-buffer-create "*foo*")
  2152. '((display-buffer-reuse-window
  2153. display-buffer-pop-up-window
  2154. display-buffer-pop-up-frame)
  2155. (reusable-frames . 0)
  2156. (window-height . 10) (window-width . 40)))
  2157. @end group
  2158. @end example
  2159. @noindent
  2160. Evaluating the form above will cause @code{display-buffer} to proceed as
  2161. follows: If a buffer called *foo* already appears on a visible or
  2162. iconified frame, it will reuse its window. Otherwise, it will try to
  2163. pop up a new window or, if that is impossible, a new frame and show the
  2164. buffer there. If all these steps fail, it will proceed using whatever
  2165. @code{display-buffer-base-action} and
  2166. @code{display-buffer-fallback-action} prescribe.
  2167. Furthermore, @code{display-buffer} will try to adjust a reused window
  2168. (provided *foo* was put by @code{display-buffer} there before) or a
  2169. popped-up window as follows: If the window is part of a vertical
  2170. combination, it will set its height to ten lines. Note that if, instead
  2171. of the number 10, we specified the function
  2172. @code{fit-window-to-buffer}, @code{display-buffer} would come up with a
  2173. one-line window to fit the empty buffer. If the window is part of a
  2174. horizontal combination, it sets its width to 40 columns. Whether a new
  2175. window is vertically or horizontally combined depends on the shape of
  2176. the window split and the values of
  2177. @code{split-window-preferred-function}, @code{split-height-threshold}
  2178. and @code{split-width-threshold} (@pxref{Choosing Window Options}).
  2179. Now suppose we combine this call with a preexisting setup for
  2180. @code{display-buffer-alist} as follows.
  2181. @example
  2182. @group
  2183. (let ((display-buffer-alist
  2184. (cons
  2185. '("\\*foo\\*"
  2186. (display-buffer-reuse-window display-buffer-below-selected)
  2187. (reusable-frames)
  2188. (window-height . 5))
  2189. display-buffer-alist)))
  2190. (display-buffer
  2191. (get-buffer-create "*foo*")
  2192. '((display-buffer-reuse-window
  2193. display-buffer-pop-up-window
  2194. display-buffer-pop-up-frame)
  2195. (reusable-frames . 0)
  2196. (window-height . 10) (window-width . 40))))
  2197. @end group
  2198. @end example
  2199. @noindent
  2200. This form will have @code{display-buffer} first try reusing a window
  2201. that shows *foo* on the selected frame. If there's no such window, it
  2202. will try to split the selected window or, if that is impossible, use the
  2203. window below the selected window.
  2204. If there's no window below the selected one, or the window below the
  2205. selected one is dedicated to its buffer, @code{display-buffer} will
  2206. proceed as described in the previous example. Note, however, that when
  2207. it tries to adjust the height of any reused or popped-up window, it will
  2208. in any case try to set its number of lines to 5 since that value
  2209. overrides the corresponding specification in the @var{action} argument
  2210. of @code{display-buffer}.
  2211. @node Choosing Window Options
  2212. @section Additional Options for Displaying Buffers
  2213. The behavior of the standard display actions of @code{display-buffer}
  2214. (@pxref{Choosing Window}) can be modified by a variety of user
  2215. options.
  2216. @defopt pop-up-windows
  2217. If the value of this variable is non-@code{nil}, @code{display-buffer}
  2218. is allowed to split an existing window to make a new window for
  2219. displaying in. This is the default.
  2220. This variable is provided mainly for backward compatibility. It is
  2221. obeyed by @code{display-buffer} via a special mechanism in
  2222. @code{display-buffer-fallback-action}, which only calls the action
  2223. function @code{display-buffer-pop-up-window} (@pxref{Display Action
  2224. Functions}) when the value is @code{nil}. It is not consulted by
  2225. @code{display-buffer-pop-up-window} itself, which the user may specify
  2226. directly in @code{display-buffer-alist} etc.
  2227. @end defopt
  2228. @defopt split-window-preferred-function
  2229. This variable specifies a function for splitting a window, in order to
  2230. make a new window for displaying a buffer. It is used by the
  2231. @code{display-buffer-pop-up-window} action function to actually split
  2232. the window (@pxref{Display Action Functions}).
  2233. The default value is @code{split-window-sensibly}, which is documented
  2234. below. The value must be a function that takes one argument, a window,
  2235. and return either a new window (which will be used to display the
  2236. desired buffer) or @code{nil} (which means the splitting failed).
  2237. @end defopt
  2238. @defun split-window-sensibly &optional window
  2239. This function tries to split @var{window}, and return the newly created
  2240. window. If @var{window} cannot be split, it returns @code{nil}. If
  2241. @var{window} is omitted or @code{nil}, it defaults to the selected
  2242. window.
  2243. This function obeys the usual rules that determine when a window may
  2244. be split (@pxref{Splitting Windows}). It first tries to split by
  2245. placing the new window below, subject to the restriction imposed by
  2246. @code{split-height-threshold} (see below), in addition to any other
  2247. restrictions. If that fails, it tries to split by placing the new
  2248. window to the right, subject to @code{split-width-threshold} (see
  2249. below). If that fails, and the window is the only window on its
  2250. frame, this function again tries to split and place the new window
  2251. below, disregarding @code{split-height-threshold}. If this fails as
  2252. well, this function gives up and returns @code{nil}.
  2253. @end defun
  2254. @defopt split-height-threshold
  2255. This variable, used by @code{split-window-sensibly}, specifies whether
  2256. to split the window placing the new window below. If it is an
  2257. integer, that means to split only if the original window has at least
  2258. that many lines. If it is @code{nil}, that means not to split this
  2259. way.
  2260. @end defopt
  2261. @defopt split-width-threshold
  2262. This variable, used by @code{split-window-sensibly}, specifies whether
  2263. to split the window placing the new window to the right. If the value
  2264. is an integer, that means to split only if the original window has at
  2265. least that many columns. If the value is @code{nil}, that means not
  2266. to split this way.
  2267. @end defopt
  2268. @defopt even-window-sizes
  2269. This variable, if non-@code{nil}, causes @code{display-buffer} to even
  2270. window sizes whenever it reuses an existing window and that window is
  2271. adjacent to the selected one.
  2272. If its value is @code{width-only}, sizes are evened only if the reused
  2273. window is on the left or right of the selected one and the selected
  2274. window is wider than the reused one. If its value is @code{height-only}
  2275. sizes are evened only if the reused window is above or beneath the
  2276. selected window and the selected window is higher than the reused one.
  2277. Any other non-@code{nil} value means to even sizes in any of these cases
  2278. provided the selected window is larger than the reused one in the sense
  2279. of their combination.
  2280. @end defopt
  2281. @defopt pop-up-frames
  2282. If the value of this variable is non-@code{nil}, that means
  2283. @code{display-buffer} may display buffers by making new frames. The
  2284. default is @code{nil}.
  2285. A non-@code{nil} value also means that when @code{display-buffer} is
  2286. looking for a window already displaying @var{buffer-or-name}, it can
  2287. search any visible or iconified frame, not just the selected frame.
  2288. This variable is provided mainly for backward compatibility. It is
  2289. obeyed by @code{display-buffer} via a special mechanism in
  2290. @code{display-buffer-fallback-action}, which calls the action function
  2291. @code{display-buffer-pop-up-frame} (@pxref{Display Action Functions})
  2292. if the value is non-@code{nil}. (This is done before attempting to
  2293. split a window.) This variable is not consulted by
  2294. @code{display-buffer-pop-up-frame} itself, which the user may specify
  2295. directly in @code{display-buffer-alist} etc.
  2296. @end defopt
  2297. @defopt pop-up-frame-function
  2298. This variable specifies a function for creating a new frame, in order
  2299. to make a new window for displaying a buffer. It is used by the
  2300. @code{display-buffer-pop-up-frame} action function (@pxref{Display
  2301. Action Functions}).
  2302. The value should be a function that takes no arguments and returns a
  2303. frame, or @code{nil} if no frame could be created. The default value
  2304. is a function that creates a frame using the parameters specified by
  2305. @code{pop-up-frame-alist} (see below).
  2306. @end defopt
  2307. @defopt pop-up-frame-alist
  2308. This variable holds an alist of frame parameters (@pxref{Frame
  2309. Parameters}), which is used by the default function in
  2310. @code{pop-up-frame-function} to make a new frame. The default is
  2311. @code{nil}.
  2312. @end defopt
  2313. @defopt same-window-buffer-names
  2314. A list of buffer names for buffers that should be displayed in the
  2315. selected window. If a buffer's name is in this list,
  2316. @code{display-buffer} handles the buffer by showing it in the selected
  2317. window.
  2318. @end defopt
  2319. @defopt same-window-regexps
  2320. A list of regular expressions that specify buffers that should be
  2321. displayed in the selected window. If the buffer's name matches any of
  2322. the regular expressions in this list, @code{display-buffer} handles the
  2323. buffer by showing it in the selected window.
  2324. @end defopt
  2325. @defun same-window-p buffer-name
  2326. This function returns @code{t} if displaying a buffer
  2327. named @var{buffer-name} with @code{display-buffer} would
  2328. put it in the selected window.
  2329. @end defun
  2330. @node Window History
  2331. @section Window History
  2332. @cindex window history
  2333. Each window remembers in a list the buffers it has previously displayed,
  2334. and the order in which these buffers were removed from it. This history
  2335. is used, for example, by @code{replace-buffer-in-windows}
  2336. (@pxref{Buffers and Windows}). The list is automatically maintained by
  2337. Emacs, but you can use the following functions to explicitly inspect or
  2338. alter it:
  2339. @defun window-prev-buffers &optional window
  2340. This function returns a list specifying the previous contents of
  2341. @var{window}. The optional argument @var{window} should be a live
  2342. window and defaults to the selected one.
  2343. Each list element has the form @code{(@var{buffer} @var{window-start}
  2344. @var{window-pos})}, where @var{buffer} is a buffer previously shown in
  2345. the window, @var{window-start} is the window start position
  2346. (@pxref{Window Start and End}) when that buffer was last shown, and
  2347. @var{window-pos} is the point position (@pxref{Window Point}) when
  2348. that buffer was last shown in @var{window}.
  2349. The list is ordered so that earlier elements correspond to more
  2350. recently-shown buffers, and the first element usually corresponds to the
  2351. buffer most recently removed from the window.
  2352. @end defun
  2353. @defun set-window-prev-buffers window prev-buffers
  2354. This function sets @var{window}'s previous buffers to the value of
  2355. @var{prev-buffers}. The argument @var{window} must be a live window
  2356. and defaults to the selected one. The argument @var{prev-buffers}
  2357. should be a list of the same form as that returned by
  2358. @code{window-prev-buffers}.
  2359. @end defun
  2360. In addition, each buffer maintains a list of @dfn{next buffers}, which
  2361. is a list of buffers re-shown by @code{switch-to-prev-buffer} (see
  2362. below). This list is mainly used by @code{switch-to-prev-buffer} and
  2363. @code{switch-to-next-buffer} for choosing buffers to switch to.
  2364. @defun window-next-buffers &optional window
  2365. This function returns the list of buffers recently re-shown in
  2366. @var{window} via @code{switch-to-prev-buffer}. The @var{window}
  2367. argument must denote a live window or @code{nil} (meaning the selected
  2368. window).
  2369. @end defun
  2370. @defun set-window-next-buffers window next-buffers
  2371. This function sets the next buffer list of @var{window} to
  2372. @var{next-buffers}. The @var{window} argument should be a live window
  2373. or @code{nil} (meaning the selected window). The argument
  2374. @var{next-buffers} should be a list of buffers.
  2375. @end defun
  2376. The following commands can be used to cycle through the global buffer
  2377. list, much like @code{bury-buffer} and @code{unbury-buffer}. However,
  2378. they cycle according to the specified window's history list, rather
  2379. than the global buffer list. In addition, they restore
  2380. window-specific window start and point positions, and may show a
  2381. buffer even if it is already shown in another window. The
  2382. @code{switch-to-prev-buffer} command, in particular, is used by
  2383. @code{replace-buffer-in-windows}, @code{bury-buffer} and
  2384. @code{quit-window} to find a replacement buffer for a window.
  2385. @deffn Command switch-to-prev-buffer &optional window bury-or-kill
  2386. This command displays the previous buffer in @var{window}. The
  2387. argument @var{window} should be a live window or @code{nil} (meaning
  2388. the selected window). If the optional argument @var{bury-or-kill} is
  2389. non-@code{nil}, this means that the buffer currently shown in
  2390. @var{window} is about to be buried or killed and consequently should
  2391. not be switched to in future invocations of this command.
  2392. The previous buffer is usually the buffer shown before the buffer
  2393. currently shown in @var{window}. However, a buffer that has been buried
  2394. or killed, or has been already shown by a recent invocation of
  2395. @code{switch-to-prev-buffer}, does not qualify as previous buffer.
  2396. If repeated invocations of this command have already shown all buffers
  2397. previously shown in @var{window}, further invocations will show buffers
  2398. from the buffer list of the frame @var{window} appears on (@pxref{Buffer
  2399. List}), trying to skip buffers that are already shown in another window
  2400. on that frame.
  2401. @end deffn
  2402. @deffn Command switch-to-next-buffer &optional window
  2403. This command switches to the next buffer in @var{window}, thus undoing
  2404. the effect of the last @code{switch-to-prev-buffer} command in
  2405. @var{window}. The argument @var{window} must be a live window and
  2406. defaults to the selected one.
  2407. If there is no recent invocation of @code{switch-to-prev-buffer} that
  2408. can be undone, this function tries to show a buffer from the buffer list
  2409. of the frame @var{window} appears on (@pxref{Buffer List}).
  2410. @end deffn
  2411. By default @code{switch-to-prev-buffer} and @code{switch-to-next-buffer}
  2412. can switch to a buffer that is already shown in another window on the
  2413. same frame. The following option can be used to override this behavior.
  2414. @defopt switch-to-visible-buffer
  2415. If this variable is non-@code{nil}, @code{switch-to-prev-buffer} and
  2416. @code{switch-to-next-buffer} may switch to a buffer that is already
  2417. visible on the same frame, provided the buffer was shown in the
  2418. relevant window before. If it is @code{nil},
  2419. @code{switch-to-prev-buffer} and @code{switch-to-next-buffer} always
  2420. try to avoid switching to a buffer that is already visible in another
  2421. window on the same frame. The default is @code{t}.
  2422. @end defopt
  2423. @node Dedicated Windows
  2424. @section Dedicated Windows
  2425. @cindex dedicated window
  2426. Functions for displaying a buffer can be told to not use specific
  2427. windows by marking these windows as @dfn{dedicated} to their buffers.
  2428. @code{display-buffer} (@pxref{Choosing Window}) never uses a dedicated
  2429. window for displaying another buffer in it. @code{get-lru-window} and
  2430. @code{get-largest-window} (@pxref{Cyclic Window Ordering}) do not
  2431. consider dedicated windows as candidates when their @var{dedicated}
  2432. argument is non-@code{nil}. The behavior of @code{set-window-buffer}
  2433. (@pxref{Buffers and Windows}) with respect to dedicated windows is
  2434. slightly different, see below.
  2435. Functions supposed to remove a buffer from a window or a window from
  2436. a frame can behave specially when a window they operate on is dedicated.
  2437. We will distinguish three basic cases, namely where (1) the window is
  2438. not the only window on its frame, (2) the window is the only window on
  2439. its frame but there are other frames on the same terminal left, and (3)
  2440. the window is the only window on the only frame on the same terminal.
  2441. In particular, @code{delete-windows-on} (@pxref{Deleting Windows})
  2442. handles case (2) by deleting the associated frame and case (3) by
  2443. showing another buffer in that frame's only window. The function
  2444. @code{replace-buffer-in-windows} (@pxref{Buffers and Windows}) which is
  2445. called when a buffer gets killed, deletes the window in case (1) and
  2446. behaves like @code{delete-windows-on} otherwise.
  2447. @c FIXME: Does replace-buffer-in-windows _delete_ a window in case (1)?
  2448. When @code{bury-buffer} (@pxref{Buffer List}) operates on the
  2449. selected window (which shows the buffer that shall be buried), it
  2450. handles case (2) by calling @code{frame-auto-hide-function}
  2451. (@pxref{Quitting Windows}) to deal with the selected frame. The other
  2452. two cases are handled as with @code{replace-buffer-in-windows}.
  2453. @defun window-dedicated-p &optional window
  2454. This function returns non-@code{nil} if @var{window} is dedicated to its
  2455. buffer and @code{nil} otherwise. More precisely, the return value is
  2456. the value assigned by the last call of @code{set-window-dedicated-p} for
  2457. @var{window}, or @code{nil} if that function was never called with
  2458. @var{window} as its argument. The default for @var{window} is the
  2459. selected window.
  2460. @end defun
  2461. @defun set-window-dedicated-p window flag
  2462. This function marks @var{window} as dedicated to its buffer if
  2463. @var{flag} is non-@code{nil}, and non-dedicated otherwise.
  2464. As a special case, if @var{flag} is @code{t}, @var{window} becomes
  2465. @dfn{strongly} dedicated to its buffer. @code{set-window-buffer}
  2466. signals an error when the window it acts upon is strongly dedicated to
  2467. its buffer and does not already display the buffer it is asked to
  2468. display. Other functions do not treat @code{t} differently from any
  2469. non-@code{nil} value.
  2470. @end defun
  2471. @node Quitting Windows
  2472. @section Quitting Windows
  2473. When you want to get rid of a window used for displaying a buffer, you
  2474. can call @code{delete-window} or @code{delete-windows-on}
  2475. (@pxref{Deleting Windows}) to remove that window from its frame. If the
  2476. buffer is shown on a separate frame, you might want to call
  2477. @code{delete-frame} (@pxref{Deleting Frames}) instead. If, on the other
  2478. hand, a window has been reused for displaying the buffer, you might
  2479. prefer showing the buffer previously shown in that window, by calling the
  2480. function @code{switch-to-prev-buffer} (@pxref{Window History}).
  2481. Finally, you might want to either bury (@pxref{Buffer List}) or kill
  2482. (@pxref{Killing Buffers}) the window's buffer.
  2483. The following command uses information on how the window for
  2484. displaying the buffer was obtained in the first place, thus attempting
  2485. to automate the above decisions for you.
  2486. @deffn Command quit-window &optional kill window
  2487. This command quits @var{window} and buries its buffer. The argument
  2488. @var{window} must be a live window and defaults to the selected one.
  2489. With prefix argument @var{kill} non-@code{nil}, it kills the buffer
  2490. instead of burying it. It calls the function @code{quit-restore-window}
  2491. described next to deal with the window and its buffer.
  2492. @end deffn
  2493. @defun quit-restore-window &optional window bury-or-kill
  2494. This function tries to restore the state of @var{window} that existed
  2495. before its buffer was displayed in it. The optional argument
  2496. @var{window} must be a live window and defaults to the selected one.
  2497. If @var{window} was created specially for displaying its buffer, this
  2498. function deletes @var{window} provided its frame contains at least one
  2499. other live window. If @var{window} is the only window on its frame and
  2500. there are other frames on the frame's terminal, the value of the
  2501. optional argument @var{bury-or-kill} determines how to proceed with the
  2502. window. If @var{bury-or-kill} equals @code{kill}, the frame is deleted
  2503. unconditionally. Otherwise, the fate of the frame is determined by
  2504. calling @code{frame-auto-hide-function} (see below) with that frame as
  2505. sole argument.
  2506. Otherwise, this function tries to redisplay the buffer previously shown
  2507. in @var{window}. It also tries to restore the window start
  2508. (@pxref{Window Start and End}) and point (@pxref{Window Point})
  2509. positions of the previously shown buffer. If, in addition,
  2510. @var{window}'s buffer was temporarily resized, this function will also
  2511. try to restore the original height of @var{window}.
  2512. The cases described so far require that the buffer shown in @var{window}
  2513. is still the buffer displayed by the last buffer display function for
  2514. this window. If another buffer has been shown in the meantime, or the
  2515. buffer previously shown no longer exists, this function calls
  2516. @code{switch-to-prev-buffer} (@pxref{Window History}) to show some other
  2517. buffer instead.
  2518. The optional argument @var{bury-or-kill} specifies how to deal with
  2519. @var{window}'s buffer. The following values are handled:
  2520. @table @code
  2521. @item nil
  2522. This means to not deal with the buffer in any particular way. As a
  2523. consequence, if @var{window} is not deleted, invoking
  2524. @code{switch-to-prev-buffer} will usually show the buffer again.
  2525. @item append
  2526. This means that if @var{window} is not deleted, its buffer is moved to
  2527. the end of @var{window}'s list of previous buffers, so it's less likely
  2528. that a future invocation of @code{switch-to-prev-buffer} will switch to
  2529. it. Also, it moves the buffer to the end of the frame's buffer list.
  2530. @item bury
  2531. This means that if @var{window} is not deleted, its buffer is removed
  2532. from @var{window}'s list of previous buffers. Also, it moves the buffer
  2533. to the end of the frame's buffer list. This value provides the most
  2534. reliable remedy to not have @code{switch-to-prev-buffer} switch to this
  2535. buffer again without killing the buffer.
  2536. @item kill
  2537. This means to kill @var{window}'s buffer.
  2538. @end table
  2539. @code{quit-restore-window} bases its decisions on information stored in
  2540. @var{window}'s @code{quit-restore} window parameter (@pxref{Window
  2541. Parameters}), and resets that parameter to @code{nil} after it's done.
  2542. @end defun
  2543. The following option specifies how to deal with a frame containing just
  2544. one window that should be either quit, or whose buffer should be buried.
  2545. @defopt frame-auto-hide-function
  2546. The function specified by this option is called to automatically hide
  2547. frames. This function is called with one argument---a frame.
  2548. The function specified here is called by @code{bury-buffer}
  2549. (@pxref{Buffer List}) when the selected window is dedicated and shows
  2550. the buffer to bury. It is also called by @code{quit-restore-window}
  2551. (see above) when the frame of the window to quit has been specially
  2552. created for displaying that window's buffer and the buffer is not
  2553. killed.
  2554. The default is to call @code{iconify-frame} (@pxref{Visibility of
  2555. Frames}). Alternatively, you may specify either @code{delete-frame}
  2556. (@pxref{Deleting Frames}) to remove the frame from its display,
  2557. @code{ignore} to leave the frame unchanged, or any other function that
  2558. can take a frame as its sole argument.
  2559. Note that the function specified by this option is called only if the
  2560. specified frame contains just one live window and there is at least one
  2561. other frame on the same terminal.
  2562. @end defopt
  2563. @node Window Point
  2564. @section Windows and Point
  2565. @cindex window position
  2566. @cindex window point
  2567. @cindex position in window
  2568. @cindex point in window
  2569. Each window has its own value of point (@pxref{Point}), independent of
  2570. the value of point in other windows displaying the same buffer. This
  2571. makes it useful to have multiple windows showing one buffer.
  2572. @itemize @bullet
  2573. @item
  2574. The window point is established when a window is first created; it is
  2575. initialized from the buffer's point, or from the window point of another
  2576. window opened on the buffer if such a window exists.
  2577. @item
  2578. Selecting a window sets the value of point in its buffer from the
  2579. window's value of point. Conversely, deselecting a window sets the
  2580. window's value of point from that of the buffer. Thus, when you switch
  2581. between windows that display a given buffer, the point value for the
  2582. selected window is in effect in the buffer, while the point values for
  2583. the other windows are stored in those windows.
  2584. @item
  2585. As long as the selected window displays the current buffer, the window's
  2586. point and the buffer's point always move together; they remain equal.
  2587. @end itemize
  2588. @cindex cursor
  2589. As far as the user is concerned, point is where the cursor is, and
  2590. when the user switches to another buffer, the cursor jumps to the
  2591. position of point in that buffer.
  2592. @defun window-point &optional window
  2593. This function returns the current position of point in @var{window}.
  2594. For a nonselected window, this is the value point would have (in that
  2595. window's buffer) if that window were selected. The default for
  2596. @var{window} is the selected window.
  2597. When @var{window} is the selected window, the value returned is the
  2598. value of point in that window's buffer. Strictly speaking, it would be
  2599. more correct to return the top-level value of point, outside of any
  2600. @code{save-excursion} forms. But that value is hard to find.
  2601. @end defun
  2602. @defun set-window-point window position
  2603. This function positions point in @var{window} at position
  2604. @var{position} in @var{window}'s buffer. It returns @var{position}.
  2605. If @var{window} is selected, this simply does @code{goto-char} in
  2606. @var{window}'s buffer.
  2607. @end defun
  2608. @defvar window-point-insertion-type
  2609. This variable specifies the marker insertion type (@pxref{Marker
  2610. Insertion Types}) of @code{window-point}. The default is @code{nil},
  2611. so @code{window-point} will stay behind text inserted there.
  2612. @end defvar
  2613. @node Window Start and End
  2614. @section The Window Start and End Positions
  2615. @cindex window start position
  2616. @cindex display-start position
  2617. Each window maintains a marker used to keep track of a buffer position
  2618. that specifies where in the buffer display should start. This position
  2619. is called the @dfn{display-start} position of the window (or just the
  2620. @dfn{start}). The character after this position is the one that appears
  2621. at the upper left corner of the window. It is usually, but not
  2622. inevitably, at the beginning of a text line.
  2623. After switching windows or buffers, and in some other cases, if the
  2624. window start is in the middle of a line, Emacs adjusts the window
  2625. start to the start of a line. This prevents certain operations from
  2626. leaving the window start at a meaningless point within a line. This
  2627. feature may interfere with testing some Lisp code by executing it
  2628. using the commands of Lisp mode, because they trigger this
  2629. readjustment. To test such code, put it into a command and bind the
  2630. command to a key.
  2631. @defun window-start &optional window
  2632. @cindex window top line
  2633. This function returns the display-start position of window
  2634. @var{window}. If @var{window} is @code{nil}, the selected window is
  2635. used.
  2636. When you create a window, or display a different buffer in it, the
  2637. display-start position is set to a display-start position recently used
  2638. for the same buffer, or to @code{point-min} if the buffer doesn't have
  2639. any.
  2640. Redisplay updates the window-start position (if you have not specified
  2641. it explicitly since the previous redisplay)---to make sure point appears
  2642. on the screen. Nothing except redisplay automatically changes the
  2643. window-start position; if you move point, do not expect the window-start
  2644. position to change in response until after the next redisplay.
  2645. @end defun
  2646. @defun window-group-start &optional window
  2647. @vindex window-group-start-function
  2648. This function is like @code{window-start}, except that when
  2649. @var{window} is a part of a group of windows (@pxref{Window Group}),
  2650. @code{window-group-start} returns the start position of the entire
  2651. group. This condition holds when the buffer local variable
  2652. @code{window-group-start-function} is set to a function. In this
  2653. case, @code{window-group-start} calls the function with the single
  2654. argument @var{window}, then returns its result.
  2655. @end defun
  2656. @cindex window end position
  2657. @defun window-end &optional window update
  2658. This function returns the position where display of its buffer ends in
  2659. @var{window}. The default for @var{window} is the selected window.
  2660. Simply changing the buffer text or moving point does not update the
  2661. value that @code{window-end} returns. The value is updated only when
  2662. Emacs redisplays and redisplay completes without being preempted.
  2663. If the last redisplay of @var{window} was preempted, and did not finish,
  2664. Emacs does not know the position of the end of display in that window.
  2665. In that case, this function returns @code{nil}.
  2666. If @var{update} is non-@code{nil}, @code{window-end} always returns an
  2667. up-to-date value for where display ends, based on the current
  2668. @code{window-start} value. If a previously saved value of that position
  2669. is still valid, @code{window-end} returns that value; otherwise it
  2670. computes the correct value by scanning the buffer text.
  2671. Even if @var{update} is non-@code{nil}, @code{window-end} does not
  2672. attempt to scroll the display if point has moved off the screen, the
  2673. way real redisplay would do. It does not alter the
  2674. @code{window-start} value. In effect, it reports where the displayed
  2675. text will end if scrolling is not required.
  2676. @end defun
  2677. @vindex window-group-end-function
  2678. @defun window-group-end &optional window update
  2679. This function is like @code{window-end}, except that when @var{window}
  2680. is a part of a group of windows (@pxref{Window Group}),
  2681. @code{window-group-end} returns the end position of the entire group.
  2682. This condition holds when the buffer local variable
  2683. @code{window-group-end-function} is set to a function. In this case,
  2684. @code{window-group-end} calls the function with the two arguments
  2685. @var{window} and @var{update}, then returns its result. The argument
  2686. @var{update} has the same meaning as in @code{window-end}.
  2687. @end defun
  2688. @defun set-window-start window position &optional noforce
  2689. This function sets the display-start position of @var{window} to
  2690. @var{position} in @var{window}'s buffer. It returns @var{position}.
  2691. The display routines insist that the position of point be visible when a
  2692. buffer is displayed. Normally, they change the display-start position
  2693. (that is, scroll the window) whenever necessary to make point visible.
  2694. However, if you specify the start position with this function using
  2695. @code{nil} for @var{noforce}, it means you want display to start at
  2696. @var{position} even if that would put the location of point off the
  2697. screen. If this does place point off screen, the display routines move
  2698. point to the left margin on the middle line in the window.
  2699. For example, if point @w{is 1} and you set the start of the window
  2700. @w{to 37}, the start of the next line, point will be above the top
  2701. of the window. The display routines will automatically move point if
  2702. it is still 1 when redisplay occurs. Here is an example:
  2703. @example
  2704. @group
  2705. ;; @r{Here is what @samp{foo} looks like before executing}
  2706. ;; @r{the @code{set-window-start} expression.}
  2707. @end group
  2708. @group
  2709. ---------- Buffer: foo ----------
  2710. @point{}This is the contents of buffer foo.
  2711. 2
  2712. 3
  2713. 4
  2714. 5
  2715. 6
  2716. ---------- Buffer: foo ----------
  2717. @end group
  2718. @group
  2719. (set-window-start
  2720. (selected-window)
  2721. (save-excursion
  2722. (goto-char 1)
  2723. (forward-line 1)
  2724. (point)))
  2725. @result{} 37
  2726. @end group
  2727. @group
  2728. ;; @r{Here is what @samp{foo} looks like after executing}
  2729. ;; @r{the @code{set-window-start} expression.}
  2730. ---------- Buffer: foo ----------
  2731. 2
  2732. 3
  2733. @point{}4
  2734. 5
  2735. 6
  2736. ---------- Buffer: foo ----------
  2737. @end group
  2738. @end example
  2739. If @var{noforce} is non-@code{nil}, and @var{position} would place point
  2740. off screen at the next redisplay, then redisplay computes a new window-start
  2741. position that works well with point, and thus @var{position} is not used.
  2742. @end defun
  2743. @vindex set-window-group-start-function
  2744. @defun set-window-group-start window position &optional noforce
  2745. This function is like @code{set-window-start}, except that when
  2746. @var{window} is a part of a group of windows (@pxref{Window Group}),
  2747. @code{set-window-group-start} sets the start position of the entire
  2748. group. This condition holds when the buffer local variable
  2749. @code{set-window-group-start-function} is set to a function. In this
  2750. case, @code{set-window-group-start} calls the function with the three
  2751. arguments @var{window}, @var{position}, and @var{noforce}, then
  2752. returns its result. The arguments @var{position} and @var{noforce} in
  2753. this function have the same meaning as in @code{set-window-start}.
  2754. @end defun
  2755. @defun pos-visible-in-window-p &optional position window partially
  2756. This function returns non-@code{nil} if @var{position} is within the
  2757. range of text currently visible on the screen in @var{window}. It
  2758. returns @code{nil} if @var{position} is scrolled vertically out of
  2759. view. Locations that are partially obscured are not considered
  2760. visible unless @var{partially} is non-@code{nil}. The argument
  2761. @var{position} defaults to the current position of point in
  2762. @var{window}; @var{window} defaults to the selected window. If
  2763. @var{position} is @code{t}, that means to check either the first
  2764. visible position of the last screen line in @var{window}, or the
  2765. end-of-buffer position, whichever comes first.
  2766. This function considers only vertical scrolling. If @var{position} is
  2767. out of view only because @var{window} has been scrolled horizontally,
  2768. @code{pos-visible-in-window-p} returns non-@code{nil} anyway.
  2769. @xref{Horizontal Scrolling}.
  2770. If @var{position} is visible, @code{pos-visible-in-window-p} returns
  2771. @code{t} if @var{partially} is @code{nil}; if @var{partially} is
  2772. non-@code{nil}, and the character following @var{position} is fully
  2773. visible, it returns a list of the form @code{(@var{x} @var{y})}, where
  2774. @var{x} and @var{y} are the pixel coordinates relative to the top left
  2775. corner of the window; otherwise it returns an extended list of the form
  2776. @code{(@var{x} @var{y} @var{rtop} @var{rbot} @var{rowh} @var{vpos})},
  2777. where @var{rtop} and @var{rbot} specify the number of off-window pixels
  2778. at the top and bottom of the row at @var{position}, @var{rowh} specifies
  2779. the visible height of that row, and @var{vpos} specifies the vertical
  2780. position (zero-based row number) of that row.
  2781. Here is an example:
  2782. @example
  2783. @group
  2784. ;; @r{If point is off the screen now, recenter it now.}
  2785. (or (pos-visible-in-window-p
  2786. (point) (selected-window))
  2787. (recenter 0))
  2788. @end group
  2789. @end example
  2790. @end defun
  2791. @vindex pos-visible-in-window-group-p-function
  2792. @defun pos-visible-in-window-group-p &optional position window partially
  2793. This function is like @code{pos-visible-in-window-p}, except that when
  2794. @var{window} is a part of a group of windows (@pxref{Window Group}),
  2795. @code{pos-visible-in-window-group-p} tests the visibility of @var{pos}
  2796. in the entire group, not just in the single @var{window}. This
  2797. condition holds when the buffer local variable
  2798. @code{pos-visible-in-window-group-p-function} is set to a function.
  2799. In this case @code{pos-visible-in-window-group-p} calls the function
  2800. with the three arguments @var{position}, @var{window}, and
  2801. @var{partially}, then returns its result. The arguments
  2802. @var{position} and @var{partially} have the same meaning as in
  2803. @code{pos-visible-in-window-p}.
  2804. @end defun
  2805. @defun window-line-height &optional line window
  2806. This function returns the height of text line @var{line} in
  2807. @var{window}. If @var{line} is one of @code{header-line} or
  2808. @code{mode-line}, @code{window-line-height} returns information about
  2809. the corresponding line of the window. Otherwise, @var{line} is a text
  2810. line number starting from 0. A negative number counts from the end of
  2811. the window. The default for @var{line} is the current line in
  2812. @var{window}; the default for @var{window} is the selected window.
  2813. If the display is not up to date, @code{window-line-height} returns
  2814. @code{nil}. In that case, @code{pos-visible-in-window-p} may be used
  2815. to obtain related information.
  2816. If there is no line corresponding to the specified @var{line},
  2817. @code{window-line-height} returns @code{nil}. Otherwise, it returns
  2818. a list @code{(@var{height} @var{vpos} @var{ypos} @var{offbot})},
  2819. where @var{height} is the height in pixels of the visible part of the
  2820. line, @var{vpos} and @var{ypos} are the vertical position in lines and
  2821. pixels of the line relative to the top of the first text line, and
  2822. @var{offbot} is the number of off-window pixels at the bottom of the
  2823. text line. If there are off-window pixels at the top of the (first)
  2824. text line, @var{ypos} is negative.
  2825. @end defun
  2826. @node Textual Scrolling
  2827. @section Textual Scrolling
  2828. @cindex textual scrolling
  2829. @cindex scrolling textually
  2830. @dfn{Textual scrolling} means moving the text up or down through a
  2831. window. It works by changing the window's display-start location. It
  2832. may also change the value of @code{window-point} to keep point on the
  2833. screen (@pxref{Window Point}).
  2834. The basic textual scrolling functions are @code{scroll-up} (which
  2835. scrolls forward) and @code{scroll-down} (which scrolls backward). In
  2836. these function names, ``up'' and ``down'' refer to the direction of
  2837. motion of the buffer text relative to the window. Imagine that the
  2838. text is written on a long roll of paper and that the scrolling
  2839. commands move the paper up and down. Thus, if you are looking at the
  2840. middle of a buffer and repeatedly call @code{scroll-down}, you will
  2841. eventually see the beginning of the buffer.
  2842. Unfortunately, this sometimes causes confusion, because some people
  2843. tend to think in terms of the opposite convention: they
  2844. imagine the window moving over text that remains in place, so that
  2845. ``down'' commands take you to the end of the buffer. This convention
  2846. is consistent with fact that such a command is bound to a key named
  2847. @key{PageDown} on modern keyboards.
  2848. @ignore
  2849. We have not switched to this convention as that is likely to break
  2850. existing Emacs Lisp code.
  2851. @end ignore
  2852. Textual scrolling functions (aside from @code{scroll-other-window})
  2853. have unpredictable results if the current buffer is not the one
  2854. displayed in the selected window. @xref{Current Buffer}.
  2855. If the window contains a row taller than the height of the window
  2856. (for example in the presence of a large image), the scroll functions
  2857. will adjust the window's vertical scroll position to scroll the
  2858. partially visible row. Lisp callers can disable this feature by
  2859. binding the variable @code{auto-window-vscroll} to @code{nil}
  2860. (@pxref{Vertical Scrolling}).
  2861. @deffn Command scroll-up &optional count
  2862. This function scrolls forward by @var{count} lines in the selected
  2863. window.
  2864. If @var{count} is negative, it scrolls backward instead. If
  2865. @var{count} is @code{nil} (or omitted), the distance scrolled is
  2866. @code{next-screen-context-lines} lines less than the height of the
  2867. window's text area.
  2868. If the selected window cannot be scrolled any further, this function
  2869. signals an error. Otherwise, it returns @code{nil}.
  2870. @end deffn
  2871. @deffn Command scroll-down &optional count
  2872. This function scrolls backward by @var{count} lines in the selected
  2873. window.
  2874. If @var{count} is negative, it scrolls forward instead. In other
  2875. respects, it behaves the same way as @code{scroll-up} does.
  2876. @end deffn
  2877. @deffn Command scroll-up-command &optional count
  2878. This behaves like @code{scroll-up}, except that if the selected window
  2879. cannot be scrolled any further and the value of the variable
  2880. @code{scroll-error-top-bottom} is @code{t}, it tries to move to the
  2881. end of the buffer instead. If point is already there, it signals an
  2882. error.
  2883. @end deffn
  2884. @deffn Command scroll-down-command &optional count
  2885. This behaves like @code{scroll-down}, except that if the selected
  2886. window cannot be scrolled any further and the value of the variable
  2887. @code{scroll-error-top-bottom} is @code{t}, it tries to move to the
  2888. beginning of the buffer instead. If point is already there, it
  2889. signals an error.
  2890. @end deffn
  2891. @deffn Command scroll-other-window &optional count
  2892. This function scrolls the text in another window upward @var{count}
  2893. lines. Negative values of @var{count}, or @code{nil}, are handled
  2894. as in @code{scroll-up}.
  2895. You can specify which buffer to scroll by setting the variable
  2896. @code{other-window-scroll-buffer} to a buffer. If that buffer isn't
  2897. already displayed, @code{scroll-other-window} displays it in some
  2898. window.
  2899. When the selected window is the minibuffer, the next window is normally
  2900. the leftmost one immediately above it. You can specify a different
  2901. window to scroll, when the minibuffer is selected, by setting the variable
  2902. @code{minibuffer-scroll-window}. This variable has no effect when any
  2903. other window is selected. When it is non-@code{nil} and the
  2904. minibuffer is selected, it takes precedence over
  2905. @code{other-window-scroll-buffer}. @xref{Definition of
  2906. minibuffer-scroll-window}.
  2907. When the minibuffer is active, it is the next window if the selected
  2908. window is the one at the bottom right corner. In this case,
  2909. @code{scroll-other-window} attempts to scroll the minibuffer. If the
  2910. minibuffer contains just one line, it has nowhere to scroll to, so the
  2911. line reappears after the echo area momentarily displays the message
  2912. @samp{End of buffer}.
  2913. @end deffn
  2914. @defvar other-window-scroll-buffer
  2915. If this variable is non-@code{nil}, it tells @code{scroll-other-window}
  2916. which buffer's window to scroll.
  2917. @end defvar
  2918. @defopt scroll-margin
  2919. This option specifies the size of the scroll margin---a minimum number
  2920. of lines between point and the top or bottom of a window. Whenever
  2921. point gets within this many lines of the top or bottom of the window,
  2922. redisplay scrolls the text automatically (if possible) to move point
  2923. out of the margin, closer to the center of the window.
  2924. @end defopt
  2925. @defopt scroll-conservatively
  2926. This variable controls how scrolling is done automatically when point
  2927. moves off the screen (or into the scroll margin). If the value is a
  2928. positive integer @var{n}, then redisplay scrolls the text up to
  2929. @var{n} lines in either direction, if that will bring point back into
  2930. proper view. This behavior is called @dfn{conservative scrolling}.
  2931. Otherwise, scrolling happens in the usual way, under the control of
  2932. other variables such as @code{scroll-up-aggressively} and
  2933. @code{scroll-down-aggressively}.
  2934. The default value is zero, which means that conservative scrolling
  2935. never happens.
  2936. @end defopt
  2937. @defopt scroll-down-aggressively
  2938. The value of this variable should be either @code{nil} or a fraction
  2939. @var{f} between 0 and 1. If it is a fraction, that specifies where on
  2940. the screen to put point when scrolling down. More precisely, when a
  2941. window scrolls down because point is above the window start, the new
  2942. start position is chosen to put point @var{f} part of the window
  2943. height from the top. The larger @var{f}, the more aggressive the
  2944. scrolling.
  2945. A value of @code{nil} is equivalent to .5, since its effect is to center
  2946. point. This variable automatically becomes buffer-local when set in any
  2947. fashion.
  2948. @end defopt
  2949. @defopt scroll-up-aggressively
  2950. Likewise, for scrolling up. The value, @var{f}, specifies how far
  2951. point should be placed from the bottom of the window; thus, as with
  2952. @code{scroll-up-aggressively}, a larger value scrolls more aggressively.
  2953. @end defopt
  2954. @defopt scroll-step
  2955. This variable is an older variant of @code{scroll-conservatively}.
  2956. The difference is that if its value is @var{n}, that permits scrolling
  2957. only by precisely @var{n} lines, not a smaller number. This feature
  2958. does not work with @code{scroll-margin}. The default value is zero.
  2959. @end defopt
  2960. @cindex @code{scroll-command} property
  2961. @defopt scroll-preserve-screen-position
  2962. If this option is @code{t}, whenever a scrolling command moves point
  2963. off-window, Emacs tries to adjust point to keep the cursor at its old
  2964. vertical position in the window, rather than the window edge.
  2965. If the value is non-@code{nil} and not @code{t}, Emacs adjusts point
  2966. to keep the cursor at the same vertical position, even if the
  2967. scrolling command didn't move point off-window.
  2968. This option affects all scroll commands that have a non-@code{nil}
  2969. @code{scroll-command} symbol property.
  2970. @end defopt
  2971. @defopt next-screen-context-lines
  2972. The value of this variable is the number of lines of continuity to
  2973. retain when scrolling by full screens. For example, @code{scroll-up}
  2974. with an argument of @code{nil} scrolls so that this many lines at the
  2975. bottom of the window appear instead at the top. The default value is
  2976. @code{2}.
  2977. @end defopt
  2978. @defopt scroll-error-top-bottom
  2979. If this option is @code{nil} (the default), @code{scroll-up-command}
  2980. and @code{scroll-down-command} simply signal an error when no more
  2981. scrolling is possible.
  2982. If the value is @code{t}, these commands instead move point to the
  2983. beginning or end of the buffer (depending on scrolling direction);
  2984. only if point is already on that position do they signal an error.
  2985. @end defopt
  2986. @deffn Command recenter &optional count
  2987. @cindex centering point
  2988. This function scrolls the text in the selected window so that point is
  2989. displayed at a specified vertical position within the window. It does
  2990. not move point with respect to the text.
  2991. If @var{count} is a non-negative number, that puts the line containing
  2992. point @var{count} lines down from the top of the window. If
  2993. @var{count} is a negative number, then it counts upward from the
  2994. bottom of the window, so that @minus{}1 stands for the last usable
  2995. line in the window.
  2996. If @var{count} is @code{nil} (or a non-@code{nil} list),
  2997. @code{recenter} puts the line containing point in the middle of the
  2998. window. If @var{count} is @code{nil}, this function may redraw the
  2999. frame, according to the value of @code{recenter-redisplay}.
  3000. When @code{recenter} is called interactively, @var{count} is the raw
  3001. prefix argument. Thus, typing @kbd{C-u} as the prefix sets the
  3002. @var{count} to a non-@code{nil} list, while typing @kbd{C-u 4} sets
  3003. @var{count} to 4, which positions the current line four lines from the
  3004. top.
  3005. With an argument of zero, @code{recenter} positions the current line at
  3006. the top of the window. The command @code{recenter-top-bottom} offers
  3007. a more convenient way to achieve this.
  3008. @end deffn
  3009. @vindex recenter-window-group-function
  3010. @defun recenter-window-group &optional count
  3011. This function is like @code{recenter}, except that when the selected
  3012. window is part of a group of windows (@pxref{Window Group}),
  3013. @code{recenter-window-group} scrolls the entire group. This condition
  3014. holds when the buffer local variable
  3015. @code{recenter-window-group-function} is set to a function. In this
  3016. case, @code{recenter-window-group} calls the function with the
  3017. argument @var{count}, then returns its result. The argument
  3018. @var{count} has the same meaning as in @code{recenter}, but with
  3019. respect to the entire window group.
  3020. @end defun
  3021. @defopt recenter-redisplay
  3022. If this variable is non-@code{nil}, calling @code{recenter} with a
  3023. @code{nil} argument redraws the frame. The default value is
  3024. @code{tty}, which means only redraw the frame if it is a tty frame.
  3025. @end defopt
  3026. @deffn Command recenter-top-bottom &optional count
  3027. This command, which is the default binding for @kbd{C-l}, acts like
  3028. @code{recenter}, except if called with no argument. In that case,
  3029. successive calls place point according to the cycling order defined
  3030. by the variable @code{recenter-positions}.
  3031. @end deffn
  3032. @defopt recenter-positions
  3033. This variable controls how @code{recenter-top-bottom} behaves when
  3034. called with no argument. The default value is @code{(middle top
  3035. bottom)}, which means that successive calls of
  3036. @code{recenter-top-bottom} with no argument cycle between placing
  3037. point at the middle, top, and bottom of the window.
  3038. @end defopt
  3039. @node Vertical Scrolling
  3040. @section Vertical Fractional Scrolling
  3041. @cindex vertical fractional scrolling
  3042. @cindex vertical scroll position
  3043. @dfn{Vertical fractional scrolling} means shifting text in a window
  3044. up or down by a specified multiple or fraction of a line. Each window
  3045. has a @dfn{vertical scroll position}, which is a number, never less than
  3046. zero. It specifies how far to raise the contents of the window.
  3047. Raising the window contents generally makes all or part of some lines
  3048. disappear off the top, and all or part of some other lines appear at the
  3049. bottom. The usual value is zero.
  3050. The vertical scroll position is measured in units of the normal line
  3051. height, which is the height of the default font. Thus, if the value is
  3052. .5, that means the window contents are scrolled up half the normal line
  3053. height. If it is 3.3, that means the window contents are scrolled up
  3054. somewhat over three times the normal line height.
  3055. What fraction of a line the vertical scrolling covers, or how many
  3056. lines, depends on what the lines contain. A value of .5 could scroll a
  3057. line whose height is very short off the screen, while a value of 3.3
  3058. could scroll just part of the way through a tall line or an image.
  3059. @defun window-vscroll &optional window pixels-p
  3060. This function returns the current vertical scroll position of
  3061. @var{window}. The default for @var{window} is the selected window.
  3062. If @var{pixels-p} is non-@code{nil}, the return value is measured in
  3063. pixels, rather than in units of the normal line height.
  3064. @example
  3065. @group
  3066. (window-vscroll)
  3067. @result{} 0
  3068. @end group
  3069. @end example
  3070. @end defun
  3071. @defun set-window-vscroll window lines &optional pixels-p
  3072. This function sets @var{window}'s vertical scroll position to
  3073. @var{lines}. If @var{window} is @code{nil}, the selected window is
  3074. used. The argument @var{lines} should be zero or positive; if not, it
  3075. is taken as zero.
  3076. The actual vertical scroll position must always correspond
  3077. to an integral number of pixels, so the value you specify
  3078. is rounded accordingly.
  3079. The return value is the result of this rounding.
  3080. @example
  3081. @group
  3082. (set-window-vscroll (selected-window) 1.2)
  3083. @result{} 1.13
  3084. @end group
  3085. @end example
  3086. If @var{pixels-p} is non-@code{nil}, @var{lines} specifies a number of
  3087. pixels. In this case, the return value is @var{lines}.
  3088. @end defun
  3089. @defvar auto-window-vscroll
  3090. If this variable is non-@code{nil}, the @code{line-move},
  3091. @code{scroll-up}, and @code{scroll-down} functions will automatically
  3092. modify the vertical scroll position to scroll through display rows
  3093. that are taller than the height of the window, for example in the
  3094. presence of large images.
  3095. @end defvar
  3096. @node Horizontal Scrolling
  3097. @section Horizontal Scrolling
  3098. @cindex horizontal scrolling
  3099. @dfn{Horizontal scrolling} means shifting the image in the window left
  3100. or right by a specified multiple of the normal character width. Each
  3101. window has a @dfn{horizontal scroll position}, which is a number, never
  3102. less than zero. It specifies how far to shift the contents left.
  3103. Shifting the window contents left generally makes all or part of some
  3104. characters disappear off the left, and all or part of some other
  3105. characters appear at the right. The usual value is zero.
  3106. The horizontal scroll position is measured in units of the normal
  3107. character width, which is the width of space in the default font. Thus,
  3108. if the value is 5, that means the window contents are scrolled left by 5
  3109. times the normal character width. How many characters actually
  3110. disappear off to the left depends on their width, and could vary from
  3111. line to line.
  3112. Because we read from side to side in the inner loop, and from top
  3113. to bottom in the outer loop, the effect of horizontal scrolling is
  3114. not like that of textual or vertical scrolling. Textual scrolling
  3115. involves selection of a portion of text to display, and vertical
  3116. scrolling moves the window contents contiguously; but horizontal
  3117. scrolling causes part of @emph{each line} to go off screen.
  3118. Usually, no horizontal scrolling is in effect; then the leftmost
  3119. column is at the left edge of the window. In this state, scrolling to
  3120. the right is meaningless, since there is no data to the left of the edge
  3121. to be revealed by it; so this is not allowed. Scrolling to the left is
  3122. allowed; it scrolls the first columns of text off the edge of the window
  3123. and can reveal additional columns on the right that were truncated
  3124. before. Once a window has a nonzero amount of leftward horizontal
  3125. scrolling, you can scroll it back to the right, but only so far as to
  3126. reduce the net horizontal scroll to zero. There is no limit to how far
  3127. left you can scroll, but eventually all the text will disappear off the
  3128. left edge.
  3129. @vindex auto-hscroll-mode
  3130. If @code{auto-hscroll-mode} is set, redisplay automatically alters
  3131. the horizontal scrolling of a window as necessary to ensure that point
  3132. is always visible. However, you can still set the horizontal
  3133. scrolling value explicitly. The value you specify serves as a lower
  3134. bound for automatic scrolling, i.e., automatic scrolling will not
  3135. scroll a window to a column less than the specified one.
  3136. @deffn Command scroll-left &optional count set-minimum
  3137. This function scrolls the selected window @var{count} columns to the
  3138. left (or to the right if @var{count} is negative). The default
  3139. for @var{count} is the window width, minus 2.
  3140. The return value is the total amount of leftward horizontal scrolling in
  3141. effect after the change---just like the value returned by
  3142. @code{window-hscroll} (below).
  3143. Note that text in paragraphs whose base direction is right-to-left
  3144. (@pxref{Bidirectional Display}) moves in the opposite direction: e.g.,
  3145. it moves to the right when @code{scroll-left} is invoked with a
  3146. positive value of @var{count}.
  3147. Once you scroll a window as far right as it can go, back to its normal
  3148. position where the total leftward scrolling is zero, attempts to scroll
  3149. any farther right have no effect.
  3150. If @var{set-minimum} is non-@code{nil}, the new scroll amount becomes
  3151. the lower bound for automatic scrolling; that is, automatic scrolling
  3152. will not scroll a window to a column less than the value returned by
  3153. this function. Interactive calls pass non-@code{nil} for
  3154. @var{set-minimum}.
  3155. @end deffn
  3156. @deffn Command scroll-right &optional count set-minimum
  3157. This function scrolls the selected window @var{count} columns to the
  3158. right (or to the left if @var{count} is negative). The default
  3159. for @var{count} is the window width, minus 2. Aside from the direction
  3160. of scrolling, this works just like @code{scroll-left}.
  3161. @end deffn
  3162. @defun window-hscroll &optional window
  3163. This function returns the total leftward horizontal scrolling of
  3164. @var{window}---the number of columns by which the text in @var{window}
  3165. is scrolled left past the left margin. (In right-to-left paragraphs,
  3166. the value is the total amount of the rightward scrolling instead.)
  3167. The default for @var{window} is the selected window.
  3168. The return value is never negative. It is zero when no horizontal
  3169. scrolling has been done in @var{window} (which is usually the case).
  3170. @example
  3171. @group
  3172. (window-hscroll)
  3173. @result{} 0
  3174. @end group
  3175. @group
  3176. (scroll-left 5)
  3177. @result{} 5
  3178. @end group
  3179. @group
  3180. (window-hscroll)
  3181. @result{} 5
  3182. @end group
  3183. @end example
  3184. @end defun
  3185. @defun set-window-hscroll window columns
  3186. This function sets horizontal scrolling of @var{window}. The value of
  3187. @var{columns} specifies the amount of scrolling, in terms of columns
  3188. from the left margin (right margin in right-to-left paragraphs). The
  3189. argument @var{columns} should be zero or positive; if not, it is taken
  3190. as zero. Fractional values of @var{columns} are not supported at
  3191. present.
  3192. Note that @code{set-window-hscroll} may appear not to work if you test
  3193. it by evaluating a call with @kbd{M-:} in a simple way. What happens
  3194. is that the function sets the horizontal scroll value and returns, but
  3195. then redisplay adjusts the horizontal scrolling to make point visible,
  3196. and this overrides what the function did. You can observe the
  3197. function's effect if you call it while point is sufficiently far from
  3198. the left margin that it will remain visible.
  3199. The value returned is @var{columns}.
  3200. @example
  3201. @group
  3202. (set-window-hscroll (selected-window) 10)
  3203. @result{} 10
  3204. @end group
  3205. @end example
  3206. @end defun
  3207. Here is how you can determine whether a given position @var{position}
  3208. is off the screen due to horizontal scrolling:
  3209. @c FIXME: Maybe hscroll-on-screen-p is a better name?
  3210. @example
  3211. @group
  3212. (defun hscroll-on-screen (window position)
  3213. (save-excursion
  3214. (goto-char position)
  3215. (and
  3216. (>= (- (current-column) (window-hscroll window)) 0)
  3217. (< (- (current-column) (window-hscroll window))
  3218. (window-width window)))))
  3219. @end group
  3220. @end example
  3221. @node Coordinates and Windows
  3222. @section Coordinates and Windows
  3223. @cindex frame-relative coordinate
  3224. @cindex coordinate, relative to frame
  3225. @cindex window position
  3226. This section describes functions that report the position of a window.
  3227. Most of these functions report positions relative to an origin at the
  3228. native position of the window's frame (@pxref{Frame Geometry}). Some
  3229. functions report positions relative to the origin of the display of the
  3230. window's frame. In any case, the origin has the coordinates (0, 0) and
  3231. X and Y coordinates increase rightward and downward
  3232. respectively.
  3233. For the following functions, X and Y coordinates are reported in
  3234. integer character units, i.e., numbers of lines and columns
  3235. respectively. On a graphical display, each ``line'' and ``column''
  3236. corresponds to the height and width of the default character specified by
  3237. the frame's default font (@pxref{Frame Font}).
  3238. @defun window-edges &optional window body absolute pixelwise
  3239. This function returns a list of the edge coordinates of @var{window}.
  3240. If @var{window} is omitted or @code{nil}, it defaults to the selected
  3241. window.
  3242. The return value has the form @code{(@var{left} @var{top} @var{right}
  3243. @var{bottom})}. These list elements are, respectively, the X
  3244. coordinate of the leftmost column occupied by the window, the Y
  3245. coordinate of the topmost row, the X coordinate one column to the
  3246. right of the rightmost column, and the Y coordinate one row down from
  3247. the bottommost row.
  3248. Note that these are the actual outer edges of the window, including any
  3249. header line, mode line, scroll bar, fringes, window divider and display
  3250. margins. On a text terminal, if the window has a neighbor on its right,
  3251. its right edge includes the separator line between the window and its
  3252. neighbor.
  3253. If the optional argument @var{body} is @code{nil}, this means to
  3254. return the edges corresponding to the total size of @var{window}.
  3255. @var{body} non-@code{nil} means to return the edges of @var{window}'s
  3256. body (aka text area). If @var{body} is non-@code{nil}, @var{window}
  3257. must specify a live window.
  3258. If the optional argument @var{absolute} is @code{nil}, this means to
  3259. return edges relative to the native position of @var{window}'s frame.
  3260. @var{absolute} non-@code{nil} means to return coordinates relative to
  3261. the origin (0, 0) of @var{window}'s display. On non-graphical systems
  3262. this argument has no effect.
  3263. If the optional argument @var{pixelwise} is @code{nil}, this means to
  3264. return the coordinates in terms of the default character width and
  3265. height of @var{window}'s frame (@pxref{Frame Font}), rounded if
  3266. necessary. @var{pixelwise} non-@code{nil} means to return the
  3267. coordinates in pixels. Note that the pixel specified by @var{right} and
  3268. @var{bottom} is immediately outside of these edges. If @var{absolute}
  3269. is non-@code{nil}, @var{pixelwise} is implicitly non-@code{nil} too.
  3270. @end defun
  3271. @defun window-body-edges &optional window
  3272. This function returns the edges of @var{window}'s body (@pxref{Window
  3273. Sizes}). Calling @code{(window-body-edges window)} is equivalent to
  3274. calling @code{(window-edges window t)}, see above.
  3275. @end defun
  3276. @comment The following two functions are confusing and hardly used.
  3277. @ignore
  3278. @defun window-left-column &optional window
  3279. This function returns the leftmost column of @var{window}. This value
  3280. equals the @var{left} entry in the list returned by @code{(window-edges
  3281. window)} minus the number of columns occupied by the internal border of
  3282. @var{window}'s frame.
  3283. @end defun
  3284. @defun window-top-line &optional window
  3285. This function returns the topmost row of @var{window}. This value is
  3286. equal to the @var{top} entry in the list returned by @code{(window-edges
  3287. window)} minus the number of lines occupied by the internal border of
  3288. @var{window}'s frame.
  3289. @end defun
  3290. @end ignore
  3291. The following functions can be used to relate a set of
  3292. frame-relative coordinates to a window:
  3293. @defun window-at x y &optional frame
  3294. This function returns the live window at the coordinates @var{x} and
  3295. @var{y} given in default character sizes (@pxref{Frame Font}) relative
  3296. to the native position of @var{frame} (@pxref{Frame Geometry}).
  3297. If there is no window at that position, the return value is @code{nil}.
  3298. If @var{frame} is omitted or @code{nil}, it defaults to the selected
  3299. frame.
  3300. @end defun
  3301. @defun coordinates-in-window-p coordinates window
  3302. This function checks whether a window @var{window} occupies the frame
  3303. relative coordinates @var{coordinates}, and if so, which part of the
  3304. window that is. @var{window} should be a live window.
  3305. @var{coordinates} should be a cons cell of the form @code{(@var{x}
  3306. . @var{y})}, where @var{x} and @var{y} are given in default character
  3307. sizes (@pxref{Frame Font}) relative to the native position of
  3308. @var{window}'s frame (@pxref{Frame Geometry}).
  3309. If there is no window at the specified position, the return value is
  3310. @code{nil} . Otherwise, the return value is one of the following:
  3311. @table @code
  3312. @item (@var{relx} . @var{rely})
  3313. The coordinates are inside @var{window}. The numbers @var{relx} and
  3314. @var{rely} are the equivalent window-relative coordinates for the
  3315. specified position, counting from 0 at the top left corner of the
  3316. window.
  3317. @item mode-line
  3318. The coordinates are in the mode line of @var{window}.
  3319. @item header-line
  3320. The coordinates are in the header line of @var{window}.
  3321. @item right-divider
  3322. The coordinates are in the divider separating @var{window} from a
  3323. window on the right.
  3324. @item bottom-divider
  3325. The coordinates are in the divider separating @var{window} from a
  3326. window beneath.
  3327. @item vertical-line
  3328. The coordinates are in the vertical line between @var{window} and its
  3329. neighbor to the right. This value occurs only if the window doesn't
  3330. have a scroll bar; positions in a scroll bar are considered outside the
  3331. window for these purposes.
  3332. @item left-fringe
  3333. @itemx right-fringe
  3334. The coordinates are in the left or right fringe of the window.
  3335. @item left-margin
  3336. @itemx right-margin
  3337. The coordinates are in the left or right margin of the window.
  3338. @item nil
  3339. The coordinates are not in any part of @var{window}.
  3340. @end table
  3341. The function @code{coordinates-in-window-p} does not require a frame as
  3342. argument because it always uses the frame that @var{window} is on.
  3343. @end defun
  3344. The following functions return window positions in pixels, rather
  3345. than character units. Though mostly useful on graphical displays,
  3346. they can also be called on text terminals, where the screen area of
  3347. each text character is taken to be one pixel.
  3348. @defun window-pixel-edges &optional window
  3349. This function returns a list of pixel coordinates for the edges of
  3350. @var{window}. Calling @code{(window-pixel-edges window)} is equivalent
  3351. to calling @code{(window-edges window nil nil t)}, see above.
  3352. @end defun
  3353. @comment The following two functions are confusing and hardly used.
  3354. @ignore
  3355. @defun window-pixel-left &optional window
  3356. This function returns the left pixel edge of window @var{window}. This
  3357. value equals the @var{left} entry in the list returned by
  3358. @code{(window-pixel-edges window)} minus the number of pixels occupied
  3359. by the internal border of @var{window}'s frame. @var{window} must be a
  3360. valid window and defaults to the selected one.
  3361. @end defun
  3362. @defun window-pixel-top &optional window
  3363. This function returns the top pixel edge of window @var{window}. This
  3364. value is equal to the @var{top} entry in the list returned by
  3365. @code{(window-pixel-edges window)} minus the number of pixels occupied
  3366. by the internal border of @var{window}'s frame. @var{window} must be a
  3367. valid window and defaults to the selected one.
  3368. @end defun
  3369. @end ignore
  3370. @defun window-body-pixel-edges &optional window
  3371. This function returns the pixel edges of @var{window}'s body. Calling
  3372. @code{(window-body-pixel-edges window)} is equivalent to calling
  3373. @code{(window-edges window t nil t)}, see above.
  3374. @end defun
  3375. The following functions return window positions in pixels, relative to
  3376. the origin of the display screen rather than that of the frame:
  3377. @defun window-absolute-pixel-edges &optional window
  3378. This function returns the pixel coordinates of @var{WINDOW} relative to
  3379. an origin at (0, 0) of the display of @var{window}'s frame. Calling
  3380. @code{(window-absolute-pixel-edges)} is equivalent to calling
  3381. @code{(window-edges window nil t t)}, see above.
  3382. @end defun
  3383. @defun window-absolute-body-pixel-edges &optional window
  3384. This function returns the pixel coordinates of @var{WINDOW}'s body
  3385. relative to an origin at (0, 0) of the display of @var{window}'s frame.
  3386. Calling @code{(window-absolute-body-pixel-edges window)} is equivalent
  3387. to calling @code{(window-edges window t t t)}, see above.
  3388. Combined with @code{set-mouse-absolute-pixel-position}, this function
  3389. can be used to move the mouse pointer to an arbitrary buffer position
  3390. visible in some window:
  3391. @example
  3392. @group
  3393. (let ((edges (window-absolute-body-pixel-edges))
  3394. (position (pos-visible-in-window-p nil nil t)))
  3395. (set-mouse-absolute-pixel-position
  3396. (+ (nth 0 edges) (nth 0 position))
  3397. (+ (nth 1 edges) (nth 1 position))))
  3398. @end group
  3399. @end example
  3400. On a graphical terminal this form ``warps'' the mouse cursor to the
  3401. upper left corner of the glyph at the selected window's point. A
  3402. position calculated this way can be also used to show a tooltip window
  3403. there.
  3404. @end defun
  3405. The following function returns the screen coordinates of a buffer
  3406. position visible in a window:
  3407. @defun window-absolute-pixel-position &optional position window
  3408. If the buffer position @var{position} is visible in window @var{window},
  3409. this function returns the display coordinates of the upper/left corner
  3410. of the glyph at @var{position}. The return value is a cons of the X-
  3411. and Y-coordinates of that corner, relative to an origin at (0, 0) of
  3412. @var{window}'s display. It returns @code{nil} if @var{position} is not
  3413. visible in @var{window}.
  3414. @var{window} must be a live window and defaults to the selected
  3415. window. @var{position} defaults to the value of @code{window-point}
  3416. of @var{window}.
  3417. This means that in order to move the mouse pointer to the position of
  3418. point in the selected window, it's sufficient to write:
  3419. @example
  3420. @group
  3421. (let ((position (window-absolute-pixel-position)))
  3422. (set-mouse-absolute-pixel-position
  3423. (car position) (cdr position)))
  3424. @end group
  3425. @end example
  3426. @end defun
  3427. @node Window Configurations
  3428. @section Window Configurations
  3429. @cindex window configurations
  3430. @cindex saving window information
  3431. A @dfn{window configuration} records the entire layout of one
  3432. frame---all windows, their sizes, which buffers they contain, how those
  3433. buffers are scrolled, and their value of point; also their
  3434. fringes, margins, and scroll bar settings. It also includes the value
  3435. of @code{minibuffer-scroll-window}. As a special exception, the window
  3436. configuration does not record the value of point in the selected window
  3437. for the current buffer.
  3438. You can bring back an entire frame layout by restoring a previously
  3439. saved window configuration. If you want to record the layout of all
  3440. frames instead of just one, use a frame configuration instead of a
  3441. window configuration. @xref{Frame Configurations}.
  3442. @defun current-window-configuration &optional frame
  3443. This function returns a new object representing @var{frame}'s current
  3444. window configuration. The default for @var{frame} is the selected
  3445. frame. The variable @code{window-persistent-parameters} specifies
  3446. which window parameters (if any) are saved by this function.
  3447. @xref{Window Parameters}.
  3448. @end defun
  3449. @defun set-window-configuration configuration
  3450. This function restores the configuration of windows and buffers as
  3451. specified by @var{configuration}, for the frame that @var{configuration}
  3452. was created for.
  3453. The argument @var{configuration} must be a value that was previously
  3454. returned by @code{current-window-configuration}. The configuration is
  3455. restored in the frame from which @var{configuration} was made, whether
  3456. that frame is selected or not. In some rare cases this may trigger
  3457. execution of the @code{window-size-change-functions} (@pxref{Window
  3458. Hooks}) even if the size of windows did not change at all. The
  3459. @code{window-configuration-change-hook} functions will be called if and
  3460. only if at least one window was added to or deleted from the frame.
  3461. If the frame from which @var{configuration} was saved is dead, all this
  3462. function does is restore the three variables @code{window-min-height},
  3463. @code{window-min-width} and @code{minibuffer-scroll-window}. In this
  3464. case, the function returns @code{nil}. Otherwise, it returns @code{t}.
  3465. Here is a way of using this function to get the same effect
  3466. as @code{save-window-excursion}:
  3467. @example
  3468. @group
  3469. (let ((config (current-window-configuration)))
  3470. (unwind-protect
  3471. (progn (split-window-below nil)
  3472. @dots{})
  3473. (set-window-configuration config)))
  3474. @end group
  3475. @end example
  3476. @end defun
  3477. @defmac save-window-excursion forms@dots{}
  3478. This macro records the window configuration of the selected frame,
  3479. executes @var{forms} in sequence, then restores the earlier window
  3480. configuration. The return value is the value of the final form in
  3481. @var{forms}.
  3482. Most Lisp code should not use this macro; @code{save-selected-window}
  3483. is typically sufficient. In particular, this macro cannot reliably
  3484. prevent the code in @var{forms} from opening new windows, because new
  3485. windows might be opened in other frames (@pxref{Choosing Window}), and
  3486. @code{save-window-excursion} only saves and restores the window
  3487. configuration on the current frame.
  3488. Do not use this macro in @code{window-size-change-functions}; exiting
  3489. the macro triggers execution of @code{window-size-change-functions},
  3490. leading to an endless loop.
  3491. @end defmac
  3492. @defun window-configuration-p object
  3493. This function returns @code{t} if @var{object} is a window configuration.
  3494. @end defun
  3495. @defun compare-window-configurations config1 config2
  3496. This function compares two window configurations as regards the
  3497. structure of windows, but ignores the values of point and the
  3498. saved scrolling positions---it can return @code{t} even if those
  3499. aspects differ.
  3500. The function @code{equal} can also compare two window configurations; it
  3501. regards configurations as unequal if they differ in any respect, even a
  3502. saved point.
  3503. @end defun
  3504. @defun window-configuration-frame config
  3505. This function returns the frame for which the window configuration
  3506. @var{config} was made.
  3507. @end defun
  3508. Other primitives to look inside of window configurations would make
  3509. sense, but are not implemented because we did not need them. See the
  3510. file @file{winner.el} for some more operations on windows
  3511. configurations.
  3512. The objects returned by @code{current-window-configuration} die
  3513. together with the Emacs process. In order to store a window
  3514. configuration on disk and read it back in another Emacs session, you
  3515. can use the functions described next. These functions are also useful
  3516. to clone the state of a frame into an arbitrary live window
  3517. (@code{set-window-configuration} effectively clones the windows of a
  3518. frame into the root window of that very frame only).
  3519. @cindex window state
  3520. @defun window-state-get &optional window writable
  3521. This function returns the state of @var{window} as a Lisp object. The
  3522. argument @var{window} must be a valid window and defaults to the root
  3523. window of the selected frame.
  3524. If the optional argument @var{writable} is non-@code{nil}, this means to
  3525. not use markers for sampling positions like @code{window-point} or
  3526. @code{window-start}. This argument should be non-@code{nil} when the
  3527. state will be written to disk and read back in another session.
  3528. Together, the argument @var{writable} and the variable
  3529. @code{window-persistent-parameters} specify which window parameters are
  3530. saved by this function. @xref{Window Parameters}.
  3531. @end defun
  3532. The value returned by @code{window-state-get} can be used in the same
  3533. session to make a clone of a window in another window. It can be also
  3534. written to disk and read back in another session. In either case, use
  3535. the following function to restore the state of the window.
  3536. @defun window-state-put state &optional window ignore
  3537. This function puts the window state @var{state} into @var{window}.
  3538. The argument @var{state} should be the state of a window returned by
  3539. an earlier invocation of @code{window-state-get}, see above. The
  3540. optional argument @var{window} can be either a live window or an
  3541. internal window (@pxref{Windows and Frames}) and defaults to the
  3542. selected one. If @var{window} is not live, it is replaced by a live
  3543. window before putting @var{state} into it.
  3544. If the optional argument @var{ignore} is non-@code{nil}, it means to ignore
  3545. minimum window sizes and fixed-size restrictions. If @var{ignore}
  3546. is @code{safe}, this means windows can get as small as one line
  3547. and/or two columns.
  3548. @end defun
  3549. @node Window Parameters
  3550. @section Window Parameters
  3551. @cindex window parameters
  3552. This section describes how window parameters can be used to associate
  3553. additional information with windows.
  3554. @defun window-parameter window parameter
  3555. This function returns @var{window}'s value for @var{parameter}. The
  3556. default for @var{window} is the selected window. If @var{window} has no
  3557. setting for @var{parameter}, this function returns @code{nil}.
  3558. @end defun
  3559. @defun window-parameters &optional window
  3560. This function returns all parameters of @var{window} and their values.
  3561. The default for @var{window} is the selected window. The return value
  3562. is either @code{nil}, or an association list whose elements have the form
  3563. @code{(@var{parameter} . @var{value})}.
  3564. @end defun
  3565. @defun set-window-parameter window parameter value
  3566. This function sets @var{window}'s value of @var{parameter} to
  3567. @var{value} and returns @var{value}. The default for @var{window}
  3568. is the selected window.
  3569. @end defun
  3570. By default, the functions that save and restore window configurations or the
  3571. states of windows (@pxref{Window Configurations}) do not care about
  3572. window parameters. This means that when you change the value of a
  3573. parameter within the body of a @code{save-window-excursion}, the
  3574. previous value is not restored when that macro exits. It also means
  3575. that when you restore via @code{window-state-put} a window state saved
  3576. earlier by @code{window-state-get}, all cloned windows have their
  3577. parameters reset to @code{nil}. The following variable allows you to
  3578. override the standard behavior:
  3579. @defvar window-persistent-parameters
  3580. This variable is an alist specifying which parameters get saved by
  3581. @code{current-window-configuration} and @code{window-state-get}, and
  3582. subsequently restored by @code{set-window-configuration} and
  3583. @code{window-state-put}. @xref{Window Configurations}.
  3584. The @sc{car} of each entry of this alist is a symbol specifying the
  3585. parameter. The @sc{cdr} should be one of the following:
  3586. @table @asis
  3587. @item @code{nil}
  3588. This value means the parameter is saved neither by
  3589. @code{window-state-get} nor by @code{current-window-configuration}.
  3590. @item @code{t}
  3591. This value specifies that the parameter is saved by
  3592. @code{current-window-configuration} and (provided its @var{writable}
  3593. argument is @code{nil}) by @code{window-state-get}.
  3594. @item @code{writable}
  3595. This means that the parameter is saved unconditionally by both
  3596. @code{current-window-configuration} and @code{window-state-get}. This
  3597. value should not be used for parameters whose values do not have a read
  3598. syntax. Otherwise, invoking @code{window-state-put} in another session
  3599. may fail with an @code{invalid-read-syntax} error.
  3600. @end table
  3601. @end defvar
  3602. Some functions (notably @code{delete-window},
  3603. @code{delete-other-windows} and @code{split-window}), may behave specially
  3604. when their @var{window} argument has a parameter set. You can override
  3605. such special behavior by binding the following variable to a
  3606. non-@code{nil} value:
  3607. @defvar ignore-window-parameters
  3608. If this variable is non-@code{nil}, some standard functions do not
  3609. process window parameters. The functions currently affected by this are
  3610. @code{split-window}, @code{delete-window}, @code{delete-other-windows},
  3611. and @code{other-window}.
  3612. An application can bind this variable to a non-@code{nil} value around
  3613. calls to these functions. If it does so, the application is fully
  3614. responsible for correctly assigning the parameters of all involved
  3615. windows when exiting that function.
  3616. @end defvar
  3617. The following parameters are currently used by the window management
  3618. code:
  3619. @table @asis
  3620. @item @code{delete-window}
  3621. This parameter affects the execution of @code{delete-window}
  3622. (@pxref{Deleting Windows}).
  3623. @item @code{delete-other-windows}
  3624. This parameter affects the execution of @code{delete-other-windows}
  3625. (@pxref{Deleting Windows}).
  3626. @item @code{split-window}
  3627. This parameter affects the execution of @code{split-window}
  3628. (@pxref{Splitting Windows}).
  3629. @item @code{other-window}
  3630. This parameter affects the execution of @code{other-window}
  3631. (@pxref{Cyclic Window Ordering}).
  3632. @item @code{no-other-window}
  3633. This parameter marks the window as not selectable by @code{other-window}
  3634. (@pxref{Cyclic Window Ordering}).
  3635. @item @code{clone-of}
  3636. This parameter specifies the window that this one has been cloned
  3637. from. It is installed by @code{window-state-get} (@pxref{Window
  3638. Configurations}).
  3639. @item @code{preserved-size}
  3640. This parameter specifies a buffer, a direction where @code{nil} means
  3641. vertical and @code{t} horizontal, and a size in pixels. If this window
  3642. displays the specified buffer and its size in the indicated direction
  3643. equals the size specified by this parameter, then Emacs will try to
  3644. preserve the size of this window in the indicated direction. This
  3645. parameter is installed and updated by the function
  3646. @code{window-preserve-size} (@pxref{Preserving Window Sizes}).
  3647. @item @code{quit-restore}
  3648. This parameter is installed by the buffer display functions
  3649. (@pxref{Choosing Window}) and consulted by @code{quit-restore-window}
  3650. (@pxref{Quitting Windows}). It contains four elements:
  3651. The first element is one of the symbols @code{window}, meaning that the
  3652. window has been specially created by @code{display-buffer}; @code{frame},
  3653. a separate frame has been created; @code{same}, the window has
  3654. displayed the same buffer before; or @code{other}, the window showed
  3655. another buffer before.
  3656. The second element is either one of the symbols @code{window} or
  3657. @code{frame}, or a list whose elements are the buffer shown in the
  3658. window before, that buffer's window start and window point positions,
  3659. and the window's height at that time.
  3660. The third element is the window selected at the time the parameter was
  3661. created. The function @code{quit-restore-window} tries to reselect that
  3662. window when it deletes the window passed to it as argument.
  3663. The fourth element is the buffer whose display caused the creation of
  3664. this parameter. @code{quit-restore-window} deletes the specified window
  3665. only if it still shows that buffer.
  3666. @end table
  3667. There are additional parameters @code{window-atom} and @code{window-side};
  3668. these are reserved and should not be used by applications.
  3669. @node Window Hooks
  3670. @section Hooks for Window Scrolling and Changes
  3671. @cindex hooks for window operations
  3672. This section describes how a Lisp program can take action whenever a
  3673. window displays a different part of its buffer or a different buffer.
  3674. There are three actions that can change this: scrolling the window,
  3675. switching buffers in the window, and changing the size of the window.
  3676. The first two actions run @code{window-scroll-functions}; the last runs
  3677. @code{window-size-change-functions}.
  3678. @defvar window-scroll-functions
  3679. This variable holds a list of functions that Emacs should call before
  3680. redisplaying a window with scrolling. Displaying a different buffer in
  3681. the window also runs these functions.
  3682. This variable is not a normal hook, because each function is called with
  3683. two arguments: the window, and its new display-start position.
  3684. These functions must take care when using @code{window-end}
  3685. (@pxref{Window Start and End}); if you need an up-to-date value, you
  3686. must use the @var{update} argument to ensure you get it.
  3687. @strong{Warning:} don't use this feature to alter the way the window
  3688. is scrolled. It's not designed for that, and such use probably won't
  3689. work.
  3690. @end defvar
  3691. @defvar window-size-change-functions
  3692. This variable holds a list of functions to be called if the size of any
  3693. window changes for any reason. The functions are called once per
  3694. redisplay, and once for each frame on which size changes have occurred.
  3695. Each function receives the frame as its sole argument. To find out
  3696. whether a specific window has changed size, compare the return values of
  3697. @code{window-pixel-width-before-size-change} and
  3698. @code{window-pixel-width} respectively
  3699. @code{window-pixel-height-before-size-change} and
  3700. @code{window-pixel-height} for that window (@pxref{Window Sizes}).
  3701. These function are usually only called when at least one window was
  3702. added or has changed size since the last time this hook was run for the
  3703. associated frame. In some rare cases this hook also runs when a window
  3704. that was added intermittently has been deleted afterwards. In these
  3705. cases none of the windows on the frame will appear to have changed its
  3706. size.
  3707. You may use @code{save-selected-window} in these functions
  3708. (@pxref{Selecting Windows}). However, do not use
  3709. @code{save-window-excursion} (@pxref{Window Configurations}); exiting
  3710. that macro counts as a size change, which would cause these functions to
  3711. be called again.
  3712. @end defvar
  3713. @defvar window-configuration-change-hook
  3714. A normal hook that is run every time the window configuration of a frame
  3715. changes. Window configuration changes include splitting and deleting
  3716. windows and the display of a different buffer in a window. Resizing the
  3717. frame or individual windows do not count as configuration changes. Use
  3718. @code{window-size-change-functions}, see above, when you want to track
  3719. size changes that are not caused by the deletion or creation of windows.
  3720. The buffer-local part of this hook is run once for each window on the
  3721. affected frame, with the relevant window selected and its buffer
  3722. current. The global part is run once for the modified frame, with that
  3723. frame selected.
  3724. @end defvar
  3725. In addition, you can use @code{jit-lock-register} to register a Font
  3726. Lock fontification function, which will be called whenever parts of a
  3727. buffer are (re)fontified because a window was scrolled or its size
  3728. changed. @xref{Other Font Lock Variables}.