@c -*-texinfo-*-
@setfilename ../info/display
@node Emacs Display, Tips, System Interface, Top
@chapter Emacs Display

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

@menu
* Refresh Screen::      Clearing the screen and redrawing everything on it.
* Screen Attributes::   How big is the Emacs screen.
* Truncation::          Folding or wrapping long text lines.
* The Echo Area::       Where messages are displayed.
* Selective Display::   Hiding part of the buffer text.
* Overlay Arrow::       Display of an arrow to indicate position.
* Temporary Displays::  Displays that go away automatically.
* Waiting::             Forcing display update and waiting for user.
* Blinking::            How Emacs shows the matching open parenthesis.
* Control Char Display::  How control characters are displayed.
* Beeping::             Audible signal to the user.
* Window Systems::      Which window system is being used.
@end menu

@node Refresh Screen, Screen Attributes, Emacs Display, Emacs Display
@section Refreshing the Screen

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

@node Screen Attributes, Truncation, Refresh Screen, Emacs Display
@section Screen Attributes
@cindex screen attributes
@cindex screen size
@cindex display lines
@cindex display columns
@cindex resize redisplay

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

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

@example
(screen-height)
     @result{} 50
@end example
@end defun

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

@example
(screen-width)
     @result{} 80
@end example
@end defun

@defun set-screen-height lines &optional not-actual-size
  This function declares that the terminal can display @var{lines} lines.
The sizes of existing windows will be altered proportionally to fit.

  If @var{not-actual-size} is non-@code{nil}, then Emacs will display
@var{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 @var{lines} is different from what it was previously, then the
entire screen is cleared and redisplayed using the new size.

  This function returns @code{nil}.
@end defun

@defun set-screen-width columns &optional not-actual-size
  This function declares that the terminal can display @var{columns}
columns.  The details are as in @code{set-screen-height}.
@end defun

@defvar no-redraw-on-reenter
@cindex @code{suspend-emacs}, related to @code{no-redraw-on-reenter}
@cindex resume, related to @code{no-redraw-on-reenter}
  This variable controls whether Emacs redraws the entire screen after
it has been suspended and resumed.  Non-@code{nil} means yes, @code{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.
@end defvar

@defvar inverse-video
@cindex highlighting
  This variable controls whether Emacs uses inverse video for all text
on the screen.  Non-@code{nil} means yes, @code{nil} means no.  The
default is @code{nil}.
@end defvar

@defopt mode-line-inverse-video
  This variable controls the use of inverse video for mode lines.  If it
is non-@code{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 @code{t}.
@end defopt

@node Truncation, The Echo Area, Screen Attributes, Emacs Display
@section Truncation
@cindex line wrapping
@cindex continuation lines
@cindex @samp{$} in display
@cindex @samp{\} in display

  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 @samp{$} in the rightmost column of
the window.  When a line is continued or ``wrapped'' onto the next line,
this is shown with a @samp{\} on the rightmost column of the window.
The additional screen lines used to display a long text line are called
@dfn{continuation} lines.  (Note that wrapped lines are not filled;
filling has nothing to do with truncation and continuation.
@xref{Filling}.)

@defopt truncate-lines
   This buffer-local variable controls how Emacs displays lines that
extend beyond the right edge of the window.  If it is non-@code{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 @code{nil}.

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

@defvar default-truncate-lines
  This variable is the default value for @code{truncate-lines} in buffers
that do not override it.
@end defvar

@defopt truncate-partial-width-windows
@cindex horizontal split lines
  This variable determines how lines that are too wide to fit on the
screen are displayed in side-by-side windows (@pxref{Splitting
Windows}).  If it is non-@code{nil}, then wide lines are truncated
(with a @samp{$} at the end of the line); otherwise they are wrapped
(with a @samp{\} at the end of the line).
@end defopt


@node The Echo Area, Selective Display, Truncation, Emacs Display
@section The Echo Area
@cindex error display
@cindex echo area

  The @dfn{echo area} is used for displaying messages made with the
@code{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
@cite{GNU Emacs Manual} specifies the rules for resolving conflicts
between the echo area and the minibuffer for use of that screen space
(@pxref{Minibuffer,, The Minibuffer, emacs, The GNU Emacs Manual}).

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

@defun message string &rest arguments
  This function prints a one-line message in the echo area.  The
argument @var{string} is similar to a C language @code{printf} control
string.  See @code{format} in @ref{String Conversion}, for the details
on the conversion specifications.  @code{message} returns the
constructed string.

@example
(message "Minibuffer depth is %d." (minibuffer-depth))
@result{} "Minibuffer depth is 0."

---------- Echo Area ----------
Minibuffer depth is 0.
---------- Echo Area ----------
@end example
@end defun

@defvar 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-@code{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 @code{nil} except when bound to @code{t} for
brief periods of time.
@end defvar

@node Selective Display, Overlay Arrow, The Echo Area, Emacs Display
@section Selective Display
@cindex selective display

  @dfn{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, @kbd{C-f} (@code{forward-char}) moves point unhesitatingly into
invisible space.  However, the replacement of newline characters with
carriage return characters affects some editing commands.  For example,
@code{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.

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

@itemize @bullet
@item
If the value of @code{selective-display} is @code{t}, then any portion
of a line that follows a control-m will not be displayed.

@item
If the value of @code{selective-display} is a positive integer, then
lines that start with more than @code{selective-display}
columns of indentation will not be displayed.
@end itemize

  When some portion of a buffer is invisible, the vertical movement
commands operate as if that portion did not exist, allowing a single
@code{next-line} command to skip any number of invisible lines.
However, character movement commands (such as @code{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 @emph{display} of the buffer
@code{foo}, which changes with the value of @code{selective-display}.  The
@emph{contents} of the buffer do not change.

@example
(setq selective-display nil)
     @result{} 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)
     @result{} 2

---------- Buffer: foo ----------
1 on this column
 2on this column
 2on this column
1 on this column
---------- Buffer: foo ----------
@end example
@end defvar

@defvar selective-display-ellipses
If this buffer-local variable is non-@code{nil}, then Emacs displays
@samp{@dots{}} at the end of a line that is followed by invisible text.
This example is a continuation of the previous one.

@example
(setq selective-display-ellipses t)
     @result{} t

---------- Buffer: foo ----------
1 on this column
 2on this column ...
 2on this column
1 on this column
---------- Buffer: foo ----------
@end example
@end defvar

@node Overlay Arrow, Temporary Displays, Selective Display, Emacs Display
@section Overlay Arrow
@cindex overlay arrow

  The @dfn{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.

@defvar overlay-arrow-string
This variable holds the string to display as an arrow, or @code{nil} if
the arrow feature is not in use.
@end defvar

@defvar 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.
@c !!! overlay-arrow-position: but the overlay string may remain in the display
@c of some other buffer until an update is required.  This should be fixed
@c now.  Is it?
@end defvar

@node Temporary Displays, Waiting, Overlay Arrow, Emacs Display
@section 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.

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

  The buffer is named by the string @var{buffer-name}, and it need not
already exist.  The argument @var{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 @code{with-output-to-temp-buffer}
exits.

  @code{with-output-to-temp-buffer} first binds @code{standard-output}
to the buffer, then it evaluates the forms in @var{forms}.  With
@code{standard-output} rebound, any output directed there will naturally
be inserted into that buffer.  Only Lisp output directed to the stream
@code{standard-output} is affected; screen display and messages in the
echo area, although output in the general sense of the word, are not
affected.  @xref{Output Functions}.

  The value of the last form in @var{forms} is returned.

@example
---------- Buffer: foo ----------
 This is the contents of foo.
---------- Buffer: foo ----------

(with-output-to-temp-buffer "foo"
    (print 20)
    (print standard-output))
@result{} #<buffer foo>

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

#<buffer foo>

---------- Buffer: foo ----------
@end example
@end defspec

@defvar temp-buffer-show-hook
  The value of the @code{temp-buffer-show-hook} variable is either
@code{nil} or is called as a function to display a help buffer.  This
variable is used by @code{with-output-to-temp-buffer}.
@end defvar

@defun momentary-string-display string position &optional char message
  This function momentarily displays @var{string} in the current
buffer at @var{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 @var{char}, Emacs ignores it.
Otherwise, that character remains buffered for subsequent use as input.
Thus, typing @var{char} will simply remove the string from the display,
while typing (say) @kbd{C-f} will remove the string from the display and
later (presumably) move point forward.  The argument @var{char} is a
space by default.

  The result of @code{momentary-string-display} is not useful.

  If @var{message} is non-@code{nil}, it is displayed in the echo
area.  If it is @code{nil}, then instructions to type @var{char} are
displayed there, e.g., @samp{Type RET to continue editing}.

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

@example
---------- Buffer: foo ----------
This is the contents of foo.
@point{}This is the contents of foo.
---------- Buffer: foo ----------

(momentary-string-display
   "******* Important Message! *******" (point) ?\r
   "Type RET when done reading")
@result{} 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
@end example

  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.
@end defun

@node Waiting, Blinking, Temporary Displays, Emacs Display
@section Waiting for Elapsed Time or Input
@cindex pausing
@cindex waiting

  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.  @code{sit-for} performs a pause with an update of
screen, while @code{sleep-for} performs a pause without updating the
screen.

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

@cindex forcing redisplay
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
@code{(sit-for 0)}.

The purpose of @code{sit-for} to give the user time to read text
that you display.
@end defun

@defun sleep-for seconds
This function simply pauses for @var{seconds} seconds without updating
the display.  It pays no attention to available input.  It returns
@code{nil}.

Use @code{sleep-for} when you wish to guarantee a delay.
@end defun

@node Blinking, Control Char Display, Waiting, Emacs Display
@section Blinking
@cindex parenthesis matching
@cindex blinking
@cindex balancing parentheses
@cindex close parenthesis

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

@vindex blink-paren-function
@defvar 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 @code{blink-paren-hook} may be @code{nil}, in which case
nothing is done.

@quotation
@strong{Note:} in version 18, this function is named
@code{blink-paren-hook}, but since it is not called with the standard
convention for hooks, it is being renamed to @code{blink-paren-function}
in version 19.
@end quotation
@end defvar

@defvar blink-matching-paren
If this variable is @code{nil}, then @code{blink-matching-open} does
nothing.
@end defvar

@defvar blink-matching-paren-distance
This variable specifies the maximum distance to scan for a matching
parenthesis before giving up.
@end defvar

@defun blink-matching-open
This function is the default value of @code{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 @code{blink-matching-paren-distance}
characters.

Here is an example of calling this function explicitly.

@example
(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)))
@end example
@end defun

@node Control Char Display, Beeping, Blinking, Emacs Display
@section 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.

@defopt ctl-arrow
@cindex control characters in display
  This buffer-local variable controls how control characters are
displayed.  If it is non-@code{nil}, they are displayed as an uparrow
followed by the character: @samp{^A}.  If it is @code{nil}, they are
displayed as a backslash followed by three octal digits: @samp{\001}.
@end defopt

@defvar default-ctl-arrow
  The value of this variable is the default value for @code{ctl-arrow} in
buffers that do not override it.  This is the same as @code{(default-value
'ctl-arrow)} (@pxref{Default Value}).
@end defvar

@defopt 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 @code{tab-to-tab-stop}.  @xref{Indent Tabs}.
@end defopt

@node Beeping, Window Systems, Control Char Display, Emacs Display
@section Beeping
@cindex beeping
@cindex bell

  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.  (@xref{Errors}.)

@defun ding &optional dont-terminate
@cindex keyboard macro termination
  This function beeps, or flashes the screen (see @code{visible-bell} below).
It also terminates any keyboard macro currently executing unless
@var{dont-terminate} is non-@code{nil}.
@end defun

@defun beep &optional dont-terminate
This is a synonym for @code{ding}.
@end defun

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

@node Window Systems,, Beeping, Emacs Display
@section 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.

@defvar window-system
@cindex X Window System
  This variable tells Lisp programs what window system Emacs is running
under.  Its value should be a symbol such as @code{x} (if Emacs is
running under X Windows) or @code{nil} (if Emacs is running on an ordinary
terminal).
@end defvar

@defvar window-system-version
  This variable distinguishes between different versions of the X Window
System.  Its value is 10 or 11 when using X Windows; @code{nil}
otherwise.
@end defvar

@defvar window-setup-hook
  The value of the @code{window-setup-hook} variable is either
@code{nil} or a function for Emacs to call after loading your
@file{.emacs} file and the default initialization file (if any), after
loading terminal-specific Lisp code, and after calling
@code{term-setup-hook}.  @code{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.
@end defvar
