xdisp.c 896 KB
Newer Older
Jim Blandy's avatar
Jim Blandy committed
1
/* Display generation from window structure and buffer text.
2

Glenn Morris's avatar
Glenn Morris committed
3
Copyright (C) 1985-1988, 1993-1995, 1997-2012 Free Software Foundation, Inc.
Jim Blandy's avatar
Jim Blandy committed
4 5 6

This file is part of GNU Emacs.

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

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
18
along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
Jim Blandy's avatar
Jim Blandy committed
19

Gerd Moellmann's avatar
Gerd Moellmann committed
20 21 22 23 24 25 26 27 28 29 30 31 32
/* 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'
33
   in xdisp.c is the only entry into the inner redisplay code.
Gerd Moellmann's avatar
Gerd Moellmann committed
34 35 36 37 38 39 40 41 42 43 44

   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.

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

57
   What does redisplay do?  Obviously, it has to figure out somehow what
Gerd Moellmann's avatar
Gerd Moellmann committed
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
   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
78
   You will find a lot of redisplay optimizations when you start
Gerd Moellmann's avatar
Gerd Moellmann committed
79 80
   looking at the innards of redisplay.  The overall goal of all these
   optimizations is to make redisplay fast because it is done
81 82 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
   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
114 115 116 117 118 119 120 121 122 123 124 125 126 127

   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
128
   interface functions taking an iterator structure (struct it)
Gerd Moellmann's avatar
Gerd Moellmann committed
129 130
   argument.

Pavel Janík's avatar
Pavel Janík committed
131
   Iteration over things to be displayed is then simple.  It is
132 133 134 135 136 137 138
   started by initializing an iterator with a call to init_iterator,
   passing it the buffer position where to start iteration.  For
   iteration over strings, pass -1 as the position to init_iterator,
   and call reseat_to_string when the string is ready, to initialize
   the iterator for that string.  Thereafter, 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
139 140 141 142 143 144 145 146 147 148
   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
149 150
   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
151 152 153
   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
154 155 156 157 158
   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
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178

   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
179 180 181 182 183 184 185 186 187 188
   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
189
   concerned, the effect of calling bidi_move_to_visually_next, the
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
   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
219
   glyph of a suitably computed width.  Both the blanks and the
220 221
   stretch glyph are given the face of the background of the line.
   This way, the terminal-specific back-end can still draw the glyphs
222 223
   left to right, even for R2L lines.

224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253
   Bidirectional display and character compositions

   Some scripts cannot be displayed by drawing each character
   individually, because adjacent characters change each other's shape
   on display.  For example, Arabic and Indic scripts belong to this
   category.

   Emacs display supports this by providing "character compositions",
   most of which is implemented in composite.c.  During the buffer
   scan that delivers characters to PRODUCE_GLYPHS, if the next
   character to be delivered is a composed character, the iteration
   calls composition_reseat_it and next_element_from_composition.  If
   they succeed to compose the character with one or more of the
   following characters, the whole sequence of characters that where
   composed is recorded in the `struct composition_it' object that is
   part of the buffer iterator.  The composed sequence could produce
   one or more font glyphs (called "grapheme clusters") on the screen.
   Each of these grapheme clusters is then delivered to PRODUCE_GLYPHS
   in the direction corresponding to the current bidi scan direction
   (recorded in the scan_dir member of the `struct bidi_it' object
   that is part of the buffer iterator).  In particular, if the bidi
   iterator currently scans the buffer backwards, the grapheme
   clusters are delivered back to front.  This reorders the grapheme
   clusters as appropriate for the current bidi context.  Note that
   this means that the grapheme clusters are always stored in the
   LGSTRING object (see composite.c) in the logical order.

   Moving an iterator in bidirectional text
   without producing glyphs

254 255 256 257 258 259 260
   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
U. Ser's avatar
U. Ser committed
261
   delivers.  This is important when functions from the move_it_*
262 263 264 265 266 267 268 269 270 271
   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
272

273
#include <config.h>
Jim Blandy's avatar
Jim Blandy committed
274
#include <stdio.h>
275
#include <limits.h>
276

Jim Blandy's avatar
Jim Blandy committed
277
#include "lisp.h"
278
#include "atimer.h"
279
#include "keyboard.h"
Jim Blandy's avatar
Jim Blandy committed
280
#include "frame.h"
Jim Blandy's avatar
Jim Blandy committed
281 282 283
#include "window.h"
#include "termchar.h"
#include "dispextern.h"
Kenichi Handa's avatar
Kenichi Handa committed
284
#include "character.h"
285
#include "buffer.h"
286
#include "charset.h"
Jim Blandy's avatar
Jim Blandy committed
287 288
#include "indent.h"
#include "commands.h"
289
#include "keymap.h"
Jim Blandy's avatar
Jim Blandy committed
290 291
#include "macros.h"
#include "disptab.h"
292
#include "termhooks.h"
293
#include "termopts.h"
294
#include "intervals.h"
295 296
#include "coding.h"
#include "process.h"
Andreas Schwab's avatar
Andreas Schwab committed
297
#include "region-cache.h"
Kenichi Handa's avatar
Kenichi Handa committed
298
#include "font.h"
Dave Love's avatar
Dave Love committed
299
#include "fontset.h"
300
#include "blockinput.h"
Andreas Schwab's avatar
Andreas Schwab committed
301

302
#ifdef HAVE_X_WINDOWS
Andreas Schwab's avatar
Andreas Schwab committed
303 304
#include "xterm.h"
#endif
Daniel Colascione's avatar
Daniel Colascione committed
305
#ifdef HAVE_NTGUI
306 307
#include "w32term.h"
#endif
308 309 310
#ifdef HAVE_NS
#include "nsterm.h"
#endif
311 312 313
#ifdef USE_GTK
#include "gtkutil.h"
#endif
Jim Blandy's avatar
Jim Blandy committed
314

315 316
#include "font.h"

317 318 319 320
#ifndef FRAME_X_OUTPUT
#define FRAME_X_OUTPUT(f) ((f)->output_data.x)
#endif

Gerd Moellmann's avatar
Gerd Moellmann committed
321 322
#define INFINITY 10000000

323
Lisp_Object Qoverriding_local_map, Qoverriding_terminal_local_map;
324
Lisp_Object Qwindow_scroll_functions;
325 326
static Lisp_Object Qwindow_text_change_functions;
static Lisp_Object Qredisplay_end_trigger_functions;
327
Lisp_Object Qinhibit_point_motion_hooks;
328 329 330 331 332 333 334
static Lisp_Object QCeval, QCpropertize;
Lisp_Object QCfile, QCdata;
static Lisp_Object Qfontified;
static Lisp_Object Qgrow_only;
static Lisp_Object Qinhibit_eval_during_redisplay;
static Lisp_Object Qbuffer_position, Qposition, Qobject;
static Lisp_Object Qright_to_left, Qleft_to_right;
Gerd Moellmann's avatar
Gerd Moellmann committed
335

336
/* Cursor shapes.  */
337 338
Lisp_Object Qbar, Qhbar, Qbox, Qhollow;

339
/* Pointer shapes.  */
340 341
static Lisp_Object Qarrow, Qhand;
Lisp_Object Qtext;
Kenichi Handa's avatar
Kenichi Handa committed
342

343
/* Holds the list (error).  */
344
static Lisp_Object list_of_error;
345

346
static Lisp_Object Qfontification_functions;
Gerd Moellmann's avatar
Gerd Moellmann committed
347

348 349
static Lisp_Object Qwrap_prefix;
static Lisp_Object Qline_prefix;
350
static Lisp_Object Qredisplay_internal;
351

352 353
/* Non-nil means don't actually do any redisplay.  */

354
Lisp_Object Qinhibit_redisplay;
355

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

Kenichi Handa's avatar
Kenichi Handa committed
358
Lisp_Object Qdisplay;
Gerd Moellmann's avatar
Gerd Moellmann committed
359

360 361 362 363 364
Lisp_Object Qspace, QCalign_to;
static Lisp_Object QCrelative_width, QCrelative_height;
Lisp_Object Qleft_margin, Qright_margin;
static Lisp_Object Qspace_width, Qraise;
static Lisp_Object Qslice;
Kenichi Handa's avatar
Kenichi Handa committed
365
Lisp_Object Qcenter;
366 367
static Lisp_Object Qmargin, Qpointer;
static Lisp_Object Qline_height;
Gerd Moellmann's avatar
Gerd Moellmann committed
368

Paul Eggert's avatar
Paul Eggert committed
369
/* These setters are used only in this file, so they can be private.  */
370
static void
Paul Eggert's avatar
Paul Eggert committed
371 372 373 374
wset_base_line_number (struct window *w, Lisp_Object val)
{
  w->base_line_number = val;
}
375
static void
Paul Eggert's avatar
Paul Eggert committed
376 377 378 379
wset_base_line_pos (struct window *w, Lisp_Object val)
{
  w->base_line_pos = val;
}
380
static void
Paul Eggert's avatar
Paul Eggert committed
381 382 383 384
wset_column_number_displayed (struct window *w, Lisp_Object val)
{
  w->column_number_displayed = val;
}
385
static void
Paul Eggert's avatar
Paul Eggert committed
386 387 388 389 390
wset_region_showing (struct window *w, Lisp_Object val)
{
  w->region_showing = val;
}

Kenichi Handa's avatar
Kenichi Handa committed
391 392 393 394 395
#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.  */

396 397 398 399 400 401 402 403
#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
404

405 406
#else /* !HAVE_WINDOW_SYSTEM */
#define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) 0
Kenichi Handa's avatar
Kenichi Handa committed
407 408
#endif /* HAVE_WINDOW_SYSTEM */

409 410 411 412 413 414 415 416 417 418 419 420 421 422 423
/* Test if the display element loaded in IT, or the underlying buffer
   or string character, is a space or a TAB character.  This is used
   to determine where word wrapping can occur.  */

#define IT_DISPLAYING_WHITESPACE(it)					\
  ((it->what == IT_CHARACTER && (it->c == ' ' || it->c == '\t'))	\
   || ((STRINGP (it->string)						\
	&& (SREF (it->string, IT_STRING_BYTEPOS (*it)) == ' '		\
	    || SREF (it->string, IT_STRING_BYTEPOS (*it)) == '\t'))	\
       || (it->s							\
	   && (it->s[IT_BYTEPOS (*it)] == ' '				\
	       || it->s[IT_BYTEPOS (*it)] == '\t'))			\
       || (IT_BYTEPOS (*it) < ZV_BYTE					\
	   && (*BYTE_POS_ADDR (IT_BYTEPOS (*it)) == ' '			\
	       || *BYTE_POS_ADDR (IT_BYTEPOS (*it)) == '\t'))))		\
424

Gerd Moellmann's avatar
Gerd Moellmann committed
425 426
/* Name of the face used to highlight trailing whitespace.  */

427
static Lisp_Object Qtrailing_whitespace;
Gerd Moellmann's avatar
Gerd Moellmann committed
428

429 430
/* Name and number of the face used to highlight escape glyphs.  */

431
static Lisp_Object Qescape_glyph;
432

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

435
static Lisp_Object Qnobreak_space;
Juri Linkov's avatar
Juri Linkov committed
436

Gerd Moellmann's avatar
Gerd Moellmann committed
437
/* The symbol `image' which is the car of the lists used to represent
438
   images in Lisp.  Also a tool bar style.  */
Gerd Moellmann's avatar
Gerd Moellmann committed
439 440 441

Lisp_Object Qimage;

Kenichi Handa's avatar
Kenichi Handa committed
442
/* The image map types.  */
443 444 445
Lisp_Object QCmap;
static Lisp_Object QCpointer;
static Lisp_Object Qrect, Qcircle, Qpoly;
Kenichi Handa's avatar
Kenichi Handa committed
446

447
/* Tool bar styles */
448
Lisp_Object Qboth, Qboth_horiz, Qtext_image_horiz;
449

Gerd Moellmann's avatar
Gerd Moellmann committed
450 451
/* Non-zero means print newline to stdout before next mini-buffer
   message.  */
Jim Blandy's avatar
Jim Blandy committed
452 453 454

int noninteractive_need_newline;

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

457
static int message_log_need_newline;
458

459 460 461 462 463 464
/* 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
465 466 467 468 469

/* 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
470

Gerd Moellmann's avatar
Gerd Moellmann committed
471
static struct text_pos this_line_start_pos;
Jim Blandy's avatar
Jim Blandy committed
472

Gerd Moellmann's avatar
Gerd Moellmann committed
473 474 475 476 477 478
/* 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
479 480

static int this_line_vpos;
Gerd Moellmann's avatar
Gerd Moellmann committed
481 482 483 484 485 486 487
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
488

489 490 491 492 493 494
/* The smallest character position seen by move_it_* functions as they
   move across display lines.  Used to set MATRIX_ROW_START_CHARPOS of
   hscrolled lines, see display_line.  */

static struct text_pos this_line_min_pos;

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

static struct buffer *this_line_buffer;


Kenichi Handa's avatar
Kenichi Handa committed
500 501 502
/* 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
503 504
   numerical position.  */

505
static Lisp_Object Qlast_arrow_position, Qlast_arrow_string;
Kenichi Handa's avatar
Kenichi Handa committed
506 507 508 509

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

510
static Lisp_Object Qoverlay_arrow_string, Qoverlay_arrow_bitmap;
511

512
Lisp_Object Qmenu_bar_update_hook;
513

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

Gerd Moellmann's avatar
Gerd Moellmann committed
516
static int overlay_arrow_seen;
Karl Heuer's avatar
Karl Heuer committed
517

Gerd Moellmann's avatar
Gerd Moellmann committed
518 519 520
/* 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
521 522 523

int buffer_shared;

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

Gerd Moellmann's avatar
Gerd Moellmann committed
526
static Lisp_Object default_invis_vector[3];
Jim Blandy's avatar
Jim Blandy committed
527

Gerd Moellmann's avatar
Gerd Moellmann committed
528 529 530 531
/* 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.  */

532 533
Lisp_Object echo_area_window;

534 535 536 537 538
/* 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.  */

539
static Lisp_Object Vmessage_stack;
540

541 542
/* Nonzero means multibyte characters were enabled when the echo area
   message was specified.  */
Gerd Moellmann's avatar
Gerd Moellmann committed
543

544
static int message_enable_multibyte;
545

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

Jim Blandy's avatar
Jim Blandy committed
548 549
int update_mode_lines;

Gerd Moellmann's avatar
Gerd Moellmann committed
550
/* Nonzero if window sizes or contents have changed since last
551
   redisplay that finished.  */
Gerd Moellmann's avatar
Gerd Moellmann committed
552

Jim Blandy's avatar
Jim Blandy committed
553 554
int windows_or_buffers_changed;

555 556 557 558
/* Nonzero means a frame's cursor type has been changed.  */

int cursor_type_changed;

Gerd Moellmann's avatar
Gerd Moellmann committed
559 560 561
/* Nonzero after display_mode_line if %l was used and it displayed a
   line number.  */

562
static int line_number_displayed;
563

564 565 566 567
/* The name of the *Messages* buffer, a string.  */

static Lisp_Object Vmessages_buffer_name;

568 569
/* Current, index 0, and last displayed echo area message.  Either
   buffers from echo_buffers, or nil to indicate no message.  */
570 571 572

Lisp_Object echo_area_buffer[2];

573
/* The buffers referenced from echo_area_buffer.  */
574 575 576 577 578 579 580 581 582 583 584 585 586 587 588

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.  */

589
static int message_buf_print;
590

591 592
/* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable.  */

593 594
static Lisp_Object Qinhibit_menubar_update;
static Lisp_Object Qmessage_truncate_lines;
595

596
/* Set to 1 in clear_message to make redisplay_internal aware
597
   of an emptied echo area.  */
598 599 600

static int message_cleared_p;

Gerd Moellmann's avatar
Gerd Moellmann committed
601 602
/* A scratch glyph row with contents used for generating truncation
   glyphs.  Also used in direct_output_for_insert.  */
603

Gerd Moellmann's avatar
Gerd Moellmann committed
604
#define MAX_SCRATCH_GLYPHS 100
605
static struct glyph_row scratch_glyph_row;
Gerd Moellmann's avatar
Gerd Moellmann committed
606
static struct glyph scratch_glyphs[MAX_SCRATCH_GLYPHS];
607

Gerd Moellmann's avatar
Gerd Moellmann committed
608 609 610 611
/* Ascent and height of the last line processed by move_it_to.  */

static int last_max_ascent, last_height;

612 613 614 615
/* Non-zero if there's a help-echo in the echo area.  */

int help_echo_showing_p;

616 617 618 619 620 621
/* 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
622
/* The maximum distance to look ahead for text properties.  Values
623
   that are too small let us call compute_char_face and similar
Gerd Moellmann's avatar
Gerd Moellmann committed
624 625 626 627 628 629
   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

630 631 632 633 634 635 636 637 638 639
/* SAVE_IT and RESTORE_IT are called when we save a snapshot of the
   iterator state and later restore it.  This is needed because the
   bidi iterator on bidi.c keeps a stacked cache of its states, which
   is really a singleton.  When we use scratch iterator objects to
   move around the buffer, we can cause the bidi cache to be pushed or
   popped, and therefore we need to restore the cache state when we
   return to the original iterator.  */
#define SAVE_IT(ITCOPY,ITORIG,CACHE)		\
  do {						\
    if (CACHE)					\
640
      bidi_unshelve_cache (CACHE, 1);		\
641
    ITCOPY = ITORIG;				\
Juanma Barranquero's avatar
Juanma Barranquero committed
642
    CACHE = bidi_shelve_cache ();		\
643 644 645 646 647 648
  } while (0)

#define RESTORE_IT(pITORIG,pITCOPY,CACHE)	\
  do {						\
    if (pITORIG != pITCOPY)			\
      *(pITORIG) = *(pITCOPY);			\
649
    bidi_unshelve_cache (CACHE, 0);		\
650 651 652
    CACHE = NULL;				\
  } while (0)

653
#ifdef GLYPH_DEBUG
654

Gerd Moellmann's avatar
Gerd Moellmann committed
655
/* Non-zero means print traces of redisplay if compiled with
656
   GLYPH_DEBUG defined.  */
Gerd Moellmann's avatar
Gerd Moellmann committed
657 658

int trace_redisplay_p;
659

660
#endif /* GLYPH_DEBUG */
661

662 663
#ifdef DEBUG_TRACE_MOVE
/* Non-zero means trace with TRACE_MOVE to stderr.  */
664 665 666 667
int trace_move;

#define TRACE_MOVE(x)	if (trace_move) fprintf x; else (void) 0
#else
668
#define TRACE_MOVE(x)	(void) 0
Gerd Moellmann's avatar
Gerd Moellmann committed
669
#endif
670

671
static Lisp_Object Qauto_hscroll_mode;
672

673 674
/* Buffer being redisplayed -- for redisplay_window_error.  */

675
static struct buffer *displayed_buffer;
676

Gerd Moellmann's avatar
Gerd Moellmann committed
677 678 679
/* Value returned from text property handlers (see below).  */

enum prop_handled
680
{
Gerd Moellmann's avatar
Gerd Moellmann committed
681 682 683 684 685
  HANDLED_NORMALLY,
  HANDLED_RECOMPUTE_PROPS,
  HANDLED_OVERLAY_STRING_CONSUMED,
  HANDLED_RETURN
};
686

Gerd Moellmann's avatar
Gerd Moellmann committed
687 688
/* A description of text properties that redisplay is interested
   in.  */
689

Gerd Moellmann's avatar
Gerd Moellmann committed
690 691 692 693
struct props
{
  /* The name of the property.  */
  Lisp_Object *name;
694

Gerd Moellmann's avatar
Gerd Moellmann committed
695 696 697 698 699
  /* 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.  */
700
  enum prop_handled (*handler) (struct it *it);
Gerd Moellmann's avatar
Gerd Moellmann committed
701 702
};

703 704 705 706 707 708
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
709 710 711 712

/* Properties handled by iterators.  */

static struct props it_props[] =
Karl Heuer's avatar
Karl Heuer committed
713
{
Gerd Moellmann's avatar
Gerd Moellmann committed
714 715 716 717 718 719
  {&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},
720
  {&Qcomposition,	COMPOSITION_PROP_IDX,	handle_composition_prop},
Gerd Moellmann's avatar
Gerd Moellmann committed
721 722
  {NULL,		0,			NULL}
};
Karl Heuer's avatar
Karl Heuer committed
723

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

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

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

Gerd Moellmann's avatar
Gerd Moellmann committed
731 732 733 734
enum move_it_result
{
  /* Not used.  Undefined value.  */
  MOVE_UNDEFINED,
735

Gerd Moellmann's avatar
Gerd Moellmann committed
736 737
  /* Move ended at the requested buffer position or ZV.  */
  MOVE_POS_MATCH_OR_ZV,
738

Gerd Moellmann's avatar
Gerd Moellmann committed
739 740
  /* Move ended at the requested X pixel position.  */
  MOVE_X_REACHED,
741

Gerd Moellmann's avatar
Gerd Moellmann committed
742 743 744
  /* Move within a line ended at the end of a line that must be
     continued.  */
  MOVE_LINE_CONTINUED,
745

Gerd Moellmann's avatar
Gerd Moellmann committed
746 747 748
  /* Move within a line ended at the end of a line that would
     be displayed truncated.  */
  MOVE_LINE_TRUNCATED,
749

Gerd Moellmann's avatar
Gerd Moellmann committed
750 751 752
  /* Move within a line ended at a line end.  */
  MOVE_NEWLINE_OR_CR
};
753

754 755 756 757 758 759 760 761
/* 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;

762 763 764 765 766
/* Similarly for the image cache.  */

#ifdef HAVE_WINDOW_SYSTEM
#define CLEAR_IMAGE_CACHE_COUNT	101
static int clear_image_cache_count;
Eli Zaretskii's avatar
Eli Zaretskii committed
767 768 769

/* Null glyph slice */
static struct glyph_slice null_glyph_slice = { 0, 0, 0, 0 };
770 771
#endif

772
/* True while redisplay_internal is in progress.  */
773

774
bool redisplaying_p;
775

776
static Lisp_Object Qinhibit_free_realized_faces;
777
static Lisp_Object Qmode_line_default_help_echo;
778

779 780 781 782 783 784
/* 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;
785
ptrdiff_t help_echo_pos;
786 787 788 789 790

/* Temporary variable for XTread_socket.  */

Lisp_Object previous_help_echo_string;

791 792 793 794 795 796
/* Platform-independent portion of hourglass implementation. */

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

/* If non-null, an asynchronous timer that, when it expires, displays
797
   an hourglass cursor on all frames.  */
798 799
struct atimer *hourglass_atimer;

800 801 802 803
/* Name of the face used to display glyphless characters.  */
Lisp_Object Qglyphless_char;

/* Symbol for the purpose of Vglyphless_char_display.  */
804
static Lisp_Object Qglyphless_char_display;
805 806

/* Method symbols for Vglyphless_char_display.  */
807
static Lisp_Object Qhex_code, Qempty_box, Qthin_space, Qzero_width;
808 809 810 811

/* Default pixel width of `thin-space' display method.  */
#define THIN_SPACE_WIDTH 1

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

Gerd Moellmann's avatar
Gerd Moellmann committed
816 817 818

/* Function prototypes.  */

819
static void setup_for_ellipsis (struct it *, int);
820
static void set_iterator_to_next (struct it *, int);
821 822 823
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);
824
static int cursor_row_p (struct glyph_row *);
825 826 827 828 829 830 831
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 *);

832 833
static void pint2str (char *, int, ptrdiff_t);
static void pint2hrstr (char *, int, ptrdiff_t);
834 835 836
static struct text_pos run_window_scroll_functions (Lisp_Object,
                                                    struct text_pos);
static void reconsider_clip_changes (struct window *, struct buffer *);
837
static int text_outside_line_unchanged_p (struct window *,
838
					  ptrdiff_t, ptrdiff_t);
839
static void store_mode_line_noprop_char (char);
840
static int store_mode_line_noprop (const char *, int, int);
841
static void handle_stop (struct it *);
842
static void handle_stop_backwards (struct it *, ptrdiff_t);
843
static void vmessage (const char *, va_list) ATTRIBUTE_FORMAT_PRINTF (1, 0);
844 845 846 847
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,
848 849
                                  int (*) (ptrdiff_t, Lisp_Object, ptrdiff_t, ptrdiff_t),
                                  ptrdiff_t, Lisp_Object, ptrdiff_t, ptrdiff_t);
850
static void clear_garbaged_frames (void);
851
static int current_message_1 (ptrdiff_t, Lisp_Object, ptrdiff_t, ptrdiff_t);
852
static void pop_message (void);
853 854 855
static int truncate_message_1 (ptrdiff_t, Lisp_Object, ptrdiff_t, ptrdiff_t);
static void set_message (const char *, Lisp_Object, ptrdiff_t, int);
static int set_message_1 (ptrdiff_t, Lisp_Object, ptrdiff_t, ptrdiff_t);
856
static int display_echo_area (struct window *);
857 858
static int display_echo_area_1 (ptrdiff_t, Lisp_Object, ptrdiff_t, ptrdiff_t);
static int resize_mini_window_1 (ptrdiff_t, Lisp_Object, ptrdiff_t, ptrdiff_t);
859 860 861 862 863 864 865 866 867 868 869
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 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);
870
static int try_scrolling (Lisp_Object, int, ptrdiff_t, ptrdiff_t, int, int);
871
static int try_cursor_movement (Lisp_Object, struct text_pos, int *);
872 873
static int trailing_whitespace_p (ptrdiff_t);
static intmax_t message_log_check_duplicate (ptrdiff_t, ptrdiff_t);
874
static void push_it (struct it *, struct text_pos *);
875
static void iterate_out_of_display_property (struct it *);
876 877 878
static void pop_it (struct it *);
static void sync_frame_with_window_matrix_rows (struct window *);
static void select_frame_for_redisplay (Lisp_Object);
879
static void redisplay_internal (void);
880 881 882
static int echo_area_display (int);
static void redisplay_windows (Lisp_Object);
static void redisplay_window (Lisp_Object, int);
883
static Lisp_Object redisplay_window_error (Lisp_Object);
884 885
static Lisp_Object redisplay_window_0 (Lisp_Object);
static Lisp_Object redisplay_window_1 (Lisp_Object);
886
static int set_cursor_from_row (struct window *, struct glyph_row *,
887
				struct glyph_matrix *, ptrdiff_t, ptrdiff_t,
888
				int, int);
889 890 891 892 893 894 895
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);
896
static int store_mode_line_string (const char *, Lisp_Object, int, int, int, Lisp_Object);
897
static const char *decode_mode_spec (struct window *, int, int, Lisp_Object *);
898
static void display_menu_bar (struct window *);
899 900
static ptrdiff_t display_count_lines (ptrdiff_t, ptrdiff_t, ptrdiff_t,
				      ptrdiff_t *);
901
static int display_string (const char *, Lisp_Object, Lisp_Object,
902
                           ptrdiff_t, ptrdiff_t, struct it *, int, int, int, int);
903 904
static void compute_line_metrics (struct it *);
static void run_redisplay_end_trigger_hook (struct it *);
905 906
static int get_overlay_strings (struct it *, ptrdiff_t);
static int get_overlay_strings_1 (struct it *, ptrdiff_t, int);
907 908 909 910 911 912 913 914 915 916 917 918 919 920
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 *);
921
static void load_overlay_strings (struct it *, ptrdiff_t);
922 923
static int init_from_display_pos (struct it *, struct window *,
                                  struct display_pos *);
924
static void reseat_to_string (struct it *, const char *,
925
                              Lisp_Object, ptrdiff_t, ptrdiff_t, int, int);
926
static int get_next_display_element (struct it *);
927
static enum move_it_result
928
       move_it_in_display_line_to (struct it *, ptrdiff_t, int,
929
				   enum move_operation_enum);
930
void move_it_vertically_backward (struct it *, int);
931
static void get_visually_first_element (struct it *);
932 933 934 935 936
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 *);
937
static int forward_to_next_line_start (struct it *, int *, struct bidi_it *);
938
static struct text_pos string_pos_nchars_ahead (struct text_pos,
939 940 941 942
                                                Lisp_Object, ptrdiff_t);
static struct text_pos string_pos (ptrdiff_t, Lisp_Object);
static struct text_pos c_string_pos (ptrdiff_t, const char *, int);
static ptrdiff_t number_of_chars (const char *, int);
943 944 945 946
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);
947
static ptrdiff_t next_overlay_change (ptrdiff_t);
948
static int handle_display_spec (struct it *, Lisp_Object, Lisp_Object,
949
				Lisp_Object, struct text_pos *, ptrdiff_t, int);
950 951
static int handle_single_display_spec (struct it *, Lisp_Object,
                                       Lisp_Object, Lisp_Object,
952
                                       struct text_pos *, ptrdiff_t, int, int);
953 954 955
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
956 957 958

#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)
959

Gerd Moellmann's avatar
Gerd Moellmann committed
960
#ifdef HAVE_WINDOW_SYSTEM
961

962 963
static void x_consider_frame_title (Lisp_Object);
static int tool_bar_lines_needed (struct frame *, int *);
964 965 966 967 968 969 970 971 972
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);
973

974

Gerd Moellmann's avatar
Gerd Moellmann committed
975
#endif /* HAVE_WINDOW_SYSTEM */
976

977
static void produce_special_glyphs (struct it *, enum display_element_type);
978
static void show_mouse_face (Mouse_HLInfo *, enum draw_glyphs_face);
979 980 981
static int coords_in_mouse_face_p (struct window *, int, int);


Gerd Moellmann's avatar
Gerd Moellmann committed
982 983 984 985

/***********************************************************************
		      Window display dimensions
 ***********************************************************************/
986

987 988 989 990 991
/* 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
992

993
int
994
window_text_bottom_y (struct window *w)
Gerd Moellmann's avatar
Gerd Moellmann committed
995
{
996
  int height = WINDOW_TOTAL_HEIGHT (w);
997

Gerd Moellmann's avatar
Gerd Moellmann committed
998 999 1000
  if (WINDOW_WANTS_MODELINE_P (w))
    height -= CURRENT_MODE_LINE_HEIGHT (w);
  return height;
1001 1002
}

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

1007
int
1008
window_box_width (struct window *w, int area)
Gerd Moellmann's avatar
Gerd Moellmann committed
1009
{
1010
  int cols = XFASTINT (w->total_cols);
1011
  int pixels = 0;
1012

Gerd Moellmann's avatar
Gerd Moellmann committed
1013
  if (!w->pseudo_window_p)
1014
    {
1015
      cols -= WINDOW_SCROLL_BAR_COLS (w);
1016

Gerd Moellmann's avatar
Gerd Moellmann committed
1017 1018
      if (area == TEXT_AREA)
	{
1019 1020 1021 1022
	  if (INTEGERP (w->left_margin_cols))
	    cols -= XFASTINT (w->left_margin_cols);
	  if (INTEGERP (w->right_margin_cols))
	    cols -= XFASTINT (w->right_margin_cols);
1023
	  pixels = -WINDOW_TOTAL_FRINGE_WIDTH (w);
Gerd Moellmann's avatar
Gerd Moellmann committed