Next: , Previous: , Up: Display   [Contents][Index]


52.8 Temporary Displays

Temporary displays are used by commands to put output into a buffer and then present it to the user for perusal rather than for editing. Many of the help commands use this feature.

Special Form: with-output-to-temp-buffer buffer-name forms…

This function executes forms while arranging to insert any output they print into the buffer named buffer-name. The buffer is then shown in some window for viewing, displayed but not selected.

The string buffer-name specifies the temporary buffer, which need not already exist. The argument must be a string, not a buffer. The buffer is erased initially (with no questions asked), and it is marked as unmodified after with-output-to-temp-buffer exits.

with-output-to-temp-buffer binds standard-output to the temporary buffer, then it evaluates the forms in forms. Output using the Lisp output functions within forms goes by default to that buffer (but screen display and messages in the echo area, although they are “output” in the general sense of the word, are not affected). See Output Functions.

The value of the last form in forms is returned.

---------- Buffer: foo ----------
 This is the contents of foo.
---------- Buffer: foo ----------
(with-output-to-temp-buffer "foo"
    (print 20)
    (print standard-output))
⇒ #<buffer foo>

---------- Buffer: foo ----------
20

#<buffer foo>

---------- Buffer: foo ----------
Variable: temp-buffer-show-function

If this variable is non-nil, with-output-to-temp-buffer calls it as a function to do the job of displaying a help buffer. The function gets one argument, which is the buffer it should display.

In Emacs versions 18 and earlier, this variable was called temp-buffer-show-hook.

Function: momentary-string-display string position &optional char message

This function momentarily displays string in the current buffer at position. It has no effect on the undo list or on the buffer’s modification status.

The momentary display remains until the next input event. If the next input event is char, momentary-string-display ignores it and returns. Otherwise, that event remains buffered for subsequent use as input. Thus, typing char will simply remove the string from the display, while typing (say) C-f will remove the string from the display and later (presumably) move point forward. The argument char is a space by default.

The return value of momentary-string-display is not meaningful.

You can do the same job in a more general way by creating an extent with a begin-glyph property. See Extent Properties.

If message is non-nil, it is displayed in the echo area while string is displayed in the buffer. If it is nil, a default message says to type char to continue.

In this example, point is initially located at the beginning of the second line:

---------- Buffer: foo ----------
This is the contents of foo.
∗Second line.
---------- Buffer: foo ----------
(momentary-string-display
  "**** Important Message! ****"
  (point) ?\r
  "Type RET when done reading")
⇒ t
---------- Buffer: foo ----------
This is the contents of foo.
**** Important Message! ****Second line.
---------- Buffer: foo ----------

---------- Echo Area ----------
Type RET when done reading
---------- Echo Area ----------

This function works by actually changing the text in the buffer. As a result, if you later undo in this buffer, you will see the message come and go.


Next: , Previous: , Up: Display   [Contents][Index]