Emacs Display
*************

This chapter describes a number of features related to the display that Emacs presents to the user.

Refreshing the Screen
=====================

 -- Command: redraw-display
     This function clears the screen and redraws what is supposed to appear on it.

Screen Attributes
=================

The screen attribute functions describe and define the characteristics of the terminal.

 -- Function: screen-height
     This function returns the number of lines on the screen that are available for display.

          (screen-height)
               => 50

 -- Function: screen-width
     This function returns the number of columns on the screen that are available for display.

          (screen-width)
               => 80

 -- Function: set-screen-height lines &optional not-actual-size
     This function declares that the terminal can display LINES lines. The sizes of existing windows will be altered proportionally to fit.

     If NOT-ACTUAL-SIZE is non-nil, then Emacs will display LINES lines of output, but will not change its value for the actual height of the screen.  Knowing the correct actual size may be necessary for correct cursor positioning.

     If LINES is different from what it was previously, then the entire screen is cleared and redisplayed using the new size.

     This function returns nil.

 -- Function: set-screen-width columns &optional not-actual-size
     This function declares that the terminal can display COLUMNS columns.  The details are as in set-screen-height.

 -- Variable: no-redraw-on-reenter
     This variable controls whether Emacs redraws the entire screen after it has been suspended and resumed.  Non-nil means yes, nil means no.  On most terminals, it is necessary to redraw.  Not redrawing is useful if the terminal can remember and restore the Emacs screen contents.

 -- Variable: inverse-video
     This variable controls whether Emacs uses inverse video for all text on the screen.  Non-nil means yes, nil means no.  The default is nil.

 -- User Option: mode-line-inverse-video
     This variable controls the use of inverse video for mode lines.  If it is non-nil, then mode lines are displayed in inverse video (or another suitable display mode).  Otherwise, mode lines are displayed normal, just like the rest of the screen.  The default is t.

Truncation
==========

When a line of text extends beyond the right edge of a window, the line can either be truncated or continued on the next line.  When a line is truncated, this is shown with a $ in the rightmost column of the window.  When a line is continued or ``wrapped'' onto the next line, this is shown with a \ on the rightmost column of the window. The additional screen lines used to display a long text line are called continuation lines.  (Note that wrapped lines are not filled; filling has nothing to do with truncation and continuation. See Filling.)

 -- User Option: truncate-lines
     This buffer-local variable controls how Emacs displays lines that extend beyond the right edge of the window.  If it is non-nil, then Emacs does not display continuation lines; but rather each line of text will take exactly one screen line, and a dollar sign will be shown at the edge of any line that extends to or beyond the edge of the window.  The default is nil.

     If the variable truncate-partial-width-windows is non-nil, then truncation is used for windows that are not the full width of the screen, regardless of the value of truncate-lines.

 -- Variable: default-truncate-lines
     This variable is the default value for truncate-lines in buffers that do not override it.

 -- User Option: truncate-partial-width-windows
     This variable determines how lines that are too wide to fit on the screen are displayed in side-by-side windows (see Splitting Windows).  If it is non-nil, then wide lines are truncated (with a $ at the end of the line); otherwise they are wrapped (with a \ at the end of the line).

The Echo Area
=============

The echo area is used for displaying messages made with the message primitive, and for echoing keystrokes.  It is not the same as the minibuffer, despite the fact that the minibuffer appears (when active) in the same place on the screen as the echo area.  The GNU Emacs Manual specifies the rules for resolving conflicts between the echo area and the minibuffer for use of that screen space (see The Minibuffer (The GNU Emacs Manual)).

You can write output in the echo area by using the Lisp printing funtions with t as the stream (see Output Functions), or as follows:

 -- Function: message string &rest arguments
     This function prints a one-line message in the echo area.  The argument STRING is similar to a C language printf control string.  See format in String Conversion, for the details on the conversion specifications.  message returns the constructed string.

          (message "Minibuffer depth is %d." (minibuffer-depth))
          => "Minibuffer depth is 0."

          ---------- Echo Area ----------
          Minibuffer depth is 0.
          ---------- Echo Area ----------

 -- Variable: cursor-in-echo-area
     This variable controls where the cursor is positioned when a message is displayed in the echo area.  If it is non-nil, then the cursor appears at the end of the message.  Otherwise, the cursor appears at point---not in the echo area at all.

     The value is normally nil except when bound to t for brief periods of time.

Selective Display
=================

Selective display is a class of minor modes in which specially marked lines do not appear on the screen, or in which highly indented lines do not appear.

The first variant, explicit selective display, is designed for use in a Lisp program.  The program controls which lines are hidden by altering the text.  Outline mode uses this variant.  In the second variant, the choice of lines to hide is made automatically based on indentation. This variant is designed as a user-level feature.

The way you control explicit selective display is by replacing a newline (control-j) with a control-m.  The text which was formerly a line following that newline is now invisible.  Strictly speaking, it is no longer a separate line, since only newlines can separate lines; it is now part of the previous line.

On its own, selective display does not affect editing commands.  For example, C-f (forward-char) moves point unhesitatingly into invisible space.  However, the replacement of newline characters with carriage return characters affects some editing commands.  For example, next-line skips invisible lines, since it searches only for newlines.  Modes that use selective display can also define commands that take account of the newlines, or which make parts of the text visible or invisible.

When you write a selectively displayed buffer into a file, all the control-m's are replaced by their original newlines.  This means that when you next read in the file, it looks OK, with nothing invisible. Selective display is an effect that is seen only in Emacs.

 -- Variable: selective-display
     This buffer-local variable enables selective display.  This means that lines, or portions of lines, may be made invisible.

       * If the value of selective-display is t, then any portion of a line that follows a control-m will not be displayed.

       * If the value of selective-display is a positive integer, then lines that start with more than selective-display columns of indentation will not be displayed.

     When some portion of a buffer is invisible, the vertical movement commands operate as if that portion did not exist, allowing a single next-line command to skip any number of invisible lines. However, character movement commands (such as forward-char) will not skip the invisible portion, and it is possible (if tricky) to insert or delete parts of an invisible portion.

     In the examples below, what is shown is the display of the buffer foo, which changes with the value of selective-display.  The contents of the buffer do not change.

          (setq selective-display nil)
               => nil

          ---------- Buffer: foo ----------
          1 on this column
           2on this column
            3n this column
            3n this column
           2on this column
          1 on this column
          ---------- Buffer: foo ----------

          (setq selective-display 2)
               => 2

          ---------- Buffer: foo ----------
          1 on this column
           2on this column
           2on this column
          1 on this column
          ---------- Buffer: foo ----------

 -- Variable: selective-display-ellipses
     If this buffer-local variable is non-nil, then Emacs displays ... at the end of a line that is followed by invisible text. This example is a continuation of the previous one.

          (setq selective-display-ellipses t)
               => t

          ---------- Buffer: foo ----------
          1 on this column
           2on this column ...
           2on this column
          1 on this column
          ---------- Buffer: foo ----------

Overlay Arrow
=============

The overlay arrow is useful for directing the user's attention to a particular line in a buffer.  For example, in the modes used for interface to debuggers, the overlay arrow indicates the current line of code about to be executed.

 -- Variable: overlay-arrow-string
     This variable holds the string to display as an arrow, or nil if the arrow feature is not in use.

 -- Variable: overlay-arrow-position
     This variable holds a marker which indicates where to display the arrow. It should point at the beginning of a line.  The arrow text will be displayed at the beginning of that line, overlaying any text that would otherwise appear.  Since the arrow is usually short, and the line usually begins with indentation, normally nothing significant is overwritten.

     The overlay string is displayed only in the buffer which this marker points into.  Thus, only one buffer can have an overlay arrow at any given time.

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 buffer is named by the string BUFFER-NAME, and it need not already exist.  The argument BUFFER-NAME 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 first binds standard-output to the buffer, then it evaluates the forms in FORMS.  With standard-output rebound, any output directed there will naturally be inserted into that buffer.  Only Lisp output directed to the stream standard-output is affected; screen display and messages in the echo area, although 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-hook
     The value of the temp-buffer-show-hook variable is either nil or is called as a function to display a help buffer.  This variable is used by with-output-to-temp-buffer.

 -- Function: momentary-string-display string position &optional char message
     This function momentarily displays STRING in the current buffer at POSITION (which is a character offset from the beginning of the buffer).  The display remains until the next character is typed.

     If the next character the user types is CHAR, Emacs ignores it. Otherwise, that character 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 result of momentary-string-display is not useful.

     If MESSAGE is non-nil, it is displayed in the echo area.  If it is nil, then instructions to type CHAR are displayed there, e.g., Type RET to continue editing.

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

          ---------- Buffer: foo ----------
          This is the contents of foo.
          -!-This is the contents of foo.
          ---------- 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! *******This is the contents of foo.
          ---------- Buffer: foo ----------

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

     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.

Waiting for Elapsed Time or Input
=================================

The waiting commands are designed to make Emacs wait for a certain amount of time to pass or until there is input.  For example, you may wish to pause in the middle of a computation to allow the user time to view the display.  sit-for performs a pause with an update of screen, while sleep-for performs a pause without updating the screen.

 -- Function: sit-for seconds
     This function performs redisplay (provided there is no pending input from the user), then waits SECONDS seconds, or until input is available.  The result is t if sit-for waited the full time with no input arriving (see input-pending-p in Keyboard Input).  Otherwise, nil is returned.

     Redisplay is always preempted if input arrives, and does not happen at all if input is available before it starts.  Thus, there is no way to force screen updating if there is pending input; however, if there is no input pending, you can force an update with no delay by using (sit-for 0).

     The purpose of sit-for to give the user time to read text that you display.

 -- Function: sleep-for seconds
     This function simply pauses for SECONDS seconds without updating the display.  It pays no attention to available input.  It returns nil.

     Use sleep-for when you wish to guarantee a delay.

Blinking
========

This section describes the mechanism by which Emacs shows a matching open parenthesis when the user inserts a close parenthesis.

 -- Variable: blink-paren-hook
     The value of this variable should be a function (of no arguments) to be called whenever a char with close parenthesis syntax is inserted. The value of blink-paren-hook may be nil, in which case nothing is done.

          Note: in version 18, this function is named blink-paren-hook, but since it is not called with the standard convention for hooks, it is being renamed to blink-paren-function in version 19.

 -- Variable: blink-matching-paren
     If this variable is nil, then blink-matching-open does nothing.

 -- Variable: blink-matching-paren-distance
     This variable specifies the maximum distance to scan for a matching parenthesis before giving up.

 -- Function: blink-matching-open
     This function is the default value of blink-paren-hook.  It assumes that point follows a character with close parenthesis syntax and moves the cursor momentarily to the matching opening character.  If that character is not already on the screen, then its context is shown by displaying it in the echo area.  To avoid long delays, this function does not search farther than blink-matching-paren-distance characters.

     Here is an example of calling this function explicitly.

          (defun interactive-blink-matching-open ()
            "Indicate momentarily the start of sexp before point."
            (interactive)
            (let ((blink-matching-paren-distance (buffer-size))
                  (blink-matching-paren t))
              (blink-matching-open)))

Display of Control Characters
=============================

These variables affect the way certain characters are displayed on the screen.  Since they change the number of columns the characters occupy, they also affect the indentation functions.

 -- User Option: ctl-arrow
     This buffer-local variable controls how control characters are displayed.  If it is non-nil, they are displayed as an uparrow followed by the character: ^A.  If it is nil, they are displayed as a backslash followed by three octal digits: \001.

 -- Variable: default-ctl-arrow
     The value of this variable is the default value for ctl-arrow in buffers that do not override it.  This is the same as (default-value 'ctl-arrow) (see Default Value).

 -- User Option: tab-width
     The value of this variable is the spacing between tab stops used for displaying tab characters in Emacs buffers.  The default is 8.  Note that this feature is completely independent from the user-settable tab stops used by the command tab-to-tab-stop.  See Indent Tabs.

Beeping
=======

You can make Emacs ring a bell (or blink the screen) to attract the user's attention.  Be conservative about how often you do this; frequent bells can become irritating.  Also be careful not to use beeping alone when signaling an error is appropriate.  (see Errors.)

 -- Function: ding &optional dont-terminate
     This function beeps, or flashes the screen (see visible-bell below). It also terminates any keyboard macro currently executing unless DONT-TERMINATE is non-nil.

 -- Function: beep &optional dont-terminate
     This is a synonym for ding.

 -- Variable: visible-bell
     This variable determines whether Emacs will try to flash the screen to represent a bell.  Non-nil means yes, nil means no.  This is effective only if the termcap entry for the terminal in use has the visible bell flag (vb) set.

Window Systems
==============

Emacs works with several window systems, most notably X Windows.  Note that both Emacs and the X Window System use the term ``window'', but use it differently.  The entire Emacs screen is a single window as far as X Windows is concerned; the individual Emacs windows are not known to X Windows at all.

 -- Variable: window-system
     This variable tells Lisp programs what window system Emacs is running under.  Its value should be a symbol such as x (if Emacs is running under X Windows) or nil (if Emacs is running on an ordinary terminal).

 -- Variable: window-system-version
     This variable distinguishes between different versions of the X Window System.  Its value is 10 or 11 when using X Windows; nil otherwise.

 -- Variable: window-setup-hook
     The value of the window-setup-hook variable is either nil or a function for Emacs to call after loading your .emacs file and the default initialization file (if any), after loading terminal-specific Lisp code, and after calling term-setup-hook.  window-setup-hook is called with no arguments.

     This hook is used for internal purposes: setting up communication with the window system, and creating the initial window.  Users should not interfere with it.