diff options
| author | Glenn Morris | 2018-11-04 09:37:03 -0800 |
|---|---|---|
| committer | Glenn Morris | 2018-11-04 09:37:03 -0800 |
| commit | 410e65e4ce6f871fd1b8a2ef4b227cbeeb17c1dd (patch) | |
| tree | 7b7272b5ddfc5b51992b590e1ec63136a3f20381 | |
| parent | 4fbdccedd58ffe4cd5f7ed7b744123cc25084bc4 (diff) | |
| parent | 6937c35d3260fe3fc32249313c7e9b6231cbd3dd (diff) | |
| download | emacs-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.texi | 127 | ||||
| -rw-r--r-- | doc/lispref/control.texi | 228 | ||||
| -rw-r--r-- | doc/lispref/elisp.texi | 16 | ||||
| -rw-r--r-- | doc/lispref/frames.texi | 10 | ||||
| -rw-r--r-- | doc/lispref/sequences.texi | 20 | ||||
| -rw-r--r-- | doc/lispref/windows.texi | 1459 | ||||
| -rw-r--r-- | lisp/emacs-lisp/pcase.el | 43 |
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. |
| 49 | Also, all commands that display information in a window, including | 49 | Also, 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 |
| 52 | window without affecting the selected window. | 52 | nonselected 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 |
| 55 | regions, because they can have different values of point. However, | 55 | regions, because they can have different values of point. However, |
| @@ -347,11 +347,9 @@ heights of all the windows in the selected frame. | |||
| 347 | in response to a user command. There are several different ways in | 347 | in response to a user command. There are several different ways in |
| 348 | which commands do this. | 348 | which 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 |
| 351 | buffer by ``taking over'' the selected window, expecting that the | 351 | display the buffer by ``taking over'' the selected window, expecting |
| 352 | user's attention will be diverted to that buffer. These commands | 352 | that the user's attention will be diverted to that buffer. |
| 353 | usually 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 |
| 357 | over the selected window, e.g., by splitting off a new window and | 355 | over 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 |
| 377 | selected window and (ii) prefer to create a new frame to display the | 375 | selected window and (ii) prefer to either create a new frame or use a |
| 378 | desired buffer instead of splitting a window---as though the variable | 376 | window on some other frame to display the desired buffer. Several of |
| 379 | @code{pop-up-frames} is set to @code{t} (@pxref{Window Choice}). | 377 | these commands are bound in the @kbd{C-x 5} prefix key. |
| 380 | Several 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 | ||
| 391 | The @code{display-buffer} command (as well as commands that call it | 388 | The @code{display-buffer} command (as well as commands that call it |
| 392 | internally) chooses a window to display by following the steps given | 389 | internally) chooses a window to display by following the steps given |
| 393 | below. @xref{Choosing Window,,Choosing a Window for Display, elisp, | 390 | below. @xref{Choosing Window,,Choosing a Window for Displaying a |
| 394 | The Emacs Lisp Reference Manual}, for details about how to alter this | 391 | Buffer, elisp, The Emacs Lisp Reference Manual}, for details about how |
| 395 | sequence of steps. | 392 | to 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 |
| 401 | First, check if the buffer should be displayed in the selected window | 396 | If the buffer should be displayed in the selected window regardless of |
| 402 | regardless of other considerations. You can tell Emacs to do this by | 397 | other considerations, reuse the selected window. By default, this |
| 403 | adding the desired buffer's name to the list | 398 | step 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 | 399 | regular expression matching the buffer's name together with a |
| 405 | expression to the list @code{same-window-regexps}. By default, these | 400 | reference to the @code{display-buffer-same-window} action function |
| 406 | variables are @code{nil}, so this step is skipped. | 401 | (@pxref{Buffer Display Action Functions,,Action Functions for Buffer |
| 402 | Display, elisp, The Emacs Lisp Reference Manual}) to the option | ||
| 403 | @code{display-buffer-alist} (@pxref{Choosing Window,,Choosing a Window | ||
| 404 | for Displaying a Buffer, elisp, The Emacs Lisp Reference Manual}). | ||
| 405 | For example, to display the buffer @file{*scratch*} preferably in the | ||
| 406 | selected 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 | |||
| 416 | By default, @code{display-buffer-alist} is @code{nil}. | ||
| 407 | 417 | ||
| 408 | @item | 418 | @item |
| 409 | Otherwise, if the buffer is already displayed in an existing window, | 419 | Otherwise, if the buffer is already displayed in an existing window, |
| 410 | reuse that window. Normally, only windows on the selected frame | 420 | reuse that window. Normally, only windows on the selected frame are |
| 411 | are considered, but windows on other frames are also reusable if you | 421 | considered, but windows on other frames are also reusable if you use |
| 412 | change @code{pop-up-frames} (see below) to @code{t}. | 422 | the corresponding @code{reusable-frames} action alist entry |
| 423 | (@pxref{Buffer Display Action Alists,,Action Alists for Buffer | ||
| 424 | Display, elisp, The Emacs Lisp Reference Manual}). See the | ||
| 425 | next step for an example of how to do that. | ||
| 413 | 426 | ||
| 414 | @vindex pop-up-frames | ||
| 415 | @item | 427 | @item |
| 416 | Otherwise, optionally create a new frame and display the buffer there. | 428 | Otherwise, optionally create a new frame and display the buffer there. |
| 417 | By default, this step is skipped. To enable it, change the variable | 429 | By 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 | 430 | the option @code{display-buffer-base-action} (@pxref{Choosing |
| 419 | @code{graphic-only} means to do this only on graphical displays. | 431 | Window,,Choosing a Window for Displaying a Buffer, elisp, The Emacs |
| 432 | Lisp 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 | |||
| 443 | This customization will also try to make the preceding step search for | ||
| 444 | a reusable window on all visible or iconified frames. | ||
| 420 | 445 | ||
| 421 | @item | 446 | @item |
| 422 | Otherwise, try to create a new window by splitting a window on the | 447 | Otherwise, 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 |
| 438 | Otherwise, display the buffer in a window previously showing it. | 463 | Otherwise, display the buffer in a window previously showing it. |
| 439 | Normally, only windows on the selected frame are considered, but if | 464 | Normally, 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 | 465 | a suitable @code{reusable-frames} action alist entry (see above) the |
| 441 | frame. | 466 | window may be also on another frame. |
| 442 | 467 | ||
| 443 | @item | 468 | @item |
| 444 | Otherwise, display the buffer in an existing window on the selected | 469 | Otherwise, 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 | |||
| 449 | and display the buffer there. | 474 | and display the buffer there. |
| 450 | @end itemize | 475 | @end itemize |
| 451 | 476 | ||
| 452 | A more advanced and flexible way to customize the behavior of | ||
| 453 | @code{display-buffer} is by using the option @code{display-buffer-alist} | ||
| 454 | mentioned 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 | ||
| 462 | Some buffers are shown in windows for perusal rather than for editing. | 482 | Some buffers are shown in windows for perusal rather than for editing. |
| 463 | Help commands (@pxref{Help}) typically use a buffer called @file{*Help*} | 483 | Help commands (@pxref{Help}) typically use a buffer called @file{*Help*} |
| 464 | for that purpose, minibuffer completion (@pxref{Completion}) uses a | 484 | for that purpose, minibuffer completion (@pxref{Completion}) uses a |
| 465 | buffer called @file{*Completions*} instead. Such buffers are usually | 485 | buffer called @file{*Completions*}, etc. Such buffers are usually |
| 466 | displayed only for a short period of time. | 486 | displayed 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 |
| 470 | buffer, on the other hand, is normally displayed in a window at the | 490 | @file{*Completions*} buffer, on the other hand, is normally displayed |
| 471 | bottom of the selected frame, regardless of the number of windows | 491 | in a window at the bottom of the selected frame, regardless of the |
| 472 | already shown on that frame. | 492 | number 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 |
| 475 | fashion, we recommend customizing the variable | 495 | fashion, 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, |
| 477 | for Display, elisp, The Emacs Lisp Reference Manual}). For example, | 497 | elisp, The Emacs Lisp Reference Manual}) appropriately. For example, |
| 478 | to display @file{*Completions*} by splitting a window as described in | 498 | to display @file{*Completions*} always below the selected window, use |
| 479 | the previous section, use the following form in your initialization | 499 | the following form in your initialization file (@pxref{Init File}): |
| 480 | file (@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 |
| 492 | Emacs usually tries to make its window just as large as necessary to | 511 | Emacs usually tries to make its window just as large as necessary to |
| 493 | display all of its contents. To resize windows showing other | 512 | display all of its contents. To resize windows showing other |
| 494 | temporary displays like, for example, the @file{*Help*} buffer | 513 | temporary displays, like, for example, the @file{*Help*} buffer, turn |
| 495 | accordingly, turn on the minor mode (@pxref{Minor Modes}) | 514 | on 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 |
| 497 | Displays, elisp, The Emacs Lisp Reference Manual}). | 516 | Reference 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}). | |||
| 502 | can be controlled by customizing the options | 521 | can 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 |
| 505 | Reference Manual}) and cannot exceed the size of the containing frame. | 524 | Reference 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 | ||
| 424 | Aside from the four basic conditional forms, Emacs Lisp also | 424 | Aside from the four basic conditional forms, Emacs Lisp also |
| 425 | has a pattern-matching conditional form, the @code{pcase} macro, | 425 | has a pattern-matching conditional form, the @code{pcase} macro, |
| 426 | a hybrid of @code{cond} and @code{cl-case} | 426 | a hybrid of @code{cond} and @code{cl-case} |
| 427 | (@pxref{Conditionals,,,cl,Common Lisp Extensions}) | 427 | (@pxref{Conditionals,,,cl,Common Lisp Extensions}) |
| 428 | that overcomes their limitations and introduces | 428 | that overcomes their limitations and introduces |
| 429 | the @dfn{pattern matching} programming style. | 429 | the @dfn{pattern matching programming style}. |
| 430 | First, the limitations: | 430 | The limitations that @code{pcase} overcomes are: |
| 431 | 431 | ||
| 432 | @itemize | 432 | @itemize |
| 433 | @item The @code{cond} form chooses among alternatives | 433 | @item |
| 434 | by evaluating the predicate @var{condition} of each | 434 | The @code{cond} form chooses among alternatives by evaluating the |
| 435 | of its clauses (@pxref{Conditionals}). | 435 | predicate @var{condition} of each of its clauses |
| 436 | The primary limitation is that variables let-bound in @var{condition} | 436 | (@pxref{Conditionals}). The primary limitation is that variables |
| 437 | are not available to the clause's @var{body-forms}. | 437 | let-bound in @var{condition} are not available to the clause's |
| 438 | @var{body-forms}. | ||
| 438 | 439 | ||
| 439 | Another annoyance (more an inconvenience than a limitation) | 440 | Another annoyance (more an inconvenience than a limitation) |
| 440 | is that when a series of @var{condition} predicates implement | 441 | is that when a series of @var{condition} predicates implement |
| 441 | equality tests, there is a lot of repeated code. | 442 | equality tests, there is a lot of repeated code. (@code{cl-case} |
| 442 | For that, why not use @code{cl-case}? | 443 | solves this inconvenience.) |
| 443 | 444 | ||
| 444 | @item | 445 | @item |
| 445 | The @code{cl-case} macro chooses among alternatives by evaluating | 446 | The @code{cl-case} macro chooses among alternatives by evaluating |
| 446 | the equality of its first argument against a set of specific | 447 | the equality of its first argument against a set of specific |
| 447 | values. | 448 | values. |
| 448 | The limitations are two-fold: | 449 | |
| 450 | Its 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. | 454 | The equality tests use @code{eql}. |
| 455 | @item | ||
| 456 | The values must be known and written in advance. | ||
| 453 | @end enumerate | 457 | @end enumerate |
| 454 | 458 | ||
| 455 | @noindent | 459 | @noindent |
| 456 | These render @code{cl-case} unsuitable for strings or compound | 460 | These render @code{cl-case} unsuitable for strings or compound |
| 457 | data structures (e.g., lists or vectors). | 461 | data structures (e.g., lists or vectors). (@code{cond} doesn't have |
| 458 | For that, why not use @code{cond}? | 462 | these 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 |
| 463 | Conceptually, the @code{pcase} macro borrows the first-arg focus | 466 | Conceptually, the @code{pcase} macro borrows the first-arg focus |
| 464 | of @code{cl-case} and the clause-processing flow of @code{cond}, | 467 | of @code{cl-case} and the clause-processing flow of @code{cond}, |
| 465 | replacing @var{condition} with a generalization of | 468 | replacing @var{condition} with a generalization of |
| 466 | the equality test called @dfn{matching}, | 469 | the equality test which is a variant of @dfn{pattern matching}, |
| 467 | and adding facilities so that you can concisely express a | 470 | and adding facilities so that you can concisely express a |
| 468 | clause's predicate, and arrange to share let-bindings between | 471 | clause's predicate, and arrange to share let-bindings between |
| 469 | a clause's predicate and @var{body-forms}. | 472 | a clause's predicate and @var{body-forms}. |
| 470 | 473 | ||
| 471 | The concise expression of a predicate is known as a @dfn{pattern}. | 474 | The concise expression of a predicate is known as a @dfn{pattern}. |
| 472 | When the predicate, called on the value of the first arg, | 475 | When the predicate, called on the value of the first arg, returns |
| 473 | returns non-@code{nil}, the pattern matches the value | 476 | non-@code{nil}, we say that ``the pattern matches the value'' (or |
| 474 | (or sometimes ``the value matches the pattern''). | 477 | sometimes ``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. | |||
| 498 | Otherwise, @code{pcase} evaluates to @code{nil}. | 501 | Otherwise, @code{pcase} evaluates to @code{nil}. |
| 499 | @end defmac | 502 | @end defmac |
| 500 | 503 | ||
| 501 | Each @var{pattern} has to be a @dfn{pcase pattern}, which can either | 504 | @cindex pcase pattern |
| 502 | use one of the core patterns defined below, or use one of the patterns | 505 | Each @var{pattern} has to be a @dfn{pcase pattern}, which can use |
| 503 | defined via @code{pcase-defmacro}. | 506 | either one of the core patterns defined below, or one of the patterns |
| 507 | defined via @code{pcase-defmacro} (@pxref{Extending pcase}). | ||
| 504 | 508 | ||
| 505 | The rest of this subsection | 509 | The rest of this subsection describes different forms of core |
| 506 | describes different forms of core patterns, | 510 | patterns, presents some examples, and concludes with important caveats |
| 507 | presents some examples, | 511 | on using the let-binding facility provided by some pattern forms. A |
| 508 | and concludes with important caveats on using the | 512 | core pattern can have the following forms: |
| 509 | let-binding facility provided by some pattern forms. | ||
| 510 | A core pattern can have the following forms: | ||
| 511 | 513 | ||
| 512 | @table @code | 514 | @table @code |
| 513 | 515 | ||
| 514 | @item _ | 516 | @item _ |
| 515 | Matches any @var{expval}. | 517 | Matches any @var{expval}. |
| 516 | This is known as @dfn{don't care} or @dfn{wildcard}. | 518 | This is also known as @dfn{don't care} or @dfn{wildcard}. |
| 517 | 519 | ||
| 518 | @item '@var{val} | 520 | @item '@var{val} |
| 519 | Matches if @var{expval} is @code{equal} to @var{val}. | 521 | Matches if @var{expval} equals @var{val}. The comparison is done as |
| 522 | if 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} |
| 524 | Matches if @var{expval} is @code{equal} to the literal object. | 527 | Matches if @var{expval} equals the literal object. |
| 525 | This is a special case of @code{'@var{val}}, above, | 528 | This is a special case of @code{'@var{val}}, above, |
| 526 | possible because literal objects of these types are self-quoting. | 529 | possible 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 | |||
| 533 | If @var{symbol} is part of a sequencing pattern @var{seqpat} | 536 | If @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 |
| 535 | the portion of @var{seqpat} following the appearance of @var{symbol}. | 538 | the portion of @var{seqpat} following the appearance of @var{symbol}. |
| 536 | This usage has some caveats (@pxref{pcase-symbol-caveats,,caveats}). | 539 | This usage has some caveats, see @ref{pcase-symbol-caveats,,caveats}. |
| 537 | 540 | ||
| 538 | Two symbols to avoid are @code{t}, which behaves like @code{_} | 541 | Two 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. |
| 540 | Likewise, it makes no sense to bind keyword symbols | 543 | Likewise, 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}) |
| 544 | Matches if the predicate @var{function} returns non-@code{nil} | 547 | Matches if the predicate @var{function} returns non-@code{nil} |
| 545 | when called on @var{expval}. | 548 | when called on @var{expval}. |
| 546 | @var{function} can have one of the possible forms: | 549 | the 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}) |
| 571 | Matches if @var{function} called on @var{expval} returns a | 574 | Matches if @var{function} called on @var{expval} returns a |
| 572 | value that matches @var{pattern}. | 575 | value 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}, |
| 574 | forms described for @code{pred}, above. | 577 | above. Unlike @code{pred}, however, @code{app} tests the result |
| 575 | Unlike @code{pred}, however, | 578 | against @var{pattern}, rather than against a boolean truth value. |
| 576 | @code{app} tests the result against @var{pattern}, | ||
| 577 | rather than against a boolean truth value. | ||
| 578 | 579 | ||
| 579 | @item (guard @var{boolean-expression}) | 580 | @item (guard @var{boolean-expression}) |
| 580 | Matches if @var{boolean-expression} evaluates to non-@code{nil}. | 581 | Matches 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}) |
| 583 | Evaluates @var{expr} to get @var{exprval} | 584 | Evaluates @var{expr} to get @var{exprval} and matches if @var{exprval} |
| 584 | and matches if @var{exprval} matches @var{pattern}. | 585 | matches @var{pattern}. (It is called @code{let} because @var{pattern} |
| 585 | (It is called @code{let} because | 586 | can 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{}) |
| 599 | Attempts to match @var{pattern1}@dots{}, in order, | 599 | Attempts to match @var{pattern1}@dots{}, in order, until one of them |
| 600 | until one of them fails to match. | 600 | fails to match. In that case, @code{and} likewise fails to match, and |
| 601 | In that case, @code{and} likewise fails to match, | 601 | the rest of the sub-patterns are not tested. If all sub-patterns |
| 602 | and the rest of the sub-patterns are not tested. | 602 | match, @code{and} matches. |
| 603 | If 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{}) |
| 606 | Attempts to match @var{pattern1}, @var{pattern2}, @dots{}, in order, | 605 | Attempts to match @var{pattern1}, @var{pattern2}, @dots{}, in order, |
| 607 | until one of them succeeds. | 606 | until one of them succeeds. In that case, @code{or} likewise matches, |
| 608 | In that case, @code{or} likewise matches, | 607 | and the rest of the sub-patterns are not tested. (Note that there |
| 609 | and the rest of the sub-patterns are not tested. | 608 | must be at least two sub-patterns. |
| 610 | (Note that there must be at least two sub-patterns. | ||
| 611 | Simply @w{@code{(or @var{pattern1})}} signals error.) | 609 | Simply @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 | ||
| 1043 | This subsection describes @dfn{backquote-style patterns}, | 1041 | This subsection describes @dfn{backquote-style patterns}, |
| 1044 | a set of builtin patterns that eases structural matching. | 1042 | a set of builtin patterns that eases structural matching. |
| 1045 | For background, @xref{Pattern-Matching Conditional}. | 1043 | For background, @pxref{Pattern-Matching Conditional}. |
| 1046 | 1044 | ||
| 1047 | @dfn{Backquote-style patterns} are a powerful set of | 1045 | Backquote-style patterns are a powerful set of @code{pcase} pattern |
| 1048 | @code{pcase} pattern extensions (created using @code{pcase-defmacro}) | 1046 | extensions (created using @code{pcase-defmacro}) that make it easy to |
| 1049 | that make it easy to match @var{expval} against | 1047 | match @var{expval} against specifications of its @emph{structure}. |
| 1050 | specifications of its @emph{structure}. | ||
| 1051 | 1048 | ||
| 1052 | For example, to match @var{expval} that must be a list of two | 1049 | For example, to match @var{expval} that must be a list of two |
| 1053 | elements whose first element is a specific string and the second | 1050 | elements 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 | ||
| 1178 | Pcase patterns not only express a condition on the form of the objects | 1175 | Pcase patterns not only express a condition on the form of the objects |
| 1179 | they can match but they can also extract sub-fields of those objects. | 1176 | they can match, but they can also extract sub-fields of those objects. |
| 1180 | Say we have a list and want to extract 2 elements from it with the | 1177 | For example we can extract 2 elements from a list that is the value of |
| 1181 | following code: | 1178 | the 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 | ||
| 1188 | This will not only extract @code{x} and @code{y} but will additionally | 1185 | This will not only extract @code{x} and @code{y} but will additionally |
| 1189 | test that @code{l} is a list containing exactly 3 elements and whose | 1186 | test that @code{my-list} is a list containing exactly 3 elements and |
| 1190 | first element is the symbol @code{add}. If any of those tests fail, | 1187 | whose first element is the symbol @code{add}. If any of those tests |
| 1191 | @code{pcase} will directly return @code{nil} without calling | 1188 | fail, @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 | 1191 | Extraction of multiple values stored in an object is known as |
| 1195 | multiple values stored in the object, e.g., the 2nd and the 3rd | 1192 | @dfn{destructuring}. Using @code{pcase} patterns allows to perform |
| 1196 | element of a list or a vector. @dfn{Destructuring binding} is | 1193 | @dfn{destructuring binding}, which is similar to a local binding |
| 1197 | similar to a local binding (@pxref{Local Variables}), but it gives | 1194 | (@pxref{Local Variables}), but gives values to multiple elements of |
| 1198 | values to multiple elements of a variable by extracting those values | 1195 | a variable by extracting those values from an object of compatible |
| 1199 | from an object of compatible structure. | 1196 | structure. |
| 1200 | 1197 | ||
| 1201 | The macros described in this section use @dfn{destructuring | 1198 | The macros described in this section use @code{pcase} patterns to |
| 1202 | patterns}, which are normal Pcase patterns used in a context where we | 1199 | perform destructuring binding. The condition of the object to be of |
| 1203 | presume that the object does match the pattern, and we only want | 1200 | compatible structure means that the object must match the pattern, |
| 1204 | to extract some subfields. For example: | 1201 | because only then the object's subfields can be extracted. For |
| 1202 | example: | ||
| 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 |
| 1212 | does the same as the previous example, except that it directly tries | 1210 | does the same as the previous example, except that it directly tries |
| 1213 | to extract @code{x} and @code{y} from @code{l} without first verifying | 1211 | to extract @code{x} and @code{y} from @code{my-list} without first |
| 1214 | if @code{l} is a list which has the right number of elements and has | 1212 | verifying if @code{my-list} is a list which has the right number of |
| 1215 | @code{add} as its first element. | 1213 | elements and has @code{add} as its first element. The precise |
| 1216 | The precise behavior when the object does not actually match the | 1214 | behavior when the object does not actually match the pattern is |
| 1217 | pattern is undefined, although the body will not be silently skipped: | 1215 | undefined, although the body will not be silently skipped: either an |
| 1218 | either an error is signaled or the body is run with some of the | 1216 | error is signaled or the body is run with some of the variables |
| 1219 | variables potentially bound to arbitrary values like @code{nil}. | 1217 | potentially bound to arbitrary values like @code{nil}. |
| 1218 | |||
| 1219 | The pcase patterns that are useful for destructuring bindings are | ||
| 1220 | generally those described in @ref{Backquote Patterns}, since they | ||
| 1221 | express a specification of the structure of objects that will match. | ||
| 1222 | |||
| 1223 | For 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{} |
| 1222 | Bind variables according to @var{bindings} and then eval @var{body}. | 1227 | Perform 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 | ||
| 1228 | All @var{exp}s are evaluated first after which they are matched | 1234 | All @var{exp}s are evaluated first, after which they are matched |
| 1229 | against their respective @var{pattern}, introducing new variable | 1235 | against their respective @var{pattern}, introducing new variable |
| 1230 | bindings which can then be used inside @var{body}. | 1236 | bindings that can then be used inside @var{body}. The variable |
| 1237 | bindings are produced by destructuring binding of elements of | ||
| 1238 | @var{pattern} to the values of the corresponding elements of the | ||
| 1239 | evaluated @var{exp}. | ||
| 1231 | @end defmac | 1240 | @end defmac |
| 1232 | 1241 | ||
| 1233 | @defmac pcase-let* bindings body@dots{} | 1242 | @defmac pcase-let* bindings body@dots{} |
| 1234 | Bind variables according to @var{bindings} and then eval @var{body}. | 1243 | Perform 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 | 1249 | produced by destructuring binding of elements of @var{pattern} to the | |
| 1240 | Unlike @code{pcase-let}, but like @code{let*}, each @var{exp} is | 1250 | values of the corresponding elements of the evaluated @var{exp}. |
| 1241 | matched against its corresponding @var{pattern} before passing to the | 1251 | |
| 1242 | next element of @var{bindings}, so the variables introduced in each | 1252 | Unlike @code{pcase-let}, but similarly to @code{let*}, each @var{exp} |
| 1243 | binding are available in the @var{exp}s that follow it, additionally | 1253 | is matched against its corresponding @var{pattern} before processing |
| 1244 | to being available in @var{body}. | 1254 | the next element of @var{bindings}, so the variable bindings |
| 1255 | introduced in each one of the @var{bindings} are available in the | ||
| 1256 | @var{exp}s of the @var{bindings} that follow it, additionally to | ||
| 1257 | being 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{} |
| 1249 | This construct executes @var{body} once for each element of | 1261 | Execute @var{body} once for each element of @var{list}, on each |
| 1250 | @var{list}, in a context where the variables appearing in the the | 1262 | iteration performing a destructuring binding of variables in |
| 1251 | destructuring pattern @var{pattern} are bound to the corresponding | 1263 | @var{pattern} to the values of the corresponding subfields of the |
| 1252 | values found in the element. | 1264 | element of @var{list}. The bindings are performed as if by |
| 1253 | When @var{pattern} is a simple variable, this ends up being equivalent | 1265 | @code{pcase-let}. When @var{pattern} is a simple variable, this ends |
| 1254 | to @code{dolist}. | 1266 | up 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 | ||
| 1070 | Displaying 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 | |||
| 1072 | Side Windows | 1082 | Side 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 |
| 3265 | the frame's @code{auto-hide-function} parameter (@pxref{Frame | 3265 | Functions}), the frame's @code{auto-hide-function} parameter |
| 3266 | Interaction Parameters}) can be set to a function, in order to | 3266 | (@pxref{Frame Interaction Parameters}) can be set to a function, in |
| 3267 | appropriately deal with the frame when the window displaying the buffer | 3267 | order to appropriately deal with the frame when the window displaying |
| 3268 | shall be quit. | 3268 | the 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, |
| 3271 | to display completions in a separate window, the @code{minibuffer-exit} | 3271 | to 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 | |||
| 1049 | primarily useful for side-effects. | 1049 | primarily 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 |
| 1055 | elements of @var{sequence}. @var{arguments} can themselves include | 1056 | values that are the corresponding elements of @var{val-sequence}. |
| 1056 | sequences, allowing for nested destructuring. | 1057 | This is known as @dfn{destructuring binding}. The elements of |
| 1058 | @var{var-sequence} can themselves include sequences, allowing for | ||
| 1059 | nested destructuring. | ||
| 1057 | 1060 | ||
| 1058 | The @var{arguments} sequence can also include the @code{&rest} marker | 1061 | The @var{var-sequence} sequence can also include the @code{&rest} |
| 1059 | followed by a variable name to be bound to the rest of | 1062 | marker 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 | |||
| 1088 | The @code{pcase} patterns provide an alternative facility for | ||
| 1089 | destructuring 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 | |||
| 1542 | window is created anyway). | 1540 | window is created anyway). |
| 1543 | 1541 | ||
| 1544 | @item window-size | 1542 | @item window-size |
| 1545 | This means that @code{display-buffer} makes a new parent window when it | 1543 | This means that @code{display-buffer} makes a new parent window when |
| 1546 | splits a window and is passed a @code{window-height} or | 1544 | it 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 |
| 1548 | Action Functions}). Otherwise, window splitting behaves as for a value | 1546 | Display Action Functions}). Otherwise, window splitting behaves as |
| 1549 | of @code{nil}. | 1547 | for a value of @code{nil}. |
| 1550 | 1548 | ||
| 1551 | @item temp-buffer-resize | 1549 | @item temp-buffer-resize |
| 1552 | In this case @code{with-temp-buffer-window} makes a new parent window | 1550 | In 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 |
| 1883 | some other window, it moves through live windows in a specific order. | 1881 | some other window, it moves through live windows in a specific order. |
| 1884 | For any given configuration of windows, this order never varies. It | 1882 | For any given configuration of windows, this order never varies. It |
| 1885 | is called the @dfn{cyclic ordering of windows}. | 1883 | is called the @dfn{cyclic ordering of windows}. |
| @@ -1899,7 +1897,7 @@ if omitted or @code{nil}, it defaults to the selected window. | |||
| 1899 | The optional argument @var{minibuf} specifies whether minibuffer windows | 1897 | The optional argument @var{minibuf} specifies whether minibuffer windows |
| 1900 | should be included in the cyclic ordering. Normally, when @var{minibuf} | 1898 | should be included in the cyclic ordering. Normally, when @var{minibuf} |
| 1901 | is @code{nil}, a minibuffer window is included only if it is currently | 1899 | is @code{nil}, a minibuffer window is included only if it is currently |
| 1902 | active; this matches the behavior of @kbd{C-x o}. (Note that a | 1900 | active; this matches the behavior of @w{@kbd{C-x o}}. (Note that a |
| 1903 | minibuffer window is active as long as its minibuffer is in use; see | 1901 | minibuffer 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 |
| 2084 | margins, fringes and scroll bar settings alone. | 2082 | margins, fringes and scroll bar settings alone. |
| 2085 | 2083 | ||
| 2086 | When writing an application, you should normally use the higher-level | 2084 | When writing an application, you should normally use |
| 2085 | @code{display-buffer} (@pxref{Choosing Window}) or the higher-level | ||
| 2087 | functions described in @ref{Switching Buffers}, instead of calling | 2086 | functions 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 | ||
| 2173 | This section describes high-level functions for switching to a specified | 2171 | This section describes high-level functions for switching to a specified |
| 2174 | buffer in some window. In general, ``switching to a buffer'' means to | 2172 | buffer 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 | |||
| 2333 | This section describes lower-level functions Emacs uses to find or | ||
| 2334 | create a window for displaying a specified buffer. The common | ||
| 2335 | workhorse of these functions is @code{display-buffer} which eventually | ||
| 2336 | handles all incoming requests for buffer display (@pxref{Choosing | ||
| 2337 | Window}). | ||
| 2338 | |||
| 2339 | @code{display-buffer} delegates the task of finding a suitable | ||
| 2340 | window to so-called action functions (@pxref{Buffer Display Action | ||
| 2341 | Functions}). First, @code{display-buffer} compiles a so-called action | ||
| 2342 | alist---a special association list that action functions can use to | ||
| 2343 | fine-tune their behavior. Then it passes that alist on to each action | ||
| 2344 | function it calls (@pxref{Buffer Display Action Alists}). | ||
| 2345 | |||
| 2346 | The behavior of @code{display-buffer} is highly customizable. To | ||
| 2347 | understand how customizations are used in practice, you may wish to | ||
| 2348 | study examples illustrating the order of precedence which | ||
| 2349 | @code{display-buffer} uses to call action functions (@pxref{Precedence | ||
| 2350 | of Action Functions}). To avoid conflicts between Lisp programs | ||
| 2351 | calling @code{display-buffer} and user customizations of its behavior, | ||
| 2352 | it may make sense to follow a number of guidelines which are sketched | ||
| 2353 | in 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 | 2370 | The command @code{display-buffer} flexibly chooses a window for |
| 2334 | display, and displays a specified buffer in that window. It can be | 2371 | display, and displays a specified buffer in that window. It can be |
| 2335 | called interactively, via the key binding @kbd{C-x 4 C-o}. It is also | 2372 | called interactively, via the key binding @kbd{C-x 4 C-o}. It is also |
| 2336 | used as a subroutine by many functions and commands, including | 2373 | used 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 |
| 2338 | Buffers}). | 2375 | Buffers}). |
| 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 |
| 2344 | display in. These steps are described by means of @dfn{display | 2380 | display in. These steps are described by means of @dfn{display |
| 2345 | actions}, which have the form @code{(@var{function} . @var{alist})}. | 2381 | actions}, which have the form @code{(@var{functions} . @var{alist})}. |
| 2346 | Here, @var{function} is either a function or a list of functions, | 2382 | Here, @var{functions} is either a single function or a list of |
| 2347 | which we refer to as @dfn{action functions}; @var{alist} is an | 2383 | functions, referred to as ``action functions'' (@pxref{Buffer Display |
| 2348 | association list, which we refer to as an @dfn{action alist}. | 2384 | Action Functions}); and @var{alist} is an association list, referred |
| 2385 | to 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 |
| 2351 | an action alist. It attempts to display the buffer in some window, | 2389 | an action alist. It attempts to display the buffer in some window, |
| 2352 | picking or creating a window according to its own criteria. If | 2390 | picking or creating a window according to its own criteria. If |
| 2353 | successful, it returns the window; otherwise, it returns @code{nil}. | 2391 | successful, it returns the window; otherwise, it returns @code{nil}. |
| 2354 | @xref{Display Action Functions}, for a list of predefined action | ||
| 2355 | functions. | ||
| 2356 | 2392 | ||
| 2357 | @code{display-buffer} works by combining display actions from | 2393 | @code{display-buffer} works by combining display actions from |
| 2358 | several sources, and calling the action functions in turn, until one | 2394 | several sources, and calling the action functions in turn, until one |
| @@ -2363,12 +2399,14 @@ value. | |||
| 2363 | This command makes @var{buffer-or-name} appear in some window, without | 2399 | This command makes @var{buffer-or-name} appear in some window, without |
| 2364 | selecting the window or making the buffer current. The argument | 2400 | selecting 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 |
| 2366 | buffer. The return value is the window chosen to display the buffer. | 2402 | buffer. The return value is the window chosen to display the buffer, |
| 2403 | or @code{nil} if no suitable window was found. | ||
| 2367 | 2404 | ||
| 2368 | The optional argument @var{action}, if non-@code{nil}, should normally | 2405 | The optional argument @var{action}, if non-@code{nil}, should normally |
| 2369 | be a display action (described above). @code{display-buffer} builds a | 2406 | be a display action (described above). @code{display-buffer} builds a |
| 2370 | list of action functions and an action alist, by consolidating display | 2407 | list of action functions and an action alist, by consolidating display |
| 2371 | actions from the following sources (in order): | 2408 | actions from the following sources (in order of their precedence, |
| 2409 | from 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 |
| 2391 | Each action function is called in turn, passing the buffer as the | 2429 | In practice this means that @code{display-buffer} builds a list of all |
| 2392 | first argument and the combined action alist as the second argument, | 2430 | action functions specified by these display actions. The first |
| 2393 | until one of the functions returns non-@code{nil}. The caller can | 2431 | element of this list is the first action function specified by |
| 2394 | pass @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 |
| 2395 | indicate its readiness to handle the case of not displaying the | 2433 | @code{display-buffer-pop-up-frame}---the last action function |
| 2396 | buffer in a window. | 2434 | specified by @code{display-buffer-fallback-action}. Duplicates are |
| 2435 | not removed from this list---hence one and the same action function | ||
| 2436 | may be called multiple times during one call of @code{display-buffer}. | ||
| 2437 | |||
| 2438 | @code{display-buffer} calls the action functions specified by this | ||
| 2439 | list in turn, passing the buffer as the first argument and the | ||
| 2440 | combined action alist as the second argument, until one of the | ||
| 2441 | functions returns non-@code{nil}. @xref{Precedence of Action | ||
| 2442 | Functions}, for examples how display actions specified by different | ||
| 2443 | sources are processed by @code{display-buffer}. | ||
| 2444 | |||
| 2445 | Note that the second argument is always the list of @emph{all} action | ||
| 2446 | alist entries specified by the sources named above. Hence, the first | ||
| 2447 | element of that list is the first action alist entry specified by | ||
| 2448 | @code{display-buffer-overriding-action}, if any. Its last element is | ||
| 2449 | the last alist entry of @code{display-buffer-base-action}, if any (the | ||
| 2450 | action alist of @code{display-buffer-fallback-action} is empty). | ||
| 2451 | |||
| 2452 | Note also, that the combined action alist may contain duplicate | ||
| 2453 | entries and entries for the same key with different values. As a | ||
| 2454 | rule, action functions always use the first association of a key they | ||
| 2455 | find. Hence, the association an action function uses is not | ||
| 2456 | necessarily the association provided by the display action that | ||
| 2457 | specified that action function, | ||
| 2397 | 2458 | ||
| 2398 | The argument @var{action} can also have a non-@code{nil}, non-list | 2459 | The argument @var{action} can also have a non-@code{nil}, non-list |
| 2399 | value. This has the special meaning that the buffer should be | 2460 | value. This has the special meaning that the buffer should be |
| 2400 | displayed in a window other than the selected one, even if the | 2461 | displayed in a window other than the selected one, even if the |
| 2401 | selected window is already displaying it. If called interactively | 2462 | selected window is already displaying it. If called interactively |
| 2402 | with a prefix argument, @var{action} is @code{t}. | 2463 | with a prefix argument, @var{action} is @code{t}. Lisp programs |
| 2464 | should always supply a list value. | ||
| 2403 | 2465 | ||
| 2404 | The optional argument @var{frame}, if non-@code{nil}, specifies which | 2466 | The optional argument @var{frame}, if non-@code{nil}, specifies which |
| 2405 | frames to check when deciding whether the buffer is already displayed. | 2467 | frames to check when deciding whether the buffer is already displayed. |
| 2406 | It is equivalent to adding an element @code{(reusable-frames | 2468 | It 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 |
| 2408 | Action Functions}. | 2470 | Display Action Alists}). The @var{frame} argument is provided for |
| 2471 | compatibility 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 |
| 2412 | The value of this variable should be a display action, which is | 2475 | The value of this variable should be a display action, which is |
| 2413 | treated with the highest priority by @code{display-buffer}. The | 2476 | treated with the highest priority by @code{display-buffer}. The |
| 2414 | default value is empty, i.e., @code{(nil . nil)}. | 2477 | default 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 |
| 2418 | The value of this option is an alist mapping conditions to display | 2481 | The value of this option is an alist mapping conditions to display |
| 2419 | actions. Each condition may be either a regular expression matching a | 2482 | actions. Each condition may be either a regular expression matching a |
| 2420 | buffer name or a function that takes two arguments: a buffer name and | 2483 | buffer name or a function that takes two arguments: a buffer name and |
| 2421 | the @var{action} argument passed to @code{display-buffer}. If the name | 2484 | the @var{action} argument passed to @code{display-buffer}. If either |
| 2422 | of the buffer passed to @code{display-buffer} either matches a regular | 2485 | the name of the buffer passed to @code{display-buffer} matches a |
| 2423 | expression in this alist or the function specified by a condition | 2486 | regular expression in this alist, or the function specified by a |
| 2424 | returns non-@code{nil}, then @code{display-buffer} uses the | 2487 | condition returns non-@code{nil}, then @code{display-buffer} uses the |
| 2425 | corresponding display action to display the buffer. | 2488 | corresponding 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 | |||
| 2508 | An @dfn{action function} is a function @code{display-buffer} calls for | ||
| 2509 | choosing a window to display a buffer. Action functions take two | ||
| 2510 | arguments: @var{buffer}, the buffer to display, and @var{alist}, an | ||
| 2511 | action alist (@pxref{Buffer Display Action Alists}). They are | ||
| 2512 | supposed to return a window displaying @var{buffer} if they succeed | ||
| 2513 | and @code{nil} if they fail. | ||
| 2442 | 2514 | ||
| 2443 | The following basic action functions are defined in Emacs. Each of | 2515 | The following basic action functions are defined in Emacs. |
| 2444 | these functions takes two arguments: @var{buffer}, the buffer to | ||
| 2445 | display, and @var{alist}, an action alist. Each action function | ||
| 2446 | returns 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 |
| 2449 | This function tries to display @var{buffer} in the selected window. | 2518 | This 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 |
| 2456 | This function tries to display @var{buffer} by finding a window | 2525 | This function tries to display @var{buffer} by finding a window that |
| 2457 | that is already displaying it. | 2526 | is already displaying it. |
| 2458 | 2527 | ||
| 2459 | If @var{alist} has a non-@code{nil} @code{inhibit-same-window} entry, | 2528 | If @var{alist} has a non-@code{nil} @code{inhibit-same-window} entry, |
| 2460 | the selected window is not eligible for reuse. If @var{alist} | 2529 | the selected window is not eligible for reuse. The set of frames to |
| 2461 | contains a @code{reusable-frames} entry, its value determines which | 2530 | search for a window already displaying @var{buffer} can be specified |
| 2462 | frames to search for a reusable window: | 2531 | with 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 | 2533 | searches just the selected frame. |
| 2465 | @item | 2534 | |
| 2466 | @code{nil} means consider windows on the selected frame. | 2535 | If this function chooses a window on another frame, it makes that |
| 2467 | (Actually, the last non-minibuffer frame.) | 2536 | frame 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 | ||
| 2473 | 0 means consider windows on all visible or iconified frames. | ||
| 2474 | @item | ||
| 2475 | A frame means consider windows on that frame only. | ||
| 2476 | @end itemize | ||
| 2477 | |||
| 2478 | Note that these meanings differ slightly from those of the | ||
| 2479 | @var{all-frames} argument to @code{next-window} (@pxref{Cyclic Window | ||
| 2480 | Ordering}). | ||
| 2481 | |||
| 2482 | If @var{alist} contains no @code{reusable-frames} entry, this function | ||
| 2483 | normally searches just the selected frame; however, if the variable | ||
| 2484 | @code{pop-up-frames} is non-@code{nil}, it searches all frames on the | ||
| 2485 | current terminal. @xref{Choosing Window Options}. | ||
| 2486 | |||
| 2487 | If this function chooses a window on another frame, it makes that frame | ||
| 2488 | visible and, unless @var{alist} contains an @code{inhibit-switch-frame} | ||
| 2489 | entry (@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 |
| 2493 | This function tries to display @var{buffer} by finding a window | 2541 | This function tries to display @var{buffer} by finding a window |
| 2494 | that is displaying a buffer in a given mode. | 2542 | that is displaying a buffer in a given mode. |
| 2495 | 2543 | ||
| 2496 | If @var{alist} contains a @code{mode} entry, its value is a major mode | 2544 | If @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 | 2545 | major 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 | 2546 | contains no @code{mode} entry, the current major mode of @var{buffer} |
| 2499 | window is a candidate if it displays a buffer that derives from one of | 2547 | is used instead. A window is a candidate if it displays a buffer |
| 2500 | the given modes. | 2548 | whose mode derives from one of the modes specified thusly. |
| 2501 | 2549 | ||
| 2502 | The behavior is also controlled by entries for | 2550 | The 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}. | 2553 | does. |
| 2554 | @end defun | ||
| 2555 | |||
| 2556 | @defun display-buffer-pop-up-window buffer alist | ||
| 2557 | This function tries to display @var{buffer} by splitting the largest | ||
| 2558 | or least recently-used window (usually located on the selected frame). | ||
| 2559 | It actually performs the split by calling the function specified by | ||
| 2560 | @code{split-window-preferred-function} (@pxref{Choosing Window | ||
| 2561 | Options}). | ||
| 2562 | |||
| 2563 | The size of the new window can be adjusted by supplying | ||
| 2564 | @code{window-height} and @code{window-width} entries in @var{alist}. | ||
| 2565 | If @var{alist} contains a @code{preserve-size} entry, Emacs will also | ||
| 2566 | try to preserve the size of the new window during future resize | ||
| 2567 | operations (@pxref{Preserving Window Sizes}). | ||
| 2568 | |||
| 2569 | This function fails if no window can be split. More often than not, | ||
| 2570 | this happens because no window is large enough to allow splitting. | ||
| 2571 | Setting @code{split-height-threshold} or @code{split-width-threshold} | ||
| 2572 | to lower values may help in this regard. Spliting also fails when the | ||
| 2573 | selected frame has an @code{unsplittable} frame parameter; | ||
| 2574 | @pxref{Buffer Parameters}. | ||
| 2575 | @end defun | ||
| 2576 | |||
| 2577 | @defun display-buffer-in-previous-window buffer alist | ||
| 2578 | This function tries to display @var{buffer} in a window where it was | ||
| 2579 | previously displayed. If @var{alist} has a non-@code{nil} | ||
| 2580 | @code{inhibit-same-window} entry, the selected window is not eligible | ||
| 2581 | for reuse. If @var{alist} contains a @code{reusable-frames} entry, | ||
| 2582 | its value determines which frames to search for a suitable window. | ||
| 2506 | 2583 | ||
| 2584 | If @var{alist} has a @code{previous-window} entry and the window | ||
| 2585 | specified by that entry is live and not dedicated to another buffer, | ||
| 2586 | that window will be preferred, even if it never showed @var{buffer} | ||
| 2587 | before. | ||
| 2588 | @end defun | ||
| 2589 | |||
| 2590 | @defun display-buffer-use-some-window buffer alist | ||
| 2591 | This function tries to display @var{buffer} by choosing an existing | ||
| 2592 | window and displaying the buffer in that window. It can fail if all | ||
| 2593 | windows are dedicated to other buffers (@pxref{Dedicated Windows}). | ||
| 2594 | @end defun | ||
| 2595 | |||
| 2596 | @defun display-buffer-below-selected buffer alist | ||
| 2597 | This function tries to display @var{buffer} in a window below the | ||
| 2598 | selected window. If there is a window below the selected one and that | ||
| 2599 | window already displays @var{buffer}, it reuses that window. | ||
| 2600 | |||
| 2601 | If there is no such window, this function tries to create a new window | ||
| 2602 | by splitting the selected one, and displays @var{buffer} there. It will | ||
| 2603 | also try to adjust that window's size provided @var{alist} contains a | ||
| 2604 | suitable @code{window-height} or @code{window-width} entry, see above. | ||
| 2605 | |||
| 2606 | If splitting the selected window fails and there is a non-dedicated | ||
| 2607 | window below the selected one showing some other buffer, this function | ||
| 2608 | tries to use that window for showing @var{buffer}. | ||
| 2609 | @end defun | ||
| 2610 | |||
| 2611 | @defun display-buffer-at-bottom buffer alist | ||
| 2612 | This function tries to display @var{buffer} in a window at the bottom | ||
| 2613 | of the selected frame. | ||
| 2614 | |||
| 2615 | This either tries to split the window at the bottom of the frame or | ||
| 2616 | the frame's root window, or to reuse an existing window at the bottom | ||
| 2617 | of 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 | |||
| 2511 | frame's window. It actually performs the frame creation by calling | 2622 | frame's window. It actually performs the frame creation by calling |
| 2512 | the function specified in @code{pop-up-frame-function} | 2623 | the 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 |
| 2515 | is added to the newly created frame's parameters. | 2626 | the 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 |
| 2519 | This function tries to display @var{buffer} in a child frame | 2630 | This 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 |
| 2521 | child frame or by making a new one. If @var{alist} has a non-@code{nil} | 2632 | existing 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 | 2633 | non-@code{nil} @code{child-frame-parameters} entry, the corresponding |
| 2523 | of frame parameters to give the new frame. A @code{parent-frame} | 2634 | value is an alist of frame parameters to give the new frame. A |
| 2524 | parameter specifying the selected frame is provided by default. If the | 2635 | @code{parent-frame} parameter specifying the selected frame is |
| 2525 | child frame should be or become the child of another frame, a | 2636 | provided by default. If the child frame should become the child of |
| 2526 | corresponding entry must be added to @var{alist}. | 2637 | another frame, a corresponding entry must be added to @var{alist}. |
| 2527 | 2638 | ||
| 2528 | The appearance of child frames is largely dependent on the parameters | 2639 | The appearance of child frames is largely dependent on the parameters |
| 2529 | provided via @var{alist}. It is advisable to use at least ratios to | 2640 | provided via @var{alist}. It is advisable to use at least ratios to |
| 2530 | specify the size (@pxref{Size Parameters}) and the position | 2641 | specify 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 |
| 2533 | visible. For other parameters that should be considered see @ref{Child | 2644 | order to make sure that the child frame remains visible. For other |
| 2534 | Frames}. | 2645 | parameters 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 |
| 2538 | This function tries to display @var{buffer} by trying to find a | 2649 | This function tries to display @var{buffer} by finding a frame that |
| 2539 | frame that meets a predicate (by default any frame other than the | 2650 | meets a predicate (by default any frame other than the selected |
| 2540 | current frame). | 2651 | frame). |
| 2541 | 2652 | ||
| 2542 | If this function chooses a window on another frame, it makes that frame | 2653 | If this function chooses a window on another frame, it makes that |
| 2543 | visible and, unless @var{alist} contains an @code{inhibit-switch-frame} | 2654 | frame visible and, unless @var{alist} contains an |
| 2544 | entry (@pxref{Choosing Window Options}), raises that frame if necessary. | 2655 | @code{inhibit-switch-frame} entry, raises that frame if necessary. |
| 2545 | 2656 | ||
| 2546 | If @var{alist} has a non-@code{nil} @code{frame-predicate} entry, its | 2657 | If @var{alist} has a non-@code{nil} @code{frame-predicate} entry, its |
| 2547 | value is a function taking one argument (a frame), returning | 2658 | value 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 | |||
| 2549 | default predicate. | 2660 | default predicate. |
| 2550 | 2661 | ||
| 2551 | If @var{alist} has a non-@code{nil} @code{inhibit-same-window} entry, | 2662 | If @var{alist} has a non-@code{nil} @code{inhibit-same-window} entry, |
| 2552 | the selected window is used; thus if the selected frame has a single | 2663 | the selected window is not used; thus if the selected frame has a |
| 2553 | window, it is not used. | 2664 | single 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 |
| 2557 | This function tries to display @var{buffer} by splitting the largest | 2668 | If @var{alist} has a non-@code{nil} @code{allow-no-window} entry, then |
| 2558 | or least recently-used window (typically one on the selected frame). | 2669 | this function does not display @var{buffer} and returns the symbol |
| 2559 | It 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 | 2671 | that an action function returns either @code{nil} or a window showing |
| 2561 | Options}). | 2672 | @var{buffer}. If @var{alist} has no such @code{allow-no-window} |
| 2673 | entry, this function returns @code{nil}. | ||
| 2674 | |||
| 2675 | If this function returns @code{fail}, @code{display-buffer} will skip | ||
| 2676 | the execution of any further display actions and return @code{nil} | ||
| 2677 | immediately. If this function returns @code{nil}, | ||
| 2678 | @code{display-buffer} will continue with the next display action, if | ||
| 2679 | any. | ||
| 2562 | 2680 | ||
| 2563 | The size of the new window can be adjusted by supplying | 2681 | It 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 | 2682 | non-@code{nil} @code{allow-no-window} entry, it is also able to handle |
| 2565 | adjust the window's height, use an entry whose @sc{car} is | 2683 | a @code{nil} return value. |
| 2566 | @code{window-height} and whose @sc{cdr} is one of: | 2684 | @end defun |
| 2685 | |||
| 2686 | Two other action functions are described in their proper | ||
| 2687 | sections---@code{display-buffer-in-side-window} (@pxref{Displaying | ||
| 2688 | Buffers 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 | |||
| 2697 | An @dfn{action alist} is an association list mapping predefined | ||
| 2698 | symbols recognized by action functions to values these functions are | ||
| 2699 | supposed to interpret accordingly. In each call, | ||
| 2700 | @code{display-buffer} constructs a new, possibly empty action alist | ||
| 2701 | and passes that entire list on to any action function it calls. | ||
| 2702 | |||
| 2703 | By design, action functions are free in their interpretation of | ||
| 2704 | action alist entries. In fact, some entries like | ||
| 2705 | @code{allow-no-window} or @code{previous-window} have a meaning only | ||
| 2706 | for one or a few action functions, and are ignored by the rest. Other | ||
| 2707 | entries, like @code{inhibit-same-window} or @code{window-parameters}, | ||
| 2708 | are supposed to be respected by most action functions, including those | ||
| 2709 | provided by application programs and external packages. | ||
| 2710 | |||
| 2711 | In the previous subsection we have described in detail how | ||
| 2712 | individual action functions interpret the action alist entries they | ||
| 2713 | care about. Here we give a reference list of all known action alist | ||
| 2714 | entries according to their symbols, together with their values and | ||
| 2715 | action functions (@pxref{Buffer Display Action Functions}) that | ||
| 2716 | recognize them. Throughout this list, the terms ``buffer'' will refer | ||
| 2717 | to 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 | ||
| 2723 | If the value is non-@code{nil}, this signals that the selected window | ||
| 2724 | must 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 | ||
| 2729 | The value must specify a window that may have displayed the buffer | ||
| 2730 | previously. @code{display-buffer-in-previous-window} will give | ||
| 2731 | preference to such a window provided it is still live and not | ||
| 2732 | dedicated to another buffer. | ||
| 2733 | |||
| 2734 | @vindex mode@r{, a buffer display action alist entry} | ||
| 2735 | @item mode | ||
| 2736 | The value is either a major mode or a list of major modes. | ||
| 2737 | @code{display-buffer-reuse-mode-window} may reuse a window whenever | ||
| 2738 | the value specified by this entry matches the major mode of that | ||
| 2739 | window's buffer. Other action functions ignore such entries. | ||
| 2740 | |||
| 2741 | @vindex frame-predicate@r{, a buffer display action alist entry} | ||
| 2742 | @item frame-predicate | ||
| 2743 | The value must be a function taking one argument (a frame), supposed | ||
| 2744 | to return non-@code{nil} if that frame is a candidate for displaying | ||
| 2745 | the 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 | ||
| 2750 | The value specifies the frame(s) to search for a window that can be | ||
| 2751 | reused because it already displays the buffer. It can be set as | ||
| 2752 | follows: | ||
| 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 | ||
| 2763 | 0 means consider windows on all visible or iconified frames. | ||
| 2764 | @item | ||
| 2765 | A frame means consider windows on that frame only. | ||
| 2766 | @end itemize | ||
| 2767 | |||
| 2768 | Note that the meaning of @code{nil} differs slightly from that of the | ||
| 2769 | @var{all-frames} argument to @code{next-window} (@pxref{Cyclic Window | ||
| 2770 | Ordering}). | ||
| 2771 | |||
| 2772 | A major client of this is @code{display-buffer-reuse-window}, but all | ||
| 2773 | other action functions that try to reuse a window are affected as | ||
| 2774 | well. | ||
| 2775 | |||
| 2776 | @vindex inhibit-switch-frame@r{, a buffer display action alist entry} | ||
| 2777 | @item inhibit-switch-frame | ||
| 2778 | A non-@code{nil} value prevents another frame from being raised or | ||
| 2779 | selected, if the window chosen by @code{display-buffer} is displayed | ||
| 2780 | there. 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 | ||
| 2784 | there 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 | ||
| 2788 | The value specifies an alist of window parameters to give the chosen | ||
| 2789 | window. All action functions that choose a window should process this | ||
| 2790 | entry. | ||
| 2791 | |||
| 2792 | @vindex window-height@r{, a buffer display action alist entry} | ||
| 2793 | @item window-height | ||
| 2794 | The value specifies whether and how to adjust the height of the chosen | ||
| 2795 | window, 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 |
| 2573 | A number specifies the desired height of the new window. An integer | 2802 | A number specifies the desired height of the chosen window. An |
| 2574 | specifies the number of lines of the window. A floating-point | 2803 | integer specifies the number of lines of the window. A floating-point |
| 2575 | number gives the fraction of the window's height with respect to the | 2804 | number gives the fraction of the window's height with respect to the |
| 2576 | height of the frame's root window. | 2805 | height of the frame's root window. |
| 2577 | 2806 | ||
| 2578 | @item | 2807 | @item |
| 2579 | If the @sc{cdr} specifies a function, that function is called with one | 2808 | If the value specifies a function, that function is called with one |
| 2580 | argument: the new window. The function is supposed to adjust the | 2809 | argument---the chosen window. The function is supposed to adjust the |
| 2581 | height of the window; its return value is ignored. Suitable functions | 2810 | height of the window; its return value is ignored. Suitable functions |
| 2582 | are @code{shrink-window-if-larger-than-buffer} and | 2811 | are @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 | ||
| 2586 | To adjust the window's width, use an entry whose @sc{car} is | 2815 | All 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 | ||
| 2819 | This entry is similar to the @code{window-height} entry described | ||
| 2820 | before, but used to adjust the chosen window's width instead. The | ||
| 2821 | value 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 |
| 2594 | A number specifies the desired width of the new window. An integer | 2828 | A number specifies the desired width of the chosen window. An integer |
| 2595 | specifies the number of columns of the window. A floating-point | 2829 | specifies the number of columns of the window. A floating-point |
| 2596 | number gives the fraction of the window's width with respect to the | 2830 | number gives the fraction of the window's width with respect to the |
| 2597 | width of the frame's root window. | 2831 | width of the frame's root window. |
| 2598 | 2832 | ||
| 2599 | @item | 2833 | @item |
| 2600 | If the @sc{cdr} specifies a function, that function is called with one | 2834 | If the value specifies a function, that function is called with one |
| 2601 | argument: the new window. The function is supposed to adjust the width | 2835 | argument---the chosen window. The function is supposed to adjust the |
| 2602 | of the window; its return value is ignored. | 2836 | width of the window; its return value is ignored. |
| 2603 | @end itemize | 2837 | @end itemize |
| 2604 | 2838 | ||
| 2605 | If @var{alist} contains a @code{preserve-size} entry, Emacs will try to | 2839 | All action functions that choose a window should process this entry. |
| 2606 | preserve 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} |
| 2608 | cons cell whose @sc{car}, if non-@code{nil}, means to preserve the width | 2842 | @item preserve-size |
| 2609 | of the window and whose @sc{cdr}, if non-@code{nil}, means to preserve | 2843 | If non-@code{nil} such an entry tells Emacs to preserve the size of |
| 2610 | the height of the window. | 2844 | the window chosen (@pxref{Preserving Window Sizes}). The value should |
| 2611 | 2845 | be either @code{(t . nil)} to preserve the width of the window, | |
| 2612 | This 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 |
| 2613 | reason (e.g., if the selected frame has an @code{unsplittable} frame | 2847 | both its width and its height. All action functions that choose a |
| 2614 | parameter; @pxref{Buffer Parameters}). | 2848 | window 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 |
| 2618 | This function tries to display @var{buffer} in a window below the | 2852 | The value specifies an alist of frame parameters to give a new frame, |
| 2619 | selected window. If there is a window below the selected one and that | 2853 | if one is created. @code{display-buffer-pop-up-frame} is its one and |
| 2620 | window already displays @var{buffer}, it reuses that window. | 2854 | only addressee. |
| 2621 | 2855 | ||
| 2622 | If there is no such window, this function tries to create a new window | 2856 | @vindex parent-frame@r{, a buffer display action alist entry} |
| 2623 | by splitting the selected one and display @var{buffer} there. It will | 2857 | @item parent-frame |
| 2624 | also adjust that window's size provided @var{alist} contains a suitable | 2858 | The value specifies the parent frame to be used when the buffer is |
| 2625 | @code{window-height} or @code{window-width} entry, see above. | 2859 | displayed on a child frame. This entry is used only by |
| 2626 | 2860 | @code{display-buffer-in-child-frame}. | |
| 2627 | If splitting the selected window fails and there is a non-dedicated | 2861 | |
| 2628 | window below the selected one showing some other buffer, it uses that | 2862 | @vindex child-frame-parameters@r{, a buffer display action alist entry} |
| 2629 | window for showing @var{buffer}. | 2863 | @item child-frame-parameters |
| 2630 | @end defun | 2864 | The value specifies an alist of frame parameters to use when the buffer |
| 2631 | 2865 | is 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}. |
| 2633 | This function tries to display @var{buffer} in a window previously | 2867 | |
| 2634 | showing 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 |
| 2636 | for reuse. If @var{alist} contains a @code{reusable-frames} entry, its | 2870 | The value denotes the side of the frame or window where a new window |
| 2637 | value determines which frames to search for a suitable window as with | 2871 | displaying 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 | 2873 | where a new side window shall be placed (@pxref{Displaying Buffers in | |
| 2640 | If @var{alist} has a @code{previous-window} entry, the window | 2874 | Side Windows}). It is also used by |
| 2641 | specified by that entry will override any other window found by the | 2875 | @code{display-buffer-in-atom-window} to indicate the side of an |
| 2642 | methods above, even if that window never showed @var{buffer} before. | 2876 | existing window where the new window shall be located (@pxref{Atomic |
| 2643 | @end defun | 2877 | Windows}). |
| 2644 | |||
| 2645 | @defun display-buffer-at-bottom buffer alist | ||
| 2646 | This function tries to display @var{buffer} in a window at the bottom | ||
| 2647 | of the selected frame. | ||
| 2648 | |||
| 2649 | This either splits the window at the bottom of the frame or the | ||
| 2650 | frame's root window, or reuses an existing window at the bottom of the | ||
| 2651 | selected frame. | ||
| 2652 | @end defun | ||
| 2653 | |||
| 2654 | @defun display-buffer-use-some-window buffer alist | ||
| 2655 | This function tries to display @var{buffer} by choosing an existing | ||
| 2656 | window and displaying the buffer in that window. It can fail if all | ||
| 2657 | windows are dedicated to another buffer (@pxref{Dedicated Windows}). | ||
| 2658 | @end defun | ||
| 2659 | |||
| 2660 | @defun display-buffer-no-window buffer alist | ||
| 2661 | If @var{alist} has a non-@code{nil} @code{allow-no-window} entry, then | ||
| 2662 | this function does not display @code{buffer}. This allows you to | ||
| 2663 | override the default action and avoid displaying the buffer. It is | ||
| 2664 | assumed that when the caller specifies a non-@code{nil} | ||
| 2665 | @code{allow-no-window} value it can handle a @code{nil} value returned | ||
| 2666 | from @code{display-buffer} in this case. | ||
| 2667 | @end defun | ||
| 2668 | |||
| 2669 | If the @var{alist} argument of any of these functions contains a | ||
| 2670 | @code{window-parameters} entry, @code{display-buffer} assigns the | ||
| 2671 | elements of the associated value as window parameters of the chosen | ||
| 2672 | window. | ||
| 2673 | |||
| 2674 | To illustrate the use of action functions, consider the following | ||
| 2675 | example. | ||
| 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 | ||
| 2690 | Evaluating the form above will cause @code{display-buffer} to proceed as | ||
| 2691 | follows: If a buffer called *foo* already appears on a visible or | ||
| 2692 | iconified frame, it will reuse its window. Otherwise, it will try to | ||
| 2693 | pop up a new window or, if that is impossible, a new frame and show the | ||
| 2694 | buffer 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 | ||
| 2700 | popped-up window as follows: If the window is part of a vertical | ||
| 2701 | combination, it will set its height to ten lines. Note that if, instead | ||
| 2702 | of the number 10, we specified the function | ||
| 2703 | @code{fit-window-to-buffer}, @code{display-buffer} would come up with a | ||
| 2704 | one-line window to fit the empty buffer. If the window is part of a | ||
| 2705 | horizontal combination, it sets its width to 40 columns. Whether a new | ||
| 2706 | window is vertically or horizontally combined depends on the shape of | ||
| 2707 | the window split and the values of | ||
| 2708 | @code{split-window-preferred-function}, @code{split-height-threshold} | ||
| 2709 | and @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} |
| 2734 | This form will have @code{display-buffer} first try reusing a window | 2880 | @item slot |
| 2735 | that shows *foo* on the selected frame. If there's no such window, it | 2881 | If non-@code{nil}, the value specifies the slot of the side window |
| 2736 | will try to split the selected window or, if that is impossible, use the | 2882 | supposed to display the buffer. This entry is used only by |
| 2737 | window 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} |
| 2740 | selected one is dedicated to its buffer, @code{display-buffer} will | 2886 | @item window |
| 2741 | proceed as described in the previous example. Note, however, that when | 2887 | The value specifies a window that is in some way related to the window |
| 2742 | it tries to adjust the height of any reused or popped-up window, it will | 2888 | chosen by @code{display-buffer}. This entry is currently used by |
| 2743 | in 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 |
| 2744 | overrides the corresponding specification in the @var{action} argument | 2890 | side the new window shall be created. |
| 2745 | of @code{display-buffer}. | 2891 | |
| 2892 | @vindex allow-no-window@r{, a buffer display action alist entry} | ||
| 2893 | @item allow-no-window | ||
| 2894 | If the value is non-@code{nil}, @code{display-buffer} does not | ||
| 2895 | necessarily have to display the buffer and the caller is prepared to | ||
| 2896 | accept that. This entry is not intended for user customizations, | ||
| 2897 | since there is no guarantee that an arbitrary caller of | ||
| 2898 | @code{display-buffer} will be able to handle the case that no window | ||
| 2899 | will display the buffer. @code{display-buffer-no-window} is the only | ||
| 2900 | action 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 | ||
| 2751 | The behavior of the standard display actions of @code{display-buffer} | 2907 | The behavior of buffer display actions (@pxref{Choosing Window}) can |
| 2752 | (@pxref{Choosing Window}) can be modified by a variety of user | 2908 | be further modified by the following user options. |
| 2753 | options. | ||
| 2754 | 2909 | ||
| 2755 | @defopt pop-up-windows | 2910 | @defopt pop-up-windows |
| 2756 | If the value of this variable is non-@code{nil}, @code{display-buffer} | 2911 | If the value of this variable is non-@code{nil}, @code{display-buffer} |
| 2757 | is allowed to split an existing window to make a new window for | 2912 | is allowed to split an existing window to make a new window for |
| 2758 | displaying in. This is the default. | 2913 | displaying in. This is the default. |
| 2759 | 2914 | ||
| 2760 | This variable is provided mainly for backward compatibility. It is | 2915 | This variable is provided for backward compatibility only. It is |
| 2761 | obeyed by @code{display-buffer} via a special mechanism in | 2916 | obeyed 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 |
| 2763 | function @code{display-buffer-pop-up-window} (@pxref{Display Action | 2918 | @code{display-buffer-pop-up-window} (@pxref{Buffer Display Action |
| 2764 | Functions}) when the value is @code{nil}. It is not consulted by | 2919 | Functions}) 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 | 2920 | not consulted by @code{display-buffer-pop-up-window} itself, which the |
| 2766 | directly in @code{display-buffer-alist} etc. | 2921 | user 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 |
| 2770 | This variable specifies a function for splitting a window, in order to | 2925 | This variable specifies a function for splitting a window, in order to |
| 2771 | make a new window for displaying a buffer. It is used by the | 2926 | make 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 |
| 2773 | the window (@pxref{Display Action Functions}). | 2928 | the window. |
| 2774 | 2929 | ||
| 2775 | The default value is @code{split-window-sensibly}, which is documented | 2930 | The value must be a function that takes one argument, a window, and |
| 2776 | below. The value must be a function that takes one argument, a window, | 2931 | returns either a new window (which will be used to display the desired |
| 2777 | and return either a new window (which will be used to display the | 2932 | buffer) or @code{nil} (which means the splitting failed). The default |
| 2778 | desired buffer) or @code{nil} (which means the splitting failed). | 2933 | value 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 |
| 2782 | This function tries to split @var{window}, and return the newly created | 2937 | This function tries to split @var{window} and return the newly created |
| 2783 | window. If @var{window} cannot be split, it returns @code{nil}. If | 2938 | window. 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 |
| 2785 | window. | 2940 | window. |
| @@ -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 |
| 2791 | restrictions. If that fails, it tries to split by placing the new | 2946 | restrictions. If that fails, it tries to split by placing the new |
| 2792 | window to the right, subject to @code{split-width-threshold} (see | 2947 | window to the right, subject to @code{split-width-threshold} (see |
| 2793 | below). If that fails, and the window is the only window on its | 2948 | below). If that also fails, and the window is the only window on its |
| 2794 | frame, this function again tries to split and place the new window | 2949 | frame, this function again tries to split and place the new window |
| 2795 | below, disregarding @code{split-height-threshold}. If this fails as | 2950 | below, disregarding @code{split-height-threshold}. If this fails as |
| 2796 | well, this function gives up and returns @code{nil}. | 2951 | well, 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 |
| 2800 | This variable, used by @code{split-window-sensibly}, specifies whether | 2955 | This variable specifies whether @code{split-window-sensibly} is |
| 2801 | to split the window placing the new window below. If it is an | 2956 | allowed to split the window placing the new window below. If it is an |
| 2802 | integer, that means to split only if the original window has at least | 2957 | integer, that means to split only if the original window has at least |
| 2803 | that many lines. If it is @code{nil}, that means not to split this | 2958 | that many lines. If it is @code{nil}, that means not to split this |
| 2804 | way. | 2959 | way. |
| 2805 | @end defopt | 2960 | @end defopt |
| 2806 | 2961 | ||
| 2807 | @defopt split-width-threshold | 2962 | @defopt split-width-threshold |
| 2808 | This variable, used by @code{split-window-sensibly}, specifies whether | 2963 | This variable specifies whether @code{split-window-sensibly} is |
| 2809 | to split the window placing the new window to the right. If the value | 2964 | allowed to split the window placing the new window to the right. If |
| 2810 | is an integer, that means to split only if the original window has at | 2965 | the value is an integer, that means to split only if the original |
| 2811 | least that many columns. If the value is @code{nil}, that means not | 2966 | window has at least that many columns. If the value is @code{nil}, |
| 2812 | to split this way. | 2967 | that means not to split this way. |
| 2813 | @end defopt | 2968 | @end defopt |
| 2814 | 2969 | ||
| 2815 | @defopt even-window-sizes | 2970 | @defopt even-window-sizes |
| 2816 | This variable, if non-@code{nil}, causes @code{display-buffer} to even | 2971 | This variable, if non-@code{nil}, causes @code{display-buffer} to even |
| 2817 | window sizes whenever it reuses an existing window and that window is | 2972 | window sizes whenever it reuses an existing window, and that window is |
| 2818 | adjacent to the selected one. | 2973 | adjacent to the selected one. |
| 2819 | 2974 | ||
| 2820 | If its value is @code{width-only}, sizes are evened only if the reused | 2975 | If 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. | |||
| 2839 | This variable is provided mainly for backward compatibility. It is | 2994 | This variable is provided mainly for backward compatibility. It is |
| 2840 | obeyed by @code{display-buffer} via a special mechanism in | 2995 | obeyed 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 |
| 2843 | if the value is non-@code{nil}. (This is done before attempting to | 2998 | Functions}) if the value is non-@code{nil}. (This is done before |
| 2844 | split a window.) This variable is not consulted by | 2999 | attempting 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 |
| 2846 | directly in @code{display-buffer-alist} etc. | 3001 | directly 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 |
| 2850 | This variable specifies a function for creating a new frame, in order | 3005 | This variable specifies a function for creating a new frame, in order |
| 2851 | to make a new window for displaying a buffer. It is used by the | 3006 | to 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. |
| 2853 | Action Functions}). | ||
| 2854 | 3008 | ||
| 2855 | The value should be a function that takes no arguments and returns a | 3009 | The value should be a function that takes no arguments and returns a |
| 2856 | frame, or @code{nil} if no frame could be created. The default value | 3010 | frame, 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 |
| 2862 | This variable holds an alist of frame parameters (@pxref{Frame | 3016 | This variable holds an alist of frame parameters (@pxref{Frame |
| 2863 | Parameters}), which is used by the default function in | 3017 | Parameters}), 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 | 3021 | This option is provided for backward compatibility only. Note, that |
| 2869 | A list of buffer names for buffers that should be displayed in the | 3022 | when @code{display-buffer-pop-up-frame} calls the function specified |
| 2870 | selected window. If a buffer's name is in this list, | 3023 | by @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 |
| 2872 | window. | 3025 | @code{pop-up-frame-alist} so that the values specified by the action |
| 3026 | alist entry effectively override any corresponding values of | ||
| 3027 | @code{pop-up-frame-alist}. | ||
| 3028 | |||
| 3029 | Hence, users should set up a @code{pop-up-frame-parameters} action | ||
| 3030 | alist entry in @code{display-buffer-alist} instead of customizing | ||
| 3031 | @code{pop-up-frame-alist}. Only this will guarantee that the value of | ||
| 3032 | a parameter specified by the user overrides the value of that | ||
| 3033 | parameter 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 |
| 2876 | A list of regular expressions that specify buffers that should be | 3037 | to maintain compatibility with code that uses older options like |
| 2877 | displayed in the selected window. If the buffer's name matches any of | 3038 | @code{pop-up-windows}, @code{pop-up-frames}, |
| 2878 | the regular expressions in this list, @code{display-buffer} handles the | 3039 | @code{pop-up-frame-alist}, @code{same-window-buffer-names} and |
| 2879 | buffer by showing it in the selected window. | 3040 | @code{same-window-regexps}. Lisp Programs and users should refrain |
| 2880 | @end defopt | 3041 | from using these options. Above we already warned against customizing |
| 3042 | @code{pop-up-frame-alist}. Here we describe how to convert the | ||
| 3043 | remaining options to use display actions instead. | ||
| 3044 | |||
| 3045 | @table @code | ||
| 3046 | @item pop-up-windows | ||
| 3047 | @vindex pop-up-windows@r{, replacement for} | ||
| 3048 | This 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 | ||
| 3050 | much better to list in @code{display-buffer-base-action} the action | ||
| 3051 | functions 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} | ||
| 3065 | Instead 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} | ||
| 3081 | Instead of adding a buffer name or a regular expression to one of | ||
| 3082 | these options use a @code{display-buffer-alist} entry for that buffer | ||
| 3083 | specifying 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 | |||
| 3102 | From the past subsections we already know that @code{display-buffer} | ||
| 3103 | must be supplied with a number of display actions (@pxref{Choosing | ||
| 3104 | Window}) in order to display a buffer. In a completely uncustomized | ||
| 3105 | Emacs, these actions are specified by | ||
| 3106 | @code{display-buffer-fallback-action} in the following order of | ||
| 3107 | precedence: Reuse a window, pop up a new window on the same frame, use | ||
| 3108 | a window previously showing the buffer, use some window and pop up a | ||
| 3109 | new frame. (Note that the remaining actions named by | ||
| 3110 | @code{display-buffer-fallback-action} are void in an uncustomized | ||
| 3111 | Emacs). | ||
| 3112 | |||
| 3113 | Consider the following form: | ||
| 3114 | |||
| 3115 | @example | ||
| 3116 | (display-buffer (get-buffer-create "*foo*")) | ||
| 3117 | @end example | ||
| 3118 | |||
| 3119 | @noindent | ||
| 3120 | Evaluating this form in the buffer @file{*scratch*} of an uncustomized | ||
| 3121 | Emacs session will usually fail to reuse a window that shows | ||
| 3122 | @file{*foo*} already, but succeed in popping up a new window. | ||
| 3123 | Evaluating the same form again will now not cause any visible | ||
| 3124 | changes---@code{display-buffer} reused the window already showing | ||
| 3125 | @file{*foo*} because that action was applicable and had the highest | ||
| 3126 | precedence among all applicable actions. | ||
| 3127 | |||
| 3128 | Popping up a new window will fail if there is not enough space on | ||
| 3129 | the selected frame. In an uncustomized Emacs it typically fails when | ||
| 3130 | there are already two windows on a frame. For example, if you now | ||
| 3131 | type @w{@kbd{C-x 1}} followed by @w{@kbd{C-x 2}} and evaluate the form | ||
| 3132 | once more, @file{*foo*} should show up in the lower | ||
| 3133 | window---@code{display-buffer} just used ``some'' window. If, before | ||
| 3134 | typing @w{@kbd{C-x 2}} you had typed @w{@kbd{C-x o}}, @file{*foo*} | ||
| 3135 | would have been shown in the upper window because ``some'' window | ||
| 3136 | stands for the ``least recently used'' window and the selected window | ||
| 3137 | has 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 | ||
| 3140 | shown in the lower window. Type @w{@kbd{C-x o}} to get there followed | ||
| 3141 | by @w{@kbd{C-x left}} and evaluate the form again. This should | ||
| 3142 | display @file{*foo*} in the same, lower window because that window had | ||
| 3143 | already shown @file{*foo*} previously and was therefore chosen instead | ||
| 3144 | of some other window. | ||
| 3145 | |||
| 3146 | So far we have only observed the default behavior in an uncustomized | ||
| 3147 | Emacs session. To see how this behavior can be customized, let's | ||
| 3148 | consider the option @code{display-buffer-base-action}. It provides a | ||
| 3149 | very coarse customization which conceptually affects the display of | ||
| 3150 | @emph{any} buffer. It can be used to supplement the actions supplied | ||
| 3151 | by @code{display-buffer-fallback-action} by reordering them or by | ||
| 3152 | adding actions that are not present there but fit more closely the | ||
| 3153 | user's editing practice. However, it can also be used to change the | ||
| 3154 | default behavior in a more profound way. | ||
| 3155 | |||
| 3156 | Let's consider a user who, as a rule, prefers to display buffers on | ||
| 3157 | another 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 | ||
| 3169 | This setting will cause @code{display-buffer} to first try to find a | ||
| 3170 | window showing the buffer on a visible or iconified frame and, if no | ||
| 3171 | such frame exists, pop up a new frame. You can observe this behavior | ||
| 3172 | on a graphical system by typing @w{@kbd{C-x 1}} in the window showing | ||
| 3173 | @file{*scratch*} and evaluating our canonical @code{display-buffer} | ||
| 3174 | form. This will usually create (and give focus to) a new frame whose | ||
| 3175 | root window shows @file{*foo*}. Iconify that frame and evaluate the | ||
| 3176 | canonical form again: @code{display-buffer} will reuse the window on | ||
| 3177 | the new frame (usually raising the frame and giving it focus too). | ||
| 3178 | |||
| 3179 | Only if creating a new frame fails, @code{display-buffer} will | ||
| 3180 | apply the actions supplied by @code{display-buffer-fallback-action} | ||
| 3181 | which means to again try reusing a window, popping up a new window and | ||
| 3182 | so on. A trivial way to make frame creation fail is supplied by the | ||
| 3183 | following 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 | ||
| 3193 | We will forget about that form immediately after observing that it | ||
| 3194 | fails to create a new frame and uses a fallback action instead. | ||
| 3195 | |||
| 3196 | Note that @code{display-buffer-reuse-window} appears redundant in | ||
| 3197 | the customization of @code{display-buffer-base-action} because it is | ||
| 3198 | already part of @code{display-buffer-fallback-action} and should be | ||
| 3199 | tried there anyway. However, that would fail because due to the | ||
| 3200 | precedence 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. | ||
| 3203 | In 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 | ||
| 3214 | would cause @code{display-buffer} to @emph{always} pop up a new frame | ||
| 3215 | which is probably not what our user wants. | ||
| 3216 | |||
| 3217 | So far, we have only shown how @emph{users} can customize the | ||
| 3218 | default behavior of @code{display-buffer}. Let us now see how | ||
| 3219 | @emph{applications} can change the course of @code{display-buffer}. | ||
| 3220 | The 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 | ||
| 3225 | below the selected window (to immediately attract the attention of the | ||
| 3226 | user to the new window) or, if that fails, in a window at the bottom | ||
| 3227 | of 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 | ||
| 3238 | In order to see how this new, modified form works, delete any frame | ||
| 3239 | showing @file{*foo*}, type @w{@kbd{C-x 1}} followed by @w{@kbd{C-x 2}} in the | ||
| 3240 | window 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}} | ||
| 3243 | you had typed @w{@kbd{C-x o}}, @code{display-buffer} would have split the | ||
| 3244 | window at the bottom instead. | ||
| 3245 | |||
| 3246 | Suppose now that, before evaluating the new form, you have made the | ||
| 3247 | selected window as small as possible, for example, by evaluating the | ||
| 3248 | form @code{(fit-window-to-buffer)} in that window. In that case, | ||
| 3249 | @code{display-buffer} would have failed to split the selected window | ||
| 3250 | and would have split the frame's root window instead, effectively | ||
| 3251 | displaying @file{*foo*} at the bottom of the frame. | ||
| 3252 | |||
| 3253 | In either case, evaluating the new form a second time should reuse | ||
| 3254 | the window already showing @file{*foo*} since both functions supplied | ||
| 3255 | by the @var{action} argument try to reuse such a window first. | ||
| 3256 | |||
| 3257 | By setting the @var{action} argument, an application effectively | ||
| 3258 | overrules any customization of @code{display-buffer-base-action}. Our | ||
| 3259 | user can now either accept the choice of the application, or redouble | ||
| 3260 | by 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 | ||
| 3272 | Trying this with the new, modified form above in a configuration that | ||
| 3273 | does not show @file{*foo*} anywhere, will display @file{*foo*} on a | ||
| 3274 | separate 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 | ||
| 3278 | alist entry in our specification of @code{display-buffer-alist}. | ||
| 3279 | @code{display-buffer} always takes the first one it finds---in our | ||
| 3280 | case the one specified by @code{display-buffer-base-action}. If we | ||
| 3281 | wanted to use a different specification, for example, to exclude | ||
| 3282 | iconified frames showing @file{*foo*} from the list of reusable ones, | ||
| 3283 | we 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 | ||
| 3296 | If 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 | ||
| 3298 | visible. | ||
| 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 | ||
| 3303 | be incorrect. @code{display-buffer-alist} is the standard option for | ||
| 3304 | users to direct the course of display of specific buffers in a | ||
| 3305 | preferred 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 | ||
| 3311 | because it overrides the @var{action} argument of | ||
| 3312 | @code{display-buffer}, and it allows to explicitly specify the | ||
| 3313 | affected buffers. In fact, displaying other buffers is not affected | ||
| 3314 | in 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 | ||
| 3321 | continues 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 | ||
| 3326 | an ace up their sleeves which they can use to overrule any | ||
| 3327 | customization 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 | ||
| 3342 | Evaluating this form will usually display @file{*foo*} in the selected | ||
| 3343 | window regardless of the @var{action} argument and any user | ||
| 3344 | customizations. (Usually, an application will not bother to also | ||
| 3345 | provide an @var{action} argument. Here it just serves to illustrate | ||
| 3346 | the fact that it gets overridden.) | ||
| 3347 | |||
| 3348 | It might be illustrative to look at the list of action functions | ||
| 3349 | @code{display-buffer} would have tried to display @file{*foo*} with | ||
| 3350 | the customizations we provided here. The list (including comments | ||
| 3351 | explaining 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 | ||
| 3372 | Note 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 | |||
| 3377 | The 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 | ||
| 3387 | which shows that we have used the second specification of | ||
| 3388 | @code{display-buffer-alist} above, overriding the specification | ||
| 3389 | supplied by @code{display-buffer-base-action}. Suppose our user had | ||
| 3390 | written 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 | ||
| 3404 | In this case the @code{inhibit-same-window} alist entry will | ||
| 3405 | successfully invalidate the @code{display-buffer-same-window} | ||
| 3406 | specification from @code{display-buffer-overriding-action} and | ||
| 3407 | @code{display-buffer} will show @file{*foo*} on another frame. To | ||
| 3408 | make @code{display-buffer-overriding-action} more robust in this | ||
| 3409 | regard, 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 | ||
| 3421 | This last example shows that while the precedence order of action | ||
| 3422 | functions is fixed, as described in @ref{Choosing Window}, an action | ||
| 3423 | alist entry specified by a display action ranked lower in that order | ||
| 3424 | can 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 | |||
| 3433 | In its most simplistic form, a frame accommodates always one single | ||
| 3434 | window that can be used for displaying a buffer. As a consequence, it | ||
| 3435 | is always the latest call of @code{display-buffer} that will have | ||
| 3436 | succeeded in placing its buffer there. | ||
| 3437 | |||
| 3438 | Since working with such a frame is not very practical, Emacs by | ||
| 3439 | default allows for more complex frame layouts controlled by the | ||
| 3440 | default values of the frame size and the @code{split-height-threshold} | ||
| 3441 | and @code{split-width-threshold} options. Displaying a buffer not yet | ||
| 3442 | shown 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 | ||
| 3446 | one of these thresholds or manually changes the frame's layout. The | ||
| 3447 | default behavior is also abandoned when calling @code{display-buffer} | ||
| 3448 | with a non-@code{nil} @var{action} argument or the user customizes one | ||
| 3449 | of the options mentioned in the previous subsections. Mastering | ||
| 3450 | @code{display-buffer} soon may become a frustrating experience due to | ||
| 3451 | the plethora of applicable display actions and the resulting frame | ||
| 3452 | layouts. | ||
| 3453 | |||
| 3454 | However, refraining from using buffer display functions and falling | ||
| 3455 | back on a split & delete windows metaphor is not a good idea either. | ||
| 3456 | Buffer display functions give Lisp programs and users a framework to | ||
| 3457 | reconcile their different needs; no comparable framework exists for | ||
| 3458 | splitting and deleting windows. Buffer display functions also allow | ||
| 3459 | to at least partially restore the layout of a frame when removing a | ||
| 3460 | buffer from it later (@pxref{Quitting Windows}). | ||
| 3461 | |||
| 3462 | Below we will give a number of guidelines to redeem the frustration | ||
| 3463 | mentioned above and thus to avoid literally losing buffers in-between | ||
| 3464 | the windows of a frame. | ||
| 3465 | |||
| 3466 | @table @asis | ||
| 3467 | @item Write display actions without stress | ||
| 3468 | Writing display actions can be a pain because one has to lump together | ||
| 3469 | action functions and action alists in one huge list. (Historical | ||
| 3470 | reasons prevented us from having @code{display-buffer} support | ||
| 3471 | separate arguments for these.) It might help to memorize some basic | ||
| 3472 | forms like the ones listed below: | ||
| 3473 | |||
| 3474 | @example | ||
| 3475 | '(nil (inhibit-same-window . t)) | ||
| 3476 | @end example | ||
| 3477 | |||
| 3478 | @noindent | ||
| 3479 | specifies an action alist entry only and no action function. Its sole | ||
| 3480 | purpose is to inhibit a @code{display-buffer-same-window} function | ||
| 3481 | specified elsewhere from showing the buffer in the same window, see | ||
| 3482 | also the last example of the preceding subsection. | ||
| 3483 | |||
| 3484 | @example | ||
| 3485 | '(display-buffer-below-selected) | ||
| 3486 | @end example | ||
| 3487 | |||
| 3488 | @noindent | ||
| 3489 | on the other hand, specifies one action function and an empty action | ||
| 3490 | alist. To combine the effects of the above two specifications one | ||
| 3491 | would write the form | ||
| 3492 | |||
| 3493 | @example | ||
| 3494 | '(display-buffer-below-selected (inhibit-same-window . t)) | ||
| 3495 | @end example | ||
| 3496 | |||
| 3497 | @noindent | ||
| 3498 | to 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 | ||
| 3508 | and 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 | ||
| 3519 | That 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 | ||
| 3533 | In a customization of @code{display-buffer-alist} it would be used as | ||
| 3534 | follows: | ||
| 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 | ||
| 3548 | To 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 | ||
| 3566 | user options---Lisp programs must never set or rebind them. | ||
| 3567 | @code{display-buffer-overriding-action}, on the other hand, is | ||
| 3568 | reserved for applications---who seldom use that option and if they use | ||
| 3569 | it, then with utmost care. | ||
| 3570 | |||
| 3571 | Older implementations of @code{display-buffer} frequently caused | ||
| 3572 | users and applications to fight over the settings of user options like | ||
| 3573 | @code{pop-up-frames} and @code{pop-up-windows} (@pxref{Choosing Window | ||
| 3574 | Options}). This was one major reason for redesigning | ||
| 3575 | @code{display-buffer}---to provide a clear framework specifying what | ||
| 3576 | users and applications should be allowed to do. | ||
| 3577 | |||
| 3578 | Lisp programs must be prepared that user customizations may | ||
| 3579 | cause buffers to get displayed in an unexpected way. They should | ||
| 3580 | never assume in their subsequent behavior, that the buffer has been | ||
| 3581 | shown 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 | ||
| 3585 | arbitrary buffers get displayed. Otherwise, they will risk to lose | ||
| 3586 | the characteristics of showing a buffer for a certain purpose. | ||
| 3587 | Suppose a Lisp program has been written to compare different versions | ||
| 3588 | of a buffer in two windows side-by-side. If the customization of | ||
| 3589 | @code{display-buffer-alist} prescribes that any such buffer should be | ||
| 3590 | always shown in or below the selected window, the program will have a | ||
| 3591 | hard 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 | ||
| 3595 | should customize @code{display-buffer-base-action}. An example of how | ||
| 3596 | users who prefer working with multiple frames would do that was given | ||
| 3597 | in the previous subsection. @code{display-buffer-alist} should be | ||
| 3598 | reserved for displaying specific buffers in a specific way. | ||
| 3599 | |||
| 3600 | @item Consider reusing a window that already shows the buffer | ||
| 3601 | Generally, it's always a good idea for users and Lisp | ||
| 3602 | programmers to be prepared for the case that a window already shows | ||
| 3603 | the buffer in question and to reuse that window. In the preceding | ||
| 3604 | subsection we have shown that failing to do so properly may cause | ||
| 3605 | @code{display-buffer} to continuously pop up a new frame although a | ||
| 3606 | frame showing that buffer existed already. In a few cases only, it | ||
| 3607 | might be undesirable to reuse a window, for example, when a different | ||
| 3608 | portion of the buffer should be shown in that window. | ||
| 3609 | |||
| 3610 | Hence, @code{display-buffer-reuse-window} is one action function | ||
| 3611 | that should be used as often as possible, both in @var{action} | ||
| 3612 | arguments and customizations. An @code{inhibit-same-window} entry in | ||
| 3613 | the @var{action} argument usually takes care of the most common case | ||
| 3614 | where reusing a window showing the buffer should be avoided---that | ||
| 3615 | where the window in question is the selected one. | ||
| 3616 | |||
| 3617 | @item Attract focus to the window chosen | ||
| 3618 | This is a no-brainer for people working with multiple frames---the | ||
| 3619 | frame showing the buffer will automatically raise and get focus unless | ||
| 3620 | an @code{inhibit-switch-frame} entry forbids it. For single frame | ||
| 3621 | users 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 | ||
| 3624 | regard. They split or use a seemingly arbitrary (often the largest or | ||
| 3625 | least recently used) window, distracting the user's attention. | ||
| 3626 | |||
| 3627 | Some Lisp programs therefore try to choose a window at the bottom of | ||
| 3628 | the frame, for example, in order to display the buffer in vicinity of | ||
| 3629 | the minibuffer window where the user is expected to answer a question | ||
| 3630 | related to the new window. For non-input related actions | ||
| 3631 | @code{display-buffer-below-selected} might be preferable because the | ||
| 3632 | selected 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 | ||
| 3636 | buffers in sequence and making sure that all these buffers are shown | ||
| 3637 | orderly in the resulting window configuration. Again, the standard | ||
| 3638 | action functions @code{display-buffer-pop-up-window} and | ||
| 3639 | @code{display-buffer-use-some-window} are not very suited for this | ||
| 3640 | purpose due to their somewhat chaotic nature in more complex | ||
| 3641 | configurations. | ||
| 3642 | |||
| 3643 | To produce a window configuration displaying multiple buffers (or | ||
| 3644 | different views of one and the same buffer) in one and the same | ||
| 3645 | display cycle, Lisp programmers will unavoidably have to write | ||
| 3646 | their own action functions. A few tricks listed below might help in | ||
| 3647 | this regard. | ||
| 3648 | |||
| 3649 | @itemize @bullet | ||
| 3650 | @item | ||
| 3651 | Making windows atomic (@pxref{Atomic Windows}) avoids breaking an | ||
| 3652 | existing window composition when popping up a new window. | ||
| 3653 | The new window will pop up outside the composition instead. | ||
| 3654 | |||
| 3655 | @item | ||
| 3656 | Temporarily dedicating windows to their buffers (@pxref{Dedicated | ||
| 3657 | Windows}) avoids using a window for displaying a different | ||
| 3658 | buffer. A non-dedicated window will be used instead. | ||
| 3659 | |||
| 3660 | @item | ||
| 3661 | Calling @code{window-preserve-size} (@pxref{Preserving Window Sizes}) | ||
| 3662 | will try to keep the size of the argument window unchanged when | ||
| 3663 | popping up a new window. You have to make sure that another window in | ||
| 3664 | the same combination can be shrunk instead, though. | ||
| 3665 | |||
| 3666 | @item | ||
| 3667 | Side windows (@pxref{Side Windows}) can be used for displaying | ||
| 3668 | specific buffers always in a window at the same position of a frame. | ||
| 3669 | This permits grouping buffers that do not compete for being shown at | ||
| 3670 | the same time on a frame and showing any such buffer in the same window | ||
| 3671 | without disrupting the display of other buffers. | ||
| 3672 | |||
| 3673 | @item | ||
| 3674 | Child frames (@pxref{Child Frames}) can be used to display a buffer | ||
| 3675 | within the screen estate of the selected frame without disrupting that | ||
| 3676 | frame's window configuration and without the overhead associated with | ||
| 3677 | full-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 | ||
| 2883 | This function returns @code{t} if displaying a buffer | ||
| 2884 | named @var{buffer-name} with @code{display-buffer} would | ||
| 2885 | put 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 | |||
| 3202 | containing all the normal windows. | 3996 | containing 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 |
| 3205 | specific buffers always in the same area of a frame. Hence they can be | 3999 | specific buffers always in the same area of a frame. Hence they can |
| 3206 | regarded as a generalization of the concept provided by | 4000 | be 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 |
| 3208 | the remaining sides of a frame. With suitable customizations, however, | 4002 | Functions}) to the remaining sides of a frame. With suitable |
| 3209 | side windows can be also used to provide frame layouts similar to those | 4003 | customizations, however, side windows can be also used to provide |
| 3210 | found in so-called integrated development environments (IDEs). | 4004 | frame layouts similar to those found in so-called integrated |
| 4005 | development 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 | ||
| 3224 | The following action function for @code{display-buffer} (@pxref{Display | 4019 | The following action function for @code{display-buffer} (@pxref{Buffer |
| 3225 | Action Functions}) creates or reuses a side window for displaying the | 4020 | Display Action Functions}) creates or reuses a side window for |
| 3226 | specified buffer. | 4021 | displaying the specified buffer. |
| 3227 | 4022 | ||
| 3228 | @defun display-buffer-in-side-window buffer alist | 4023 | @defun display-buffer-in-side-window buffer alist |
| 3229 | This function displays @var{buffer} in a side window of the selected | 4024 | This 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 | ||
| 3265 | By default, side windows cannot be split via @code{split-window} | 4060 | By 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 |
| 3267 | by any buffer display action (@pxref{Display Action Functions}) unless | 4062 | split by any buffer display action (@pxref{Buffer Display Action |
| 3268 | it is explicitly specified as target of that action. Note also that | 4063 | Functions}) unless it is explicitly specified as target of that |
| 3269 | @code{delete-other-windows} cannot make a side window the only window on | 4064 | action. Note also that @code{delete-other-windows} cannot make a side |
| 3270 | its frame (@pxref{Deleting Windows}). | 4065 | window 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 |
| 3456 | are accessible via @kbd{C-x o} by installing the @code{no-other-window} | 4251 | are accessible via @w{@kbd{C-x o}} by installing the @code{no-other-window} |
| 3457 | parameter for each of these windows. In addition, it makes sure that | 4252 | parameter for each of these windows. In addition, it makes sure that |
| 3458 | side windows are not deleted via @kbd{C-x 1} by installing the | 4253 | side 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 | ||
| 3548 | To create a new atomic window from an existing live window or to add a | 4343 | To create a new atomic window from an existing live window or to add a |
| 3549 | new window to an existing atomic window, the following buffer display | 4344 | new window to an existing atomic window, the following buffer display |
| 3550 | action function (@pxref{Display Action Functions}) can be used: | 4345 | action 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 |
| 3553 | This function tries to display @var{buffer} in a new window that will be | 4348 | This 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. |
| 268 | BODY should be an expression, and BINDINGS should be a list of bindings | 268 | As with `pcase-let', BINDINGS are of the form (PATTERN EXP), but the |
| 269 | of the form (PATTERN EXP). | 269 | EXP in each binding in BINDINGS can use the results of the destructuring |
| 270 | See `pcase-let' for discussion of how PATTERN is matched." | 270 | bindings that precede it in BINDINGS' order. |
| 271 | |||
| 272 | Each EXP should match (i.e. be of compatible structure) to its | ||
| 273 | respective PATTERN; a mismatch may signal an error or may go | ||
| 274 | undetected, 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. |
| 284 | BODY should be a list of expressions, and BINDINGS should be a list of bindings | 288 | BODY should be a list of expressions, and BINDINGS should be a list of |
| 285 | of the form (PATTERN EXP). | 289 | bindings of the form (PATTERN EXP). |
| 286 | The PATTERNs are only used to extract data, so the code does not test | 290 | All EXPs are evaluated first, and then used to perform destructuring |
| 287 | whether the data does match the corresponding patterns: a mismatch | 291 | bindings by matching each EXP against its respective PATTERN. Then |
| 288 | may signal an error or may go undetected, binding variables to arbitrary | 292 | BODY is evaluated with those bindings in effect. |
| 289 | values, such as nil." | 293 | |
| 294 | Each EXP should match (i.e. be of compatible structure) to its | ||
| 295 | respective PATTERN; a mismatch may signal an error or may go | ||
| 296 | undetected, 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. |
| 308 | More specifically, this is just a shorthand for the following combination | 315 | PATTERN should be a `pcase' pattern describing the structure of |
| 309 | of `dolist' and `pcase-let': | 316 | LIST elements, and LIST is a list of objects that match PATTERN, |
| 310 | 317 | i.e. have a structure that is compatible with PATTERN. | |
| 311 | (dolist (x LIST) (pcase-let ((PATTERN x)) BODY...)) | 318 | For each element of LIST, this macro binds the variables in |
| 319 | PATTERN to the corresponding subfields of the LIST element, and | ||
| 320 | then evaluates BODY with these bindings in effect. The | ||
| 321 | destructuring bindings of variables in PATTERN to the subfields | ||
| 322 | of 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)) |