| 1 |
@c -*-texinfo-*- |
|---|
| 2 |
@c This is part of the GNU Emacs Lisp Reference Manual. |
|---|
| 3 |
@c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998, 1999, 2000, 2001, |
|---|
| 4 |
@c 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. |
|---|
| 5 |
@c See the file elisp.texi for copying conditions. |
|---|
| 6 |
@setfilename ../info/display |
|---|
| 7 |
@node Display, System Interface, Processes, Top |
|---|
| 8 |
@chapter Emacs Display |
|---|
| 9 |
|
|---|
| 10 |
This chapter describes a number of features related to the display |
|---|
| 11 |
that Emacs presents to the user. |
|---|
| 12 |
|
|---|
| 13 |
@menu |
|---|
| 14 |
* Refresh Screen:: Clearing the screen and redrawing everything on it. |
|---|
| 15 |
* Forcing Redisplay:: Forcing redisplay. |
|---|
| 16 |
* Truncation:: Folding or wrapping long text lines. |
|---|
| 17 |
* The Echo Area:: Displaying messages at the bottom of the screen. |
|---|
| 18 |
* Warnings:: Displaying warning messages for the user. |
|---|
| 19 |
* Invisible Text:: Hiding part of the buffer text. |
|---|
| 20 |
* Selective Display:: Hiding part of the buffer text (the old way). |
|---|
| 21 |
* Temporary Displays:: Displays that go away automatically. |
|---|
| 22 |
* Overlays:: Use overlays to highlight parts of the buffer. |
|---|
| 23 |
* Width:: How wide a character or string is on the screen. |
|---|
| 24 |
* Line Height:: Controlling the height of lines. |
|---|
| 25 |
* Faces:: A face defines a graphics style for text characters: |
|---|
| 26 |
font, colors, etc. |
|---|
| 27 |
* Fringes:: Controlling window fringes. |
|---|
| 28 |
* Scroll Bars:: Controlling vertical scroll bars. |
|---|
| 29 |
* Display Property:: Enabling special display features. |
|---|
| 30 |
* Images:: Displaying images in Emacs buffers. |
|---|
| 31 |
* Buttons:: Adding clickable buttons to Emacs buffers. |
|---|
| 32 |
* Abstract Display:: Emacs' Widget for Object Collections. |
|---|
| 33 |
* Blinking:: How Emacs shows the matching open parenthesis. |
|---|
| 34 |
* Usual Display:: The usual conventions for displaying nonprinting chars. |
|---|
| 35 |
* Display Tables:: How to specify other conventions. |
|---|
| 36 |
* Beeping:: Audible signal to the user. |
|---|
| 37 |
* Window Systems:: Which window system is being used. |
|---|
| 38 |
@end menu |
|---|
| 39 |
|
|---|
| 40 |
@node Refresh Screen |
|---|
| 41 |
@section Refreshing the Screen |
|---|
| 42 |
|
|---|
| 43 |
The function @code{redraw-frame} clears and redisplays the entire |
|---|
| 44 |
contents of a given frame (@pxref{Frames}). This is useful if the |
|---|
| 45 |
screen is corrupted. |
|---|
| 46 |
|
|---|
| 47 |
@c Emacs 19 feature |
|---|
| 48 |
@defun redraw-frame frame |
|---|
| 49 |
This function clears and redisplays frame @var{frame}. |
|---|
| 50 |
@end defun |
|---|
| 51 |
|
|---|
| 52 |
Even more powerful is @code{redraw-display}: |
|---|
| 53 |
|
|---|
| 54 |
@deffn Command redraw-display |
|---|
| 55 |
This function clears and redisplays all visible frames. |
|---|
| 56 |
@end deffn |
|---|
| 57 |
|
|---|
| 58 |
In Emacs, processing user input takes priority over redisplay. If |
|---|
| 59 |
you call these functions when input is available, they don't redisplay |
|---|
| 60 |
immediately, but the requested redisplay does happen |
|---|
| 61 |
eventually---after all the input has been processed. |
|---|
| 62 |
|
|---|
| 63 |
Normally, suspending and resuming Emacs also refreshes the screen. |
|---|
| 64 |
Some terminal emulators record separate contents for display-oriented |
|---|
| 65 |
programs such as Emacs and for ordinary sequential display. If you are |
|---|
| 66 |
using such a terminal, you might want to inhibit the redisplay on |
|---|
| 67 |
resumption. |
|---|
| 68 |
|
|---|
| 69 |
@defvar no-redraw-on-reenter |
|---|
| 70 |
@cindex suspend (cf. @code{no-redraw-on-reenter}) |
|---|
| 71 |
@cindex resume (cf. @code{no-redraw-on-reenter}) |
|---|
| 72 |
This variable controls whether Emacs redraws the entire screen after it |
|---|
| 73 |
has been suspended and resumed. Non-@code{nil} means there is no need |
|---|
| 74 |
to redraw, @code{nil} means redrawing is needed. The default is @code{nil}. |
|---|
| 75 |
@end defvar |
|---|
| 76 |
|
|---|
| 77 |
@node Forcing Redisplay |
|---|
| 78 |
@section Forcing Redisplay |
|---|
| 79 |
@cindex forcing redisplay |
|---|
| 80 |
|
|---|
| 81 |
Emacs normally tries to redisplay the screen whenever it waits for |
|---|
| 82 |
input. With this function you can request an immediate attempt to |
|---|
| 83 |
redisplay, in the middle of Lisp code, without actually waiting for |
|---|
| 84 |
input. |
|---|
| 85 |
|
|---|
| 86 |
@defun redisplay &optional force |
|---|
| 87 |
This function tries immediately to redisplay, provided there are no |
|---|
| 88 |
pending input events. It is equivalent to @code{(sit-for 0)}. |
|---|
| 89 |
|
|---|
| 90 |
If the optional argument @var{force} is non-@code{nil}, it does all |
|---|
| 91 |
pending redisplay work even if input is available, with no |
|---|
| 92 |
pre-emption. |
|---|
| 93 |
|
|---|
| 94 |
The function returns @code{t} if it actually tried to redisplay, and |
|---|
| 95 |
@code{nil} otherwise. A value of @code{t} does not mean that |
|---|
| 96 |
redisplay proceeded to completion; it could have been pre-empted by |
|---|
| 97 |
newly arriving terminal input. |
|---|
| 98 |
@end defun |
|---|
| 99 |
|
|---|
| 100 |
@code{redisplay} with no argument tries immediately to redisplay, |
|---|
| 101 |
but has no effect on the usual rules for what parts of the screen to |
|---|
| 102 |
redisplay. By contrast, the following function adds certain windows |
|---|
| 103 |
to the pending redisplay work (as if their contents had completely |
|---|
| 104 |
changed), but doesn't immediately try to do any redisplay work. |
|---|
| 105 |
|
|---|
| 106 |
@defun force-window-update &optional object |
|---|
| 107 |
This function forces some or all windows to be updated on next |
|---|
| 108 |
redisplay. If @var{object} is a window, it requires eventual |
|---|
| 109 |
redisplay of that window. If @var{object} is a buffer or buffer name, |
|---|
| 110 |
it requires eventual redisplay of all windows displaying that buffer. |
|---|
| 111 |
If @var{object} is @code{nil} (or omitted), it requires eventual |
|---|
| 112 |
redisplay of all windows. |
|---|
| 113 |
@end defun |
|---|
| 114 |
|
|---|
| 115 |
@code{force-window-update} does not do a redisplay immediately. |
|---|
| 116 |
(Emacs will do that when it waits for input.) Rather, its effect is |
|---|
| 117 |
to put more work on the queue to be done by redisplay whenever there |
|---|
| 118 |
is a chance. |
|---|
| 119 |
|
|---|
| 120 |
Emacs redisplay normally stops if input arrives, and does not happen |
|---|
| 121 |
at all if input is available before it starts. Most of the time, this |
|---|
| 122 |
is exactly what you want. However, you can prevent preemption by |
|---|
| 123 |
binding @code{redisplay-dont-pause} to a non-@code{nil} value. |
|---|
| 124 |
|
|---|
| 125 |
@defvar redisplay-dont-pause |
|---|
| 126 |
If this variable is non-@code{nil}, pending input does not |
|---|
| 127 |
prevent or halt redisplay; redisplay occurs, and finishes, |
|---|
| 128 |
regardless of whether input is available. |
|---|
| 129 |
@end defvar |
|---|
| 130 |
|
|---|
| 131 |
@defvar redisplay-preemption-period |
|---|
| 132 |
This variable specifies how many seconds Emacs waits between checks |
|---|
| 133 |
for new input during redisplay. (The default is 0.1 seconds.) If |
|---|
| 134 |
input has arrived when Emacs checks, it pre-empts redisplay and |
|---|
| 135 |
processes the available input before trying again to redisplay. |
|---|
| 136 |
|
|---|
| 137 |
If this variable is @code{nil}, Emacs does not check for input during |
|---|
| 138 |
redisplay, and redisplay cannot be preempted by input. |
|---|
| 139 |
|
|---|
| 140 |
This variable is only obeyed on graphical terminals. For |
|---|
| 141 |
text terminals, see @ref{Terminal Output}. |
|---|
| 142 |
@end defvar |
|---|
| 143 |
|
|---|
| 144 |
@node Truncation |
|---|
| 145 |
@section Truncation |
|---|
| 146 |
@cindex line wrapping |
|---|
| 147 |
@cindex line truncation |
|---|
| 148 |
@cindex continuation lines |
|---|
| 149 |
@cindex @samp{$} in display |
|---|
| 150 |
@cindex @samp{\} in display |
|---|
| 151 |
|
|---|
| 152 |
When a line of text extends beyond the right edge of a window, Emacs |
|---|
| 153 |
can @dfn{continue} the line (make it ``wrap'' to the next screen |
|---|
| 154 |
line), or @dfn{truncate} the line (limit it to one screen line). The |
|---|
| 155 |
additional screen lines used to display a long text line are called |
|---|
| 156 |
@dfn{continuation} lines. Continuation is not the same as filling; |
|---|
| 157 |
continuation happens on the screen only, not in the buffer contents, |
|---|
| 158 |
and it breaks a line precisely at the right margin, not at a word |
|---|
| 159 |
boundary. @xref{Filling}. |
|---|
| 160 |
|
|---|
| 161 |
On a graphical display, tiny arrow images in the window fringes |
|---|
| 162 |
indicate truncated and continued lines (@pxref{Fringes}). On a text |
|---|
| 163 |
terminal, a @samp{$} in the rightmost column of the window indicates |
|---|
| 164 |
truncation; a @samp{\} on the rightmost column indicates a line that |
|---|
| 165 |
``wraps.'' (The display table can specify alternate characters to use |
|---|
| 166 |
for this; @pxref{Display Tables}). |
|---|
| 167 |
|
|---|
| 168 |
@defopt truncate-lines |
|---|
| 169 |
This buffer-local variable controls how Emacs displays lines that extend |
|---|
| 170 |
beyond the right edge of the window. The default is @code{nil}, which |
|---|
| 171 |
specifies continuation. If the value is non-@code{nil}, then these |
|---|
| 172 |
lines are truncated. |
|---|
| 173 |
|
|---|
| 174 |
If the variable @code{truncate-partial-width-windows} is non-@code{nil}, |
|---|
| 175 |
then truncation is always used for side-by-side windows (within one |
|---|
| 176 |
frame) regardless of the value of @code{truncate-lines}. |
|---|
| 177 |
@end defopt |
|---|
| 178 |
|
|---|
| 179 |
@defopt default-truncate-lines |
|---|
| 180 |
This variable is the default value for @code{truncate-lines}, for |
|---|
| 181 |
buffers that do not have buffer-local values for it. |
|---|
| 182 |
@end defopt |
|---|
| 183 |
|
|---|
| 184 |
@defopt truncate-partial-width-windows |
|---|
| 185 |
This variable controls display of lines that extend beyond the right |
|---|
| 186 |
edge of the window, in side-by-side windows (@pxref{Splitting Windows}). |
|---|
| 187 |
If it is non-@code{nil}, these lines are truncated; otherwise, |
|---|
| 188 |
@code{truncate-lines} says what to do with them. |
|---|
| 189 |
@end defopt |
|---|
| 190 |
|
|---|
| 191 |
When horizontal scrolling (@pxref{Horizontal Scrolling}) is in use in |
|---|
| 192 |
a window, that forces truncation. |
|---|
| 193 |
|
|---|
| 194 |
If your buffer contains @emph{very} long lines, and you use |
|---|
| 195 |
continuation to display them, just thinking about them can make Emacs |
|---|
| 196 |
redisplay slow. The column computation and indentation functions also |
|---|
| 197 |
become slow. Then you might find it advisable to set |
|---|
| 198 |
@code{cache-long-line-scans} to @code{t}. |
|---|
| 199 |
|
|---|
| 200 |
@defvar cache-long-line-scans |
|---|
| 201 |
If this variable is non-@code{nil}, various indentation and motion |
|---|
| 202 |
functions, and Emacs redisplay, cache the results of scanning the |
|---|
| 203 |
buffer, and consult the cache to avoid rescanning regions of the buffer |
|---|
| 204 |
unless they are modified. |
|---|
| 205 |
|
|---|
| 206 |
Turning on the cache slows down processing of short lines somewhat. |
|---|
| 207 |
|
|---|
| 208 |
This variable is automatically buffer-local in every buffer. |
|---|
| 209 |
@end defvar |
|---|
| 210 |
|
|---|
| 211 |
@node The Echo Area |
|---|
| 212 |
@section The Echo Area |
|---|
| 213 |
@cindex error display |
|---|
| 214 |
@cindex echo area |
|---|
| 215 |
|
|---|
| 216 |
The @dfn{echo area} is used for displaying error messages |
|---|
| 217 |
(@pxref{Errors}), for messages made with the @code{message} primitive, |
|---|
| 218 |
and for echoing keystrokes. It is not the same as the minibuffer, |
|---|
| 219 |
despite the fact that the minibuffer appears (when active) in the same |
|---|
| 220 |
place on the screen as the echo area. The @cite{GNU Emacs Manual} |
|---|
| 221 |
specifies the rules for resolving conflicts between the echo area and |
|---|
| 222 |
the minibuffer for use of that screen space (@pxref{Minibuffer,, The |
|---|
| 223 |
Minibuffer, emacs, The GNU Emacs Manual}). |
|---|
| 224 |
|
|---|
| 225 |
You can write output in the echo area by using the Lisp printing |
|---|
| 226 |
functions with @code{t} as the stream (@pxref{Output Functions}), or |
|---|
| 227 |
explicitly. |
|---|
| 228 |
|
|---|
| 229 |
@menu |
|---|
| 230 |
* Displaying Messages:: Explicitly displaying text in the echo area. |
|---|
| 231 |
* Progress:: Informing user about progress of a long operation. |
|---|
| 232 |
* Logging Messages:: Echo area messages are logged for the user. |
|---|
| 233 |
* Echo Area Customization:: Controlling the echo area. |
|---|
| 234 |
@end menu |
|---|
| 235 |
|
|---|
| 236 |
@node Displaying Messages |
|---|
| 237 |
@subsection Displaying Messages in the Echo Area |
|---|
| 238 |
@cindex display message in echo area |
|---|
| 239 |
|
|---|
| 240 |
This section describes the functions for explicitly producing echo |
|---|
| 241 |
area messages. Many other Emacs features display messages there, too. |
|---|
| 242 |
|
|---|
| 243 |
@defun message format-string &rest arguments |
|---|
| 244 |
This function displays a message in the echo area. The argument |
|---|
| 245 |
@var{format-string} is similar to a C language @code{printf} format |
|---|
| 246 |
string. See @code{format} in @ref{Formatting Strings}, for the details |
|---|
| 247 |
on the conversion specifications. @code{message} returns the |
|---|
| 248 |
constructed string. |
|---|
| 249 |
|
|---|
| 250 |
In batch mode, @code{message} prints the message text on the standard |
|---|
| 251 |
error stream, followed by a newline. |
|---|
| 252 |
|
|---|
| 253 |
If @var{format-string}, or strings among the @var{arguments}, have |
|---|
| 254 |
@code{face} text properties, these affect the way the message is displayed. |
|---|
| 255 |
|
|---|
| 256 |
@c Emacs 19 feature |
|---|
| 257 |
If @var{format-string} is @code{nil} or the empty string, |
|---|
| 258 |
@code{message} clears the echo area; if the echo area has been |
|---|
| 259 |
expanded automatically, this brings it back to its normal size. |
|---|
| 260 |
If the minibuffer is active, this brings the minibuffer contents back |
|---|
| 261 |
onto the screen immediately. |
|---|
| 262 |
|
|---|
| 263 |
@example |
|---|
| 264 |
@group |
|---|
| 265 |
(message "Minibuffer depth is %d." |
|---|
| 266 |
(minibuffer-depth)) |
|---|
| 267 |
@print{} Minibuffer depth is 0. |
|---|
| 268 |
@result{} "Minibuffer depth is 0." |
|---|
| 269 |
@end group |
|---|
| 270 |
|
|---|
| 271 |
@group |
|---|
| 272 |
---------- Echo Area ---------- |
|---|
| 273 |
Minibuffer depth is 0. |
|---|
| 274 |
---------- Echo Area ---------- |
|---|
| 275 |
@end group |
|---|
| 276 |
@end example |
|---|
| 277 |
|
|---|
| 278 |
To automatically display a message in the echo area or in a pop-buffer, |
|---|
| 279 |
depending on its size, use @code{display-message-or-buffer} (see below). |
|---|
| 280 |
@end defun |
|---|
| 281 |
|
|---|
| 282 |
@defmac with-temp-message message &rest body |
|---|
| 283 |
This construct displays a message in the echo area temporarily, during |
|---|
| 284 |
the execution of @var{body}. It displays @var{message}, executes |
|---|
| 285 |
@var{body}, then returns the value of the last body form while restoring |
|---|
| 286 |
the previous echo area contents. |
|---|
| 287 |
@end defmac |
|---|
| 288 |
|
|---|
| 289 |
@defun message-or-box format-string &rest arguments |
|---|
| 290 |
This function displays a message like @code{message}, but may display it |
|---|
| 291 |
in a dialog box instead of the echo area. If this function is called in |
|---|
| 292 |
a command that was invoked using the mouse---more precisely, if |
|---|
| 293 |
@code{last-nonmenu-event} (@pxref{Command Loop Info}) is either |
|---|
| 294 |
@code{nil} or a list---then it uses a dialog box or pop-up menu to |
|---|
| 295 |
display the message. Otherwise, it uses the echo area. (This is the |
|---|
| 296 |
same criterion that @code{y-or-n-p} uses to make a similar decision; see |
|---|
| 297 |
@ref{Yes-or-No Queries}.) |
|---|
| 298 |
|
|---|
| 299 |
You can force use of the mouse or of the echo area by binding |
|---|
| 300 |
@code{last-nonmenu-event} to a suitable value around the call. |
|---|
| 301 |
@end defun |
|---|
| 302 |
|
|---|
| 303 |
@defun message-box format-string &rest arguments |
|---|
| 304 |
@anchor{message-box} |
|---|
| 305 |
This function displays a message like @code{message}, but uses a dialog |
|---|
| 306 |
box (or a pop-up menu) whenever that is possible. If it is impossible |
|---|
| 307 |
to use a dialog box or pop-up menu, because the terminal does not |
|---|
| 308 |
support them, then @code{message-box} uses the echo area, like |
|---|
| 309 |
@code{message}. |
|---|
| 310 |
@end defun |
|---|
| 311 |
|
|---|
| 312 |
@defun display-message-or-buffer message &optional buffer-name not-this-window frame |
|---|
| 313 |
This function displays the message @var{message}, which may be either a |
|---|
| 314 |
string or a buffer. If it is shorter than the maximum height of the |
|---|
| 315 |
echo area, as defined by @code{max-mini-window-height}, it is displayed |
|---|
| 316 |
in the echo area, using @code{message}. Otherwise, |
|---|
| 317 |
@code{display-buffer} is used to show it in a pop-up buffer. |
|---|
| 318 |
|
|---|
| 319 |
Returns either the string shown in the echo area, or when a pop-up |
|---|
| 320 |
buffer is used, the window used to display it. |
|---|
| 321 |
|
|---|
| 322 |
If @var{message} is a string, then the optional argument |
|---|
| 323 |
@var{buffer-name} is the name of the buffer used to display it when a |
|---|
| 324 |
pop-up buffer is used, defaulting to @samp{*Message*}. In the case |
|---|
| 325 |
where @var{message} is a string and displayed in the echo area, it is |
|---|
| 326 |
not specified whether the contents are inserted into the buffer anyway. |
|---|
| 327 |
|
|---|
| 328 |
The optional arguments @var{not-this-window} and @var{frame} are as for |
|---|
| 329 |
@code{display-buffer}, and only used if a buffer is displayed. |
|---|
| 330 |
@end defun |
|---|
| 331 |
|
|---|
| 332 |
@defun current-message |
|---|
| 333 |
This function returns the message currently being displayed in the |
|---|
| 334 |
echo area, or @code{nil} if there is none. |
|---|
| 335 |
@end defun |
|---|
| 336 |
|
|---|
| 337 |
@node Progress |
|---|
| 338 |
@subsection Reporting Operation Progress |
|---|
| 339 |
@cindex progress reporting |
|---|
| 340 |
|
|---|
| 341 |
When an operation can take a while to finish, you should inform the |
|---|
| 342 |
user about the progress it makes. This way the user can estimate |
|---|
| 343 |
remaining time and clearly see that Emacs is busy working, not hung. |
|---|
| 344 |
|
|---|
| 345 |
Functions listed in this section provide simple and efficient way of |
|---|
| 346 |
reporting operation progress. Here is a working example that does |
|---|
| 347 |
nothing useful: |
|---|
| 348 |
|
|---|
| 349 |
@smallexample |
|---|
| 350 |
(let ((progress-reporter |
|---|
| 351 |
(make-progress-reporter "Collecting mana for Emacs..." |
|---|
| 352 |
0 500))) |
|---|
| 353 |
(dotimes (k 500) |
|---|
| 354 |
(sit-for 0.01) |
|---|
| 355 |
(progress-reporter-update progress-reporter k)) |
|---|
| 356 |
(progress-reporter-done progress-reporter)) |
|---|
| 357 |
@end smallexample |
|---|
| 358 |
|
|---|
| 359 |
@defun make-progress-reporter message min-value max-value &optional current-value min-change min-time |
|---|
| 360 |
This function creates and returns a @dfn{progress reporter}---an |
|---|
| 361 |
object you will use as an argument for all other functions listed |
|---|
| 362 |
here. The idea is to precompute as much data as possible to make |
|---|
| 363 |
progress reporting very fast. |
|---|
| 364 |
|
|---|
| 365 |
When this progress reporter is subsequently used, it will display |
|---|
| 366 |
@var{message} in the echo area, followed by progress percentage. |
|---|
| 367 |
@var{message} is treated as a simple string. If you need it to depend |
|---|
| 368 |
on a filename, for instance, use @code{format} before calling this |
|---|
| 369 |
function. |
|---|
| 370 |
|
|---|
| 371 |
@var{min-value} and @var{max-value} arguments stand for starting and |
|---|
| 372 |
final states of your operation. For instance, if you scan a buffer, |
|---|
| 373 |
they should be the results of @code{point-min} and @code{point-max} |
|---|
| 374 |
correspondingly. It is required that @var{max-value} is greater than |
|---|
| 375 |
@var{min-value}. If you create progress reporter when some part of |
|---|
| 376 |
the operation has already been completed, then specify |
|---|
| 377 |
@var{current-value} argument. But normally you should omit it or set |
|---|
| 378 |
it to @code{nil}---it will default to @var{min-value} then. |
|---|
| 379 |
|
|---|
| 380 |
Remaining arguments control the rate of echo area updates. Progress |
|---|
| 381 |
reporter will wait for at least @var{min-change} more percents of the |
|---|
| 382 |
operation to be completed before printing next message. |
|---|
| 383 |
@var{min-time} specifies the minimum time in seconds to pass between |
|---|
| 384 |
successive prints. It can be fractional. Depending on Emacs and |
|---|
| 385 |
system capabilities, progress reporter may or may not respect this |
|---|
| 386 |
last argument or do it with varying precision. Default value for |
|---|
| 387 |
@var{min-change} is 1 (one percent), for @var{min-time}---0.2 |
|---|
| 388 |
(seconds.) |
|---|
| 389 |
|
|---|
| 390 |
This function calls @code{progress-reporter-update}, so the first |
|---|
| 391 |
message is printed immediately. |
|---|
| 392 |
@end defun |
|---|
| 393 |
|
|---|
| 394 |
@defun progress-reporter-update reporter value |
|---|
| 395 |
This function does the main work of reporting progress of your |
|---|
| 396 |
operation. It displays the message of @var{reporter}, followed by |
|---|
| 397 |
progress percentage determined by @var{value}. If percentage is zero, |
|---|
| 398 |
or close enough according to the @var{min-change} and @var{min-time} |
|---|
| 399 |
arguments, then it is omitted from the output. |
|---|
| 400 |
|
|---|
| 401 |
@var{reporter} must be the result of a call to |
|---|
| 402 |
@code{make-progress-reporter}. @var{value} specifies the current |
|---|
| 403 |
state of your operation and must be between @var{min-value} and |
|---|
| 404 |
@var{max-value} (inclusive) as passed to |
|---|
| 405 |
@code{make-progress-reporter}. For instance, if you scan a buffer, |
|---|
| 406 |
then @var{value} should be the result of a call to @code{point}. |
|---|
| 407 |
|
|---|
| 408 |
This function respects @var{min-change} and @var{min-time} as passed |
|---|
| 409 |
to @code{make-progress-reporter} and so does not output new messages |
|---|
| 410 |
on every invocation. It is thus very fast and normally you should not |
|---|
| 411 |
try to reduce the number of calls to it: resulting overhead will most |
|---|
| 412 |
likely negate your effort. |
|---|
| 413 |
@end defun |
|---|
| 414 |
|
|---|
| 415 |
@defun progress-reporter-force-update reporter value &optional new-message |
|---|
| 416 |
This function is similar to @code{progress-reporter-update} except |
|---|
| 417 |
that it prints a message in the echo area unconditionally. |
|---|
| 418 |
|
|---|
| 419 |
The first two arguments have the same meaning as for |
|---|
| 420 |
@code{progress-reporter-update}. Optional @var{new-message} allows |
|---|
| 421 |
you to change the message of the @var{reporter}. Since this functions |
|---|
| 422 |
always updates the echo area, such a change will be immediately |
|---|
| 423 |
presented to the user. |
|---|
| 424 |
@end defun |
|---|
| 425 |
|
|---|
| 426 |
@defun progress-reporter-done reporter |
|---|
| 427 |
This function should be called when the operation is finished. It |
|---|
| 428 |
prints the message of @var{reporter} followed by word ``done'' in the |
|---|
| 429 |
echo area. |
|---|
| 430 |
|
|---|
| 431 |
You should always call this function and not hope for |
|---|
| 432 |
@code{progress-reporter-update} to print ``100%.'' Firstly, it may |
|---|
| 433 |
never print it, there are many good reasons for this not to happen. |
|---|
| 434 |
Secondly, ``done'' is more explicit. |
|---|
| 435 |
@end defun |
|---|
| 436 |
|
|---|
| 437 |
@defmac dotimes-with-progress-reporter (var count [result]) message body@dots{} |
|---|
| 438 |
This is a convenience macro that works the same way as @code{dotimes} |
|---|
| 439 |
does, but also reports loop progress using the functions described |
|---|
| 440 |
above. It allows you to save some typing. |
|---|
| 441 |
|
|---|
| 442 |
You can rewrite the example in the beginning of this node using |
|---|
| 443 |
this macro this way: |
|---|
| 444 |
|
|---|
| 445 |
@example |
|---|
| 446 |
(dotimes-with-progress-reporter |
|---|
| 447 |
(k 500) |
|---|
| 448 |
"Collecting some mana for Emacs..." |
|---|
| 449 |
(sit-for 0.01)) |
|---|
| 450 |
@end example |
|---|
| 451 |
@end defmac |
|---|
| 452 |
|
|---|
| 453 |
@node Logging Messages |
|---|
| 454 |
@subsection Logging Messages in @samp{*Messages*} |
|---|
| 455 |
@cindex logging echo-area messages |
|---|
| 456 |
|
|---|
| 457 |
Almost all the messages displayed in the echo area are also recorded |
|---|
| 458 |
in the @samp{*Messages*} buffer so that the user can refer back to |
|---|
| 459 |
them. This includes all the messages that are output with |
|---|
| 460 |
@code{message}. |
|---|
| 461 |
|
|---|
| 462 |
@defopt message-log-max |
|---|
| 463 |
This variable specifies how many lines to keep in the @samp{*Messages*} |
|---|
| 464 |
buffer. The value @code{t} means there is no limit on how many lines to |
|---|
| 465 |
keep. The value @code{nil} disables message logging entirely. Here's |
|---|
| 466 |
how to display a message and prevent it from being logged: |
|---|
| 467 |
|
|---|
| 468 |
@example |
|---|
| 469 |
(let (message-log-max) |
|---|
| 470 |
(message @dots{})) |
|---|
| 471 |
@end example |
|---|
| 472 |
@end defopt |
|---|
| 473 |
|
|---|
| 474 |
To make @samp{*Messages*} more convenient for the user, the logging |
|---|
| 475 |
facility combines successive identical messages. It also combines |
|---|
| 476 |
successive related messages for the sake of two cases: question |
|---|
| 477 |
followed by answer, and a series of progress messages. |
|---|
| 478 |
|
|---|
| 479 |
A ``question followed by an answer'' means two messages like the |
|---|
| 480 |
ones produced by @code{y-or-n-p}: the first is @samp{@var{question}}, |
|---|
| 481 |
and the second is @samp{@var{question}...@var{answer}}. The first |
|---|
| 482 |
message conveys no additional information beyond what's in the second, |
|---|
| 483 |
so logging the second message discards the first from the log. |
|---|
| 484 |
|
|---|
| 485 |
A ``series of progress messages'' means successive messages like |
|---|
| 486 |
those produced by @code{make-progress-reporter}. They have the form |
|---|
| 487 |
@samp{@var{base}...@var{how-far}}, where @var{base} is the same each |
|---|
| 488 |
time, while @var{how-far} varies. Logging each message in the series |
|---|
| 489 |
discards the previous one, provided they are consecutive. |
|---|
| 490 |
|
|---|
| 491 |
The functions @code{make-progress-reporter} and @code{y-or-n-p} |
|---|
| 492 |
don't have to do anything special to activate the message log |
|---|
| 493 |
combination feature. It operates whenever two consecutive messages |
|---|
| 494 |
are logged that share a common prefix ending in @samp{...}. |
|---|
| 495 |
|
|---|
| 496 |
@node Echo Area Customization |
|---|
| 497 |
@subsection Echo Area Customization |
|---|
| 498 |
|
|---|
| 499 |
These variables control details of how the echo area works. |
|---|
| 500 |
|
|---|
| 501 |
@defvar cursor-in-echo-area |
|---|
| 502 |
This variable controls where the cursor appears when a message is |
|---|
| 503 |
displayed in the echo area. If it is non-@code{nil}, then the cursor |
|---|
| 504 |
appears at the end of the message. Otherwise, the cursor appears at |
|---|
| 505 |
point---not in the echo area at all. |
|---|
| 506 |
|
|---|
| 507 |
The value is normally @code{nil}; Lisp programs bind it to @code{t} |
|---|
| 508 |
for brief periods of time. |
|---|
| 509 |
@end defvar |
|---|
| 510 |
|
|---|
| 511 |
@defvar echo-area-clear-hook |
|---|
| 512 |
This normal hook is run whenever the echo area is cleared---either by |
|---|
| 513 |
@code{(message nil)} or for any other reason. |
|---|
| 514 |
@end defvar |
|---|
| 515 |
|
|---|
| 516 |
@defvar echo-keystrokes |
|---|
| 517 |
This variable determines how much time should elapse before command |
|---|
| 518 |
characters echo. Its value must be an integer or floating point number, |
|---|
| 519 |
which specifies the |
|---|
| 520 |
number of seconds to wait before echoing. If the user types a prefix |
|---|
| 521 |
key (such as @kbd{C-x}) and then delays this many seconds before |
|---|
| 522 |
continuing, the prefix key is echoed in the echo area. (Once echoing |
|---|
| 523 |
begins in a key sequence, all subsequent characters in the same key |
|---|
| 524 |
sequence are echoed immediately.) |
|---|
| 525 |
|
|---|
| 526 |
If the value is zero, then command input is not echoed. |
|---|
| 527 |
@end defvar |
|---|
| 528 |
|
|---|
| 529 |
@defvar message-truncate-lines |
|---|
| 530 |
Normally, displaying a long message resizes the echo area to display |
|---|
| 531 |
the entire message. But if the variable @code{message-truncate-lines} |
|---|
| 532 |
is non-@code{nil}, the echo area does not resize, and the message is |
|---|
| 533 |
truncated to fit it, as in Emacs 20 and before. |
|---|
| 534 |
@end defvar |
|---|
| 535 |
|
|---|
| 536 |
The variable @code{max-mini-window-height}, which specifies the |
|---|
| 537 |
maximum height for resizing minibuffer windows, also applies to the |
|---|
| 538 |
echo area (which is really a special use of the minibuffer window. |
|---|
| 539 |
@xref{Minibuffer Misc}. |
|---|
| 540 |
|
|---|
| 541 |
@node Warnings |
|---|
| 542 |
@section Reporting Warnings |
|---|
| 543 |
@cindex warnings |
|---|
| 544 |
|
|---|
| 545 |
@dfn{Warnings} are a facility for a program to inform the user of a |
|---|
| 546 |
possible problem, but continue running. |
|---|
| 547 |
|
|---|
| 548 |
@menu |
|---|
| 549 |
* Warning Basics:: Warnings concepts and functions to report them. |
|---|
| 550 |
* Warning Variables:: Variables programs bind to customize their warnings. |
|---|
| 551 |
* Warning Options:: Variables users set to control display of warnings. |
|---|
| 552 |
@end menu |
|---|
| 553 |
|
|---|
| 554 |
@node Warning Basics |
|---|
| 555 |
@subsection Warning Basics |
|---|
| 556 |
@cindex severity level |
|---|
| 557 |
|
|---|
| 558 |
Every warning has a textual message, which explains the problem for |
|---|
| 559 |
the user, and a @dfn{severity level} which is a symbol. Here are the |
|---|
| 560 |
possible severity levels, in order of decreasing severity, and their |
|---|
| 561 |
meanings: |
|---|
| 562 |
|
|---|
| 563 |
@table @code |
|---|
| 564 |
@item :emergency |
|---|
| 565 |
A problem that will seriously impair Emacs operation soon |
|---|
| 566 |
if you do not attend to it promptly. |
|---|
| 567 |
@item :error |
|---|
| 568 |
A report of data or circumstances that are inherently wrong. |
|---|
| 569 |
@item :warning |
|---|
| 570 |
A report of data or circumstances that are not inherently wrong, but |
|---|
| 571 |
raise suspicion of a possible problem. |
|---|
| 572 |
@item :debug |
|---|
| 573 |
A report of information that may be useful if you are debugging. |
|---|
| 574 |
@end table |
|---|
| 575 |
|
|---|
| 576 |
When your program encounters invalid input data, it can either |
|---|
| 577 |
signal a Lisp error by calling @code{error} or @code{signal} or report |
|---|
| 578 |
a warning with severity @code{:error}. Signaling a Lisp error is the |
|---|
| 579 |
easiest thing to do, but it means the program cannot continue |
|---|
| 580 |
processing. If you want to take the trouble to implement a way to |
|---|
| 581 |
continue processing despite the bad data, then reporting a warning of |
|---|
| 582 |
severity @code{:error} is the right way to inform the user of the |
|---|
| 583 |
problem. For instance, the Emacs Lisp byte compiler can report an |
|---|
| 584 |
error that way and continue compiling other functions. (If the |
|---|
| 585 |
program signals a Lisp error and then handles it with |
|---|
| 586 |
@code{condition-case}, the user won't see the error message; it could |
|---|
| 587 |
show the message to the user by reporting it as a warning.) |
|---|
| 588 |
|
|---|
| 589 |
@cindex warning type |
|---|
| 590 |
Each warning has a @dfn{warning type} to classify it. The type is a |
|---|
| 591 |
list of symbols. The first symbol should be the custom group that you |
|---|
| 592 |
use for the program's user options. For example, byte compiler |
|---|
| 593 |
warnings use the warning type @code{(bytecomp)}. You can also |
|---|
| 594 |
subcategorize the warnings, if you wish, by using more symbols in the |
|---|
| 595 |
list. |
|---|
| 596 |
|
|---|
| 597 |
@defun display-warning type message &optional level buffer-name |
|---|
| 598 |
This function reports a warning, using @var{message} as the message |
|---|
| 599 |
and @var{type} as the warning type. @var{level} should be the |
|---|
| 600 |
severity level, with @code{:warning} being the default. |
|---|
| 601 |
|
|---|
| 602 |
@var{buffer-name}, if non-@code{nil}, specifies the name of the buffer |
|---|
| 603 |
for logging the warning. By default, it is @samp{*Warnings*}. |
|---|
| 604 |
@end defun |
|---|
| 605 |
|
|---|
| 606 |
@defun lwarn type level message &rest args |
|---|
| 607 |
This function reports a warning using the value of @code{(format |
|---|
| 608 |
@var{message} @var{args}...)} as the message. In other respects it is |
|---|
| 609 |
equivalent to @code{display-warning}. |
|---|
| 610 |
@end defun |
|---|
| 611 |
|
|---|
| 612 |
@defun warn message &rest args |
|---|
| 613 |
This function reports a warning using the value of @code{(format |
|---|
| 614 |
@var{message} @var{args}...)} as the message, @code{(emacs)} as the |
|---|
| 615 |
type, and @code{:warning} as the severity level. It exists for |
|---|
| 616 |
compatibility only; we recommend not using it, because you should |
|---|
| 617 |
specify a specific warning type. |
|---|
| 618 |
@end defun |
|---|
| 619 |
|
|---|
| 620 |
@node Warning Variables |
|---|
| 621 |
@subsection Warning Variables |
|---|
| 622 |
|
|---|
| 623 |
Programs can customize how their warnings appear by binding |
|---|
| 624 |
the variables described in this section. |
|---|
| 625 |
|
|---|
| 626 |
@defvar warning-levels |
|---|
| 627 |
This list defines the meaning and severity order of the warning |
|---|
| 628 |
severity levels. Each element defines one severity level, |
|---|
| 629 |
and they are arranged in order of decreasing severity. |
|---|
| 630 |
|
|---|
| 631 |
Each element has the form @code{(@var{level} @var{string} |
|---|
| 632 |
@var{function})}, where @var{level} is the severity level it defines. |
|---|
| 633 |
@var{string} specifies the textual description of this level. |
|---|
| 634 |
@var{string} should use @samp{%s} to specify where to put the warning |
|---|
| 635 |
type information, or it can omit the @samp{%s} so as not to include |
|---|
| 636 |
that information. |
|---|
| 637 |
|
|---|
| 638 |
The optional @var{function}, if non-@code{nil}, is a function to call |
|---|
| 639 |
with no arguments, to get the user's attention. |
|---|
| 640 |
|
|---|
| 641 |
Normally you should not change the value of this variable. |
|---|
| 642 |
@end defvar |
|---|
| 643 |
|
|---|
| 644 |
@defvar warning-prefix-function |
|---|
| 645 |
If non-@code{nil}, the value is a function to generate prefix text for |
|---|
| 646 |
warnings. Programs can bind the variable to a suitable function. |
|---|
| 647 |
@code{display-warning} calls this function with the warnings buffer |
|---|
| 648 |
current, and the function can insert text in it. That text becomes |
|---|
| 649 |
the beginning of the warning message. |
|---|
| 650 |
|
|---|
| 651 |
The function is called with two arguments, the severity level and its |
|---|
| 652 |
entry in @code{warning-levels}. It should return a list to use as the |
|---|
| 653 |
entry (this value need not be an actual member of |
|---|
| 654 |
@code{warning-levels}). By constructing this value, the function can |
|---|
| 655 |
change the severity of the warning, or specify different handling for |
|---|
| 656 |
a given severity level. |
|---|
| 657 |
|
|---|
| 658 |
If the variable's value is @code{nil} then there is no function |
|---|
| 659 |
to call. |
|---|
| 660 |
@end defvar |
|---|
| 661 |
|
|---|
| 662 |
@defvar warning-series |
|---|
| 663 |
Programs can bind this variable to @code{t} to say that the next |
|---|
| 664 |
warning should begin a series. When several warnings form a series, |
|---|
| 665 |
that means to leave point on the first warning of the series, rather |
|---|
| 666 |
than keep moving it for each warning so that it appears on the last one. |
|---|
| 667 |
The series ends when the local binding is unbound and |
|---|
| 668 |
@code{warning-series} becomes @code{nil} again. |
|---|
| 669 |
|
|---|
| 670 |
The value can also be a symbol with a function definition. That is |
|---|
| 671 |
equivalent to @code{t}, except that the next warning will also call |
|---|
| 672 |
the function with no arguments with the warnings buffer current. The |
|---|
| 673 |
function can insert text which will serve as a header for the series |
|---|
| 674 |
of warnings. |
|---|
| 675 |
|
|---|
| 676 |
Once a series has begun, the value is a marker which points to the |
|---|
| 677 |
buffer position in the warnings buffer of the start of the series. |
|---|
| 678 |
|
|---|
| 679 |
The variable's normal value is @code{nil}, which means to handle |
|---|
| 680 |
each warning separately. |
|---|
| 681 |
@end defvar |
|---|
| 682 |
|
|---|
| 683 |
@defvar warning-fill-prefix |
|---|
| 684 |
When this variable is non-@code{nil}, it specifies a fill prefix to |
|---|
| 685 |
use for filling each warning's text. |
|---|
| 686 |
@end defvar |
|---|
| 687 |
|
|---|
| 688 |
@defvar warning-type-format |
|---|
| 689 |
This variable specifies the format for displaying the warning type |
|---|
| 690 |
in the warning message. The result of formatting the type this way |
|---|
| 691 |
gets included in the message under the control of the string in the |
|---|
| 692 |
entry in @code{warning-levels}. The default value is @code{" (%s)"}. |
|---|
| 693 |
If you bind it to @code{""} then the warning type won't appear at |
|---|
| 694 |
all. |
|---|
| 695 |
@end defvar |
|---|
| 696 |
|
|---|
| 697 |
@node Warning Options |
|---|
| 698 |
@subsection Warning Options |
|---|
| 699 |
|
|---|
| 700 |
These variables are used by users to control what happens |
|---|
| 701 |
when a Lisp program reports a warning. |
|---|
| 702 |
|
|---|
| 703 |
@defopt warning-minimum-level |
|---|
| 704 |
This user option specifies the minimum severity level that should be |
|---|
| 705 |
shown immediately to the user. The default is @code{:warning}, which |
|---|
| 706 |
means to immediately display all warnings except @code{:debug} |
|---|
| 707 |
warnings. |
|---|
| 708 |
@end defopt |
|---|
| 709 |
|
|---|
| 710 |
@defopt warning-minimum-log-level |
|---|
| 711 |
This user option specifies the minimum severity level that should be |
|---|
| 712 |
logged in the warnings buffer. The default is @code{:warning}, which |
|---|
| 713 |
means to log all warnings except @code{:debug} warnings. |
|---|
| 714 |
@end defopt |
|---|
| 715 |
|
|---|
| 716 |
@defopt warning-suppress-types |
|---|
| 717 |
This list specifies which warning types should not be displayed |
|---|
| 718 |
immediately for the user. Each element of the list should be a list |
|---|
| 719 |
of symbols. If its elements match the first elements in a warning |
|---|
| 720 |
type, then that warning is not displayed immediately. |
|---|
| 721 |
@end defopt |
|---|
| 722 |
|
|---|
| 723 |
@defopt warning-suppress-log-types |
|---|
| 724 |
This list specifies which warning types should not be logged in the |
|---|
| 725 |
warnings buffer. Each element of the list should be a list of |
|---|
| 726 |
symbols. If it matches the first few elements in a warning type, then |
|---|
| 727 |
that warning is not logged. |
|---|
| 728 |
@end defopt |
|---|
| 729 |
|
|---|
| 730 |
@node Invisible Text |
|---|
| 731 |
@section Invisible Text |
|---|
| 732 |
|
|---|
| 733 |
@cindex invisible text |
|---|
| 734 |
You can make characters @dfn{invisible}, so that they do not appear on |
|---|
| 735 |
the screen, with the @code{invisible} property. This can be either a |
|---|
| 736 |
text property (@pxref{Text Properties}) or a property of an overlay |
|---|
| 737 |
(@pxref{Overlays}). Cursor motion also partly ignores these |
|---|
| 738 |
characters; if the command loop finds point within them, it moves |
|---|
| 739 |
point to the other side of them. |
|---|
| 740 |
|
|---|
| 741 |
In the simplest case, any non-@code{nil} @code{invisible} property makes |
|---|
| 742 |
a character invisible. This is the default case---if you don't alter |
|---|
| 743 |
the default value of @code{buffer-invisibility-spec}, this is how the |
|---|
| 744 |
@code{invisible} property works. You should normally use @code{t} |
|---|
| 745 |
as the value of the @code{invisible} property if you don't plan |
|---|
| 746 |
to set @code{buffer-invisibility-spec} yourself. |
|---|
| 747 |
|
|---|
| 748 |
More generally, you can use the variable @code{buffer-invisibility-spec} |
|---|
| 749 |
to control which values of the @code{invisible} property make text |
|---|
| 750 |
invisible. This permits you to classify the text into different subsets |
|---|
| 751 |
in advance, by giving them different @code{invisible} values, and |
|---|
| 752 |
subsequently make various subsets visible or invisible by changing the |
|---|
| 753 |
value of @code{buffer-invisibility-spec}. |
|---|
| 754 |
|
|---|
| 755 |
Controlling visibility with @code{buffer-invisibility-spec} is |
|---|
| 756 |
especially useful in a program to display the list of entries in a |
|---|
| 757 |
database. It permits the implementation of convenient filtering |
|---|
| 758 |
commands to view just a part of the entries in the database. Setting |
|---|
| 759 |
this variable is very fast, much faster than scanning all the text in |
|---|
| 760 |
the buffer looking for properties to change. |
|---|
| 761 |
|
|---|
| 762 |
@defvar buffer-invisibility-spec |
|---|
| 763 |
This variable specifies which kinds of @code{invisible} properties |
|---|
| 764 |
actually make a character invisible. Setting this variable makes it |
|---|
| 765 |
buffer-local. |
|---|
| 766 |
|
|---|
| 767 |
@table @asis |
|---|
| 768 |
@item @code{t} |
|---|
| 769 |
A character is invisible if its @code{invisible} property is |
|---|
| 770 |
non-@code{nil}. This is the default. |
|---|
| 771 |
|
|---|
| 772 |
@item a list |
|---|
| 773 |
Each element of the list specifies a criterion for invisibility; if a |
|---|
| 774 |
character's @code{invisible} property fits any one of these criteria, |
|---|
| 775 |
the character is invisible. The list can have two kinds of elements: |
|---|
| 776 |
|
|---|
| 777 |
@table @code |
|---|
| 778 |
@item @var{atom} |
|---|
| 779 |
A character is invisible if its @code{invisible} property value |
|---|
| 780 |
is @var{atom} or if it is a list with @var{atom} as a member. |
|---|
| 781 |
|
|---|
| 782 |
@item (@var{atom} . t) |
|---|
| 783 |
A character is invisible if its @code{invisible} property value is |
|---|
| 784 |
@var{atom} or if it is a list with @var{atom} as a member. Moreover, |
|---|
| 785 |
a sequence of such characters displays as an ellipsis. |
|---|
| 786 |
@end table |
|---|
| 787 |
@end table |
|---|
| 788 |
@end defvar |
|---|
| 789 |
|
|---|
| 790 |
Two functions are specifically provided for adding elements to |
|---|
| 791 |
@code{buffer-invisibility-spec} and removing elements from it. |
|---|
| 792 |
|
|---|
| 793 |
@defun add-to-invisibility-spec element |
|---|
| 794 |
This function adds the element @var{element} to |
|---|
| 795 |
@code{buffer-invisibility-spec}. If @code{buffer-invisibility-spec} |
|---|
| 796 |
was @code{t}, it changes to a list, @code{(t)}, so that text whose |
|---|
| 797 |
@code{invisible} property is @code{t} remains invisible. |
|---|
| 798 |
@end defun |
|---|
| 799 |
|
|---|
| 800 |
@defun remove-from-invisibility-spec element |
|---|
| 801 |
This removes the element @var{element} from |
|---|
| 802 |
@code{buffer-invisibility-spec}. This does nothing if @var{element} |
|---|
| 803 |
is not in the list. |
|---|
| 804 |
@end defun |
|---|
| 805 |
|
|---|
| 806 |
A convention for use of @code{buffer-invisibility-spec} is that a |
|---|
| 807 |
major mode should use the mode's own name as an element of |
|---|
| 808 |
@code{buffer-invisibility-spec} and as the value of the |
|---|
| 809 |
@code{invisible} property: |
|---|
| 810 |
|
|---|
| 811 |
@example |
|---|
| 812 |
;; @r{If you want to display an ellipsis:} |
|---|
| 813 |
(add-to-invisibility-spec '(my-symbol . t)) |
|---|
| 814 |
;; @r{If you don't want ellipsis:} |
|---|
| 815 |
(add-to-invisibility-spec 'my-symbol) |
|---|
| 816 |
|
|---|
| 817 |
(overlay-put (make-overlay beginning end) |
|---|
| 818 |
'invisible 'my-symbol) |
|---|
| 819 |
|
|---|
| 820 |
;; @r{When done with the overlays:} |
|---|
| 821 |
(remove-from-invisibility-spec '(my-symbol . t)) |
|---|
| 822 |
;; @r{Or respectively:} |
|---|
| 823 |
(remove-from-invisibility-spec 'my-symbol) |
|---|
| 824 |
@end example |
|---|
| 825 |
|
|---|
| 826 |
@vindex line-move-ignore-invisible |
|---|
| 827 |
Ordinarily, functions that operate on text or move point do not care |
|---|
| 828 |
whether the text is invisible. The user-level line motion commands |
|---|
| 829 |
explicitly ignore invisible newlines if |
|---|
| 830 |
@code{line-move-ignore-invisible} is non-@code{nil} (the default), but |
|---|
| 831 |
only because they are explicitly programmed to do so. |
|---|
| 832 |
|
|---|
| 833 |
However, if a command ends with point inside or immediately before |
|---|
| 834 |
invisible text, the main editing loop moves point further forward or |
|---|
| 835 |
further backward (in the same direction that the command already moved |
|---|
| 836 |
it) until that condition is no longer true. Thus, if the command |
|---|
| 837 |
moved point back into an invisible range, Emacs moves point back to |
|---|
| 838 |
the beginning of that range, and then back one more character. If the |
|---|
| 839 |
command moved point forward into an invisible range, Emacs moves point |
|---|
| 840 |
forward up to the first visible character that follows the invisible |
|---|
| 841 |
text. |
|---|
| 842 |
|
|---|
| 843 |
Incremental search can make invisible overlays visible temporarily |
|---|
| 844 |
and/or permanently when a match includes invisible text. To enable |
|---|
| 845 |
this, the overlay should have a non-@code{nil} |
|---|
| 846 |
@code{isearch-open-invisible} property. The property value should be a |
|---|
| 847 |
function to be called with the overlay as an argument. This function |
|---|
| 848 |
should make the overlay visible permanently; it is used when the match |
|---|
| 849 |
overlaps the overlay on exit from the search. |
|---|
| 850 |
|
|---|
| 851 |
During the search, such overlays are made temporarily visible by |
|---|
| 852 |
temporarily modifying their invisible and intangible properties. If you |
|---|
| 853 |
want this to be done differently for a certain overlay, give it an |
|---|
| 854 |
@code{isearch-open-invisible-temporary} property which is a function. |
|---|
| 855 |
The function is called with two arguments: the first is the overlay, and |
|---|
| 856 |
the second is @code{nil} to make the overlay visible, or @code{t} to |
|---|
| 857 |
make it invisible again. |
|---|
| 858 |
|
|---|
| 859 |
@node Selective Display |
|---|
| 860 |
@section Selective Display |
|---|
| 861 |
@c @cindex selective display Duplicates selective-display |
|---|
| 862 |
|
|---|
| 863 |
@dfn{Selective display} refers to a pair of related features for |
|---|
| 864 |
hiding certain lines on the screen. |
|---|
| 865 |
|
|---|
| 866 |
The first variant, explicit selective display, is designed for use |
|---|
| 867 |
in a Lisp program: it controls which lines are hidden by altering the |
|---|
| 868 |
text. This kind of hiding in some ways resembles the effect of the |
|---|
| 869 |
@code{invisible} property (@pxref{Invisible Text}), but the two |
|---|
| 870 |
features are different and do not work the same way. |
|---|
| 871 |
|
|---|
| 872 |
In the second variant, the choice of lines to hide is made |
|---|
| 873 |
automatically based on indentation. This variant is designed to be a |
|---|
| 874 |
user-level feature. |
|---|
| 875 |
|
|---|
| 876 |
The way you control explicit selective display is by replacing a |
|---|
| 877 |
newline (control-j) with a carriage return (control-m). The text that |
|---|
| 878 |
was formerly a line following that newline is now hidden. Strictly |
|---|
| 879 |
speaking, it is temporarily no longer a line at all, since only |
|---|
| 880 |
newlines can separate lines; it is now part of the previous line. |
|---|
| 881 |
|
|---|
| 882 |
Selective display does not directly affect editing commands. For |
|---|
| 883 |
example, @kbd{C-f} (@code{forward-char}) moves point unhesitatingly |
|---|
| 884 |
into hidden text. However, the replacement of newline characters with |
|---|
| 885 |
carriage return characters affects some editing commands. For |
|---|
| 886 |
example, @code{next-line} skips hidden lines, since it searches only |
|---|
| 887 |
for newlines. Modes that use selective display can also define |
|---|
| 888 |
commands that take account of the newlines, or that control which |
|---|
| 889 |
parts of the text are hidden. |
|---|
| 890 |
|
|---|
| 891 |
When you write a selectively displayed buffer into a file, all the |
|---|
| 892 |
control-m's are output as newlines. This means that when you next read |
|---|
| 893 |
in the file, it looks OK, with nothing hidden. The selective display |
|---|
| 894 |
effect is seen only within Emacs. |
|---|
| 895 |
|
|---|
| 896 |
@defvar selective-display |
|---|
| 897 |
This buffer-local variable enables selective display. This means that |
|---|
| 898 |
lines, or portions of lines, may be made hidden. |
|---|
| 899 |
|
|---|
| 900 |
@itemize @bullet |
|---|
| 901 |
@item |
|---|
| 902 |
If the value of @code{selective-display} is @code{t}, then the character |
|---|
| 903 |
control-m marks the start of hidden text; the control-m, and the rest |
|---|
| 904 |
of the line following it, are not displayed. This is explicit selective |
|---|
| 905 |
display. |
|---|
| 906 |
|
|---|
| 907 |
@item |
|---|
| 908 |
If the value of @code{selective-display} is a positive integer, then |
|---|
| 909 |
lines that start with more than that many columns of indentation are not |
|---|
| 910 |
displayed. |
|---|
| 911 |
@end itemize |
|---|
| 912 |
|
|---|
| 913 |
When some portion of a buffer is hidden, the vertical movement |
|---|
| 914 |
commands operate as if that portion did not exist, allowing a single |
|---|
| 915 |
@code{next-line} command to skip any number of hidden lines. |
|---|
| 916 |
However, character movement commands (such as @code{forward-char}) do |
|---|
| 917 |
not skip the hidden portion, and it is possible (if tricky) to insert |
|---|
| 918 |
or delete text in an hidden portion. |
|---|
| 919 |
|
|---|
| 920 |
In the examples below, we show the @emph{display appearance} of the |
|---|
| 921 |
buffer @code{foo}, which changes with the value of |
|---|
| 922 |
@code{selective-display}. The @emph{contents} of the buffer do not |
|---|
| 923 |
change. |
|---|
| 924 |
|
|---|
| 925 |
@example |
|---|
| 926 |
@group |
|---|
| 927 |
(setq selective-display nil) |
|---|
| 928 |
@result{} nil |
|---|
| 929 |
|
|---|
| 930 |
---------- Buffer: foo ---------- |
|---|
| 931 |
1 on this column |
|---|
| 932 |
2on this column |
|---|
| 933 |
3n this column |
|---|
| 934 |
3n this column |
|---|
| 935 |
2on this column |
|---|
| 936 |
1 on this column |
|---|
| 937 |
---------- Buffer: foo ---------- |
|---|
| 938 |
@end group |
|---|
| 939 |
|
|---|
| 940 |
@group |
|---|
| 941 |
(setq selective-display 2) |
|---|
| 942 |
@result{} 2 |
|---|
| 943 |
|
|---|
| 944 |
---------- Buffer: foo ---------- |
|---|
| 945 |
1 on this column |
|---|
| 946 |
2on this column |
|---|
| 947 |
2on this column |
|---|
| 948 |
1 on this column |
|---|
| 949 |
---------- Buffer: foo ---------- |
|---|
| 950 |
@end group |
|---|
| 951 |
@end example |
|---|
| 952 |
@end defvar |
|---|
| 953 |
|
|---|
| 954 |
@defvar selective-display-ellipses |
|---|
| 955 |
If this buffer-local variable is non-@code{nil}, then Emacs displays |
|---|
| 956 |
@samp{@dots{}} at the end of a line that is followed by hidden text. |
|---|
| 957 |
This example is a continuation of the previous one. |
|---|
| 958 |
|
|---|
| 959 |
@example |
|---|
| 960 |
@group |
|---|
| 961 |
(setq selective-display-ellipses t) |
|---|
| 962 |
@result{} t |
|---|
| 963 |
|
|---|
| 964 |
---------- Buffer: foo ---------- |
|---|
| 965 |
1 on this column |
|---|
| 966 |
2on this column ... |
|---|
| 967 |
2on this column |
|---|
| 968 |
1 on this column |
|---|
| 969 |
---------- Buffer: foo ---------- |
|---|
| 970 |
@end group |
|---|
| 971 |
@end example |
|---|
| 972 |
|
|---|
| 973 |
You can use a display table to substitute other text for the ellipsis |
|---|
| 974 |
(@samp{@dots{}}). @xref{Display Tables}. |
|---|
| 975 |
@end defvar |
|---|
| 976 |
|
|---|
| 977 |
@node Temporary Displays |
|---|
| 978 |
@section Temporary Displays |
|---|
| 979 |
|
|---|
| 980 |
Temporary displays are used by Lisp programs to put output into a |
|---|
| 981 |
buffer and then present it to the user for perusal rather than for |
|---|
| 982 |
editing. Many help commands use this feature. |
|---|
| 983 |
|
|---|
| 984 |
@defspec with-output-to-temp-buffer buffer-name forms@dots{} |
|---|
| 985 |
This function executes @var{forms} while arranging to insert any output |
|---|
| 986 |
they print into the buffer named @var{buffer-name}, which is first |
|---|
| 987 |
created if necessary, and put into Help mode. Finally, the buffer is |
|---|
| 988 |
displayed in some window, but not selected. |
|---|
| 989 |
|
|---|
| 990 |
If the @var{forms} do not change the major mode in the output buffer, |
|---|
| 991 |
so that it is still Help mode at the end of their execution, then |
|---|
| 992 |
@code{with-output-to-temp-buffer} makes this buffer read-only at the |
|---|
| 993 |
end, and also scans it for function and variable names to make them |
|---|
| 994 |
into clickable cross-references. @xref{Docstring hyperlinks, , Tips |
|---|
| 995 |
for Documentation Strings}, in particular the item on hyperlinks in |
|---|
| 996 |
documentation strings, for more details. |
|---|
| 997 |
|
|---|
| 998 |
The string @var{buffer-name} specifies the temporary buffer, which |
|---|
| 999 |
need not already exist. The argument must be a string, not a buffer. |
|---|
| 1000 |
The buffer is erased initially (with no questions asked), and it is |
|---|
| 1001 |
marked as unmodified after @code{with-output-to-temp-buffer} exits. |
|---|
| 1002 |
|
|---|
| 1003 |
@code{with-output-to-temp-buffer} binds @code{standard-output} to the |
|---|
| 1004 |
temporary buffer, then it evaluates the forms in @var{forms}. Output |
|---|
| 1005 |
using the Lisp output functions within @var{forms} goes by default to |
|---|
| 1006 |
that buffer (but screen display and messages in the echo area, although |
|---|
| 1007 |
they are ``output'' in the general sense of the word, are not affected). |
|---|
| 1008 |
@xref{Output Functions}. |
|---|
| 1009 |
|
|---|
| 1010 |
Several hooks are available for customizing the behavior |
|---|
| 1011 |
of this construct; they are listed below. |
|---|
| 1012 |
|
|---|
| 1013 |
The value of the last form in @var{forms} is returned. |
|---|
| 1014 |
|
|---|
| 1015 |
@example |
|---|
| 1016 |
@group |
|---|
| 1017 |
---------- Buffer: foo ---------- |
|---|
| 1018 |
This is the contents of foo. |
|---|
| 1019 |
---------- Buffer: foo ---------- |
|---|
| 1020 |
@end group |
|---|
| 1021 |
|
|---|
| 1022 |
@group |
|---|
| 1023 |
(with-output-to-temp-buffer "foo" |
|---|
| 1024 |
(print 20) |
|---|
| 1025 |
(print standard-output)) |
|---|
| 1026 |
@result{} #<buffer foo> |
|---|
| 1027 |
|
|---|
| 1028 |
---------- Buffer: foo ---------- |
|---|
| 1029 |
20 |
|---|
| 1030 |
|
|---|
| 1031 |
#<buffer foo> |
|---|
| 1032 |
|
|---|
| 1033 |
---------- Buffer: foo ---------- |
|---|
| 1034 |
@end group |
|---|
| 1035 |
@end example |
|---|
| 1036 |
@end defspec |
|---|
| 1037 |
|
|---|
| 1038 |
@defvar temp-buffer-show-function |
|---|
| 1039 |
If this variable is non-@code{nil}, @code{with-output-to-temp-buffer} |
|---|
| 1040 |
calls it as a function to do the job of displaying a help buffer. The |
|---|
| 1041 |
function gets one argument, which is the buffer it should display. |
|---|
| 1042 |
|
|---|
| 1043 |
It is a good idea for this function to run @code{temp-buffer-show-hook} |
|---|
| 1044 |
just as @code{with-output-to-temp-buffer} normally would, inside of |
|---|
| 1045 |
@code{save-selected-window} and with the chosen window and buffer |
|---|
| 1046 |
selected. |
|---|
| 1047 |
@end defvar |
|---|
| 1048 |
|
|---|
| 1049 |
@defvar temp-buffer-setup-hook |
|---|
| 1050 |
This normal hook is run by @code{with-output-to-temp-buffer} before |
|---|
| 1051 |
evaluating @var{body}. When the hook runs, the temporary buffer is |
|---|
| 1052 |
current. This hook is normally set up with a function to put the |
|---|
| 1053 |
buffer in Help mode. |
|---|
| 1054 |
@end defvar |
|---|
| 1055 |
|
|---|
| 1056 |
@defvar temp-buffer-show-hook |
|---|
| 1057 |
This normal hook is run by @code{with-output-to-temp-buffer} after |
|---|
| 1058 |
displaying the temporary buffer. When the hook runs, the temporary buffer |
|---|
| 1059 |
is current, and the window it was displayed in is selected. This hook |
|---|
| 1060 |
is normally set up with a function to make the buffer read only, and |
|---|
| 1061 |
find function names and variable names in it, provided the major mode |
|---|
| 1062 |
is Help mode. |
|---|
| 1063 |
@end defvar |
|---|
| 1064 |
|
|---|
| 1065 |
@defun momentary-string-display string position &optional char message |
|---|
| 1066 |
This function momentarily displays @var{string} in the current buffer at |
|---|
| 1067 |
@var{position}. It has no effect on the undo list or on the buffer's |
|---|
| 1068 |
modification status. |
|---|
| 1069 |
|
|---|
| 1070 |
The momentary display remains until the next input event. If the next |
|---|
| 1071 |
input event is @var{char}, @code{momentary-string-display} ignores it |
|---|
| 1072 |
and returns. Otherwise, that event remains buffered for subsequent use |
|---|
| 1073 |
as input. Thus, typing @var{char} will simply remove the string from |
|---|
| 1074 |
the display, while typing (say) @kbd{C-f} will remove the string from |
|---|
| 1075 |
the display and later (presumably) move point forward. The argument |
|---|
| 1076 |
@var{char} is a space by default. |
|---|
| 1077 |
|
|---|
| 1078 |
The return value of @code{momentary-string-display} is not meaningful. |
|---|
| 1079 |
|
|---|
| 1080 |
If the string @var{string} does not contain control characters, you can |
|---|
| 1081 |
do the same job in a more general way by creating (and then subsequently |
|---|
| 1082 |
deleting) an overlay with a @code{before-string} property. |
|---|
| 1083 |
@xref{Overlay Properties}. |
|---|
| 1084 |
|
|---|
| 1085 |
If @var{message} is non-@code{nil}, it is displayed in the echo area |
|---|
| 1086 |
while @var{string} is displayed in the buffer. If it is @code{nil}, a |
|---|
| 1087 |
default message says to type @var{char} to continue. |
|---|
| 1088 |
|
|---|
| 1089 |
In this example, point is initially located at the beginning of the |
|---|
| 1090 |
second line: |
|---|
| 1091 |
|
|---|
| 1092 |
@example |
|---|
| 1093 |
@group |
|---|
| 1094 |
---------- Buffer: foo ---------- |
|---|
| 1095 |
This is the contents of foo. |
|---|
| 1096 |
@point{}Second line. |
|---|
| 1097 |
---------- Buffer: foo ---------- |
|---|
| 1098 |
@end group |
|---|
| 1099 |
|
|---|
| 1100 |
@group |
|---|
| 1101 |
(momentary-string-display |
|---|
| 1102 |
"**** Important Message! ****" |
|---|
| 1103 |
(point) ?\r |
|---|
| 1104 |
"Type RET when done reading") |
|---|
| 1105 |
@result{} t |
|---|
| 1106 |
@end group |
|---|
| 1107 |
|
|---|
| 1108 |
@group |
|---|
| 1109 |
---------- Buffer: foo ---------- |
|---|
| 1110 |
This is the contents of foo. |
|---|
| 1111 |
**** Important Message! ****Second line. |
|---|
| 1112 |
---------- Buffer: foo ---------- |
|---|
| 1113 |
|
|---|
| 1114 |
---------- Echo Area ---------- |
|---|
| 1115 |
Type RET when done reading |
|---|
| 1116 |
---------- Echo Area ---------- |
|---|
| 1117 |
@end group |
|---|
| 1118 |
@end example |
|---|
| 1119 |
@end defun |
|---|
| 1120 |
|
|---|
| 1121 |
@node Overlays |
|---|
| 1122 |
@section Overlays |
|---|
| 1123 |
@cindex overlays |
|---|
| 1124 |
|
|---|
| 1125 |
You can use @dfn{overlays} to alter the appearance of a buffer's text on |
|---|
| 1126 |
the screen, for the sake of presentation features. An overlay is an |
|---|
| 1127 |
object that belongs to a particular buffer, and has a specified |
|---|
| 1128 |
beginning and end. It also has properties that you can examine and set; |
|---|
| 1129 |
these affect the display of the text within the overlay. |
|---|
| 1130 |
|
|---|
| 1131 |
An overlay uses markers to record its beginning and end; thus, |
|---|
| 1132 |
editing the text of the buffer adjusts the beginning and end of each |
|---|
| 1133 |
overlay so that it stays with the text. When you create the overlay, |
|---|
| 1134 |
you can specify whether text inserted at the beginning should be |
|---|
| 1135 |
inside the overlay or outside, and likewise for the end of the overlay. |
|---|
| 1136 |
|
|---|
| 1137 |
@menu |
|---|
| 1138 |
* Managing Overlays:: Creating and moving overlays. |
|---|
| 1139 |
* Overlay Properties:: How to read and set properties. |
|---|
| 1140 |
What properties do to the screen display. |
|---|
| 1141 |
* Finding Overlays:: Searching for overlays. |
|---|
| 1142 |
@end menu |
|---|
| 1143 |
|
|---|
| 1144 |
@node Managing Overlays |
|---|
| 1145 |
@subsection Managing Overlays |
|---|
| 1146 |
|
|---|
| 1147 |
This section describes the functions to create, delete and move |
|---|
| 1148 |
overlays, and to examine their contents. Overlay changes are not |
|---|
| 1149 |
recorded in the buffer's undo list, since the overlays are not |
|---|
| 1150 |
part of the buffer's contents. |
|---|
| 1151 |
|
|---|
| 1152 |
@defun overlayp object |
|---|
| 1153 |
This function returns @code{t} if @var{object} is an overlay. |
|---|
| 1154 |
@end defun |
|---|
| 1155 |
|
|---|
| 1156 |
@defun make-overlay start end &optional buffer front-advance rear-advance |
|---|
| 1157 |
This function creates and returns an overlay that belongs to |
|---|
| 1158 |
@var{buffer} and ranges from @var{start} to @var{end}. Both @var{start} |
|---|
| 1159 |
and @var{end} must specify buffer positions; they may be integers or |
|---|
| 1160 |
markers. If @var{buffer} is omitted, the overlay is created in the |
|---|
| 1161 |
current buffer. |
|---|
| 1162 |
|
|---|
| 1163 |
The arguments @var{front-advance} and @var{rear-advance} specify the |
|---|
| 1164 |
marker insertion type for the start of the overlay and for the end of |
|---|
| 1165 |
the overlay, respectively. @xref{Marker Insertion Types}. If they |
|---|
| 1166 |
are both @code{nil}, the default, then the overlay extends to include |
|---|
| 1167 |
any text inserted at the beginning, but not text inserted at the end. |
|---|
| 1168 |
If @var{front-advance} is non-@code{nil}, text inserted at the |
|---|
| 1169 |
beginning of the overlay is excluded from the overlay. If |
|---|
| 1170 |
@var{rear-advance} is non-@code{nil}, text inserted at the end of the |
|---|
| 1171 |
overlay is included in the overlay. |
|---|
| 1172 |
@end defun |
|---|
| 1173 |
|
|---|
| 1174 |
@defun overlay-start overlay |
|---|
| 1175 |
This function returns the position at which @var{overlay} starts, |
|---|
| 1176 |
as an integer. |
|---|
| 1177 |
@end defun |
|---|
| 1178 |
|
|---|
| 1179 |
@defun overlay-end overlay |
|---|
| 1180 |
This function returns the position at which @var{overlay} ends, |
|---|
| 1181 |
as an integer. |
|---|
| 1182 |
@end defun |
|---|
| 1183 |
|
|---|
| 1184 |
@defun overlay-buffer overlay |
|---|
| 1185 |
This function returns the buffer that @var{overlay} belongs to. It |
|---|
| 1186 |
returns @code{nil} if @var{overlay} has been deleted. |
|---|
| 1187 |
@end defun |
|---|
| 1188 |
|
|---|
| 1189 |
@defun delete-overlay overlay |
|---|
| 1190 |
This function deletes @var{overlay}. The overlay continues to exist as |
|---|
| 1191 |
a Lisp object, and its property list is unchanged, but it ceases to be |
|---|
| 1192 |
attached to the buffer it belonged to, and ceases to have any effect on |
|---|
| 1193 |
display. |
|---|
| 1194 |
|
|---|
| 1195 |
A deleted overlay is not permanently disconnected. You can give it a |
|---|
| 1196 |
position in a buffer again by calling @code{move-overlay}. |
|---|
| 1197 |
@end defun |
|---|
| 1198 |
|
|---|
| 1199 |
@defun move-overlay overlay start end &optional buffer |
|---|
| 1200 |
This function moves @var{overlay} to @var{buffer}, and places its bounds |
|---|
| 1201 |
at @var{start} and @var{end}. Both arguments @var{start} and @var{end} |
|---|
| 1202 |
must specify buffer positions; they may be integers or markers. |
|---|
| 1203 |
|
|---|
|
|---|