aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGlenn Morris2018-11-04 09:37:03 -0800
committerGlenn Morris2018-11-04 09:37:03 -0800
commit410e65e4ce6f871fd1b8a2ef4b227cbeeb17c1dd (patch)
tree7b7272b5ddfc5b51992b590e1ec63136a3f20381
parent4fbdccedd58ffe4cd5f7ed7b744123cc25084bc4 (diff)
parent6937c35d3260fe3fc32249313c7e9b6231cbd3dd (diff)
downloademacs-410e65e4ce6f871fd1b8a2ef4b227cbeeb17c1dd.tar.gz
emacs-410e65e4ce6f871fd1b8a2ef4b227cbeeb17c1dd.zip
Merge from origin/emacs-26
6937c35 (origin/emacs-26) Improve recent changes in documentation of ... c04b48c Rewrite documentation of buffer display 7cadb32 ; * doc/lispref/control.texi (pcase Macro): Fix another typo. 963f1d9 ; * doc/lispref/control.texi (pcase Macro): Fix a typo. e824c91 Improve documentation of destructuring-binding macros
-rw-r--r--doc/emacs/windows.texi127
-rw-r--r--doc/lispref/control.texi228
-rw-r--r--doc/lispref/elisp.texi16
-rw-r--r--doc/lispref/frames.texi10
-rw-r--r--doc/lispref/sequences.texi20
-rw-r--r--doc/lispref/windows.texi1459
-rw-r--r--lisp/emacs-lisp/pcase.el43
7 files changed, 1378 insertions, 525 deletions
diff --git a/doc/emacs/windows.texi b/doc/emacs/windows.texi
index 17ce4ad04d3..8cc514494dc 100644
--- a/doc/emacs/windows.texi
+++ b/doc/emacs/windows.texi
@@ -48,8 +48,8 @@ other windows at all. However, there are other commands such as
48@kbd{C-x 4 b} that select a different window and switch buffers in it. 48@kbd{C-x 4 b} that select a different window and switch buffers in it.
49Also, all commands that display information in a window, including 49Also, all commands that display information in a window, including
50(for example) @kbd{C-h f} (@code{describe-function}) and @kbd{C-x C-b} 50(for example) @kbd{C-h f} (@code{describe-function}) and @kbd{C-x C-b}
51(@code{list-buffers}), work by switching buffers in a nonselected 51(@code{list-buffers}), usually work by displaying buffers in a
52window without affecting the selected window. 52nonselected window without affecting the selected window.
53 53
54 When multiple windows show the same buffer, they can have different 54 When multiple windows show the same buffer, they can have different
55regions, because they can have different values of point. However, 55regions, because they can have different values of point. However,
@@ -347,11 +347,9 @@ heights of all the windows in the selected frame.
347in response to a user command. There are several different ways in 347in response to a user command. There are several different ways in
348which commands do this. 348which commands do this.
349 349
350 Many commands, like @kbd{C-x C-f} (@code{find-file}), display the 350 Many commands, like @kbd{C-x C-f} (@code{find-file}), by default
351buffer by ``taking over'' the selected window, expecting that the 351display the buffer by ``taking over'' the selected window, expecting
352user's attention will be diverted to that buffer. These commands 352that the user's attention will be diverted to that buffer.
353usually work by calling @code{switch-to-buffer} internally
354(@pxref{Select Buffer}).
355 353
356 Some commands try to display intelligently, trying not to take 354 Some commands try to display intelligently, trying not to take
357over the selected window, e.g., by splitting off a new window and 355over the selected window, e.g., by splitting off a new window and
@@ -374,10 +372,9 @@ key (@pxref{Pop Up Window}).
374 372
375 Commands with names ending in @code{-other-frame} behave like 373 Commands with names ending in @code{-other-frame} behave like
376@code{display-buffer}, except that they (i) never display in the 374@code{display-buffer}, except that they (i) never display in the
377selected window and (ii) prefer to create a new frame to display the 375selected window and (ii) prefer to either create a new frame or use a
378desired buffer instead of splitting a window---as though the variable 376window on some other frame to display the desired buffer. Several of
379@code{pop-up-frames} is set to @code{t} (@pxref{Window Choice}). 377these commands are bound in the @kbd{C-x 5} prefix key.
380Several of these commands are bound in the @kbd{C-x 5} prefix key.
381 378
382@menu 379@menu
383* Window Choice:: How @code{display-buffer} works. 380* Window Choice:: How @code{display-buffer} works.
@@ -390,33 +387,61 @@ Several of these commands are bound in the @kbd{C-x 5} prefix key.
390 387
391The @code{display-buffer} command (as well as commands that call it 388The @code{display-buffer} command (as well as commands that call it
392internally) chooses a window to display by following the steps given 389internally) chooses a window to display by following the steps given
393below. @xref{Choosing Window,,Choosing a Window for Display, elisp, 390below. @xref{Choosing Window,,Choosing a Window for Displaying a
394The Emacs Lisp Reference Manual}, for details about how to alter this 391Buffer, elisp, The Emacs Lisp Reference Manual}, for details about how
395sequence of steps. 392to alter this sequence of steps.
396 393
397@itemize 394@itemize
398@vindex same-window-buffer-names
399@vindex same-window-regexps
400@item 395@item
401First, check if the buffer should be displayed in the selected window 396If the buffer should be displayed in the selected window regardless of
402regardless of other considerations. You can tell Emacs to do this by 397other considerations, reuse the selected window. By default, this
403adding the desired buffer's name to the list 398step is skipped, but you can tell Emacs not to skip it by adding a
404@code{same-window-buffer-names}, or adding a matching regular 399regular expression matching the buffer's name together with a
405expression to the list @code{same-window-regexps}. By default, these 400reference to the @code{display-buffer-same-window} action function
406variables are @code{nil}, so this step is skipped. 401(@pxref{Buffer Display Action Functions,,Action Functions for Buffer
402Display, elisp, The Emacs Lisp Reference Manual}) to the option
403@code{display-buffer-alist} (@pxref{Choosing Window,,Choosing a Window
404for Displaying a Buffer, elisp, The Emacs Lisp Reference Manual}).
405For example, to display the buffer @file{*scratch*} preferably in the
406selected window write:
407
408@example
409@group
410(customize-set-variable
411 'display-buffer-alist
412 '("\\*scratch\\*" (display-buffer-same-window)))
413@end group
414@end example
415
416By default, @code{display-buffer-alist} is @code{nil}.
407 417
408@item 418@item
409Otherwise, if the buffer is already displayed in an existing window, 419Otherwise, if the buffer is already displayed in an existing window,
410reuse that window. Normally, only windows on the selected frame 420reuse that window. Normally, only windows on the selected frame are
411are considered, but windows on other frames are also reusable if you 421considered, but windows on other frames are also reusable if you use
412change @code{pop-up-frames} (see below) to @code{t}. 422the corresponding @code{reusable-frames} action alist entry
423(@pxref{Buffer Display Action Alists,,Action Alists for Buffer
424Display, elisp, The Emacs Lisp Reference Manual}). See the
425next step for an example of how to do that.
413 426
414@vindex pop-up-frames
415@item 427@item
416Otherwise, optionally create a new frame and display the buffer there. 428Otherwise, optionally create a new frame and display the buffer there.
417By default, this step is skipped. To enable it, change the variable 429By default, this step is skipped. To enable it, change the value of
418@code{pop-up-frames} to a non-@code{nil} value. The special value 430the option @code{display-buffer-base-action} (@pxref{Choosing
419@code{graphic-only} means to do this only on graphical displays. 431Window,,Choosing a Window for Displaying a Buffer, elisp, The Emacs
432Lisp Reference Manual}) as follows:
433
434@example
435@group
436(customize-set-variable
437 'display-buffer-base-action
438 '((display-buffer-reuse-window display-buffer-pop-up-frame)
439 (reusable-frames . 0)))
440@end group
441@end example
442
443This customization will also try to make the preceding step search for
444a reusable window on all visible or iconified frames.
420 445
421@item 446@item
422Otherwise, try to create a new window by splitting a window on the 447Otherwise, try to create a new window by splitting a window on the
@@ -436,9 +461,9 @@ window was not split before (to avoid excessive splitting).
436 461
437@item 462@item
438Otherwise, display the buffer in a window previously showing it. 463Otherwise, display the buffer in a window previously showing it.
439Normally, only windows on the selected frame are considered, but if 464Normally, only windows on the selected frame are considered, but with
440@code{pop-up-frames} is non-@code{nil} the window may be also on another 465a suitable @code{reusable-frames} action alist entry (see above) the
441frame. 466window may be also on another frame.
442 467
443@item 468@item
444Otherwise, display the buffer in an existing window on the selected 469Otherwise, display the buffer in an existing window on the selected
@@ -449,41 +474,35 @@ If all the above methods fail for whatever reason, create a new frame
449and display the buffer there. 474and display the buffer there.
450@end itemize 475@end itemize
451 476
452A more advanced and flexible way to customize the behavior of
453@code{display-buffer} is by using the option @code{display-buffer-alist}
454mentioned in the next section.
455
456 477
457@node Temporary Displays 478@node Temporary Displays
458@subsection Displaying non-editable buffers. 479@subsection Displaying non-editable buffers.
459@cindex pop-up windows
460@cindex temporary windows 480@cindex temporary windows
461 481
462Some buffers are shown in windows for perusal rather than for editing. 482Some buffers are shown in windows for perusal rather than for editing.
463Help commands (@pxref{Help}) typically use a buffer called @file{*Help*} 483Help commands (@pxref{Help}) typically use a buffer called @file{*Help*}
464for that purpose, minibuffer completion (@pxref{Completion}) uses a 484for that purpose, minibuffer completion (@pxref{Completion}) uses a
465buffer called @file{*Completions*} instead. Such buffers are usually 485buffer called @file{*Completions*}, etc. Such buffers are usually
466displayed only for a short period of time. 486displayed only for a short period of time.
467 487
468 Normally, Emacs chooses the window for such temporary displays via 488 Normally, Emacs chooses the window for such temporary displays via
469@code{display-buffer} as described above. The @file{*Completions*} 489@code{display-buffer}, as described in the previous subsection. The
470buffer, on the other hand, is normally displayed in a window at the 490@file{*Completions*} buffer, on the other hand, is normally displayed
471bottom of the selected frame, regardless of the number of windows 491in a window at the bottom of the selected frame, regardless of the
472already shown on that frame. 492number of windows already shown on that frame.
473 493
474 If you prefer Emacs to display a temporary buffer in a different 494 If you prefer Emacs to display a temporary buffer in a different
475fashion, we recommend customizing the variable 495fashion, customize the variable @code{display-buffer-alist}
476@code{display-buffer-alist} (@pxref{Choosing Window,,Choosing a Window 496(@pxref{Choosing Window,,Choosing a Window for Displaying a Buffer,
477for Display, elisp, The Emacs Lisp Reference Manual}). For example, 497elisp, The Emacs Lisp Reference Manual}) appropriately. For example,
478to display @file{*Completions*} by splitting a window as described in 498to display @file{*Completions*} always below the selected window, use
479the previous section, use the following form in your initialization 499the following form in your initialization file (@pxref{Init File}):
480file (@pxref{Init File}):
481 500
482@example 501@example
483@group 502@group
484(customize-set-variable 503(customize-set-variable
485 'display-buffer-alist 504 'display-buffer-alist
486 '(("\\*Completions\\*" display-buffer-pop-up-window))) 505 '(("\\*Completions\\*" display-buffer-below-selected)))
487@end group 506@end group
488@end example 507@end example
489 508
@@ -491,10 +510,10 @@ file (@pxref{Init File}):
491 The @file{*Completions*} buffer is also special in the sense that 510 The @file{*Completions*} buffer is also special in the sense that
492Emacs usually tries to make its window just as large as necessary to 511Emacs usually tries to make its window just as large as necessary to
493display all of its contents. To resize windows showing other 512display all of its contents. To resize windows showing other
494temporary displays like, for example, the @file{*Help*} buffer 513temporary displays, like, for example, the @file{*Help*} buffer, turn
495accordingly, turn on the minor mode (@pxref{Minor Modes}) 514on the minor mode (@pxref{Minor Modes}) @code{temp-buffer-resize-mode}
496@code{temp-buffer-resize-mode} (@pxref{Temporary Displays,,Temporary 515(@pxref{Temporary Displays,,Temporary Displays, elisp, The Emacs Lisp
497Displays, elisp, The Emacs Lisp Reference Manual}). 516Reference Manual}).
498 517
499@vindex temp-buffer-max-height 518@vindex temp-buffer-max-height
500@vindex temp-buffer-max-width 519@vindex temp-buffer-max-width
@@ -502,7 +521,7 @@ Displays, elisp, The Emacs Lisp Reference Manual}).
502can be controlled by customizing the options 521can be controlled by customizing the options
503@code{temp-buffer-max-height} and @code{temp-buffer-max-width} 522@code{temp-buffer-max-height} and @code{temp-buffer-max-width}
504(@pxref{Temporary Displays,,Temporary Displays, elisp, The Emacs Lisp 523(@pxref{Temporary Displays,,Temporary Displays, elisp, The Emacs Lisp
505Reference Manual}) and cannot exceed the size of the containing frame. 524Reference Manual}), and cannot exceed the size of the containing frame.
506 525
507 526
508@node Window Convenience 527@node Window Convenience
diff --git a/doc/lispref/control.texi b/doc/lispref/control.texi
index e5041ee627b..5cc43c428ad 100644
--- a/doc/lispref/control.texi
+++ b/doc/lispref/control.texi
@@ -419,65 +419,68 @@ This is not completely equivalent because it can evaluate @var{arg1} or
419@node Pattern-Matching Conditional 419@node Pattern-Matching Conditional
420@section Pattern-Matching Conditional 420@section Pattern-Matching Conditional
421@cindex pcase 421@cindex pcase
422@cindex pattern matching 422@cindex pattern matching, programming style
423 423
424Aside from the four basic conditional forms, Emacs Lisp also 424Aside from the four basic conditional forms, Emacs Lisp also
425has a pattern-matching conditional form, the @code{pcase} macro, 425has a pattern-matching conditional form, the @code{pcase} macro,
426a hybrid of @code{cond} and @code{cl-case} 426a hybrid of @code{cond} and @code{cl-case}
427(@pxref{Conditionals,,,cl,Common Lisp Extensions}) 427(@pxref{Conditionals,,,cl,Common Lisp Extensions})
428that overcomes their limitations and introduces 428that overcomes their limitations and introduces
429the @dfn{pattern matching} programming style. 429the @dfn{pattern matching programming style}.
430First, the limitations: 430The limitations that @code{pcase} overcomes are:
431 431
432@itemize 432@itemize
433@item The @code{cond} form chooses among alternatives 433@item
434by evaluating the predicate @var{condition} of each 434The @code{cond} form chooses among alternatives by evaluating the
435of its clauses (@pxref{Conditionals}). 435predicate @var{condition} of each of its clauses
436The primary limitation is that variables let-bound in @var{condition} 436(@pxref{Conditionals}). The primary limitation is that variables
437are not available to the clause's @var{body-forms}. 437let-bound in @var{condition} are not available to the clause's
438@var{body-forms}.
438 439
439Another annoyance (more an inconvenience than a limitation) 440Another annoyance (more an inconvenience than a limitation)
440is that when a series of @var{condition} predicates implement 441is that when a series of @var{condition} predicates implement
441equality tests, there is a lot of repeated code. 442equality tests, there is a lot of repeated code. (@code{cl-case}
442For that, why not use @code{cl-case}? 443solves this inconvenience.)
443 444
444@item 445@item
445The @code{cl-case} macro chooses among alternatives by evaluating 446The @code{cl-case} macro chooses among alternatives by evaluating
446the equality of its first argument against a set of specific 447the equality of its first argument against a set of specific
447values. 448values.
448The limitations are two-fold: 449
450Its limitations are two-fold:
449 451
450@enumerate 452@enumerate
451@item The equality tests use @code{eql}. 453@item
452@item The values must be known and written in advance. 454The equality tests use @code{eql}.
455@item
456The values must be known and written in advance.
453@end enumerate 457@end enumerate
454 458
455@noindent 459@noindent
456These render @code{cl-case} unsuitable for strings or compound 460These render @code{cl-case} unsuitable for strings or compound
457data structures (e.g., lists or vectors). 461data structures (e.g., lists or vectors). (@code{cond} doesn't have
458For that, why not use @code{cond}? 462these limitations, but it has others, see above.)
459(And here we end up in a circle.)
460@end itemize 463@end itemize
461 464
462@noindent 465@noindent
463Conceptually, the @code{pcase} macro borrows the first-arg focus 466Conceptually, the @code{pcase} macro borrows the first-arg focus
464of @code{cl-case} and the clause-processing flow of @code{cond}, 467of @code{cl-case} and the clause-processing flow of @code{cond},
465replacing @var{condition} with a generalization of 468replacing @var{condition} with a generalization of
466the equality test called @dfn{matching}, 469the equality test which is a variant of @dfn{pattern matching},
467and adding facilities so that you can concisely express a 470and adding facilities so that you can concisely express a
468clause's predicate, and arrange to share let-bindings between 471clause's predicate, and arrange to share let-bindings between
469a clause's predicate and @var{body-forms}. 472a clause's predicate and @var{body-forms}.
470 473
471The concise expression of a predicate is known as a @dfn{pattern}. 474The concise expression of a predicate is known as a @dfn{pattern}.
472When the predicate, called on the value of the first arg, 475When the predicate, called on the value of the first arg, returns
473returns non-@code{nil}, the pattern matches the value 476non-@code{nil}, we say that ``the pattern matches the value'' (or
474(or sometimes ``the value matches the pattern''). 477sometimes ``the value matches the pattern'').
475 478
476@menu 479@menu
477* The @code{pcase} macro: pcase Macro. Plus examples and caveats. 480* The @code{pcase} macro: pcase Macro. Includes examples and caveats.
478* Extending @code{pcase}: Extending pcase. Define new kinds of patterns. 481* Extending @code{pcase}: Extending pcase. Define new kinds of patterns.
479* Backquote-Style Patterns: Backquote Patterns. Structural matching. 482* Backquote-Style Patterns: Backquote Patterns. Structural patterns matching.
480* Destructuring patterns:: Using pcase patterns to extract subfields. 483* Destructuring with pcase Patterns:: Using pcase patterns to extract subfields.
481@end menu 484@end menu
482 485
483@node pcase Macro 486@node pcase Macro
@@ -498,30 +501,30 @@ of the last of @var{body-forms} in the successful clause.
498Otherwise, @code{pcase} evaluates to @code{nil}. 501Otherwise, @code{pcase} evaluates to @code{nil}.
499@end defmac 502@end defmac
500 503
501Each @var{pattern} has to be a @dfn{pcase pattern}, which can either 504@cindex pcase pattern
502use one of the core patterns defined below, or use one of the patterns 505Each @var{pattern} has to be a @dfn{pcase pattern}, which can use
503defined via @code{pcase-defmacro}. 506either one of the core patterns defined below, or one of the patterns
507defined via @code{pcase-defmacro} (@pxref{Extending pcase}).
504 508
505The rest of this subsection 509The rest of this subsection describes different forms of core
506describes different forms of core patterns, 510patterns, presents some examples, and concludes with important caveats
507presents some examples, 511on using the let-binding facility provided by some pattern forms. A
508and concludes with important caveats on using the 512core pattern can have the following forms:
509let-binding facility provided by some pattern forms.
510A core pattern can have the following forms:
511 513
512@table @code 514@table @code
513 515
514@item _ 516@item _
515Matches any @var{expval}. 517Matches any @var{expval}.
516This is known as @dfn{don't care} or @dfn{wildcard}. 518This is also known as @dfn{don't care} or @dfn{wildcard}.
517 519
518@item '@var{val} 520@item '@var{val}
519Matches if @var{expval} is @code{equal} to @var{val}. 521Matches if @var{expval} equals @var{val}. The comparison is done as
522if by @code{equal} (@pxref{Equality Predicates}).
520 523
521@item @var{keyword} 524@item @var{keyword}
522@itemx @var{integer} 525@itemx @var{integer}
523@itemx @var{string} 526@itemx @var{string}
524Matches if @var{expval} is @code{equal} to the literal object. 527Matches if @var{expval} equals the literal object.
525This is a special case of @code{'@var{val}}, above, 528This is a special case of @code{'@var{val}}, above,
526possible because literal objects of these types are self-quoting. 529possible because literal objects of these types are self-quoting.
527 530
@@ -533,17 +536,17 @@ Matches any @var{expval}, and additionally let-binds @var{symbol} to
533If @var{symbol} is part of a sequencing pattern @var{seqpat} 536If @var{symbol} is part of a sequencing pattern @var{seqpat}
534(e.g., by using @code{and}, below), the binding is also available to 537(e.g., by using @code{and}, below), the binding is also available to
535the portion of @var{seqpat} following the appearance of @var{symbol}. 538the portion of @var{seqpat} following the appearance of @var{symbol}.
536This usage has some caveats (@pxref{pcase-symbol-caveats,,caveats}). 539This usage has some caveats, see @ref{pcase-symbol-caveats,,caveats}.
537 540
538Two symbols to avoid are @code{t}, which behaves like @code{_} 541Two symbols to avoid are @code{t}, which behaves like @code{_}
539(above) and is deprecated, and @code{nil}, which signals error. 542(above) and is deprecated, and @code{nil}, which signals an error.
540Likewise, it makes no sense to bind keyword symbols 543Likewise, it makes no sense to bind keyword symbols
541(@pxref{Constant Variables}). 544(@pxref{Constant Variables}).
542 545
543@item (pred @var{function}) 546@item (pred @var{function})
544Matches if the predicate @var{function} returns non-@code{nil} 547Matches if the predicate @var{function} returns non-@code{nil}
545when called on @var{expval}. 548when called on @var{expval}.
546@var{function} can have one of the possible forms: 549the predicate @var{function} can have one of the following forms:
547 550
548@table @asis 551@table @asis
549@item function name (a symbol) 552@item function name (a symbol)
@@ -570,20 +573,17 @@ the actual function call becomes: @w{@code{(= 42 @var{expval})}}.
570@item (app @var{function} @var{pattern}) 573@item (app @var{function} @var{pattern})
571Matches if @var{function} called on @var{expval} returns a 574Matches if @var{function} called on @var{expval} returns a
572value that matches @var{pattern}. 575value that matches @var{pattern}.
573@var{function} can take one of the 576@var{function} can take one of the forms described for @code{pred},
574forms described for @code{pred}, above. 577above. Unlike @code{pred}, however, @code{app} tests the result
575Unlike @code{pred}, however, 578against @var{pattern}, rather than against a boolean truth value.
576@code{app} tests the result against @var{pattern},
577rather than against a boolean truth value.
578 579
579@item (guard @var{boolean-expression}) 580@item (guard @var{boolean-expression})
580Matches if @var{boolean-expression} evaluates to non-@code{nil}. 581Matches if @var{boolean-expression} evaluates to non-@code{nil}.
581 582
582@item (let @var{pattern} @var{expr}) 583@item (let @var{pattern} @var{expr})
583Evaluates @var{expr} to get @var{exprval} 584Evaluates @var{expr} to get @var{exprval} and matches if @var{exprval}
584and matches if @var{exprval} matches @var{pattern}. 585matches @var{pattern}. (It is called @code{let} because @var{pattern}
585(It is called @code{let} because 586can bind symbols to values using @var{symbol}.)
586@var{pattern} can bind symbols to values using @var{symbol}.)
587@end table 587@end table
588 588
589@cindex sequencing pattern 589@cindex sequencing pattern
@@ -596,18 +596,16 @@ but instead of processing values, they process sub-patterns.
596 596
597@table @code 597@table @code
598@item (and @var{pattern1}@dots{}) 598@item (and @var{pattern1}@dots{})
599Attempts to match @var{pattern1}@dots{}, in order, 599Attempts to match @var{pattern1}@dots{}, in order, until one of them
600until one of them fails to match. 600fails to match. In that case, @code{and} likewise fails to match, and
601In that case, @code{and} likewise fails to match, 601the rest of the sub-patterns are not tested. If all sub-patterns
602and the rest of the sub-patterns are not tested. 602match, @code{and} matches.
603If all sub-patterns match, @code{and} matches.
604 603
605@item (or @var{pattern1} @var{pattern2}@dots{}) 604@item (or @var{pattern1} @var{pattern2}@dots{})
606Attempts to match @var{pattern1}, @var{pattern2}, @dots{}, in order, 605Attempts to match @var{pattern1}, @var{pattern2}, @dots{}, in order,
607until one of them succeeds. 606until one of them succeeds. In that case, @code{or} likewise matches,
608In that case, @code{or} likewise matches, 607and the rest of the sub-patterns are not tested. (Note that there
609and the rest of the sub-patterns are not tested. 608must be at least two sub-patterns.
610(Note that there must be at least two sub-patterns.
611Simply @w{@code{(or @var{pattern1})}} signals error.) 609Simply @w{@code{(or @var{pattern1})}} signals error.)
612@c Issue: Is this correct and intended? 610@c Issue: Is this correct and intended?
613@c Are there exceptions, qualifications? 611@c Are there exceptions, qualifications?
@@ -1042,12 +1040,11 @@ Both use a single backquote construct (@pxref{Backquote}).
1042 1040
1043This subsection describes @dfn{backquote-style patterns}, 1041This subsection describes @dfn{backquote-style patterns},
1044a set of builtin patterns that eases structural matching. 1042a set of builtin patterns that eases structural matching.
1045For background, @xref{Pattern-Matching Conditional}. 1043For background, @pxref{Pattern-Matching Conditional}.
1046 1044
1047@dfn{Backquote-style patterns} are a powerful set of 1045Backquote-style patterns are a powerful set of @code{pcase} pattern
1048@code{pcase} pattern extensions (created using @code{pcase-defmacro}) 1046extensions (created using @code{pcase-defmacro}) that make it easy to
1049that make it easy to match @var{expval} against 1047match @var{expval} against specifications of its @emph{structure}.
1050specifications of its @emph{structure}.
1051 1048
1052For example, to match @var{expval} that must be a list of two 1049For example, to match @var{expval} that must be a list of two
1053elements whose first element is a specific string and the second 1050elements whose first element is a specific string and the second
@@ -1171,87 +1168,102 @@ evaluation results:
1171(evaluate '(sub 1 2) nil) @result{} error 1168(evaluate '(sub 1 2) nil) @result{} error
1172@end example 1169@end example
1173 1170
1174@node Destructuring patterns 1171@node Destructuring with pcase Patterns
1175@subsection Destructuring Patterns 1172@subsection Destructuring with @code{pcase} Patterns
1176@cindex destructuring patterns 1173@cindex destructuring with pcase patterns
1177 1174
1178Pcase patterns not only express a condition on the form of the objects 1175Pcase patterns not only express a condition on the form of the objects
1179they can match but they can also extract sub-fields of those objects. 1176they can match, but they can also extract sub-fields of those objects.
1180Say we have a list and want to extract 2 elements from it with the 1177For example we can extract 2 elements from a list that is the value of
1181following code: 1178the variable @code{my-list} with the following code:
1182 1179
1183@example 1180@example
1184 (pcase l 1181 (pcase my-list
1185 (`(add ,x ,y) (message "Contains %S and %S" x y))) 1182 (`(add ,x ,y) (message "Contains %S and %S" x y)))
1186@end example 1183@end example
1187 1184
1188This will not only extract @code{x} and @code{y} but will additionally 1185This will not only extract @code{x} and @code{y} but will additionally
1189test that @code{l} is a list containing exactly 3 elements and whose 1186test that @code{my-list} is a list containing exactly 3 elements and
1190first element is the symbol @code{add}. If any of those tests fail, 1187whose first element is the symbol @code{add}. If any of those tests
1191@code{pcase} will directly return @code{nil} without calling 1188fail, @code{pcase} will immediately return @code{nil} without calling
1192@code{message}. 1189@code{message}.
1193 1190
1194@dfn{Destructuring} of an object is an operation that extracts 1191Extraction of multiple values stored in an object is known as
1195multiple values stored in the object, e.g., the 2nd and the 3rd 1192@dfn{destructuring}. Using @code{pcase} patterns allows to perform
1196element of a list or a vector. @dfn{Destructuring binding} is 1193@dfn{destructuring binding}, which is similar to a local binding
1197similar to a local binding (@pxref{Local Variables}), but it gives 1194(@pxref{Local Variables}), but gives values to multiple elements of
1198values to multiple elements of a variable by extracting those values 1195a variable by extracting those values from an object of compatible
1199from an object of compatible structure. 1196structure.
1200 1197
1201The macros described in this section use @dfn{destructuring 1198The macros described in this section use @code{pcase} patterns to
1202patterns}, which are normal Pcase patterns used in a context where we 1199perform destructuring binding. The condition of the object to be of
1203presume that the object does match the pattern, and we only want 1200compatible structure means that the object must match the pattern,
1204to extract some subfields. For example: 1201because only then the object's subfields can be extracted. For
1202example:
1205 1203
1206@example 1204@example
1207 (pcase-let ((`(add ,x ,y) l)) 1205 (pcase-let ((`(add ,x ,y) my-list))
1208 (message "Contains %S and %S" x y)) 1206 (message "Contains %S and %S" x y))
1209@end example 1207@end example
1210 1208
1211@noindent 1209@noindent
1212does the same as the previous example, except that it directly tries 1210does the same as the previous example, except that it directly tries
1213to extract @code{x} and @code{y} from @code{l} without first verifying 1211to extract @code{x} and @code{y} from @code{my-list} without first
1214if @code{l} is a list which has the right number of elements and has 1212verifying if @code{my-list} is a list which has the right number of
1215@code{add} as its first element. 1213elements and has @code{add} as its first element. The precise
1216The precise behavior when the object does not actually match the 1214behavior when the object does not actually match the pattern is
1217pattern is undefined, although the body will not be silently skipped: 1215undefined, although the body will not be silently skipped: either an
1218either an error is signaled or the body is run with some of the 1216error is signaled or the body is run with some of the variables
1219variables potentially bound to arbitrary values like @code{nil}. 1217potentially bound to arbitrary values like @code{nil}.
1218
1219The pcase patterns that are useful for destructuring bindings are
1220generally those described in @ref{Backquote Patterns}, since they
1221express a specification of the structure of objects that will match.
1222
1223For an alternative facility for destructuring binding, see
1224@ref{seq-let}.
1220 1225
1221@defmac pcase-let bindings body@dots{} 1226@defmac pcase-let bindings body@dots{}
1222Bind variables according to @var{bindings} and then eval @var{body}. 1227Perform destructuring binding of variables according to
1228@var{bindings}, and then evaluate @var{body}.
1223 1229
1224@var{bindings} is a list of bindings of the form @w{@code{(@var{pattern} 1230@var{bindings} is a list of bindings of the form @w{@code{(@var{pattern}
1225@var{exp})}}, where @var{exp} is an expression to evaluate and 1231@var{exp})}}, where @var{exp} is an expression to evaluate and
1226@var{pattern} is a destructuring pattern. 1232@var{pattern} is a @code{pcase} pattern.
1227 1233
1228All @var{exp}s are evaluated first after which they are matched 1234All @var{exp}s are evaluated first, after which they are matched
1229against their respective @var{pattern}, introducing new variable 1235against their respective @var{pattern}, introducing new variable
1230bindings which can then be used inside @var{body}. 1236bindings that can then be used inside @var{body}. The variable
1237bindings are produced by destructuring binding of elements of
1238@var{pattern} to the values of the corresponding elements of the
1239evaluated @var{exp}.
1231@end defmac 1240@end defmac
1232 1241
1233@defmac pcase-let* bindings body@dots{} 1242@defmac pcase-let* bindings body@dots{}
1234Bind variables according to @var{bindings} and then eval @var{body}. 1243Perform destructuring binding of variables according to
1244@var{bindings}, and then evaluate @var{body}.
1235 1245
1236@var{bindings} is a list of bindings of the form @code{(@var{pattern} 1246@var{bindings} is a list of bindings of the form @code{(@var{pattern}
1237@var{exp})}, where @var{exp} is an expression to evaluate and 1247@var{exp})}, where @var{exp} is an expression to evaluate and
1238@var{pattern} is a destructuring pattern. 1248@var{pattern} is a @code{pcase} pattern. The variable bindings are
1239 1249produced by destructuring binding of elements of @var{pattern} to the
1240Unlike @code{pcase-let}, but like @code{let*}, each @var{exp} is 1250values of the corresponding elements of the evaluated @var{exp}.
1241matched against its corresponding @var{pattern} before passing to the 1251
1242next element of @var{bindings}, so the variables introduced in each 1252Unlike @code{pcase-let}, but similarly to @code{let*}, each @var{exp}
1243binding are available in the @var{exp}s that follow it, additionally 1253is matched against its corresponding @var{pattern} before processing
1244to being available in @var{body}. 1254the next element of @var{bindings}, so the variable bindings
1255introduced in each one of the @var{bindings} are available in the
1256@var{exp}s of the @var{bindings} that follow it, additionally to
1257being available in @var{body}.
1245@end defmac 1258@end defmac
1246 1259
1247@findex dolist
1248@defmac pcase-dolist (pattern list) body@dots{} 1260@defmac pcase-dolist (pattern list) body@dots{}
1249This construct executes @var{body} once for each element of 1261Execute @var{body} once for each element of @var{list}, on each
1250@var{list}, in a context where the variables appearing in the the 1262iteration performing a destructuring binding of variables in
1251destructuring pattern @var{pattern} are bound to the corresponding 1263@var{pattern} to the values of the corresponding subfields of the
1252values found in the element. 1264element of @var{list}. The bindings are performed as if by
1253When @var{pattern} is a simple variable, this ends up being equivalent 1265@code{pcase-let}. When @var{pattern} is a simple variable, this ends
1254to @code{dolist}. 1266up being equivalent to @code{dolist} (@pxref{Iteration}).
1255@end defmac 1267@end defmac
1256 1268
1257 1269
diff --git a/doc/lispref/elisp.texi b/doc/lispref/elisp.texi
index 0b846291a07..08414e68026 100644
--- a/doc/lispref/elisp.texi
+++ b/doc/lispref/elisp.texi
@@ -1045,9 +1045,7 @@ Windows
1045* Cyclic Window Ordering:: Moving around the existing windows. 1045* Cyclic Window Ordering:: Moving around the existing windows.
1046* Buffers and Windows:: Each window displays the contents of a buffer. 1046* Buffers and Windows:: Each window displays the contents of a buffer.
1047* Switching Buffers:: Higher-level functions for switching to a buffer. 1047* Switching Buffers:: Higher-level functions for switching to a buffer.
1048* Choosing Window:: How to choose a window for displaying a buffer. 1048* Displaying Buffers:: Displaying a buffer in a suitable window.
1049* Display Action Functions:: Subroutines for @code{display-buffer}.
1050* Choosing Window Options:: Extra options affecting how buffers are displayed.
1051* Window History:: Each window remembers the buffers displayed in it. 1049* Window History:: Each window remembers the buffers displayed in it.
1052* Dedicated Windows:: How to avoid displaying another buffer in 1050* Dedicated Windows:: How to avoid displaying another buffer in
1053 a specific window. 1051 a specific window.
@@ -1069,6 +1067,18 @@ Windows
1069 redisplay going past a certain point, 1067 redisplay going past a certain point,
1070 or window configuration changes. 1068 or window configuration changes.
1071 1069
1070Displaying Buffers
1071
1072* Choosing Window:: How to choose a window for displaying a buffer.
1073* Buffer Display Action Functions:: Support functions for buffer display.
1074* Buffer Display Action Alists:: Alists for fine-tuning buffer display
1075 action functions.
1076* Choosing Window Options:: Extra options affecting how buffers are displayed.
1077* Precedence of Action Functions:: A tutorial explaining the precedence of
1078 buffer display action functions.
1079* The Zen of Buffer Display:: How to avoid that buffers get lost in between
1080 windows.
1081
1072Side Windows 1082Side Windows
1073 1083
1074* Displaying Buffers in Side Windows:: An action function for displaying 1084* Displaying Buffers in Side Windows:: An action function for displaying
diff --git a/doc/lispref/frames.texi b/doc/lispref/frames.texi
index ba4b9313731..ad5d0fc6015 100644
--- a/doc/lispref/frames.texi
+++ b/doc/lispref/frames.texi
@@ -3261,11 +3261,11 @@ and should be preferred when specifying a non-@code{nil}
3261@code{drag-with-mode-line} parameter. 3261@code{drag-with-mode-line} parameter.
3262 3262
3263 When a child frame is used for displaying a buffer via 3263 When a child frame is used for displaying a buffer via
3264@code{display-buffer-in-child-frame} (@pxref{Display Action Functions}), 3264@code{display-buffer-in-child-frame} (@pxref{Buffer Display Action
3265the frame's @code{auto-hide-function} parameter (@pxref{Frame 3265Functions}), the frame's @code{auto-hide-function} parameter
3266Interaction Parameters}) can be set to a function, in order to 3266(@pxref{Frame Interaction Parameters}) can be set to a function, in
3267appropriately deal with the frame when the window displaying the buffer 3267order to appropriately deal with the frame when the window displaying
3268shall be quit. 3268the buffer shall be quit.
3269 3269
3270 When a child frame is used during minibuffer interaction, for example, 3270 When a child frame is used during minibuffer interaction, for example,
3271to display completions in a separate window, the @code{minibuffer-exit} 3271to display completions in a separate window, the @code{minibuffer-exit}
diff --git a/doc/lispref/sequences.texi b/doc/lispref/sequences.texi
index 6a6f4d5c82e..554716084ee 100644
--- a/doc/lispref/sequences.texi
+++ b/doc/lispref/sequences.texi
@@ -1049,15 +1049,18 @@ that @var{sequence} can be a list, vector or string. This is
1049primarily useful for side-effects. 1049primarily useful for side-effects.
1050@end defmac 1050@end defmac
1051 1051
1052@defmac seq-let arguments sequence body@dots{} 1052@anchor{seq-let}
1053@defmac seq-let var-sequence val-sequence body@dots{}
1053@cindex sequence destructuring 1054@cindex sequence destructuring
1054 This macro binds the variables defined in @var{arguments} to the 1055 This macro binds the variables defined in @var{var-sequence} to the
1055elements of @var{sequence}. @var{arguments} can themselves include 1056values that are the corresponding elements of @var{val-sequence}.
1056sequences, allowing for nested destructuring. 1057This is known as @dfn{destructuring binding}. The elements of
1058@var{var-sequence} can themselves include sequences, allowing for
1059nested destructuring.
1057 1060
1058The @var{arguments} sequence can also include the @code{&rest} marker 1061The @var{var-sequence} sequence can also include the @code{&rest}
1059followed by a variable name to be bound to the rest of 1062marker followed by a variable name to be bound to the rest of
1060@code{sequence}. 1063@var{val-sequence}.
1061 1064
1062@example 1065@example
1063@group 1066@group
@@ -1081,6 +1084,9 @@ followed by a variable name to be bound to the rest of
1081@end group 1084@end group
1082@result{} [3 4] 1085@result{} [3 4]
1083@end example 1086@end example
1087
1088The @code{pcase} patterns provide an alternative facility for
1089destructuring binding, see @ref{Destructuring with pcase Patterns}.
1084@end defmac 1090@end defmac
1085 1091
1086@defun seq-random-elt sequence 1092@defun seq-random-elt sequence
diff --git a/doc/lispref/windows.texi b/doc/lispref/windows.texi
index 52bfbde41c6..772bcdf9a6c 100644
--- a/doc/lispref/windows.texi
+++ b/doc/lispref/windows.texi
@@ -25,9 +25,7 @@ is displayed in windows.
25* Cyclic Window Ordering:: Moving around the existing windows. 25* Cyclic Window Ordering:: Moving around the existing windows.
26* Buffers and Windows:: Each window displays the contents of a buffer. 26* Buffers and Windows:: Each window displays the contents of a buffer.
27* Switching Buffers:: Higher-level functions for switching to a buffer. 27* Switching Buffers:: Higher-level functions for switching to a buffer.
28* Choosing Window:: How to choose a window for displaying a buffer. 28* Displaying Buffers:: Displaying a buffer in a suitable window.
29* Display Action Functions:: Subroutines for @code{display-buffer}.
30* Choosing Window Options:: Extra options affecting how buffers are displayed.
31* Window History:: Each window remembers the buffers displayed in it. 29* Window History:: Each window remembers the buffers displayed in it.
32* Dedicated Windows:: How to avoid displaying another buffer in 30* Dedicated Windows:: How to avoid displaying another buffer in
33 a specific window. 31 a specific window.
@@ -1542,11 +1540,11 @@ direction as the existing window combination (otherwise, a new internal
1542window is created anyway). 1540window is created anyway).
1543 1541
1544@item window-size 1542@item window-size
1545This means that @code{display-buffer} makes a new parent window when it 1543This means that @code{display-buffer} makes a new parent window when
1546splits a window and is passed a @code{window-height} or 1544it splits a window and is passed a @code{window-height} or
1547@code{window-width} entry in the @var{alist} argument (@pxref{Display 1545@code{window-width} entry in the @var{alist} argument (@pxref{Buffer
1548Action Functions}). Otherwise, window splitting behaves as for a value 1546Display Action Functions}). Otherwise, window splitting behaves as
1549of @code{nil}. 1547for a value of @code{nil}.
1550 1548
1551@item temp-buffer-resize 1549@item temp-buffer-resize
1552In this case @code{with-temp-buffer-window} makes a new parent window 1550In this case @code{with-temp-buffer-window} makes a new parent window
@@ -1879,7 +1877,7 @@ most recently used one (@pxref{Cyclic Window Ordering}).
1879@cindex ordering of windows, cyclic 1877@cindex ordering of windows, cyclic
1880@cindex window ordering, cyclic 1878@cindex window ordering, cyclic
1881 1879
1882 When you use the command @kbd{C-x o} (@code{other-window}) to select 1880 When you use the command @w{@kbd{C-x o}} (@code{other-window}) to select
1883some other window, it moves through live windows in a specific order. 1881some other window, it moves through live windows in a specific order.
1884For any given configuration of windows, this order never varies. It 1882For any given configuration of windows, this order never varies. It
1885is called the @dfn{cyclic ordering of windows}. 1883is called the @dfn{cyclic ordering of windows}.
@@ -1899,7 +1897,7 @@ if omitted or @code{nil}, it defaults to the selected window.
1899The optional argument @var{minibuf} specifies whether minibuffer windows 1897The optional argument @var{minibuf} specifies whether minibuffer windows
1900should be included in the cyclic ordering. Normally, when @var{minibuf} 1898should be included in the cyclic ordering. Normally, when @var{minibuf}
1901is @code{nil}, a minibuffer window is included only if it is currently 1899is @code{nil}, a minibuffer window is included only if it is currently
1902active; this matches the behavior of @kbd{C-x o}. (Note that a 1900active; this matches the behavior of @w{@kbd{C-x o}}. (Note that a
1903minibuffer window is active as long as its minibuffer is in use; see 1901minibuffer window is active as long as its minibuffer is in use; see
1904@ref{Minibuffers}). 1902@ref{Minibuffers}).
1905 1903
@@ -2083,7 +2081,8 @@ variables in the specified buffer. However, if the optional argument
2083@var{keep-margins} is non-@code{nil}, it leaves @var{window}'s display 2081@var{keep-margins} is non-@code{nil}, it leaves @var{window}'s display
2084margins, fringes and scroll bar settings alone. 2082margins, fringes and scroll bar settings alone.
2085 2083
2086When writing an application, you should normally use the higher-level 2084When writing an application, you should normally use
2085@code{display-buffer} (@pxref{Choosing Window}) or the higher-level
2087functions described in @ref{Switching Buffers}, instead of calling 2086functions described in @ref{Switching Buffers}, instead of calling
2088@code{set-window-buffer} directly. 2087@code{set-window-buffer} directly.
2089 2088
@@ -2168,7 +2167,6 @@ frame on its terminal, the buffer is replaced anyway.
2168@node Switching Buffers 2167@node Switching Buffers
2169@section Switching to a Buffer in a Window 2168@section Switching to a Buffer in a Window
2170@cindex switching to a buffer 2169@cindex switching to a buffer
2171@cindex displaying a buffer
2172 2170
2173This section describes high-level functions for switching to a specified 2171This section describes high-level functions for switching to a specified
2174buffer in some window. In general, ``switching to a buffer'' means to 2172buffer in some window. In general, ``switching to a buffer'' means to
@@ -2327,32 +2325,70 @@ unless @var{norecord} is non-@code{nil}.
2327@end deffn 2325@end deffn
2328 2326
2329 2327
2328@node Displaying Buffers
2329@section Displaying a Buffer in a Suitable Window
2330@cindex buffer display
2331@cindex displaying a buffer
2332
2333This section describes lower-level functions Emacs uses to find or
2334create a window for displaying a specified buffer. The common
2335workhorse of these functions is @code{display-buffer} which eventually
2336handles all incoming requests for buffer display (@pxref{Choosing
2337Window}).
2338
2339 @code{display-buffer} delegates the task of finding a suitable
2340window to so-called action functions (@pxref{Buffer Display Action
2341Functions}). First, @code{display-buffer} compiles a so-called action
2342alist---a special association list that action functions can use to
2343fine-tune their behavior. Then it passes that alist on to each action
2344function it calls (@pxref{Buffer Display Action Alists}).
2345
2346 The behavior of @code{display-buffer} is highly customizable. To
2347understand how customizations are used in practice, you may wish to
2348study examples illustrating the order of precedence which
2349@code{display-buffer} uses to call action functions (@pxref{Precedence
2350of Action Functions}). To avoid conflicts between Lisp programs
2351calling @code{display-buffer} and user customizations of its behavior,
2352it may make sense to follow a number of guidelines which are sketched
2353in the final part of this section (@pxref{The Zen of Buffer Display}).
2354
2355@menu
2356* Choosing Window:: How to choose a window for displaying a buffer.
2357* Buffer Display Action Functions:: Support functions for buffer display.
2358* Buffer Display Action Alists:: Alists for fine-tuning buffer display.
2359* Choosing Window Options:: Extra options affecting how buffers are displayed.
2360* Precedence of Action Functions:: Examples to explain the precedence of
2361 action functions.
2362* The Zen of Buffer Display:: How to avoid that buffers get lost in between
2363 windows.
2364@end menu
2365
2366
2330@node Choosing Window 2367@node Choosing Window
2331@section Choosing a Window for Display 2368@subsection Choosing a Window for Displaying a Buffer
2332 2369
2333 The command @code{display-buffer} flexibly chooses a window for 2370The command @code{display-buffer} flexibly chooses a window for
2334display, and displays a specified buffer in that window. It can be 2371display, and displays a specified buffer in that window. It can be
2335called interactively, via the key binding @kbd{C-x 4 C-o}. It is also 2372called interactively, via the key binding @kbd{C-x 4 C-o}. It is also
2336used as a subroutine by many functions and commands, including 2373used as a subroutine by many functions and commands, including
2337@code{switch-to-buffer} and @code{pop-to-buffer} (@pxref{Switching 2374@code{switch-to-buffer} and @code{pop-to-buffer} (@pxref{Switching
2338Buffers}). 2375Buffers}).
2339 2376
2377@cindex buffer display display action
2340@cindex display action 2378@cindex display action
2341@cindex action function, for @code{display-buffer}
2342@cindex action alist, for @code{display-buffer}
2343 This command performs several complex steps to find a window to 2379 This command performs several complex steps to find a window to
2344display in. These steps are described by means of @dfn{display 2380display in. These steps are described by means of @dfn{display
2345actions}, which have the form @code{(@var{function} . @var{alist})}. 2381actions}, which have the form @code{(@var{functions} . @var{alist})}.
2346Here, @var{function} is either a function or a list of functions, 2382Here, @var{functions} is either a single function or a list of
2347which we refer to as @dfn{action functions}; @var{alist} is an 2383functions, referred to as ``action functions'' (@pxref{Buffer Display
2348association list, which we refer to as an @dfn{action alist}. 2384Action Functions}); and @var{alist} is an association list, referred
2385to as ``action alist'' (@pxref{Buffer Display Action Alists}).
2386@xref{The Zen of Buffer Display}, for samples of display actions.
2349 2387
2350 An action function accepts two arguments: the buffer to display and 2388 An action function accepts two arguments: the buffer to display and
2351an action alist. It attempts to display the buffer in some window, 2389an action alist. It attempts to display the buffer in some window,
2352picking or creating a window according to its own criteria. If 2390picking or creating a window according to its own criteria. If
2353successful, it returns the window; otherwise, it returns @code{nil}. 2391successful, it returns the window; otherwise, it returns @code{nil}.
2354@xref{Display Action Functions}, for a list of predefined action
2355functions.
2356 2392
2357 @code{display-buffer} works by combining display actions from 2393 @code{display-buffer} works by combining display actions from
2358several sources, and calling the action functions in turn, until one 2394several sources, and calling the action functions in turn, until one
@@ -2363,12 +2399,14 @@ value.
2363This command makes @var{buffer-or-name} appear in some window, without 2399This command makes @var{buffer-or-name} appear in some window, without
2364selecting the window or making the buffer current. The argument 2400selecting the window or making the buffer current. The argument
2365@var{buffer-or-name} must be a buffer or the name of an existing 2401@var{buffer-or-name} must be a buffer or the name of an existing
2366buffer. The return value is the window chosen to display the buffer. 2402buffer. The return value is the window chosen to display the buffer,
2403or @code{nil} if no suitable window was found.
2367 2404
2368The optional argument @var{action}, if non-@code{nil}, should normally 2405The optional argument @var{action}, if non-@code{nil}, should normally
2369be a display action (described above). @code{display-buffer} builds a 2406be a display action (described above). @code{display-buffer} builds a
2370list of action functions and an action alist, by consolidating display 2407list of action functions and an action alist, by consolidating display
2371actions from the following sources (in order): 2408actions from the following sources (in order of their precedence,
2409from highest to lowest):
2372 2410
2373@itemize 2411@itemize
2374@item 2412@item
@@ -2388,40 +2426,65 @@ The constant @code{display-buffer-fallback-action}.
2388@end itemize 2426@end itemize
2389 2427
2390@noindent 2428@noindent
2391Each action function is called in turn, passing the buffer as the 2429In practice this means that @code{display-buffer} builds a list of all
2392first argument and the combined action alist as the second argument, 2430action functions specified by these display actions. The first
2393until one of the functions returns non-@code{nil}. The caller can 2431element of this list is the first action function specified by
2394pass @code{(allow-no-window . t)} as an element of the action alist to 2432@code{display-buffer-overriding-action}, if any. Its last element is
2395indicate its readiness to handle the case of not displaying the 2433@code{display-buffer-pop-up-frame}---the last action function
2396buffer in a window. 2434specified by @code{display-buffer-fallback-action}. Duplicates are
2435not removed from this list---hence one and the same action function
2436may be called multiple times during one call of @code{display-buffer}.
2437
2438@code{display-buffer} calls the action functions specified by this
2439list in turn, passing the buffer as the first argument and the
2440combined action alist as the second argument, until one of the
2441functions returns non-@code{nil}. @xref{Precedence of Action
2442Functions}, for examples how display actions specified by different
2443sources are processed by @code{display-buffer}.
2444
2445Note that the second argument is always the list of @emph{all} action
2446alist entries specified by the sources named above. Hence, the first
2447element of that list is the first action alist entry specified by
2448@code{display-buffer-overriding-action}, if any. Its last element is
2449the last alist entry of @code{display-buffer-base-action}, if any (the
2450action alist of @code{display-buffer-fallback-action} is empty).
2451
2452Note also, that the combined action alist may contain duplicate
2453entries and entries for the same key with different values. As a
2454rule, action functions always use the first association of a key they
2455find. Hence, the association an action function uses is not
2456necessarily the association provided by the display action that
2457specified that action function,
2397 2458
2398The argument @var{action} can also have a non-@code{nil}, non-list 2459The argument @var{action} can also have a non-@code{nil}, non-list
2399value. This has the special meaning that the buffer should be 2460value. This has the special meaning that the buffer should be
2400displayed in a window other than the selected one, even if the 2461displayed in a window other than the selected one, even if the
2401selected window is already displaying it. If called interactively 2462selected window is already displaying it. If called interactively
2402with a prefix argument, @var{action} is @code{t}. 2463with a prefix argument, @var{action} is @code{t}. Lisp programs
2464should always supply a list value.
2403 2465
2404The optional argument @var{frame}, if non-@code{nil}, specifies which 2466The optional argument @var{frame}, if non-@code{nil}, specifies which
2405frames to check when deciding whether the buffer is already displayed. 2467frames to check when deciding whether the buffer is already displayed.
2406It is equivalent to adding an element @code{(reusable-frames 2468It is equivalent to adding an element @w{@code{(reusable-frames
2407. @var{frame})} to the action alist of @var{action}. @xref{Display 2469. @var{frame})}} to the action alist of @var{action} (@pxref{Buffer
2408Action Functions}. 2470Display Action Alists}). The @var{frame} argument is provided for
2471compatibility reasons, Lisp programs should not use it.
2409@end deffn 2472@end deffn
2410 2473
2411@defvar display-buffer-overriding-action 2474@defvar display-buffer-overriding-action
2412The value of this variable should be a display action, which is 2475The value of this variable should be a display action, which is
2413treated with the highest priority by @code{display-buffer}. The 2476treated with the highest priority by @code{display-buffer}. The
2414default value is empty, i.e., @code{(nil . nil)}. 2477default value is an empty display action, i.e., @w{@code{(nil . nil)}}.
2415@end defvar 2478@end defvar
2416 2479
2417@defopt display-buffer-alist 2480@defopt display-buffer-alist
2418The value of this option is an alist mapping conditions to display 2481The value of this option is an alist mapping conditions to display
2419actions. Each condition may be either a regular expression matching a 2482actions. Each condition may be either a regular expression matching a
2420buffer name or a function that takes two arguments: a buffer name and 2483buffer name or a function that takes two arguments: a buffer name and
2421the @var{action} argument passed to @code{display-buffer}. If the name 2484the @var{action} argument passed to @code{display-buffer}. If either
2422of the buffer passed to @code{display-buffer} either matches a regular 2485the name of the buffer passed to @code{display-buffer} matches a
2423expression in this alist or the function specified by a condition 2486regular expression in this alist, or the function specified by a
2424returns non-@code{nil}, then @code{display-buffer} uses the 2487condition returns non-@code{nil}, then @code{display-buffer} uses the
2425corresponding display action to display the buffer. 2488corresponding display action to display the buffer.
2426@end defopt 2489@end defopt
2427 2490
@@ -2437,13 +2500,19 @@ This display action specifies the fallback behavior for
2437@end defvr 2500@end defvr
2438 2501
2439 2502
2440@node Display Action Functions 2503@node Buffer Display Action Functions
2441@section Action Functions for @code{display-buffer} 2504@subsection Action Functions for Buffer Display
2505@cindex buffer display action function
2506@cindex action function, for buffer display
2507
2508An @dfn{action function} is a function @code{display-buffer} calls for
2509choosing a window to display a buffer. Action functions take two
2510arguments: @var{buffer}, the buffer to display, and @var{alist}, an
2511action alist (@pxref{Buffer Display Action Alists}). They are
2512supposed to return a window displaying @var{buffer} if they succeed
2513and @code{nil} if they fail.
2442 2514
2443The following basic action functions are defined in Emacs. Each of 2515 The following basic action functions are defined in Emacs.
2444these functions takes two arguments: @var{buffer}, the buffer to
2445display, and @var{alist}, an action alist. Each action function
2446returns the window if it succeeds, and @code{nil} if it fails.
2447 2516
2448@defun display-buffer-same-window buffer alist 2517@defun display-buffer-same-window buffer alist
2449This function tries to display @var{buffer} in the selected window. 2518This function tries to display @var{buffer} in the selected window.
@@ -2453,57 +2522,99 @@ to another buffer (@pxref{Dedicated Windows}). It also fails if
2453@end defun 2522@end defun
2454 2523
2455@defun display-buffer-reuse-window buffer alist 2524@defun display-buffer-reuse-window buffer alist
2456This function tries to display @var{buffer} by finding a window 2525This function tries to display @var{buffer} by finding a window that
2457that is already displaying it. 2526is already displaying it.
2458 2527
2459If @var{alist} has a non-@code{nil} @code{inhibit-same-window} entry, 2528If @var{alist} has a non-@code{nil} @code{inhibit-same-window} entry,
2460the selected window is not eligible for reuse. If @var{alist} 2529the selected window is not eligible for reuse. The set of frames to
2461contains a @code{reusable-frames} entry, its value determines which 2530search for a window already displaying @var{buffer} can be specified
2462frames to search for a reusable window: 2531with the help of the @code{reusable-frames} action alist entry. If
2463 2532@var{alist} contains no @code{reusable-frames} entry, this function
2464@itemize @bullet 2533searches just the selected frame.
2465@item 2534
2466@code{nil} means consider windows on the selected frame. 2535If this function chooses a window on another frame, it makes that
2467(Actually, the last non-minibuffer frame.) 2536frame visible and, unless @var{alist} contains an
2468@item 2537@code{inhibit-switch-frame} entry, raises that frame if necessary.
2469@code{t} means consider windows on all frames.
2470@item
2471@code{visible} means consider windows on all visible frames.
2472@item
24730 means consider windows on all visible or iconified frames.
2474@item
2475A frame means consider windows on that frame only.
2476@end itemize
2477
2478Note that these meanings differ slightly from those of the
2479@var{all-frames} argument to @code{next-window} (@pxref{Cyclic Window
2480Ordering}).
2481
2482If @var{alist} contains no @code{reusable-frames} entry, this function
2483normally searches just the selected frame; however, if the variable
2484@code{pop-up-frames} is non-@code{nil}, it searches all frames on the
2485current terminal. @xref{Choosing Window Options}.
2486
2487If this function chooses a window on another frame, it makes that frame
2488visible and, unless @var{alist} contains an @code{inhibit-switch-frame}
2489entry (@pxref{Choosing Window Options}), raises that frame if necessary.
2490@end defun 2538@end defun
2491 2539
2492@defun display-buffer-reuse-mode-window buffer alist 2540@defun display-buffer-reuse-mode-window buffer alist
2493This function tries to display @var{buffer} by finding a window 2541This function tries to display @var{buffer} by finding a window
2494that is displaying a buffer in a given mode. 2542that is displaying a buffer in a given mode.
2495 2543
2496If @var{alist} contains a @code{mode} entry, its value is a major mode 2544If @var{alist} contains a @code{mode} entry, its value specifes a
2497(a symbol) or a list of major modes. If @var{alist} contains no 2545major mode (a symbol) or a list of major modes. If @var{alist}
2498@code{mode} entry, the current major mode of @var{buffer} is used. A 2546contains no @code{mode} entry, the current major mode of @var{buffer}
2499window is a candidate if it displays a buffer that derives from one of 2547is used instead. A window is a candidate if it displays a buffer
2500the given modes. 2548whose mode derives from one of the modes specified thusly.
2501 2549
2502The behavior is also controlled by entries for 2550The behavior is also controlled by @var{alist} entries for
2503@code{inhibit-same-window}, @code{reusable-frames} and 2551@code{inhibit-same-window}, @code{reusable-frames} and
2504@code{inhibit-switch-frame} as is done in the function 2552@code{inhibit-switch-frame}, like @code{display-buffer-reuse-window}
2505@code{display-buffer-reuse-window}. 2553does.
2554@end defun
2555
2556@defun display-buffer-pop-up-window buffer alist
2557This function tries to display @var{buffer} by splitting the largest
2558or least recently-used window (usually located on the selected frame).
2559It actually performs the split by calling the function specified by
2560@code{split-window-preferred-function} (@pxref{Choosing Window
2561Options}).
2562
2563The size of the new window can be adjusted by supplying
2564@code{window-height} and @code{window-width} entries in @var{alist}.
2565If @var{alist} contains a @code{preserve-size} entry, Emacs will also
2566try to preserve the size of the new window during future resize
2567operations (@pxref{Preserving Window Sizes}).
2568
2569This function fails if no window can be split. More often than not,
2570this happens because no window is large enough to allow splitting.
2571Setting @code{split-height-threshold} or @code{split-width-threshold}
2572to lower values may help in this regard. Spliting also fails when the
2573selected frame has an @code{unsplittable} frame parameter;
2574@pxref{Buffer Parameters}.
2575@end defun
2576
2577@defun display-buffer-in-previous-window buffer alist
2578This function tries to display @var{buffer} in a window where it was
2579previously displayed. If @var{alist} has a non-@code{nil}
2580@code{inhibit-same-window} entry, the selected window is not eligible
2581for reuse. If @var{alist} contains a @code{reusable-frames} entry,
2582its value determines which frames to search for a suitable window.
2506 2583
2584If @var{alist} has a @code{previous-window} entry and the window
2585specified by that entry is live and not dedicated to another buffer,
2586that window will be preferred, even if it never showed @var{buffer}
2587before.
2588@end defun
2589
2590@defun display-buffer-use-some-window buffer alist
2591This function tries to display @var{buffer} by choosing an existing
2592window and displaying the buffer in that window. It can fail if all
2593windows are dedicated to other buffers (@pxref{Dedicated Windows}).
2594@end defun
2595
2596@defun display-buffer-below-selected buffer alist
2597This function tries to display @var{buffer} in a window below the
2598selected window. If there is a window below the selected one and that
2599window already displays @var{buffer}, it reuses that window.
2600
2601If there is no such window, this function tries to create a new window
2602by splitting the selected one, and displays @var{buffer} there. It will
2603also try to adjust that window's size provided @var{alist} contains a
2604suitable @code{window-height} or @code{window-width} entry, see above.
2605
2606If splitting the selected window fails and there is a non-dedicated
2607window below the selected one showing some other buffer, this function
2608tries to use that window for showing @var{buffer}.
2609@end defun
2610
2611@defun display-buffer-at-bottom buffer alist
2612This function tries to display @var{buffer} in a window at the bottom
2613of the selected frame.
2614
2615This either tries to split the window at the bottom of the frame or
2616the frame's root window, or to reuse an existing window at the bottom
2617of the selected frame.
2507@end defun 2618@end defun
2508 2619
2509@defun display-buffer-pop-up-frame buffer alist 2620@defun display-buffer-pop-up-frame buffer alist
@@ -2511,37 +2622,37 @@ This function creates a new frame, and displays the buffer in that
2511frame's window. It actually performs the frame creation by calling 2622frame's window. It actually performs the frame creation by calling
2512the function specified in @code{pop-up-frame-function} 2623the function specified in @code{pop-up-frame-function}
2513(@pxref{Choosing Window Options}). If @var{alist} contains a 2624(@pxref{Choosing Window Options}). If @var{alist} contains a
2514@code{pop-up-frame-parameters} entry, the associated value 2625@code{pop-up-frame-parameters} entry, the associated value is added to
2515is added to the newly created frame's parameters. 2626the newly created frame's parameters.
2516@end defun 2627@end defun
2517 2628
2518@defun display-buffer-in-child-frame buffer alist 2629@defun display-buffer-in-child-frame buffer alist
2519This function tries to display @var{buffer} in a child frame 2630This function tries to display @var{buffer} in a child frame
2520(@pxref{Child Frames}) of the selected frame, either reusing an existing 2631(@pxref{Child Frames}) of the selected frame, either reusing an
2521child frame or by making a new one. If @var{alist} has a non-@code{nil} 2632existing child frame or by making a new one. If @var{alist} has a
2522@code{child-frame-parameters} entry, the corresponding value is an alist 2633non-@code{nil} @code{child-frame-parameters} entry, the corresponding
2523of frame parameters to give the new frame. A @code{parent-frame} 2634value is an alist of frame parameters to give the new frame. A
2524parameter specifying the selected frame is provided by default. If the 2635@code{parent-frame} parameter specifying the selected frame is
2525child frame should be or become the child of another frame, a 2636provided by default. If the child frame should become the child of
2526corresponding entry must be added to @var{alist}. 2637another frame, a corresponding entry must be added to @var{alist}.
2527 2638
2528The appearance of child frames is largely dependent on the parameters 2639The appearance of child frames is largely dependent on the parameters
2529provided via @var{alist}. It is advisable to use at least ratios to 2640provided via @var{alist}. It is advisable to use at least ratios to
2530specify the size (@pxref{Size Parameters}) and the position 2641specify the size (@pxref{Size Parameters}) and the position
2531(@pxref{Position Parameters}) of the child frame and to add the 2642(@pxref{Position Parameters}) of the child frame, and to add a
2532@code{keep-ratio} in order to make sure that the child frame remains 2643@code{keep-ratio} parameter (@pxref{Frame Interaction Parameters}), in
2533visible. For other parameters that should be considered see @ref{Child 2644order to make sure that the child frame remains visible. For other
2534Frames}. 2645parameters that should be considered see @ref{Child Frames}.
2535@end defun 2646@end defun
2536 2647
2537@defun display-buffer-use-some-frame buffer alist 2648@defun display-buffer-use-some-frame buffer alist
2538This function tries to display @var{buffer} by trying to find a 2649This function tries to display @var{buffer} by finding a frame that
2539frame that meets a predicate (by default any frame other than the 2650meets a predicate (by default any frame other than the selected
2540current frame). 2651frame).
2541 2652
2542If this function chooses a window on another frame, it makes that frame 2653If this function chooses a window on another frame, it makes that
2543visible and, unless @var{alist} contains an @code{inhibit-switch-frame} 2654frame visible and, unless @var{alist} contains an
2544entry (@pxref{Choosing Window Options}), raises that frame if necessary. 2655@code{inhibit-switch-frame} entry, raises that frame if necessary.
2545 2656
2546If @var{alist} has a non-@code{nil} @code{frame-predicate} entry, its 2657If @var{alist} has a non-@code{nil} @code{frame-predicate} entry, its
2547value is a function taking one argument (a frame), returning 2658value is a function taking one argument (a frame), returning
@@ -2549,237 +2660,281 @@ non-@code{nil} if the frame is a candidate; this function replaces the
2549default predicate. 2660default predicate.
2550 2661
2551If @var{alist} has a non-@code{nil} @code{inhibit-same-window} entry, 2662If @var{alist} has a non-@code{nil} @code{inhibit-same-window} entry,
2552the selected window is used; thus if the selected frame has a single 2663the selected window is not used; thus if the selected frame has a
2553window, it is not used. 2664single window, it is not used.
2554@end defun 2665@end defun
2555 2666
2556@defun display-buffer-pop-up-window buffer alist 2667@defun display-buffer-no-window buffer alist
2557This function tries to display @var{buffer} by splitting the largest 2668If @var{alist} has a non-@code{nil} @code{allow-no-window} entry, then
2558or least recently-used window (typically one on the selected frame). 2669this function does not display @var{buffer} and returns the symbol
2559It actually performs the split by calling the function specified in 2670@code{fail}. This constitutes the only exception to the convention
2560@code{split-window-preferred-function} (@pxref{Choosing Window 2671that an action function returns either @code{nil} or a window showing
2561Options}). 2672@var{buffer}. If @var{alist} has no such @code{allow-no-window}
2673entry, this function returns @code{nil}.
2674
2675If this function returns @code{fail}, @code{display-buffer} will skip
2676the execution of any further display actions and return @code{nil}
2677immediately. If this function returns @code{nil},
2678@code{display-buffer} will continue with the next display action, if
2679any.
2562 2680
2563The size of the new window can be adjusted by supplying 2681It is assumed that when a caller of @code{display-buffer} specifies a
2564@code{window-height} and @code{window-width} entries in @var{alist}. To 2682non-@code{nil} @code{allow-no-window} entry, it is also able to handle
2565adjust the window's height, use an entry whose @sc{car} is 2683a @code{nil} return value.
2566@code{window-height} and whose @sc{cdr} is one of: 2684@end defun
2685
2686Two other action functions are described in their proper
2687sections---@code{display-buffer-in-side-window} (@pxref{Displaying
2688Buffers in Side Windows}) and @code{display-buffer-in-atom-window}
2689(@pxref{Atomic Windows}).
2690
2691
2692@node Buffer Display Action Alists
2693@subsection Action Alists for Buffer Display
2694@cindex buffer display action alist
2695@cindex action alist for buffer display
2696
2697An @dfn{action alist} is an association list mapping predefined
2698symbols recognized by action functions to values these functions are
2699supposed to interpret accordingly. In each call,
2700@code{display-buffer} constructs a new, possibly empty action alist
2701and passes that entire list on to any action function it calls.
2702
2703 By design, action functions are free in their interpretation of
2704action alist entries. In fact, some entries like
2705@code{allow-no-window} or @code{previous-window} have a meaning only
2706for one or a few action functions, and are ignored by the rest. Other
2707entries, like @code{inhibit-same-window} or @code{window-parameters},
2708are supposed to be respected by most action functions, including those
2709provided by application programs and external packages.
2710
2711 In the previous subsection we have described in detail how
2712individual action functions interpret the action alist entries they
2713care about. Here we give a reference list of all known action alist
2714entries according to their symbols, together with their values and
2715action functions (@pxref{Buffer Display Action Functions}) that
2716recognize them. Throughout this list, the terms ``buffer'' will refer
2717to the buffer @code{display-buffer} is supposed to display, and
2718``value'' refers to the entry's value.
2719
2720@table @code
2721@vindex inhibit-same-window@r{, a buffer display action alist entry}
2722@item inhibit-same-window
2723If the value is non-@code{nil}, this signals that the selected window
2724must not be used for displaying the buffer. All action functions that
2725(re-)use an existing window should respect this entry.
2726
2727@vindex previous-window@r{, a buffer display action alist entry}
2728@item previous-window
2729The value must specify a window that may have displayed the buffer
2730previously. @code{display-buffer-in-previous-window} will give
2731preference to such a window provided it is still live and not
2732dedicated to another buffer.
2733
2734@vindex mode@r{, a buffer display action alist entry}
2735@item mode
2736The value is either a major mode or a list of major modes.
2737@code{display-buffer-reuse-mode-window} may reuse a window whenever
2738the value specified by this entry matches the major mode of that
2739window's buffer. Other action functions ignore such entries.
2740
2741@vindex frame-predicate@r{, a buffer display action alist entry}
2742@item frame-predicate
2743The value must be a function taking one argument (a frame), supposed
2744to return non-@code{nil} if that frame is a candidate for displaying
2745the buffer. This entry is used by
2746@code{display-buffer-use-some-frame}.
2747
2748@vindex reusable-frames@r{, a buffer display action alist entry}
2749@item reusable-frames
2750The value specifies the frame(s) to search for a window that can be
2751reused because it already displays the buffer. It can be set as
2752follows:
2567 2753
2568@itemize @bullet 2754@itemize @bullet
2569@item 2755@item
2570@code{nil} means to leave the height of the new window alone. 2756@code{nil} means consider only windows on the selected frame.
2757(Actually, the last frame used that is not a minibuffer-only frame.)
2758@item
2759@code{t} means consider windows on all frames.
2760@item
2761@code{visible} means consider windows on all visible frames.
2762@item
27630 means consider windows on all visible or iconified frames.
2764@item
2765A frame means consider windows on that frame only.
2766@end itemize
2767
2768Note that the meaning of @code{nil} differs slightly from that of the
2769@var{all-frames} argument to @code{next-window} (@pxref{Cyclic Window
2770Ordering}).
2771
2772A major client of this is @code{display-buffer-reuse-window}, but all
2773other action functions that try to reuse a window are affected as
2774well.
2775
2776@vindex inhibit-switch-frame@r{, a buffer display action alist entry}
2777@item inhibit-switch-frame
2778A non-@code{nil} value prevents another frame from being raised or
2779selected, if the window chosen by @code{display-buffer} is displayed
2780there. Primarily affected by this are
2781@code{display-buffer-use-some-frame} and
2782@code{display-buffer-reuse-window}.
2783@code{display-buffer-pop-up-frame} should be affected as well, but
2784there is no guarantee that the window manager will comply.
2785
2786@vindex window-parameters@r{, a buffer display action alist entry}
2787@item window-parameters
2788The value specifies an alist of window parameters to give the chosen
2789window. All action functions that choose a window should process this
2790entry.
2791
2792@vindex window-height@r{, a buffer display action alist entry}
2793@item window-height
2794The value specifies whether and how to adjust the height of the chosen
2795window, and can have the following values:
2796
2797@itemize @bullet
2798@item
2799@code{nil} means to leave the height of the chosen window alone.
2571 2800
2572@item 2801@item
2573A number specifies the desired height of the new window. An integer 2802A number specifies the desired height of the chosen window. An
2574specifies the number of lines of the window. A floating-point 2803integer specifies the number of lines of the window. A floating-point
2575number gives the fraction of the window's height with respect to the 2804number gives the fraction of the window's height with respect to the
2576height of the frame's root window. 2805height of the frame's root window.
2577 2806
2578@item 2807@item
2579If the @sc{cdr} specifies a function, that function is called with one 2808If the value specifies a function, that function is called with one
2580argument: the new window. The function is supposed to adjust the 2809argument---the chosen window. The function is supposed to adjust the
2581height of the window; its return value is ignored. Suitable functions 2810height of the window; its return value is ignored. Suitable functions
2582are @code{shrink-window-if-larger-than-buffer} and 2811are @code{shrink-window-if-larger-than-buffer} and
2583@code{fit-window-to-buffer}, see @ref{Resizing Windows}. 2812@code{fit-window-to-buffer}, see @ref{Resizing Windows}.
2584@end itemize 2813@end itemize
2585 2814
2586To adjust the window's width, use an entry whose @sc{car} is 2815All action functions that choose a window should process this entry.
2587@code{window-width} and whose @sc{cdr} is one of: 2816
2817@vindex window-width@r{, a buffer display action alist entry}
2818@item window-width
2819This entry is similar to the @code{window-height} entry described
2820before, but used to adjust the chosen window's width instead. The
2821value can be one of the following:
2588 2822
2589@itemize @bullet 2823@itemize @bullet
2590@item 2824@item
2591@code{nil} means to leave the width of the new window alone. 2825@code{nil} means to leave the width of the chosen window alone.
2592 2826
2593@item 2827@item
2594A number specifies the desired width of the new window. An integer 2828A number specifies the desired width of the chosen window. An integer
2595specifies the number of columns of the window. A floating-point 2829specifies the number of columns of the window. A floating-point
2596number gives the fraction of the window's width with respect to the 2830number gives the fraction of the window's width with respect to the
2597width of the frame's root window. 2831width of the frame's root window.
2598 2832
2599@item 2833@item
2600If the @sc{cdr} specifies a function, that function is called with one 2834If the value specifies a function, that function is called with one
2601argument: the new window. The function is supposed to adjust the width 2835argument---the chosen window. The function is supposed to adjust the
2602of the window; its return value is ignored. 2836width of the window; its return value is ignored.
2603@end itemize 2837@end itemize
2604 2838
2605If @var{alist} contains a @code{preserve-size} entry, Emacs will try to 2839All action functions that choose a window should process this entry.
2606preserve the size of the new window during future resize operations 2840
2607(@pxref{Preserving Window Sizes}). The @sc{cdr} of that entry must be a 2841@vindex preserve-size@r{, a buffer display action alist entry}
2608cons cell whose @sc{car}, if non-@code{nil}, means to preserve the width 2842@item preserve-size
2609of the window and whose @sc{cdr}, if non-@code{nil}, means to preserve 2843If non-@code{nil} such an entry tells Emacs to preserve the size of
2610the height of the window. 2844the window chosen (@pxref{Preserving Window Sizes}). The value should
2611 2845be either @code{(t . nil)} to preserve the width of the window,
2612This function can fail if no window splitting can be performed for some 2846@code{(nil . t)} to preserve its height or @code{(t . t)} to preserve
2613reason (e.g., if the selected frame has an @code{unsplittable} frame 2847both its width and its height. All action functions that choose a
2614parameter; @pxref{Buffer Parameters}). 2848window should process this entry.
2615@end defun 2849
2616 2850@vindex pop-up-frame-parameters@r{, a buffer display action alist entry}
2617@defun display-buffer-below-selected buffer alist 2851@item pop-up-frame-parameters
2618This function tries to display @var{buffer} in a window below the 2852The value specifies an alist of frame parameters to give a new frame,
2619selected window. If there is a window below the selected one and that 2853if one is created. @code{display-buffer-pop-up-frame} is its one and
2620window already displays @var{buffer}, it reuses that window. 2854only addressee.
2621 2855
2622If there is no such window, this function tries to create a new window 2856@vindex parent-frame@r{, a buffer display action alist entry}
2623by splitting the selected one and display @var{buffer} there. It will 2857@item parent-frame
2624also adjust that window's size provided @var{alist} contains a suitable 2858The value specifies the parent frame to be used when the buffer is
2625@code{window-height} or @code{window-width} entry, see above. 2859displayed on a child frame. This entry is used only by
2626 2860@code{display-buffer-in-child-frame}.
2627If splitting the selected window fails and there is a non-dedicated 2861
2628window below the selected one showing some other buffer, it uses that 2862@vindex child-frame-parameters@r{, a buffer display action alist entry}
2629window for showing @var{buffer}. 2863@item child-frame-parameters
2630@end defun 2864The value specifies an alist of frame parameters to use when the buffer
2631 2865is displayed on a child frame. This entry is used only by
2632@defun display-buffer-in-previous-window buffer alist 2866@code{display-buffer-in-child-frame}.
2633This function tries to display @var{buffer} in a window previously 2867
2634showing it. If @var{alist} has a non-@code{nil} 2868@vindex side@r{, a buffer display action alist entry}
2635@code{inhibit-same-window} entry, the selected window is not eligible 2869@item side
2636for reuse. If @var{alist} contains a @code{reusable-frames} entry, its 2870The value denotes the side of the frame or window where a new window
2637value determines which frames to search for a suitable window as with 2871displaying the buffer shall be created. This entry is used by
2638@code{display-buffer-reuse-window}. 2872@code{display-buffer-in-side-window} to indicate the side of the frame
2639 2873where a new side window shall be placed (@pxref{Displaying Buffers in
2640If @var{alist} has a @code{previous-window} entry, the window 2874Side Windows}). It is also used by
2641specified by that entry will override any other window found by the 2875@code{display-buffer-in-atom-window} to indicate the side of an
2642methods above, even if that window never showed @var{buffer} before. 2876existing window where the new window shall be located (@pxref{Atomic
2643@end defun 2877Windows}).
2644
2645@defun display-buffer-at-bottom buffer alist
2646This function tries to display @var{buffer} in a window at the bottom
2647of the selected frame.
2648
2649This either splits the window at the bottom of the frame or the
2650frame's root window, or reuses an existing window at the bottom of the
2651selected frame.
2652@end defun
2653
2654@defun display-buffer-use-some-window buffer alist
2655This function tries to display @var{buffer} by choosing an existing
2656window and displaying the buffer in that window. It can fail if all
2657windows are dedicated to another buffer (@pxref{Dedicated Windows}).
2658@end defun
2659
2660@defun display-buffer-no-window buffer alist
2661If @var{alist} has a non-@code{nil} @code{allow-no-window} entry, then
2662this function does not display @code{buffer}. This allows you to
2663override the default action and avoid displaying the buffer. It is
2664assumed that when the caller specifies a non-@code{nil}
2665@code{allow-no-window} value it can handle a @code{nil} value returned
2666from @code{display-buffer} in this case.
2667@end defun
2668
2669If the @var{alist} argument of any of these functions contains a
2670@code{window-parameters} entry, @code{display-buffer} assigns the
2671elements of the associated value as window parameters of the chosen
2672window.
2673
2674 To illustrate the use of action functions, consider the following
2675example.
2676
2677@example
2678@group
2679(display-buffer
2680 (get-buffer-create "*foo*")
2681 '((display-buffer-reuse-window
2682 display-buffer-pop-up-window
2683 display-buffer-pop-up-frame)
2684 (reusable-frames . 0)
2685 (window-height . 10) (window-width . 40)))
2686@end group
2687@end example
2688
2689@noindent
2690Evaluating the form above will cause @code{display-buffer} to proceed as
2691follows: If a buffer called *foo* already appears on a visible or
2692iconified frame, it will reuse its window. Otherwise, it will try to
2693pop up a new window or, if that is impossible, a new frame and show the
2694buffer there. If all these steps fail, it will proceed using whatever
2695@code{display-buffer-base-action} and
2696@code{display-buffer-fallback-action} prescribe.
2697
2698 Furthermore, @code{display-buffer} will try to adjust a reused window
2699(provided *foo* was put by @code{display-buffer} there before) or a
2700popped-up window as follows: If the window is part of a vertical
2701combination, it will set its height to ten lines. Note that if, instead
2702of the number 10, we specified the function
2703@code{fit-window-to-buffer}, @code{display-buffer} would come up with a
2704one-line window to fit the empty buffer. If the window is part of a
2705horizontal combination, it sets its width to 40 columns. Whether a new
2706window is vertically or horizontally combined depends on the shape of
2707the window split and the values of
2708@code{split-window-preferred-function}, @code{split-height-threshold}
2709and @code{split-width-threshold} (@pxref{Choosing Window Options}).
2710
2711 Now suppose we combine this call with a preexisting setup for
2712@code{display-buffer-alist} as follows.
2713
2714@example
2715@group
2716(let ((display-buffer-alist
2717 (cons
2718 '("\\*foo\\*"
2719 (display-buffer-reuse-window display-buffer-below-selected)
2720 (reusable-frames)
2721 (window-height . 5))
2722 display-buffer-alist)))
2723 (display-buffer
2724 (get-buffer-create "*foo*")
2725 '((display-buffer-reuse-window
2726 display-buffer-pop-up-window
2727 display-buffer-pop-up-frame)
2728 (reusable-frames . 0)
2729 (window-height . 10) (window-width . 40))))
2730@end group
2731@end example
2732 2878
2733@noindent 2879@vindex slot@r{, a buffer display action alist entry}
2734This form will have @code{display-buffer} first try reusing a window 2880@item slot
2735that shows *foo* on the selected frame. If there's no such window, it 2881If non-@code{nil}, the value specifies the slot of the side window
2736will try to split the selected window or, if that is impossible, use the 2882supposed to display the buffer. This entry is used only by
2737window below the selected window. 2883@code{display-buffer-in-side-window}.
2738 2884
2739 If there's no window below the selected one, or the window below the 2885@vindex window@r{, a buffer display action alist entry}
2740selected one is dedicated to its buffer, @code{display-buffer} will 2886@item window
2741proceed as described in the previous example. Note, however, that when 2887The value specifies a window that is in some way related to the window
2742it tries to adjust the height of any reused or popped-up window, it will 2888chosen by @code{display-buffer}. This entry is currently used by
2743in any case try to set its number of lines to 5 since that value 2889@code{display-buffer-in-atom-window} to indicate the window on whose
2744overrides the corresponding specification in the @var{action} argument 2890side the new window shall be created.
2745of @code{display-buffer}. 2891
2892@vindex allow-no-window@r{, a buffer display action alist entry}
2893@item allow-no-window
2894If the value is non-@code{nil}, @code{display-buffer} does not
2895necessarily have to display the buffer and the caller is prepared to
2896accept that. This entry is not intended for user customizations,
2897since there is no guarantee that an arbitrary caller of
2898@code{display-buffer} will be able to handle the case that no window
2899will display the buffer. @code{display-buffer-no-window} is the only
2900action function that cares about this entry.
2901@end table
2746 2902
2747 2903
2748@node Choosing Window Options 2904@node Choosing Window Options
2749@section Additional Options for Displaying Buffers 2905@subsection Additional Options for Displaying Buffers
2750 2906
2751The behavior of the standard display actions of @code{display-buffer} 2907The behavior of buffer display actions (@pxref{Choosing Window}) can
2752(@pxref{Choosing Window}) can be modified by a variety of user 2908be further modified by the following user options.
2753options.
2754 2909
2755@defopt pop-up-windows 2910@defopt pop-up-windows
2756If the value of this variable is non-@code{nil}, @code{display-buffer} 2911If the value of this variable is non-@code{nil}, @code{display-buffer}
2757is allowed to split an existing window to make a new window for 2912is allowed to split an existing window to make a new window for
2758displaying in. This is the default. 2913displaying in. This is the default.
2759 2914
2760This variable is provided mainly for backward compatibility. It is 2915This variable is provided for backward compatibility only. It is
2761obeyed by @code{display-buffer} via a special mechanism in 2916obeyed by @code{display-buffer} via a special mechanism in
2762@code{display-buffer-fallback-action}, which only calls the action 2917@code{display-buffer-fallback-action}, which calls the action function
2763function @code{display-buffer-pop-up-window} (@pxref{Display Action 2918@code{display-buffer-pop-up-window} (@pxref{Buffer Display Action
2764Functions}) when the value is @code{nil}. It is not consulted by 2919Functions}) when the value of this option is non-@code{nil}. It is
2765@code{display-buffer-pop-up-window} itself, which the user may specify 2920not consulted by @code{display-buffer-pop-up-window} itself, which the
2766directly in @code{display-buffer-alist} etc. 2921user may specify directly in @code{display-buffer-alist} etc.
2767@end defopt 2922@end defopt
2768 2923
2769@defopt split-window-preferred-function 2924@defopt split-window-preferred-function
2770This variable specifies a function for splitting a window, in order to 2925This variable specifies a function for splitting a window, in order to
2771make a new window for displaying a buffer. It is used by the 2926make a new window for displaying a buffer. It is used by the
2772@code{display-buffer-pop-up-window} action function to actually split 2927@code{display-buffer-pop-up-window} action function to actually split
2773the window (@pxref{Display Action Functions}). 2928the window.
2774 2929
2775The default value is @code{split-window-sensibly}, which is documented 2930The value must be a function that takes one argument, a window, and
2776below. The value must be a function that takes one argument, a window, 2931returns either a new window (which will be used to display the desired
2777and return either a new window (which will be used to display the 2932buffer) or @code{nil} (which means the splitting failed). The default
2778desired buffer) or @code{nil} (which means the splitting failed). 2933value is @code{split-window-sensibly}, which is documented next.
2779@end defopt 2934@end defopt
2780 2935
2781@defun split-window-sensibly &optional window 2936@defun split-window-sensibly &optional window
2782This function tries to split @var{window}, and return the newly created 2937This function tries to split @var{window} and return the newly created
2783window. If @var{window} cannot be split, it returns @code{nil}. If 2938window. If @var{window} cannot be split, it returns @code{nil}. If
2784@var{window} is omitted or @code{nil}, it defaults to the selected 2939@var{window} is omitted or @code{nil}, it defaults to the selected
2785window. 2940window.
@@ -2790,31 +2945,31 @@ placing the new window below, subject to the restriction imposed by
2790@code{split-height-threshold} (see below), in addition to any other 2945@code{split-height-threshold} (see below), in addition to any other
2791restrictions. If that fails, it tries to split by placing the new 2946restrictions. If that fails, it tries to split by placing the new
2792window to the right, subject to @code{split-width-threshold} (see 2947window to the right, subject to @code{split-width-threshold} (see
2793below). If that fails, and the window is the only window on its 2948below). If that also fails, and the window is the only window on its
2794frame, this function again tries to split and place the new window 2949frame, this function again tries to split and place the new window
2795below, disregarding @code{split-height-threshold}. If this fails as 2950below, disregarding @code{split-height-threshold}. If this fails as
2796well, this function gives up and returns @code{nil}. 2951well, this function gives up and returns @code{nil}.
2797@end defun 2952@end defun
2798 2953
2799@defopt split-height-threshold 2954@defopt split-height-threshold
2800This variable, used by @code{split-window-sensibly}, specifies whether 2955This variable specifies whether @code{split-window-sensibly} is
2801to split the window placing the new window below. If it is an 2956allowed to split the window placing the new window below. If it is an
2802integer, that means to split only if the original window has at least 2957integer, that means to split only if the original window has at least
2803that many lines. If it is @code{nil}, that means not to split this 2958that many lines. If it is @code{nil}, that means not to split this
2804way. 2959way.
2805@end defopt 2960@end defopt
2806 2961
2807@defopt split-width-threshold 2962@defopt split-width-threshold
2808This variable, used by @code{split-window-sensibly}, specifies whether 2963This variable specifies whether @code{split-window-sensibly} is
2809to split the window placing the new window to the right. If the value 2964allowed to split the window placing the new window to the right. If
2810is an integer, that means to split only if the original window has at 2965the value is an integer, that means to split only if the original
2811least that many columns. If the value is @code{nil}, that means not 2966window has at least that many columns. If the value is @code{nil},
2812to split this way. 2967that means not to split this way.
2813@end defopt 2968@end defopt
2814 2969
2815@defopt even-window-sizes 2970@defopt even-window-sizes
2816This variable, if non-@code{nil}, causes @code{display-buffer} to even 2971This variable, if non-@code{nil}, causes @code{display-buffer} to even
2817window sizes whenever it reuses an existing window and that window is 2972window sizes whenever it reuses an existing window, and that window is
2818adjacent to the selected one. 2973adjacent to the selected one.
2819 2974
2820If its value is @code{width-only}, sizes are evened only if the reused 2975If its value is @code{width-only}, sizes are evened only if the reused
@@ -2839,9 +2994,9 @@ search any visible or iconified frame, not just the selected frame.
2839This variable is provided mainly for backward compatibility. It is 2994This variable is provided mainly for backward compatibility. It is
2840obeyed by @code{display-buffer} via a special mechanism in 2995obeyed by @code{display-buffer} via a special mechanism in
2841@code{display-buffer-fallback-action}, which calls the action function 2996@code{display-buffer-fallback-action}, which calls the action function
2842@code{display-buffer-pop-up-frame} (@pxref{Display Action Functions}) 2997@code{display-buffer-pop-up-frame} (@pxref{Buffer Display Action
2843if the value is non-@code{nil}. (This is done before attempting to 2998Functions}) if the value is non-@code{nil}. (This is done before
2844split a window.) This variable is not consulted by 2999attempting to split a window.) This variable is not consulted by
2845@code{display-buffer-pop-up-frame} itself, which the user may specify 3000@code{display-buffer-pop-up-frame} itself, which the user may specify
2846directly in @code{display-buffer-alist} etc. 3001directly in @code{display-buffer-alist} etc.
2847@end defopt 3002@end defopt
@@ -2849,8 +3004,7 @@ directly in @code{display-buffer-alist} etc.
2849@defopt pop-up-frame-function 3004@defopt pop-up-frame-function
2850This variable specifies a function for creating a new frame, in order 3005This variable specifies a function for creating a new frame, in order
2851to make a new window for displaying a buffer. It is used by the 3006to make a new window for displaying a buffer. It is used by the
2852@code{display-buffer-pop-up-frame} action function (@pxref{Display 3007@code{display-buffer-pop-up-frame} action function.
2853Action Functions}).
2854 3008
2855The value should be a function that takes no arguments and returns a 3009The value should be a function that takes no arguments and returns a
2856frame, or @code{nil} if no frame could be created. The default value 3010frame, or @code{nil} if no frame could be created. The default value
@@ -2860,30 +3014,670 @@ is a function that creates a frame using the parameters specified by
2860 3014
2861@defopt pop-up-frame-alist 3015@defopt pop-up-frame-alist
2862This variable holds an alist of frame parameters (@pxref{Frame 3016This variable holds an alist of frame parameters (@pxref{Frame
2863Parameters}), which is used by the default function in 3017Parameters}), which is used by the function specified by
2864@code{pop-up-frame-function} to make a new frame. The default is 3018@code{pop-up-frame-function} to make a new frame. The default is
2865@code{nil}. 3019@code{nil}.
2866@end defopt
2867 3020
2868@defopt same-window-buffer-names 3021This option is provided for backward compatibility only. Note, that
2869A list of buffer names for buffers that should be displayed in the 3022when @code{display-buffer-pop-up-frame} calls the function specified
2870selected window. If a buffer's name is in this list, 3023by @code{pop-up-frame-function}, it prepends the value of all
2871@code{display-buffer} handles the buffer by showing it in the selected 3024@code{pop-up-frame-parameters} action alist entries to
2872window. 3025@code{pop-up-frame-alist} so that the values specified by the action
3026alist entry effectively override any corresponding values of
3027@code{pop-up-frame-alist}.
3028
3029Hence, users should set up a @code{pop-up-frame-parameters} action
3030alist entry in @code{display-buffer-alist} instead of customizing
3031@code{pop-up-frame-alist}. Only this will guarantee that the value of
3032a parameter specified by the user overrides the value of that
3033parameter specified by the caller of @code{display-buffer}.
2873@end defopt 3034@end defopt
2874 3035
2875@defopt same-window-regexps 3036 Many efforts in the design of @code{display-buffer} have been given
2876A list of regular expressions that specify buffers that should be 3037to maintain compatibility with code that uses older options like
2877displayed in the selected window. If the buffer's name matches any of 3038@code{pop-up-windows}, @code{pop-up-frames},
2878the regular expressions in this list, @code{display-buffer} handles the 3039@code{pop-up-frame-alist}, @code{same-window-buffer-names} and
2879buffer by showing it in the selected window. 3040@code{same-window-regexps}. Lisp Programs and users should refrain
2880@end defopt 3041from using these options. Above we already warned against customizing
3042@code{pop-up-frame-alist}. Here we describe how to convert the
3043remaining options to use display actions instead.
3044
3045@table @code
3046@item pop-up-windows
3047@vindex pop-up-windows@r{, replacement for}
3048This variable is @code{t} by default. Instead of customizing it to
3049@code{nil} and thus telling @code{display-buffer} what not to do, it's
3050much better to list in @code{display-buffer-base-action} the action
3051functions it should try instead as, for example:
3052
3053@example
3054@group
3055(customize-set-variable
3056 'display-buffer-base-action
3057 '((display-buffer-reuse-window display-buffer-same-window
3058 display-buffer-in-previous-window
3059 display-buffer-use-some-window)))
3060@end group
3061@end example
3062
3063@item pop-up-frames
3064@vindex pop-up-frames@r{, replacement for}
3065Instead of customizing this variable to @code{t}, customize
3066@code{display-buffer-base-action}, for example, as follows:
3067
3068@example
3069@group
3070(customize-set-variable
3071 'display-buffer-base-action
3072 '((display-buffer-reuse-window display-buffer-pop-up-frame)
3073 (reusable-frames . 0)))
3074@end group
3075@end example
3076
3077@item same-window-buffer-names
3078@itemx same-window-regexps
3079@vindex same-window-buffer-names@r{, replacement for}
3080@vindex same-window-regexps@r{, replacement for}
3081Instead of adding a buffer name or a regular expression to one of
3082these options use a @code{display-buffer-alist} entry for that buffer
3083specifying the action function @code{display-buffer-same-window}.
3084
3085@example
3086@group
3087(customize-set-variable
3088 'display-buffer-alist
3089 (cons '("\\*foo\\*" (display-buffer-same-window))
3090 display-buffer-alist))
3091@end group
3092@end example
3093@end table
3094
3095
3096@node Precedence of Action Functions
3097@subsection Precedence of Action Functions
3098@cindex precedence of buffer display action functions
3099@cindex execution order of buffer display action functions
3100@cindex buffer display action functions, precedence
3101
3102From the past subsections we already know that @code{display-buffer}
3103must be supplied with a number of display actions (@pxref{Choosing
3104Window}) in order to display a buffer. In a completely uncustomized
3105Emacs, these actions are specified by
3106@code{display-buffer-fallback-action} in the following order of
3107precedence: Reuse a window, pop up a new window on the same frame, use
3108a window previously showing the buffer, use some window and pop up a
3109new frame. (Note that the remaining actions named by
3110@code{display-buffer-fallback-action} are void in an uncustomized
3111Emacs).
3112
3113Consider the following form:
3114
3115@example
3116(display-buffer (get-buffer-create "*foo*"))
3117@end example
3118
3119@noindent
3120Evaluating this form in the buffer @file{*scratch*} of an uncustomized
3121Emacs session will usually fail to reuse a window that shows
3122@file{*foo*} already, but succeed in popping up a new window.
3123Evaluating the same form again will now not cause any visible
3124changes---@code{display-buffer} reused the window already showing
3125@file{*foo*} because that action was applicable and had the highest
3126precedence among all applicable actions.
3127
3128 Popping up a new window will fail if there is not enough space on
3129the selected frame. In an uncustomized Emacs it typically fails when
3130there are already two windows on a frame. For example, if you now
3131type @w{@kbd{C-x 1}} followed by @w{@kbd{C-x 2}} and evaluate the form
3132once more, @file{*foo*} should show up in the lower
3133window---@code{display-buffer} just used ``some'' window. If, before
3134typing @w{@kbd{C-x 2}} you had typed @w{@kbd{C-x o}}, @file{*foo*}
3135would have been shown in the upper window because ``some'' window
3136stands for the ``least recently used'' window and the selected window
3137has been least recently used if and only if it is alone on its frame.
3138
3139 Let's assume you did not type @w{@kbd{C-x o}} and @file{*foo*} is
3140shown in the lower window. Type @w{@kbd{C-x o}} to get there followed
3141by @w{@kbd{C-x left}} and evaluate the form again. This should
3142display @file{*foo*} in the same, lower window because that window had
3143already shown @file{*foo*} previously and was therefore chosen instead
3144of some other window.
3145
3146 So far we have only observed the default behavior in an uncustomized
3147Emacs session. To see how this behavior can be customized, let's
3148consider the option @code{display-buffer-base-action}. It provides a
3149very coarse customization which conceptually affects the display of
3150@emph{any} buffer. It can be used to supplement the actions supplied
3151by @code{display-buffer-fallback-action} by reordering them or by
3152adding actions that are not present there but fit more closely the
3153user's editing practice. However, it can also be used to change the
3154default behavior in a more profound way.
3155
3156 Let's consider a user who, as a rule, prefers to display buffers on
3157another frame. Such a user might provide the following customization:
3158
3159@example
3160@group
3161(customize-set-variable
3162 'display-buffer-base-action
3163 '((display-buffer-reuse-window display-buffer-pop-up-frame)
3164 (reusable-frames . 0)))
3165@end group
3166@end example
3167
3168@noindent
3169This setting will cause @code{display-buffer} to first try to find a
3170window showing the buffer on a visible or iconified frame and, if no
3171such frame exists, pop up a new frame. You can observe this behavior
3172on a graphical system by typing @w{@kbd{C-x 1}} in the window showing
3173@file{*scratch*} and evaluating our canonical @code{display-buffer}
3174form. This will usually create (and give focus to) a new frame whose
3175root window shows @file{*foo*}. Iconify that frame and evaluate the
3176canonical form again: @code{display-buffer} will reuse the window on
3177the new frame (usually raising the frame and giving it focus too).
3178
3179 Only if creating a new frame fails, @code{display-buffer} will
3180apply the actions supplied by @code{display-buffer-fallback-action}
3181which means to again try reusing a window, popping up a new window and
3182so on. A trivial way to make frame creation fail is supplied by the
3183following form:
3184
3185@example
3186@group
3187(let ((pop-up-frame-function 'ignore))
3188 (display-buffer (get-buffer-create "*foo*")))
3189@end group
3190@end example
3191
3192@noindent
3193We will forget about that form immediately after observing that it
3194fails to create a new frame and uses a fallback action instead.
3195
3196 Note that @code{display-buffer-reuse-window} appears redundant in
3197the customization of @code{display-buffer-base-action} because it is
3198already part of @code{display-buffer-fallback-action} and should be
3199tried there anyway. However, that would fail because due to the
3200precedence of @code{display-buffer-base-action} over
3201@code{display-buffer-fallback-action}, at that time
3202@code{display-buffer-pop-up-frame} would have already won the race.
3203In fact, this:
3204
3205@example
3206@group
3207(customize-set-variable
3208 'display-buffer-base-action
3209 '(display-buffer-pop-up-frame (reusable-frames . 0)))
3210@end group
3211@end example
3212
3213@noindent
3214would cause @code{display-buffer} to @emph{always} pop up a new frame
3215which is probably not what our user wants.
3216
3217 So far, we have only shown how @emph{users} can customize the
3218default behavior of @code{display-buffer}. Let us now see how
3219@emph{applications} can change the course of @code{display-buffer}.
3220The canonical way to do that is to use the @var{action} argument of
3221@code{display-buffer} or a function that calls it, like, for example,
3222@code{pop-to-buffer} (@pxref{Switching Buffers}).
3223
3224 Suppose an application wants to display @file{*foo*} preferably
3225below the selected window (to immediately attract the attention of the
3226user to the new window) or, if that fails, in a window at the bottom
3227of the frame. It could do that with a call like this:
3228
3229@example
3230@group
3231(display-buffer
3232 (get-buffer-create "*foo*")
3233 '((display-buffer-below-selected display-buffer-at-bottom)))
3234@end group
3235@end example
3236
3237@noindent
3238In order to see how this new, modified form works, delete any frame
3239showing @file{*foo*}, type @w{@kbd{C-x 1}} followed by @w{@kbd{C-x 2}} in the
3240window showing @file{*scratch*}, and subsequently evaluate that form.
3241@code{display-buffer} should split the upper window, and show
3242@file{*foo*} in the new window. Alternatively, if after @w{@kbd{C-x 2}}
3243you had typed @w{@kbd{C-x o}}, @code{display-buffer} would have split the
3244window at the bottom instead.
3245
3246 Suppose now that, before evaluating the new form, you have made the
3247selected window as small as possible, for example, by evaluating the
3248form @code{(fit-window-to-buffer)} in that window. In that case,
3249@code{display-buffer} would have failed to split the selected window
3250and would have split the frame's root window instead, effectively
3251displaying @file{*foo*} at the bottom of the frame.
3252
3253 In either case, evaluating the new form a second time should reuse
3254the window already showing @file{*foo*} since both functions supplied
3255by the @var{action} argument try to reuse such a window first.
3256
3257 By setting the @var{action} argument, an application effectively
3258overrules any customization of @code{display-buffer-base-action}. Our
3259user can now either accept the choice of the application, or redouble
3260by customizing the option @code{display-buffer-alist} as follows:
3261
3262@example
3263@group
3264(customize-set-variable
3265 'display-buffer-alist
3266 '(("\\*foo\\*"
3267 (display-buffer-reuse-window display-buffer-pop-up-frame))))
3268@end group
3269@end example
3270
3271@noindent
3272Trying this with the new, modified form above in a configuration that
3273does not show @file{*foo*} anywhere, will display @file{*foo*} on a
3274separate frame, completely ignoring the @var{action} argument of
3275@code{display-buffer}.
3276
3277 Note that we didn't care to specify a @code{reusable-frames} action
3278alist entry in our specification of @code{display-buffer-alist}.
3279@code{display-buffer} always takes the first one it finds---in our
3280case the one specified by @code{display-buffer-base-action}. If we
3281wanted to use a different specification, for example, to exclude
3282iconified frames showing @file{*foo*} from the list of reusable ones,
3283we would have to specify that separately, however:
3284
3285@example
3286@group
3287(customize-set-variable
3288 'display-buffer-alist
3289 '(("\\*foo\\*"
3290 (display-buffer-reuse-window display-buffer-pop-up-frame)
3291 (reusable-frames . visible))))
3292@end group
3293@end example
3294
3295@noindent
3296If you try this, you will notice that repeated attempts to display
3297@file{*foo*} will succeed to reuse a frame only if that frame is
3298visible.
3299
3300 The above example would allow the conclusion that users customize
3301@code{display-buffer-alist} for the sole purpose to overrule the
3302@var{action} argument chosen by applications. Such a conclusion would
3303be incorrect. @code{display-buffer-alist} is the standard option for
3304users to direct the course of display of specific buffers in a
3305preferred way regardless of whether the display is also guided by an
3306@var{action} argument.
3307
3308 We can, however, reasonably conclude that customizing
3309@code{display-buffer-alist} differs from customizing
3310@code{display-buffer-base-action} in two major aspects: it is stronger
3311because it overrides the @var{action} argument of
3312@code{display-buffer}, and it allows to explicitly specify the
3313affected buffers. In fact, displaying other buffers is not affected
3314in any way by a customization for @file{*foo*}. For example,
3315
3316@example
3317(display-buffer (get-buffer-create "*bar*"))
3318@end example
3319
3320@noindent
3321continues being governed by the settings of
3322@code{display-buffer-base-action} and
3323@code{display-buffer-fallback-action} only.
3324
3325 We could stop with our examples here but Lisp programs still have
3326an ace up their sleeves which they can use to overrule any
3327customization of @code{display-buffer-alist}. It's the variable
3328@code{display-buffer-overriding-action} which they can bind around
3329@code{display-buffer} calls as follows:
3330
3331@example
3332@group
3333(let ((display-buffer-overriding-action
3334 '((display-buffer-same-window))))
3335 (display-buffer
3336 (get-buffer-create "*foo*")
3337 '((display-buffer-below-selected display-buffer-at-bottom))))
3338@end group
3339@end example
3340
3341@noindent
3342Evaluating this form will usually display @file{*foo*} in the selected
3343window regardless of the @var{action} argument and any user
3344customizations. (Usually, an application will not bother to also
3345provide an @var{action} argument. Here it just serves to illustrate
3346the fact that it gets overridden.)
3347
3348It might be illustrative to look at the list of action functions
3349@code{display-buffer} would have tried to display @file{*foo*} with
3350the customizations we provided here. The list (including comments
3351explaining who added this and the subsequent elements) is:
3352
3353@example
3354@group
3355(display-buffer-same-window ;; `display-buffer-overriding-action'
3356 display-buffer-reuse-window ;; `display-buffer-alist'
3357 display-buffer-pop-up-frame
3358 display-buffer-below-selected ;; ACTION argument
3359 display-buffer-at-bottom
3360 display-buffer-reuse-window ;; `display-buffer-base-action'
3361 display-buffer-pop-up-frame
3362 display-buffer--maybe-same-window ;; `display-buffer-fallback-action'
3363 display-buffer-reuse-window
3364 display-buffer--maybe-pop-up-frame-or-window
3365 display-buffer-in-previous-window
3366 display-buffer-use-some-window
3367 display-buffer-pop-up-frame)
3368@end group
3369@end example
3370
3371@noindent
3372Note that among the internal functions listed here,
3373@code{display-buffer--maybe-same-window} is effectively ignored while
3374@code{display-buffer--maybe-pop-up-frame-or-window} actually runs
3375@code{display-buffer-pop-up-window}.
3376
3377The action alist passed in each function call is:
3378
3379@example
3380@group
3381((reusable-frames . visible)
3382 (reusable-frames . 0))
3383@end group
3384@end example
3385
3386@noindent
3387which shows that we have used the second specification of
3388@code{display-buffer-alist} above, overriding the specification
3389supplied by @code{display-buffer-base-action}. Suppose our user had
3390written that as
3391
3392@example
3393@group
3394(customize-set-variable
3395 'display-buffer-alist
3396 '(("\\*foo\\*"
3397 (display-buffer-reuse-window display-buffer-pop-up-frame)
3398 (inhibit-same-window . t)
3399 (reusable-frames . visible))))
3400@end group
3401@end example
3402
3403@noindent
3404In this case the @code{inhibit-same-window} alist entry will
3405successfully invalidate the @code{display-buffer-same-window}
3406specification from @code{display-buffer-overriding-action} and
3407@code{display-buffer} will show @file{*foo*} on another frame. To
3408make @code{display-buffer-overriding-action} more robust in this
3409regard, the application would have to specify an appropriate
3410@code{inhibit-same-window} entry too, for example, as follows:
3411
3412@example
3413@group
3414(let ((display-buffer-overriding-action
3415 '(display-buffer-same-window (inhibit-same-window . nil))))
3416 (display-buffer (get-buffer-create "*foo*")))
3417@end group
3418@end example
3419
3420@noindent
3421This last example shows that while the precedence order of action
3422functions is fixed, as described in @ref{Choosing Window}, an action
3423alist entry specified by a display action ranked lower in that order
3424can affect the execution of a higher ranked display action.
3425
3426
3427@node The Zen of Buffer Display
3428@subsection The Zen of Buffer Display
3429@cindex guidelines for buffer display
3430@cindex writing buffer display actions
3431@cindex buffer display conventions
3432
3433In its most simplistic form, a frame accommodates always one single
3434window that can be used for displaying a buffer. As a consequence, it
3435is always the latest call of @code{display-buffer} that will have
3436succeeded in placing its buffer there.
3437
3438 Since working with such a frame is not very practical, Emacs by
3439default allows for more complex frame layouts controlled by the
3440default values of the frame size and the @code{split-height-threshold}
3441and @code{split-width-threshold} options. Displaying a buffer not yet
3442shown on a frame then either splits the single window on that frame or
3443(re-)uses one of its two windows.
3444
3445 The default behavior is abandoned as soon as the user customizes
3446one of these thresholds or manually changes the frame's layout. The
3447default behavior is also abandoned when calling @code{display-buffer}
3448with a non-@code{nil} @var{action} argument or the user customizes one
3449of the options mentioned in the previous subsections. Mastering
3450@code{display-buffer} soon may become a frustrating experience due to
3451the plethora of applicable display actions and the resulting frame
3452layouts.
3453
3454 However, refraining from using buffer display functions and falling
3455back on a split & delete windows metaphor is not a good idea either.
3456Buffer display functions give Lisp programs and users a framework to
3457reconcile their different needs; no comparable framework exists for
3458splitting and deleting windows. Buffer display functions also allow
3459to at least partially restore the layout of a frame when removing a
3460buffer from it later (@pxref{Quitting Windows}).
3461
3462 Below we will give a number of guidelines to redeem the frustration
3463mentioned above and thus to avoid literally losing buffers in-between
3464the windows of a frame.
3465
3466@table @asis
3467@item Write display actions without stress
3468Writing display actions can be a pain because one has to lump together
3469action functions and action alists in one huge list. (Historical
3470reasons prevented us from having @code{display-buffer} support
3471separate arguments for these.) It might help to memorize some basic
3472forms like the ones listed below:
3473
3474@example
3475'(nil (inhibit-same-window . t))
3476@end example
3477
3478@noindent
3479specifies an action alist entry only and no action function. Its sole
3480purpose is to inhibit a @code{display-buffer-same-window} function
3481specified elsewhere from showing the buffer in the same window, see
3482also the last example of the preceding subsection.
3483
3484@example
3485'(display-buffer-below-selected)
3486@end example
3487
3488@noindent
3489on the other hand, specifies one action function and an empty action
3490alist. To combine the effects of the above two specifications one
3491would write the form
3492
3493@example
3494'(display-buffer-below-selected (inhibit-same-window . t))
3495@end example
3496
3497@noindent
3498to add another action function one would write
3499
3500@example
3501@group
3502'((display-buffer-below-selected display-buffer-at-bottom)
3503 (inhibit-same-window . t))
3504@end group
3505@end example
3506
3507@noindent
3508and to add another alist entry one would write
3509
3510@example
3511@group
3512'((display-buffer-below-selected display-buffer-at-bottom)
3513 (inhibit-same-window . t)
3514 (window-height . fit-window-to-buffer))
3515@end group
3516@end example
3517
3518@noindent
3519That last form can be used as @var{action} argument of
3520@code{display-buffer} in the following way:
3521
3522@example
3523@group
3524(display-buffer
3525 (get-buffer-create "*foo*")
3526 '((display-buffer-below-selected display-buffer-at-bottom)
3527 (inhibit-same-window . t)
3528 (window-height . fit-window-to-buffer)))
3529@end group
3530@end example
3531
3532@noindent
3533In a customization of @code{display-buffer-alist} it would be used as
3534follows:
3535
3536@example
3537@group
3538(customize-set-variable
3539 'display-buffer-alist
3540 '(("\\*foo\\*"
3541 (display-buffer-below-selected display-buffer-at-bottom)
3542 (inhibit-same-window . t)
3543 (window-height . fit-window-to-buffer))))
3544@end group
3545@end example
3546
3547@noindent
3548To add a customization for a second buffer one would then write:
3549
3550@example
3551@group
3552(customize-set-variable
3553 'display-buffer-alist
3554 '(("\\*foo\\*"
3555 (display-buffer-below-selected display-buffer-at-bottom)
3556 (inhibit-same-window . t)
3557 (window-height . fit-window-to-buffer))
3558 ("\\*bar\\*"
3559 (display-buffer-reuse-window display-buffer-pop-up-frame)
3560 (reusable-frames . visible))))
3561@end group
3562@end example
3563
3564@item Treat each other with respect
3565@code{display-buffer-alist} and @code{display-buffer-base-action} are
3566user options---Lisp programs must never set or rebind them.
3567@code{display-buffer-overriding-action}, on the other hand, is
3568reserved for applications---who seldom use that option and if they use
3569it, then with utmost care.
3570
3571 Older implementations of @code{display-buffer} frequently caused
3572users and applications to fight over the settings of user options like
3573@code{pop-up-frames} and @code{pop-up-windows} (@pxref{Choosing Window
3574Options}). This was one major reason for redesigning
3575@code{display-buffer}---to provide a clear framework specifying what
3576users and applications should be allowed to do.
3577
3578 Lisp programs must be prepared that user customizations may
3579cause buffers to get displayed in an unexpected way. They should
3580never assume in their subsequent behavior, that the buffer has been
3581shown precisely the way they asked for in the @var{action} argument of
3582@code{display-buffer}.
3583
3584 Users should not pose too many and too severe restrictions on how
3585arbitrary buffers get displayed. Otherwise, they will risk to lose
3586the characteristics of showing a buffer for a certain purpose.
3587Suppose a Lisp program has been written to compare different versions
3588of a buffer in two windows side-by-side. If the customization of
3589@code{display-buffer-alist} prescribes that any such buffer should be
3590always shown in or below the selected window, the program will have a
3591hard time to set up the desired window configuration via
3592@code{display-buffer}.
3593
3594 To specify a preference for showing an arbitrary buffer, users
3595should customize @code{display-buffer-base-action}. An example of how
3596users who prefer working with multiple frames would do that was given
3597in the previous subsection. @code{display-buffer-alist} should be
3598reserved for displaying specific buffers in a specific way.
3599
3600@item Consider reusing a window that already shows the buffer
3601Generally, it's always a good idea for users and Lisp
3602programmers to be prepared for the case that a window already shows
3603the buffer in question and to reuse that window. In the preceding
3604subsection we have shown that failing to do so properly may cause
3605@code{display-buffer} to continuously pop up a new frame although a
3606frame showing that buffer existed already. In a few cases only, it
3607might be undesirable to reuse a window, for example, when a different
3608portion of the buffer should be shown in that window.
3609
3610 Hence, @code{display-buffer-reuse-window} is one action function
3611that should be used as often as possible, both in @var{action}
3612arguments and customizations. An @code{inhibit-same-window} entry in
3613the @var{action} argument usually takes care of the most common case
3614where reusing a window showing the buffer should be avoided---that
3615where the window in question is the selected one.
3616
3617@item Attract focus to the window chosen
3618This is a no-brainer for people working with multiple frames---the
3619frame showing the buffer will automatically raise and get focus unless
3620an @code{inhibit-switch-frame} entry forbids it. For single frame
3621users this task can be considerably more difficult. In particular,
3622@code{display-buffer-pop-up-window} and
3623@code{display-buffer-use-some-window} can become obtrusive in this
3624regard. They split or use a seemingly arbitrary (often the largest or
3625least recently used) window, distracting the user's attention.
3626
3627Some Lisp programs therefore try to choose a window at the bottom of
3628the frame, for example, in order to display the buffer in vicinity of
3629the minibuffer window where the user is expected to answer a question
3630related to the new window. For non-input related actions
3631@code{display-buffer-below-selected} might be preferable because the
3632selected window usually already has the user's attention.
3633
3634@item Handle subsequent invocations of @code{display-buffer}
3635@code{display-buffer} is not overly well suited for displaying several
3636buffers in sequence and making sure that all these buffers are shown
3637orderly in the resulting window configuration. Again, the standard
3638action functions @code{display-buffer-pop-up-window} and
3639@code{display-buffer-use-some-window} are not very suited for this
3640purpose due to their somewhat chaotic nature in more complex
3641configurations.
3642
3643 To produce a window configuration displaying multiple buffers (or
3644different views of one and the same buffer) in one and the same
3645display cycle, Lisp programmers will unavoidably have to write
3646their own action functions. A few tricks listed below might help in
3647this regard.
3648
3649@itemize @bullet
3650@item
3651Making windows atomic (@pxref{Atomic Windows}) avoids breaking an
3652existing window composition when popping up a new window.
3653The new window will pop up outside the composition instead.
3654
3655@item
3656Temporarily dedicating windows to their buffers (@pxref{Dedicated
3657Windows}) avoids using a window for displaying a different
3658buffer. A non-dedicated window will be used instead.
3659
3660@item
3661Calling @code{window-preserve-size} (@pxref{Preserving Window Sizes})
3662will try to keep the size of the argument window unchanged when
3663popping up a new window. You have to make sure that another window in
3664the same combination can be shrunk instead, though.
3665
3666@item
3667Side windows (@pxref{Side Windows}) can be used for displaying
3668specific buffers always in a window at the same position of a frame.
3669This permits grouping buffers that do not compete for being shown at
3670the same time on a frame and showing any such buffer in the same window
3671without disrupting the display of other buffers.
3672
3673@item
3674Child frames (@pxref{Child Frames}) can be used to display a buffer
3675within the screen estate of the selected frame without disrupting that
3676frame's window configuration and without the overhead associated with
3677full-fledged frames as inflicted by @code{display-buffer-pop-up-frame}.
3678@end itemize
3679@end table
2881 3680
2882@defun same-window-p buffer-name
2883This function returns @code{t} if displaying a buffer
2884named @var{buffer-name} with @code{display-buffer} would
2885put it in the selected window.
2886@end defun
2887 3681
2888@node Window History 3682@node Window History
2889@section Window History 3683@section Window History
@@ -3202,12 +3996,13 @@ main window is either a ``normal'' live window or specifies the area
3202containing all the normal windows. 3996containing all the normal windows.
3203 3997
3204 In their most simple form of use, side windows allow to display 3998 In their most simple form of use, side windows allow to display
3205specific buffers always in the same area of a frame. Hence they can be 3999specific buffers always in the same area of a frame. Hence they can
3206regarded as a generalization of the concept provided by 4000be regarded as a generalization of the concept provided by
3207@code{display-buffer-at-bottom} (@pxref{Display Action Functions}) to 4001@code{display-buffer-at-bottom} (@pxref{Buffer Display Action
3208the remaining sides of a frame. With suitable customizations, however, 4002Functions}) to the remaining sides of a frame. With suitable
3209side windows can be also used to provide frame layouts similar to those 4003customizations, however, side windows can be also used to provide
3210found in so-called integrated development environments (IDEs). 4004frame layouts similar to those found in so-called integrated
4005development environments (IDEs).
3211 4006
3212@menu 4007@menu
3213* Displaying Buffers in Side Windows:: An action function for displaying 4008* Displaying Buffers in Side Windows:: An action function for displaying
@@ -3221,9 +4016,9 @@ found in so-called integrated development environments (IDEs).
3221@node Displaying Buffers in Side Windows 4016@node Displaying Buffers in Side Windows
3222@subsection Displaying Buffers in Side Windows 4017@subsection Displaying Buffers in Side Windows
3223 4018
3224The following action function for @code{display-buffer} (@pxref{Display 4019The following action function for @code{display-buffer} (@pxref{Buffer
3225Action Functions}) creates or reuses a side window for displaying the 4020Display Action Functions}) creates or reuses a side window for
3226specified buffer. 4021displaying the specified buffer.
3227 4022
3228@defun display-buffer-in-side-window buffer alist 4023@defun display-buffer-in-side-window buffer alist
3229This function displays @var{buffer} in a side window of the selected 4024This function displays @var{buffer} in a side window of the selected
@@ -3263,11 +4058,11 @@ explicitly provided via a @code{window-parameters} entry in @var{alist}.
3263@end defun 4058@end defun
3264 4059
3265By default, side windows cannot be split via @code{split-window} 4060By default, side windows cannot be split via @code{split-window}
3266(@pxref{Splitting Windows}). Also, a side window is not reused or split 4061(@pxref{Splitting Windows}). Also, a side window is not reused or
3267by any buffer display action (@pxref{Display Action Functions}) unless 4062split by any buffer display action (@pxref{Buffer Display Action
3268it is explicitly specified as target of that action. Note also that 4063Functions}) unless it is explicitly specified as target of that
3269@code{delete-other-windows} cannot make a side window the only window on 4064action. Note also that @code{delete-other-windows} cannot make a side
3270its frame (@pxref{Deleting Windows}). 4065window the only window on its frame (@pxref{Deleting Windows}).
3271 4066
3272 Once set up, side windows also change the behavior of the commands 4067 Once set up, side windows also change the behavior of the commands
3273@code{switch-to-prev-buffer} and @code{switch-to-next-buffer} 4068@code{switch-to-prev-buffer} and @code{switch-to-next-buffer}
@@ -3453,9 +4248,9 @@ retain their respective sizes when maximizing the frame, the variable
3453@xref{Resizing Windows}. 4248@xref{Resizing Windows}.
3454 4249
3455 The last form also makes sure that none of the created side windows 4250 The last form also makes sure that none of the created side windows
3456are accessible via @kbd{C-x o} by installing the @code{no-other-window} 4251are accessible via @w{@kbd{C-x o}} by installing the @code{no-other-window}
3457parameter for each of these windows. In addition, it makes sure that 4252parameter for each of these windows. In addition, it makes sure that
3458side windows are not deleted via @kbd{C-x 1} by installing the 4253side windows are not deleted via @w{@kbd{C-x 1}} by installing the
3459@code{no-delete-other-windows} parameter for each of these windows. 4254@code{no-delete-other-windows} parameter for each of these windows.
3460 4255
3461 Since @code{dired} buffers have no fixed names, we use a special 4256 Since @code{dired} buffers have no fixed names, we use a special
@@ -3547,7 +4342,7 @@ does is to set the @code{window-atom} parameter of each descendant of
3547 4342
3548To create a new atomic window from an existing live window or to add a 4343To create a new atomic window from an existing live window or to add a
3549new window to an existing atomic window, the following buffer display 4344new window to an existing atomic window, the following buffer display
3550action function (@pxref{Display Action Functions}) can be used: 4345action function (@pxref{Buffer Display Action Functions}) can be used:
3551 4346
3552@defun display-buffer-in-atom-window buffer alist 4347@defun display-buffer-in-atom-window buffer alist
3553This function tries to display @var{buffer} in a new window that will be 4348This function tries to display @var{buffer} in a new window that will be
diff --git a/lisp/emacs-lisp/pcase.el b/lisp/emacs-lisp/pcase.el
index 2746738d41a..a2143bfb9c8 100644
--- a/lisp/emacs-lisp/pcase.el
+++ b/lisp/emacs-lisp/pcase.el
@@ -264,10 +264,14 @@ variable name being but a special case of it)."
264 264
265;;;###autoload 265;;;###autoload
266(defmacro pcase-let* (bindings &rest body) 266(defmacro pcase-let* (bindings &rest body)
267 "Like `let*' but where you can use `pcase' patterns for bindings. 267 "Like `let*', but supports destructuring BINDINGS using `pcase' patterns.
268BODY should be an expression, and BINDINGS should be a list of bindings 268As with `pcase-let', BINDINGS are of the form (PATTERN EXP), but the
269of the form (PATTERN EXP). 269EXP in each binding in BINDINGS can use the results of the destructuring
270See `pcase-let' for discussion of how PATTERN is matched." 270bindings that precede it in BINDINGS' order.
271
272Each EXP should match (i.e. be of compatible structure) to its
273respective PATTERN; a mismatch may signal an error or may go
274undetected, binding variables to arbitrary values, such as nil."
271 (declare (indent 1) 275 (declare (indent 1)
272 (debug ((&rest (pcase-PAT &optional form)) body))) 276 (debug ((&rest (pcase-PAT &optional form)) body)))
273 (let ((cached (gethash bindings pcase--memoize))) 277 (let ((cached (gethash bindings pcase--memoize)))
@@ -280,13 +284,16 @@ See `pcase-let' for discussion of how PATTERN is matched."
280 284
281;;;###autoload 285;;;###autoload
282(defmacro pcase-let (bindings &rest body) 286(defmacro pcase-let (bindings &rest body)
283 "Like `let' but where you can use `pcase' patterns for bindings. 287 "Like `let', but supports destructuring BINDINGS using `pcase' patterns.
284BODY should be a list of expressions, and BINDINGS should be a list of bindings 288BODY should be a list of expressions, and BINDINGS should be a list of
285of the form (PATTERN EXP). 289bindings of the form (PATTERN EXP).
286The PATTERNs are only used to extract data, so the code does not test 290All EXPs are evaluated first, and then used to perform destructuring
287whether the data does match the corresponding patterns: a mismatch 291bindings by matching each EXP against its respective PATTERN. Then
288may signal an error or may go undetected, binding variables to arbitrary 292BODY is evaluated with those bindings in effect.
289values, such as nil." 293
294Each EXP should match (i.e. be of compatible structure) to its
295respective PATTERN; a mismatch may signal an error or may go
296undetected, binding variables to arbitrary values, such as nil."
290 (declare (indent 1) (debug pcase-let*)) 297 (declare (indent 1) (debug pcase-let*))
291 (if (null (cdr bindings)) 298 (if (null (cdr bindings))
292 `(pcase-let* ,bindings ,@body) 299 `(pcase-let* ,bindings ,@body)
@@ -304,11 +311,15 @@ values, such as nil."
304 311
305;;;###autoload 312;;;###autoload
306(defmacro pcase-dolist (spec &rest body) 313(defmacro pcase-dolist (spec &rest body)
307 "Superset of `dolist' where the VAR binding can be a `pcase' PATTERN. 314 "Eval BODY once for each set of bindings defined by PATTERN and LIST elements.
308More specifically, this is just a shorthand for the following combination 315PATTERN should be a `pcase' pattern describing the structure of
309of `dolist' and `pcase-let': 316LIST elements, and LIST is a list of objects that match PATTERN,
310 317i.e. have a structure that is compatible with PATTERN.
311 (dolist (x LIST) (pcase-let ((PATTERN x)) BODY...)) 318For each element of LIST, this macro binds the variables in
319PATTERN to the corresponding subfields of the LIST element, and
320then evaluates BODY with these bindings in effect. The
321destructuring bindings of variables in PATTERN to the subfields
322of the elements of LIST is performed as if by `pcase-let'.
312\n(fn (PATTERN LIST) BODY...)" 323\n(fn (PATTERN LIST) BODY...)"
313 (declare (indent 1) (debug ((pcase-PAT form) body))) 324 (declare (indent 1) (debug ((pcase-PAT form) body)))
314 (if (pcase--trivial-upat-p (car spec)) 325 (if (pcase--trivial-upat-p (car spec))