windows.texi 173 KB

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