xdisp.c 781 KB
Newer Older
Jim Blandy's avatar
Jim Blandy committed
1
/* Display generation from window structure and buffer text.
2 3
   Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994, 1995,
                 1997, 1998, 1999, 2000, 2001, 2002, 2003,
Eli Zaretskii's avatar
Eli Zaretskii committed
4 5
                 2004, 2005, 2006, 2007, 2008, 2009, 2010
                 Free Software Foundation, Inc.
Jim Blandy's avatar
Jim Blandy committed
6 7 8

This file is part of GNU Emacs.

9
GNU Emacs is free software: you can redistribute it and/or modify
Jim Blandy's avatar
Jim Blandy committed
10
it under the terms of the GNU General Public License as published by
11 12
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Jim Blandy's avatar
Jim Blandy committed
13 14 15 16 17 18 19

GNU Emacs is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
20
along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
Jim Blandy's avatar
Jim Blandy committed
21

Gerd Moellmann's avatar
Gerd Moellmann committed
22 23 24 25 26 27 28 29 30 31 32 33 34
/* New redisplay written by Gerd Moellmann <gerd@gnu.org>.

   Redisplay.

   Emacs separates the task of updating the display from code
   modifying global state, e.g. buffer text.  This way functions
   operating on buffers don't also have to be concerned with updating
   the display.

   Updating the display is triggered by the Lisp interpreter when it
   decides it's time to do it.  This is done either automatically for
   you as part of the interpreter's command loop or as the result of
   calling Lisp functions like `sit-for'.  The C function `redisplay'
35
   in xdisp.c is the only entry into the inner redisplay code.
Gerd Moellmann's avatar
Gerd Moellmann committed
36 37 38 39 40 41 42 43 44 45 46

   The following diagram shows how redisplay code is invoked.  As you
   can see, Lisp calls redisplay and vice versa.  Under window systems
   like X, some portions of the redisplay code are also called
   asynchronously during mouse movement or expose events.  It is very
   important that these code parts do NOT use the C library (malloc,
   free) because many C libraries under Unix are not reentrant.  They
   may also NOT call functions of the Lisp interpreter which could
   change the interpreter's state.  If you don't follow these rules,
   you will encounter bugs which are very hard to explain.

47
   +--------------+   redisplay     +----------------+
Gerd Moellmann's avatar
Gerd Moellmann committed
48 49 50 51 52 53 54 55 56 57 58
   | Lisp machine |---------------->| Redisplay code |<--+
   +--------------+   (xdisp.c)     +----------------+   |
	  ^				     |		 |
	  +----------------------------------+           |
	    Don't use this path when called		 |
	    asynchronously!				 |
                                                         |
                           expose_window (asynchronous)  |
                                                         |
			           X expose events  -----+

59
   What does redisplay do?  Obviously, it has to figure out somehow what
Gerd Moellmann's avatar
Gerd Moellmann committed
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
   has been changed since the last time the display has been updated,
   and to make these changes visible.  Preferably it would do that in
   a moderately intelligent way, i.e. fast.

   Changes in buffer text can be deduced from window and buffer
   structures, and from some global variables like `beg_unchanged' and
   `end_unchanged'.  The contents of the display are additionally
   recorded in a `glyph matrix', a two-dimensional matrix of glyph
   structures.  Each row in such a matrix corresponds to a line on the
   display, and each glyph in a row corresponds to a column displaying
   a character, an image, or what else.  This matrix is called the
   `current glyph matrix' or `current matrix' in redisplay
   terminology.

   For buffer parts that have been changed since the last update, a
   second glyph matrix is constructed, the so called `desired glyph
   matrix' or short `desired matrix'.  Current and desired matrix are
   then compared to find a cheap way to update the display, e.g. by
   reusing part of the display by scrolling lines.

Pavel Janík's avatar
Pavel Janík committed
80
   You will find a lot of redisplay optimizations when you start
Gerd Moellmann's avatar
Gerd Moellmann committed
81 82
   looking at the innards of redisplay.  The overall goal of all these
   optimizations is to make redisplay fast because it is done
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
   frequently.  Some of these optimizations are implemented by the
   following functions:

    . try_cursor_movement

      This function tries to update the display if the text in the
      window did not change and did not scroll, only point moved, and
      it did not move off the displayed portion of the text.

    . try_window_reusing_current_matrix

      This function reuses the current matrix of a window when text
      has not changed, but the window start changed (e.g., due to
      scrolling).

    . try_window_id

      This function attempts to redisplay a window by reusing parts of
      its existing display.  It finds and reuses the part that was not
      changed, and redraws the rest.

    . try_window

      This function performs the full redisplay of a single window
      assuming that its fonts were not changed and that the cursor
      will not end up in the scroll margins.  (Loading fonts requires
      re-adjustment of dimensions of glyph matrices, which makes this
      method impossible to use.)

   These optimizations are tried in sequence (some can be skipped if
   it is known that they are not applicable).  If none of the
   optimizations were successful, redisplay calls redisplay_windows,
   which performs a full redisplay of all windows.
Gerd Moellmann's avatar
Gerd Moellmann committed
116 117 118 119 120 121 122 123 124 125 126 127 128 129

   Desired matrices.

   Desired matrices are always built per Emacs window.  The function
   `display_line' is the central function to look at if you are
   interested.  It constructs one row in a desired matrix given an
   iterator structure containing both a buffer position and a
   description of the environment in which the text is to be
   displayed.  But this is too early, read on.

   Characters and pixmaps displayed for a range of buffer text depend
   on various settings of buffers and windows, on overlays and text
   properties, on display tables, on selective display.  The good news
   is that all this hairy stuff is hidden behind a small set of
130
   interface functions taking an iterator structure (struct it)
Gerd Moellmann's avatar
Gerd Moellmann committed
131 132
   argument.

Pavel Janík's avatar
Pavel Janík committed
133
   Iteration over things to be displayed is then simple.  It is
Gerd Moellmann's avatar
Gerd Moellmann committed
134 135 136
   started by initializing an iterator with a call to init_iterator.
   Calls to get_next_display_element fill the iterator structure with
   relevant information about the next thing to display.  Calls to
Gerd Moellmann's avatar
Gerd Moellmann committed
137 138 139 140 141 142 143 144 145 146
   set_iterator_to_next move the iterator to the next thing.

   Besides this, an iterator also contains information about the
   display environment in which glyphs for display elements are to be
   produced.  It has fields for the width and height of the display,
   the information whether long lines are truncated or continued, a
   current X and Y position, and lots of other stuff you can better
   see in dispextern.h.

   Glyphs in a desired matrix are normally constructed in a loop
147 148
   calling get_next_display_element and then PRODUCE_GLYPHS.  The call
   to PRODUCE_GLYPHS will fill the iterator structure with pixel
Gerd Moellmann's avatar
Gerd Moellmann committed
149 150 151
   information about the element being displayed and at the same time
   produce glyphs for it.  If the display element fits on the line
   being displayed, set_iterator_to_next is called next, otherwise the
152 153 154 155 156
   glyphs produced are discarded.  The function display_line is the
   workhorse of filling glyph rows in the desired matrix with glyphs.
   In addition to producing glyphs, it also handles line truncation
   and continuation, word wrap, and cursor positioning (for the
   latter, see also set_cursor_from_row).
Gerd Moellmann's avatar
Gerd Moellmann committed
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176

   Frame matrices.

   That just couldn't be all, could it?  What about terminal types not
   supporting operations on sub-windows of the screen?  To update the
   display on such a terminal, window-based glyph matrices are not
   well suited.  To be able to reuse part of the display (scrolling
   lines up and down), we must instead have a view of the whole
   screen.  This is what `frame matrices' are for.  They are a trick.

   Frames on terminals like above have a glyph pool.  Windows on such
   a frame sub-allocate their glyph memory from their frame's glyph
   pool.  The frame itself is given its own glyph matrices.  By
   coincidence---or maybe something else---rows in window glyph
   matrices are slices of corresponding rows in frame matrices.  Thus
   writing to window matrices implicitly updates a frame matrix which
   provides us with the view of the whole screen that we originally
   wanted to have without having to move many bytes around.  To be
   honest, there is a little bit more done, but not much more.  If you
   plan to extend that code, take a look at dispnew.c.  The function
177 178 179 180 181 182 183 184 185 186
   build_frame_matrix is a good starting point.

   Bidirectional display.

   Bidirectional display adds quite some hair to this already complex
   design.  The good news are that a large portion of that hairy stuff
   is hidden in bidi.c behind only 3 interfaces.  bidi.c implements a
   reordering engine which is called by set_iterator_to_next and
   returns the next character to display in the visual order.  See
   commentary on bidi.c for more details.  As far as redisplay is
187
   concerned, the effect of calling bidi_move_to_visually_next, the
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
   main interface of the reordering engine, is that the iterator gets
   magically placed on the buffer or string position that is to be
   displayed next.  In other words, a linear iteration through the
   buffer/string is replaced with a non-linear one.  All the rest of
   the redisplay is oblivious to the bidi reordering.

   Well, almost oblivious---there are still complications, most of
   them due to the fact that buffer and string positions no longer
   change monotonously with glyph indices in a glyph row.  Moreover,
   for continued lines, the buffer positions may not even be
   monotonously changing with vertical positions.  Also, accounting
   for face changes, overlays, etc. becomes more complex because
   non-linear iteration could potentially skip many positions with
   changes, and then cross them again on the way back...

   One other prominent effect of bidirectional display is that some
   paragraphs of text need to be displayed starting at the right
   margin of the window---the so-called right-to-left, or R2L
   paragraphs.  R2L paragraphs are displayed with R2L glyph rows,
   which have their reversed_p flag set.  The bidi reordering engine
   produces characters in such rows starting from the character which
   should be the rightmost on display.  PRODUCE_GLYPHS then reverses
   the order, when it fills up the glyph row whose reversed_p flag is
   set, by prepending each new glyph to what is already there, instead
   of appending it.  When the glyph row is complete, the function
   extend_face_to_end_of_line fills the empty space to the left of the
   leftmost character with special glyphs, which will display as,
   well, empty.  On text terminals, these special glyphs are simply
   blank characters.  On graphics terminals, there's a single stretch
   glyph with suitably computed width.  Both the blanks and the
   stretch glyph are given the face of the background of the line.
   This way, the terminal-specific back-end can still draw the glyphs
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
   left to right, even for R2L lines.

   Note one important detail mentioned above: that the bidi reordering
   engine, driven by the iterator, produces characters in R2L rows
   starting at the character that will be the rightmost on display.
   As far as the iterator is concerned, the geometry of such rows is
   still left to right, i.e. the iterator "thinks" the first character
   is at the leftmost pixel position.  The iterator does not know that
   PRODUCE_GLYPHS reverses the order of the glyphs that the iterator
   delivers.  This is important when functions from the the move_it_*
   family are used to get to certain screen position or to match
   screen coordinates with buffer coordinates: these functions use the
   iterator geometry, which is left to right even in R2L paragraphs.
   This works well with most callers of move_it_*, because they need
   to get to a specific column, and columns are still numbered in the
   reading order, i.e. the rightmost character in a R2L paragraph is
   still column zero.  But some callers do not get well with this; a
   notable example is mouse clicks that need to find the character
   that corresponds to certain pixel coordinates.  See
   buffer_posn_from_coords in dispnew.c for how this is handled.  */
Jim Blandy's avatar
Jim Blandy committed
240

241
#include <config.h>
Jim Blandy's avatar
Jim Blandy committed
242
#include <stdio.h>
243
#include <limits.h>
244
#include <setjmp.h>
245

Jim Blandy's avatar
Jim Blandy committed
246
#include "lisp.h"
247
#include "keyboard.h"
Jim Blandy's avatar
Jim Blandy committed
248
#include "frame.h"
Jim Blandy's avatar
Jim Blandy committed
249 250 251 252
#include "window.h"
#include "termchar.h"
#include "dispextern.h"
#include "buffer.h"
Kenichi Handa's avatar
Kenichi Handa committed
253
#include "character.h"
254
#include "charset.h"
Jim Blandy's avatar
Jim Blandy committed
255 256
#include "indent.h"
#include "commands.h"
257
#include "keymap.h"
Jim Blandy's avatar
Jim Blandy committed
258 259
#include "macros.h"
#include "disptab.h"
260
#include "termhooks.h"
261
#include "termopts.h"
262
#include "intervals.h"
263 264
#include "coding.h"
#include "process.h"
Andreas Schwab's avatar
Andreas Schwab committed
265
#include "region-cache.h"
Kenichi Handa's avatar
Kenichi Handa committed
266
#include "font.h"
Dave Love's avatar
Dave Love committed
267
#include "fontset.h"
268
#include "blockinput.h"
Andreas Schwab's avatar
Andreas Schwab committed
269

270
#ifdef HAVE_X_WINDOWS
Andreas Schwab's avatar
Andreas Schwab committed
271 272
#include "xterm.h"
#endif
273 274 275
#ifdef WINDOWSNT
#include "w32term.h"
#endif
276 277 278
#ifdef HAVE_NS
#include "nsterm.h"
#endif
279 280 281
#ifdef USE_GTK
#include "gtkutil.h"
#endif
Jim Blandy's avatar
Jim Blandy committed
282

283 284
#include "font.h"

285 286 287 288
#ifndef FRAME_X_OUTPUT
#define FRAME_X_OUTPUT(f) ((f)->output_data.x)
#endif

Gerd Moellmann's avatar
Gerd Moellmann committed
289 290
#define INFINITY 10000000

291
Lisp_Object Qoverriding_local_map, Qoverriding_terminal_local_map;
292
Lisp_Object Qwindow_scroll_functions, Vwindow_scroll_functions;
293
Lisp_Object Qwindow_text_change_functions, Vwindow_text_change_functions;
294
Lisp_Object Qredisplay_end_trigger_functions, Vredisplay_end_trigger_functions;
295
Lisp_Object Qinhibit_point_motion_hooks;
296
Lisp_Object QCeval, QCfile, QCdata, QCpropertize;
Gerd Moellmann's avatar
Gerd Moellmann committed
297
Lisp_Object Qfontified;
298
Lisp_Object Qgrow_only;
299
Lisp_Object Qinhibit_eval_during_redisplay;
300
Lisp_Object Qbuffer_position, Qposition, Qobject;
301
Lisp_Object Qright_to_left, Qleft_to_right;
Gerd Moellmann's avatar
Gerd Moellmann committed
302

303 304 305
/* Cursor shapes */
Lisp_Object Qbar, Qhbar, Qbox, Qhollow;

Kenichi Handa's avatar
Kenichi Handa committed
306 307 308
/* Pointer shapes */
Lisp_Object Qarrow, Qhand, Qtext;

309 310
Lisp_Object Qrisky_local_variable;

311 312 313
/* Holds the list (error).  */
Lisp_Object list_of_error;

Gerd Moellmann's avatar
Gerd Moellmann committed
314 315 316 317 318
/* Functions called to fontify regions of text.  */

Lisp_Object Vfontification_functions;
Lisp_Object Qfontification_functions;

319
/* Non-nil means automatically select any window when the mouse
320
   cursor moves into it.  */
321
Lisp_Object Vmouse_autoselect_window;
322

323 324 325
Lisp_Object Vwrap_prefix, Qwrap_prefix;
Lisp_Object Vline_prefix, Qline_prefix;

Gerd Moellmann's avatar
Gerd Moellmann committed
326
/* Non-zero means draw tool bar buttons raised when the mouse moves
Gerd Moellmann's avatar
Gerd Moellmann committed
327 328
   over them.  */

Gerd Moellmann's avatar
Gerd Moellmann committed
329
int auto_raise_tool_bar_buttons_p;
Gerd Moellmann's avatar
Gerd Moellmann committed
330

331 332 333 334
/* Non-zero means to reposition window if cursor line is only partially visible.  */

int make_cursor_line_fully_visible_p;

335 336 337 338 339 340
/* Margin below tool bar in pixels.  0 or nil means no margin.
   If value is `internal-border-width' or `border-width',
   the corresponding frame parameter is used.  */

Lisp_Object Vtool_bar_border;

Gerd Moellmann's avatar
Gerd Moellmann committed
341
/* Margin around tool bar buttons in pixels.  */
Gerd Moellmann's avatar
Gerd Moellmann committed
342

343
Lisp_Object Vtool_bar_button_margin;
Gerd Moellmann's avatar
Gerd Moellmann committed
344

Gerd Moellmann's avatar
Gerd Moellmann committed
345
/* Thickness of shadow to draw around tool bar buttons.  */
Gerd Moellmann's avatar
Gerd Moellmann committed
346

347
EMACS_INT tool_bar_button_relief;
Gerd Moellmann's avatar
Gerd Moellmann committed
348

349 350
/* Non-nil means automatically resize tool-bars so that all tool-bar
   items are visible, and no blank lines remain.
Gerd Moellmann's avatar
Gerd Moellmann committed
351

352 353 354
   If value is `grow-only', only make tool-bar bigger.  */

Lisp_Object Vauto_resize_tool_bars;
355

356 357 358 359 360 361 362 363
/* Type of tool bar.  Can be symbols image, text, both or both-hroiz.  */

Lisp_Object Vtool_bar_style;

/* Maximum number of characters a label can have to be shown.  */

EMACS_INT tool_bar_max_label_size;

364 365 366 367 368 369
/* Non-zero means draw block and hollow cursor as wide as the glyph
   under it.  For example, if a block cursor is over a tab, it will be
   drawn as wide as that tab on the display.  */

int x_stretch_cursor_p;

370 371 372 373
/* Non-nil means don't actually do any redisplay.  */

Lisp_Object Vinhibit_redisplay, Qinhibit_redisplay;

374 375
/* Non-zero means Lisp evaluation during redisplay is inhibited.  */

376
int inhibit_eval_during_redisplay;
377

Gerd Moellmann's avatar
Gerd Moellmann committed
378 379
/* Names of text properties relevant for redisplay.  */

Kenichi Handa's avatar
Kenichi Handa committed
380
Lisp_Object Qdisplay;
Gerd Moellmann's avatar
Gerd Moellmann committed
381 382 383

/* Symbols used in text property values.  */

Kenichi Handa's avatar
Kenichi Handa committed
384
Lisp_Object Vdisplay_pixels_per_inch;
Gerd Moellmann's avatar
Gerd Moellmann committed
385
Lisp_Object Qspace, QCalign_to, QCrelative_width, QCrelative_height;
386
Lisp_Object Qleft_margin, Qright_margin, Qspace_width, Qraise;
Kim F. Storm's avatar
Kim F. Storm committed
387
Lisp_Object Qslice;
Kenichi Handa's avatar
Kenichi Handa committed
388 389
Lisp_Object Qcenter;
Lisp_Object Qmargin, Qpointer;
390
Lisp_Object Qline_height;
Gerd Moellmann's avatar
Gerd Moellmann committed
391

392
/* Non-nil means highlight trailing whitespace.  */
Gerd Moellmann's avatar
Gerd Moellmann committed
393

394
Lisp_Object Vshow_trailing_whitespace;
Gerd Moellmann's avatar
Gerd Moellmann committed
395

396 397
/* Non-nil means escape non-break space and hyphens.  */

398
Lisp_Object Vnobreak_char_display;
399

Kenichi Handa's avatar
Kenichi Handa committed
400 401 402 403 404
#ifdef HAVE_WINDOW_SYSTEM

/* Test if overflow newline into fringe.  Called with iterator IT
   at or past right window margin, and with IT->current_x set.  */

405 406 407 408 409 410 411 412
#define IT_OVERFLOW_NEWLINE_INTO_FRINGE(IT)		\
  (!NILP (Voverflow_newline_into_fringe)		\
   && FRAME_WINDOW_P ((IT)->f)				\
   && ((IT)->bidi_it.paragraph_dir == R2L		\
       ? (WINDOW_LEFT_FRINGE_WIDTH ((IT)->w) > 0)	\
       : (WINDOW_RIGHT_FRINGE_WIDTH ((IT)->w) > 0))	\
   && (IT)->current_x == (IT)->last_visible_x		\
   && (IT)->line_wrap != WORD_WRAP)
Kenichi Handa's avatar
Kenichi Handa committed
413

414 415
#else /* !HAVE_WINDOW_SYSTEM */
#define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) 0
Kenichi Handa's avatar
Kenichi Handa committed
416 417
#endif /* HAVE_WINDOW_SYSTEM */

418 419 420 421 422 423
/* Test if the display element loaded in IT is a space or tab
   character.  This is used to determine word wrapping.  */

#define IT_DISPLAYING_WHITESPACE(it)				\
  (it->what == IT_CHARACTER && (it->c == ' ' || it->c == '\t'))

Kenichi Handa's avatar
Kenichi Handa committed
424 425 426 427 428 429
/* Non-nil means show the text cursor in void text areas
   i.e. in blank areas after eol and eob.  This used to be
   the default in 21.3.  */

Lisp_Object Vvoid_text_area_pointer;

Gerd Moellmann's avatar
Gerd Moellmann committed
430 431 432 433
/* Name of the face used to highlight trailing whitespace.  */

Lisp_Object Qtrailing_whitespace;

434 435 436 437
/* Name and number of the face used to highlight escape glyphs.  */

Lisp_Object Qescape_glyph;

Juri Linkov's avatar
Juri Linkov committed
438 439
/* Name and number of the face used to highlight non-breaking spaces.  */

440
Lisp_Object Qnobreak_space;
Juri Linkov's avatar
Juri Linkov committed
441

Gerd Moellmann's avatar
Gerd Moellmann committed
442
/* The symbol `image' which is the car of the lists used to represent
443
   images in Lisp.  Also a tool bar style.  */
Gerd Moellmann's avatar
Gerd Moellmann committed
444 445 446

Lisp_Object Qimage;

Kenichi Handa's avatar
Kenichi Handa committed
447 448 449 450
/* The image map types.  */
Lisp_Object QCmap, QCpointer;
Lisp_Object Qrect, Qcircle, Qpoly;

451
/* Tool bar styles */
452
Lisp_Object Qboth, Qboth_horiz, Qtext_image_horiz;
453

Gerd Moellmann's avatar
Gerd Moellmann committed
454 455
/* Non-zero means print newline to stdout before next mini-buffer
   message.  */
Jim Blandy's avatar
Jim Blandy committed
456 457 458

int noninteractive_need_newline;

Gerd Moellmann's avatar
Gerd Moellmann committed
459
/* Non-zero means print newline to message log before next message.  */
460

461
static int message_log_need_newline;
462

463 464 465 466 467 468
/* Three markers that message_dolog uses.
   It could allocate them itself, but that causes trouble
   in handling memory-full errors.  */
static Lisp_Object message_dolog_marker1;
static Lisp_Object message_dolog_marker2;
static Lisp_Object message_dolog_marker3;
Gerd Moellmann's avatar
Gerd Moellmann committed
469 470 471 472 473

/* The buffer position of the first character appearing entirely or
   partially on the line of the selected window which contains the
   cursor; <= 0 if not known.  Set by set_cursor_from_row, used for
   redisplay optimization in redisplay_internal.  */
Jim Blandy's avatar
Jim Blandy committed
474

Gerd Moellmann's avatar
Gerd Moellmann committed
475
static struct text_pos this_line_start_pos;
Jim Blandy's avatar
Jim Blandy committed
476

Gerd Moellmann's avatar
Gerd Moellmann committed
477 478 479 480 481 482
/* Number of characters past the end of the line above, including the
   terminating newline.  */

static struct text_pos this_line_end_pos;

/* The vertical positions and the height of this line.  */
Jim Blandy's avatar
Jim Blandy committed
483 484

static int this_line_vpos;
Gerd Moellmann's avatar
Gerd Moellmann committed
485 486 487 488 489 490 491
static int this_line_y;
static int this_line_pixel_height;

/* X position at which this display line starts.  Usually zero;
   negative if first character is partially visible.  */

static int this_line_start_x;
Jim Blandy's avatar
Jim Blandy committed
492

Gerd Moellmann's avatar
Gerd Moellmann committed
493
/* Buffer that this_line_.* variables are referring to.  */
Jim Blandy's avatar
Jim Blandy committed
494 495 496

static struct buffer *this_line_buffer;

Gerd Moellmann's avatar
Gerd Moellmann committed
497 498
/* Nonzero means truncate lines in all windows less wide than the
   frame.  */
Jim Blandy's avatar
Jim Blandy committed
499

500
Lisp_Object Vtruncate_partial_width_windows;
Jim Blandy's avatar
Jim Blandy committed
501

502
/* A flag to control how to display unibyte 8-bit character.  */
Gerd Moellmann's avatar
Gerd Moellmann committed
503

504
int unibyte_display_via_language_environment;
505

Gerd Moellmann's avatar
Gerd Moellmann committed
506 507 508
/* Nonzero means we have more than one non-mini-buffer-only frame.
   Not guaranteed to be accurate except while parsing
   frame-title-format.  */
509

510 511
int multiple_frames;

Jim Blandy's avatar
Jim Blandy committed
512 513
Lisp_Object Vglobal_mode_string;

Kenichi Handa's avatar
Kenichi Handa committed
514 515 516 517 518 519 520

/* List of variables (symbols) which hold markers for overlay arrows.
   The symbols on this list are examined during redisplay to determine
   where to display overlay arrows.  */

Lisp_Object Voverlay_arrow_variable_list;

Jim Blandy's avatar
Jim Blandy committed
521
/* Marker for where to display an arrow on top of the buffer text.  */
Gerd Moellmann's avatar
Gerd Moellmann committed
522

Jim Blandy's avatar
Jim Blandy committed
523 524
Lisp_Object Voverlay_arrow_position;

Gerd Moellmann's avatar
Gerd Moellmann committed
525 526
/* String to display for the arrow.  Only used on terminal frames.  */

Jim Blandy's avatar
Jim Blandy committed
527 528
Lisp_Object Voverlay_arrow_string;

Kenichi Handa's avatar
Kenichi Handa committed
529 530 531
/* Values of those variables at last redisplay are stored as
   properties on `overlay-arrow-position' symbol.  However, if
   Voverlay_arrow_position is a marker, last-arrow-position is its
Gerd Moellmann's avatar
Gerd Moellmann committed
532 533
   numerical position.  */

Kenichi Handa's avatar
Kenichi Handa committed
534 535 536 537 538 539
Lisp_Object Qlast_arrow_position, Qlast_arrow_string;

/* Alternative overlay-arrow-string and overlay-arrow-bitmap
   properties on a symbol in overlay-arrow-variable-list.  */

Lisp_Object Qoverlay_arrow_string, Qoverlay_arrow_bitmap;
540

Gerd Moellmann's avatar
Gerd Moellmann committed
541 542
/* Like mode-line-format, but for the title bar on a visible frame.  */

543 544
Lisp_Object Vframe_title_format;

Gerd Moellmann's avatar
Gerd Moellmann committed
545 546
/* Like mode-line-format, but for the title bar on an iconified frame.  */

547 548
Lisp_Object Vicon_title_format;

549 550 551
/* List of functions to call when a window's size changes.  These
   functions get one arg, a frame on which one or more windows' sizes
   have changed.  */
Gerd Moellmann's avatar
Gerd Moellmann committed
552

553 554
static Lisp_Object Vwindow_size_change_functions;

555
Lisp_Object Qmenu_bar_update_hook, Vmenu_bar_update_hook;
556

557
/* Nonzero if an overlay arrow has been displayed in this window.  */
Jim Blandy's avatar
Jim Blandy committed
558

Gerd Moellmann's avatar
Gerd Moellmann committed
559
static int overlay_arrow_seen;
Karl Heuer's avatar
Karl Heuer committed
560

561 562
/* Nonzero means highlight the region even in nonselected windows.  */

Gerd Moellmann's avatar
Gerd Moellmann committed
563 564 565 566 567
int highlight_nonselected_windows;

/* If cursor motion alone moves point off frame, try scrolling this
   many lines up or down if that will bring it back.  */

568
static EMACS_INT scroll_step;
Jim Blandy's avatar
Jim Blandy committed
569

570
/* Nonzero means scroll just far enough to bring point back on the
Gerd Moellmann's avatar
Gerd Moellmann committed
571 572
   screen, when appropriate.  */

573
static EMACS_INT scroll_conservatively;
574

Gerd Moellmann's avatar
Gerd Moellmann committed
575 576
/* Recenter the window whenever point gets within this many lines of
   the top or bottom of the window.  This value is translated into a
577 578
   pixel value by multiplying it with FRAME_LINE_HEIGHT, which means
   that there is really a fixed pixel height scroll margin.  */
Gerd Moellmann's avatar
Gerd Moellmann committed
579

580
EMACS_INT scroll_margin;
581

Gerd Moellmann's avatar
Gerd Moellmann committed
582 583 584
/* Number of windows showing the buffer of the selected window (or
   another buffer with the same base buffer).  keyboard.c refers to
   this.  */
Jim Blandy's avatar
Jim Blandy committed
585 586 587

int buffer_shared;

Gerd Moellmann's avatar
Gerd Moellmann committed
588
/* Vector containing glyphs for an ellipsis `...'.  */
Jim Blandy's avatar
Jim Blandy committed
589

Gerd Moellmann's avatar
Gerd Moellmann committed
590
static Lisp_Object default_invis_vector[3];
Jim Blandy's avatar
Jim Blandy committed
591

592 593 594 595 596
/* Zero means display the mode-line/header-line/menu-bar in the default face
   (this slightly odd definition is for compatibility with previous versions
   of emacs), non-zero means display them using their respective faces.

   This variable is deprecated.  */
Jim Blandy's avatar
Jim Blandy committed
597 598 599

int mode_line_inverse_video;

Gerd Moellmann's avatar
Gerd Moellmann committed
600 601
/* Prompt to display in front of the mini-buffer contents.  */

602
Lisp_Object minibuf_prompt;
Jim Blandy's avatar
Jim Blandy committed
603

Gerd Moellmann's avatar
Gerd Moellmann committed
604 605 606
/* Width of current mini-buffer prompt.  Only set after display_line
   of the line that contains the prompt.  */

Jim Blandy's avatar
Jim Blandy committed
607
int minibuf_prompt_width;
Gerd Moellmann's avatar
Gerd Moellmann committed
608 609 610 611 612

/* This is the window where the echo area message was displayed.  It
   is always a mini-buffer window, but it may not be the same window
   currently active as a mini-buffer.  */

613 614
Lisp_Object echo_area_window;

615 616 617 618 619 620 621
/* List of pairs (MESSAGE . MULTIBYTE).  The function save_message
   pushes the current message and the value of
   message_enable_multibyte on the stack, the function restore_message
   pops the stack and displays MESSAGE again.  */

Lisp_Object Vmessage_stack;

622 623
/* Nonzero means multibyte characters were enabled when the echo area
   message was specified.  */
Gerd Moellmann's avatar
Gerd Moellmann committed
624

625 626
int message_enable_multibyte;

627
/* Nonzero if we should redraw the mode lines on the next redisplay.  */
Gerd Moellmann's avatar
Gerd Moellmann committed
628

Jim Blandy's avatar
Jim Blandy committed
629 630
int update_mode_lines;

Gerd Moellmann's avatar
Gerd Moellmann committed
631
/* Nonzero if window sizes or contents have changed since last
632
   redisplay that finished.  */
Gerd Moellmann's avatar
Gerd Moellmann committed
633

Jim Blandy's avatar
Jim Blandy committed
634 635
int windows_or_buffers_changed;

636 637 638 639
/* Nonzero means a frame's cursor type has been changed.  */

int cursor_type_changed;

Gerd Moellmann's avatar
Gerd Moellmann committed
640 641 642
/* Nonzero after display_mode_line if %l was used and it displayed a
   line number.  */

643 644 645
int line_number_displayed;

/* Maximum buffer size for which to display line numbers.  */
Gerd Moellmann's avatar
Gerd Moellmann committed
646

647
Lisp_Object Vline_number_display_limit;
Karl Heuer's avatar
Karl Heuer committed
648

649
/* Line width to consider when repositioning for line number display.  */
650

651
static EMACS_INT line_number_display_limit_width;
652

Gerd Moellmann's avatar
Gerd Moellmann committed
653 654 655
/* Number of lines to keep in the message log buffer.  t means
   infinite.  nil means don't log at all.  */

Karl Heuer's avatar
Karl Heuer committed
656
Lisp_Object Vmessage_log_max;
657

658 659 660 661
/* The name of the *Messages* buffer, a string.  */

static Lisp_Object Vmessages_buffer_name;

662 663
/* Current, index 0, and last displayed echo area message.  Either
   buffers from echo_buffers, or nil to indicate no message.  */
664 665 666

Lisp_Object echo_area_buffer[2];

667
/* The buffers referenced from echo_area_buffer.  */
668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684

static Lisp_Object echo_buffer[2];

/* A vector saved used in with_area_buffer to reduce consing.  */

static Lisp_Object Vwith_echo_area_save_vector;

/* Non-zero means display_echo_area should display the last echo area
   message again.  Set by redisplay_preserve_echo_area.  */

static int display_last_displayed_message_p;

/* Nonzero if echo area is being used by print; zero if being used by
   message.  */

int message_buf_print;

685 686 687 688 689
/* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable.  */

Lisp_Object Qinhibit_menubar_update;
int inhibit_menubar_update;

690 691 692 693 694
/* When evaluating expressions from menu bar items (enable conditions,
   for instance), this is the frame they are being processed for.  */

Lisp_Object Vmenu_updating_frame;

695 696 697
/* Maximum height for resizing mini-windows.  Either a float
   specifying a fraction of the available height, or an integer
   specifying a number of lines.  */
698

699 700 701 702 703 704 705
Lisp_Object Vmax_mini_window_height;

/* Non-zero means messages should be displayed with truncated
   lines instead of being continued.  */

int message_truncate_lines;
Lisp_Object Qmessage_truncate_lines;
706

707
/* Set to 1 in clear_message to make redisplay_internal aware
708
   of an emptied echo area.  */
709 710 711

static int message_cleared_p;

712 713 714
/* How to blink the default frame cursor off.  */
Lisp_Object Vblink_cursor_alist;

Gerd Moellmann's avatar
Gerd Moellmann committed
715 716
/* A scratch glyph row with contents used for generating truncation
   glyphs.  Also used in direct_output_for_insert.  */
717

Gerd Moellmann's avatar
Gerd Moellmann committed
718 719 720
#define MAX_SCRATCH_GLYPHS 100
struct glyph_row scratch_glyph_row;
static struct glyph scratch_glyphs[MAX_SCRATCH_GLYPHS];
721

Gerd Moellmann's avatar
Gerd Moellmann committed
722 723 724 725
/* Ascent and height of the last line processed by move_it_to.  */

static int last_max_ascent, last_height;

726 727 728 729
/* Non-zero if there's a help-echo in the echo area.  */

int help_echo_showing_p;

730 731 732 733 734 735
/* If >= 0, computed, exact values of mode-line and header-line height
   to use in the macros CURRENT_MODE_LINE_HEIGHT and
   CURRENT_HEADER_LINE_HEIGHT.  */

int current_mode_line_height, current_header_line_height;

Gerd Moellmann's avatar
Gerd Moellmann committed
736
/* The maximum distance to look ahead for text properties.  Values
737
   that are too small let us call compute_char_face and similar
Gerd Moellmann's avatar
Gerd Moellmann committed
738 739 740 741 742 743
   functions too often which is expensive.  Values that are too large
   let us call compute_char_face and alike too often because we
   might not be interested in text properties that far away.  */

#define TEXT_PROP_DISTANCE_LIMIT 100

744 745
#if GLYPH_DEBUG

746 747 748 749 750
/* Variables to turn off display optimizations from Lisp.  */

int inhibit_try_window_id, inhibit_try_window_reusing;
int inhibit_try_cursor_movement;

Gerd Moellmann's avatar
Gerd Moellmann committed
751 752 753 754
/* Non-zero means print traces of redisplay if compiled with
   GLYPH_DEBUG != 0.  */

int trace_redisplay_p;
755

756
#endif /* GLYPH_DEBUG */
757

758 759
#ifdef DEBUG_TRACE_MOVE
/* Non-zero means trace with TRACE_MOVE to stderr.  */
760 761 762 763
int trace_move;

#define TRACE_MOVE(x)	if (trace_move) fprintf x; else (void) 0
#else
764
#define TRACE_MOVE(x)	(void) 0
Gerd Moellmann's avatar
Gerd Moellmann committed
765
#endif
766

767 768 769 770
/* Non-zero means automatically scroll windows horizontally to make
   point visible.  */

int automatic_hscrolling_p;
771
Lisp_Object Qauto_hscroll_mode;
772

773 774
/* How close to the margin can point get before the window is scrolled
   horizontally.  */
775
EMACS_INT hscroll_margin;
776 777

/* How much to scroll horizontally when point is inside the above margin.  */
778
Lisp_Object Vhscroll_step;
779

780
/* The variable `resize-mini-windows'.  If nil, don't resize
Eli Zaretskii's avatar
Eli Zaretskii committed
781
   mini-windows.  If t, always resize them to fit the text they
782 783 784 785 786
   display.  If `grow-only', let mini-windows grow only until they
   become empty.  */

Lisp_Object Vresize_mini_windows;

787 788 789 790
/* Buffer being redisplayed -- for redisplay_window_error.  */

struct buffer *displayed_buffer;

791 792 793 794
/* Space between overline and text. */

EMACS_INT overline_margin;

795 796 797 798 799 800
/* Require underline to be at least this many screen pixels below baseline
   This to avoid underline "merging" with the base of letters at small
   font sizes, particularly when x_use_underline_position_properties is on. */

EMACS_INT underline_minimum_offset;

Gerd Moellmann's avatar
Gerd Moellmann committed
801 802 803
/* Value returned from text property handlers (see below).  */

enum prop_handled
804
{
Gerd Moellmann's avatar
Gerd Moellmann committed
805 806 807 808 809
  HANDLED_NORMALLY,
  HANDLED_RECOMPUTE_PROPS,
  HANDLED_OVERLAY_STRING_CONSUMED,
  HANDLED_RETURN
};
810

Gerd Moellmann's avatar
Gerd Moellmann committed
811 812
/* A description of text properties that redisplay is interested
   in.  */
813

Gerd Moellmann's avatar
Gerd Moellmann committed
814 815 816 817
struct props
{
  /* The name of the property.  */
  Lisp_Object *name;
818

Gerd Moellmann's avatar
Gerd Moellmann committed
819 820 821 822 823
  /* A unique index for the property.  */
  enum prop_idx idx;

  /* A handler function called to set up iterator IT from the property
     at IT's current position.  Value is used to steer handle_stop.  */
824
  enum prop_handled (*handler) (struct it *it);
Gerd Moellmann's avatar
Gerd Moellmann committed
825 826
};

827 828 829 830 831 832
static enum prop_handled handle_face_prop (struct it *);
static enum prop_handled handle_invisible_prop (struct it *);
static enum prop_handled handle_display_prop (struct it *);
static enum prop_handled handle_composition_prop (struct it *);
static enum prop_handled handle_overlay_change (struct it *);
static enum prop_handled handle_fontified_prop (struct it *);
Gerd Moellmann's avatar
Gerd Moellmann committed
833 834 835 836

/* Properties handled by iterators.  */

static struct props it_props[] =
Karl Heuer's avatar
Karl Heuer committed
837
{
Gerd Moellmann's avatar
Gerd Moellmann committed
838 839 840 841 842 843
  {&Qfontified,		FONTIFIED_PROP_IDX,	handle_fontified_prop},
  /* Handle `face' before `display' because some sub-properties of
     `display' need to know the face.  */
  {&Qface,		FACE_PROP_IDX,		handle_face_prop},
  {&Qdisplay,		DISPLAY_PROP_IDX,	handle_display_prop},
  {&Qinvisible,		INVISIBLE_PROP_IDX,	handle_invisible_prop},
844
  {&Qcomposition,	COMPOSITION_PROP_IDX,	handle_composition_prop},
Gerd Moellmann's avatar
Gerd Moellmann committed
845 846
  {NULL,		0,			NULL}
};
Karl Heuer's avatar
Karl Heuer committed
847

Gerd Moellmann's avatar
Gerd Moellmann committed
848 849
/* Value is the position described by X.  If X is a marker, value is
   the marker_position of X.  Otherwise, value is X.  */
850

Gerd Moellmann's avatar
Gerd Moellmann committed
851
#define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
852

Gerd Moellmann's avatar
Gerd Moellmann committed
853
/* Enumeration returned by some move_it_.* functions internally.  */
854

Gerd Moellmann's avatar
Gerd Moellmann committed
855 856 857 858
enum move_it_result
{
  /* Not used.  Undefined value.  */
  MOVE_UNDEFINED,
859

Gerd Moellmann's avatar
Gerd Moellmann committed
860 861
  /* Move ended at the requested buffer position or ZV.  */
  MOVE_POS_MATCH_OR_ZV,
862

Gerd Moellmann's avatar
Gerd Moellmann committed
863 864
  /* Move ended at the requested X pixel position.  */
  MOVE_X_REACHED,
865

Gerd Moellmann's avatar
Gerd Moellmann committed
866 867 868
  /* Move within a line ended at the end of a line that must be
     continued.  */
  MOVE_LINE_CONTINUED,
869

Gerd Moellmann's avatar
Gerd Moellmann committed
870 871 872
  /* Move within a line ended at the end of a line that would
     be displayed truncated.  */
  MOVE_LINE_TRUNCATED,
873

Gerd Moellmann's avatar
Gerd Moellmann committed
874 875 876
  /* Move within a line ended at a line end.  */
  MOVE_NEWLINE_OR_CR
};
877

878 879 880 881 882 883 884 885
/* This counter is used to clear the face cache every once in a while
   in redisplay_internal.  It is incremented for each redisplay.
   Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
   cleared.  */

#define CLEAR_FACE_CACHE_COUNT	500
static int clear_face_cache_count;

886 887 888 889 890 891 892
/* Similarly for the image cache.  */

#ifdef HAVE_WINDOW_SYSTEM
#define CLEAR_IMAGE_CACHE_COUNT	101
static int clear_image_cache_count;
#endif

893 894 895 896
/* Non-zero while redisplay_internal is in progress.  */

int redisplaying_p;

897 898 899
/* Non-zero means don't free realized faces.  Bound while freeing
   realized faces is dangerous because glyph matrices might still
   reference them.  */
900

901 902
int inhibit_free_realized_faces;
Lisp_Object Qinhibit_free_realized_faces;
903

904 905 906 907 908 909 910 911 912 913 914 915
/* If a string, XTread_socket generates an event to display that string.
   (The display is done in read_char.)  */

Lisp_Object help_echo_string;
Lisp_Object help_echo_window;
Lisp_Object help_echo_object;
int help_echo_pos;

/* Temporary variable for XTread_socket.  */

Lisp_Object previous_help_echo_string;

Kim F. Storm's avatar
Kim F. Storm committed
916 917 918
/* Null glyph slice */

static struct glyph_slice null_glyph_slice = { 0, 0, 0, 0 };
919

920 921 922 923 924 925 926 927 928
/* Platform-independent portion of hourglass implementation. */

/* Non-zero means we're allowed to display a hourglass pointer.  */
int display_hourglass_p;

/* Non-zero means an hourglass cursor is currently shown.  */
int hourglass_shown_p;

/* If non-null, an asynchronous timer that, when it expires, displays
929
   an hourglass cursor on all frames.  */
930 931 932
struct atimer *hourglass_atimer;

/* Number of seconds to wait before displaying an hourglass cursor.  */
933
Lisp_Object Vhourglass_delay;
934 935 936 937 938

/* Default number of seconds to wait before displaying an hourglass
   cursor.  */
#define DEFAULT_HOURGLASS_DELAY 1

Gerd Moellmann's avatar
Gerd Moellmann committed
939 940 941

/* Function prototypes.  */

942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003
static void setup_for_ellipsis (struct it *, int);
static void mark_window_display_accurate_1 (struct window *, int);
static int single_display_spec_string_p (Lisp_Object, Lisp_Object);
static int display_prop_string_p (Lisp_Object, Lisp_Object);
static int cursor_row_p (struct window *, struct glyph_row *);
static int redisplay_mode_lines (Lisp_Object, int);
static char *decode_mode_spec_coding (Lisp_Object, char *, int);

static Lisp_Object get_it_property (struct it *it, Lisp_Object prop);

static void handle_line_prefix (struct it *);

static void pint2str (char *, int, int);
static void pint2hrstr (char *, int, int);
static struct text_pos run_window_scroll_functions (Lisp_Object,
                                                    struct text_pos);
static void reconsider_clip_changes (struct window *, struct buffer *);
static int text_outside_line_unchanged_p (struct window *, int, int);
static void store_mode_line_noprop_char (char);
static int store_mode_line_noprop (const unsigned char *, int, int);
static void x_consider_frame_title (Lisp_Object);
static void handle_stop (struct it *);
static void handle_stop_backwards (struct it *, EMACS_INT);
static int tool_bar_lines_needed (struct frame *, int *);
static int single_display_spec_intangible_p (Lisp_Object);
static void ensure_echo_area_buffers (void);
static Lisp_Object unwind_with_echo_area_buffer (Lisp_Object);
static Lisp_Object with_echo_area_buffer_unwind_data (struct window *);
static int with_echo_area_buffer (struct window *, int,
                                  int (*) (EMACS_INT, Lisp_Object, EMACS_INT, EMACS_INT),
                                  EMACS_INT, Lisp_Object, EMACS_INT, EMACS_INT);
static void clear_garbaged_frames (void);
static int current_message_1 (EMACS_INT, Lisp_Object, EMACS_INT, EMACS_INT);
static int truncate_message_1 (EMACS_INT, Lisp_Object, EMACS_INT, EMACS_INT);
static int set_message_1 (EMACS_INT, Lisp_Object, EMACS_INT, EMACS_INT);
static int display_echo_area (struct window *);
static int display_echo_area_1 (EMACS_INT, Lisp_Object, EMACS_INT, EMACS_INT);
static int resize_mini_window_1 (EMACS_INT, Lisp_Object, EMACS_INT, EMACS_INT);
static Lisp_Object unwind_redisplay (Lisp_Object);
static int string_char_and_length (const unsigned char *, int *);
static struct text_pos display_prop_end (struct it *, Lisp_Object,
                                         struct text_pos);
static int compute_window_start_on_continuation_line (struct window *);
static Lisp_Object safe_eval_handler (Lisp_Object);
static void insert_left_trunc_glyphs (struct it *);
static struct glyph_row *get_overlay_arrow_glyph_row (struct window *,
                                                      Lisp_Object);
static void extend_face_to_end_of_line (struct it *);
static int append_space_for_newline (struct it *, int);
static int cursor_row_fully_visible_p (struct window *, int, int);
static int try_scrolling (Lisp_Object, int, EMACS_INT, EMACS_INT, int, int);
static int try_cursor_movement (Lisp_Object, struct text_pos, int *);
static int trailing_whitespace_p (int);
static int message_log_check_duplicate (int, int, int, int);
static void push_it (struct it *);
static void pop_it (struct it *);
static void sync_frame_with_window_matrix_rows (struct window *);
static void select_frame_for_redisplay (Lisp_Object);
static void redisplay_internal (int);
static int echo_area_display (int);
static void redisplay_windows (Lisp_Object);
static void redisplay_window (Lisp_Object, int);
1004
static Lisp_Object redisplay_window_error (Lisp_Object);
1005 1006 1007 1008 1009 1010 1011 1012 1013
static Lisp_Object redisplay_window_0 (Lisp_Object);
static Lisp_Object redisplay_window_1 (Lisp_Object);
static int update_menu_bar (struct frame *, int, int);
static int try_window_reusing_current_matrix (struct window *);
static int try_window_id (struct window *);
static int display_line (struct it *);
static int display_mode_lines (struct window *);
static int display_mode_line (struct window *, enum face_id, Lisp_Object);
static int display_mode_element (struct it *, int, int, int, Lisp_Object, Lisp_Object, int);
1014 1015 1016
static int store_mode_line_string (const char *, Lisp_Object, int, int, int, Lisp_Object);
static const char *decode_mode_spec (struct window *, int, int, int,
				     Lisp_Object *);
1017 1018
static void display_menu_bar (struct window *);
static int display_count_lines (int, int, int, int, int *);
1019
static int display_string (const unsigned char *, Lisp_Object, Lisp_Object,
1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041
                           EMACS_INT, EMACS_INT, struct it *, int, int, int, int);
static void compute_line_metrics (struct it *);
static void run_redisplay_end_trigger_hook (struct it *);
static int get_overlay_strings (struct it *, int);
static int get_overlay_strings_1 (struct it *, int, int);
static void next_overlay_string (struct it *);
static void reseat (struct it *, struct text_pos, int);
static void reseat_1 (struct it *, struct text_pos, int);
static void back_to_previous_visible_line_start (struct it *);
void reseat_at_previous_visible_line_start (struct it *);
static void reseat_at_next_visible_line_start (struct it *, int);
static int next_element_from_ellipsis (struct it *);
static int next_element_from_display_vector (struct it *);
static int next_element_from_string (struct it *);
static int next_element_from_c_string (struct it *);
static int next_element_from_buffer (struct it *);
static int next_element_from_composition (struct it *);
static int next_element_from_image (struct it *);
static int next_element_from_stretch (struct it *);
static void load_overlay_strings (struct it *, int);
static int init_from_display_pos (struct it *, struct window *,
                                  struct display_pos *);
1042
static void reseat_to_string (struct it *, const unsigned char *,
1043
                              Lisp_Object, int, int, int, int);
1044 1045 1046
static enum move_it_result
       move_it_in_display_line_to (struct it *, EMACS_INT, int,
				   enum move_operation_enum);
1047 1048 1049 1050 1051 1052 1053 1054 1055 1056
void move_it_vertically_backward (struct it *, int);
static void init_to_row_start (struct it *, struct window *,
                               struct glyph_row *);
static int init_to_row_end (struct it *, struct window *,
                            struct glyph_row *);
static void back_to_previous_line_start (struct it *);
static int forward_to_next_line_start (struct it *, int *);
static struct text_pos string_pos_nchars_ahead (struct text_pos,
                                                Lisp_Object, int);
static struct text_pos string_pos (int, Lisp_Object);
1057 1058
static struct text_pos c_string_pos (int, const unsigned char *, int);
static int number_of_chars (const unsigned char *, int);
1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069
static void compute_stop_pos (struct it *);
static void compute_string_pos (struct text_pos *, struct text_pos,
                                Lisp_Object);
static int face_before_or_after_it_pos (struct it *, int);
static EMACS_INT next_overlay_change (EMACS_INT);
static int handle_single_display_spec (struct it *, Lisp_Object,
                                       Lisp_Object, Lisp_Object,
                                       struct text_pos *, int);
static int underlying_face_id (struct it *);
static int in_ellipses_for_invisible_text_p (struct display_pos *,
                                             struct window *);
Gerd Moellmann's avatar
Gerd Moellmann committed
1070 1071 1072

#define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
#define face_after_it_pos(IT)  face_before_or_after_it_pos ((IT), 0)
1073

Gerd Moellmann's avatar
Gerd Moellmann committed
1074
#ifdef HAVE_WINDOW_SYSTEM
1075

1076 1077 1078 1079 1080 1081 1082 1083 1084
static void update_tool_bar (struct frame *, int);
static void build_desired_tool_bar_string (struct frame *f);
static int redisplay_tool_bar (struct frame *);
static void display_tool_bar_line (struct it *, int);
static void notice_overwritten_cursor (struct window *,
                                       enum glyph_row_area,
                                       int, int, int, int);
static void append_stretch_glyph (struct it *, Lisp_Object,
                                  int, int, int);
1085 1086


1087

Gerd Moellmann's avatar
Gerd Moellmann committed
1088
#endif /* HAVE_WINDOW_SYSTEM */
1089

Gerd Moellmann's avatar
Gerd Moellmann committed
1090 1091 1092 1093

/***********************************************************************
		      Window display dimensions
 ***********************************************************************/
1094

1095 1096 1097 1098 1099
/* Return the bottom boundary y-position for text lines in window W.
   This is the first y position at which a line cannot start.
   It is relative to the top of the window.

   This is the height of W minus the height of a mode line, if any.  */
Gerd Moellmann's avatar
Gerd Moellmann committed
1100 1101

INLINE int
1102
window_text_bottom_y (struct window *w)
Gerd Moellmann's avatar
Gerd Moellmann committed
1103
{
1104
  int height = WINDOW_TOTAL_HEIGHT (w);
1105

Gerd Moellmann's avatar
Gerd Moellmann committed
1106 1107 1108
  if (WINDOW_WANTS_MODELINE_P (w))
    height -= CURRENT_MODE_LINE_HEIGHT (w);
  return height;
1109 1110
}

Gerd Moellmann's avatar
Gerd Moellmann committed
1111
/* Return the pixel width of display area AREA of window W.  AREA < 0
Kim F. Storm's avatar
Kim F. Storm committed
1112
   means return the total width of W, not including fringes to
Gerd Moellmann's avatar
Gerd Moellmann committed
1113
   the left and right of the window.  */
1114

Gerd Moellmann's avatar
Gerd Moellmann committed
1115
INLINE int
1116
window_box_width (struct window *w, int area)
Gerd Moellmann's avatar
Gerd Moellmann committed
1117
{