dispnew.c 194 KB
Newer Older
Jim Blandy's avatar
Jim Blandy committed
1
/* Updating of data structures for redisplay.
2 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

20
#include <config.h>
21 22 23

#define DISPEXTERN_INLINE EXTERN_INLINE

24
#include <signal.h>
25
#include <stdio.h>
Jim Blandy's avatar
Jim Blandy committed
26
#include <ctype.h>
27
#include <setjmp.h>
Andreas Schwab's avatar
Andreas Schwab committed
28 29
#include <unistd.h>

30
#include "lisp.h"
Jim Blandy's avatar
Jim Blandy committed
31 32
#include "termchar.h"
#include "termopts.h"
33
/* cm.h must come after dispextern.h on Windows.  */
34 35
#include "dispextern.h"
#include "cm.h"
36
#include "character.h"
37
#include "buffer.h"
38
#include "keyboard.h"
Jim Blandy's avatar
Jim Blandy committed
39
#include "frame.h"
40
#include "termhooks.h"
Jim Blandy's avatar
Jim Blandy committed
41 42 43 44
#include "window.h"
#include "commands.h"
#include "disptab.h"
#include "indent.h"
45
#include "intervals.h"
Richard M. Stallman's avatar
Richard M. Stallman committed
46
#include "blockinput.h"
Andreas Schwab's avatar
Andreas Schwab committed
47
#include "process.h"
Jim Blandy's avatar
Jim Blandy committed
48

Richard M. Stallman's avatar
Richard M. Stallman committed
49
#include "syssignal.h"
Jim Blandy's avatar
Jim Blandy committed
50

Jim Blandy's avatar
Jim Blandy committed
51 52
#ifdef HAVE_X_WINDOWS
#include "xterm.h"
Gerd Moellmann's avatar
Gerd Moellmann committed
53
#endif /* HAVE_X_WINDOWS */
Jim Blandy's avatar
Jim Blandy committed
54

55 56 57 58
#ifdef HAVE_NTGUI
#include "w32term.h"
#endif /* HAVE_NTGUI */

59 60 61 62
#ifdef HAVE_NS
#include "nsterm.h"
#endif

Gerd Moellmann's avatar
Gerd Moellmann committed
63
/* Include systime.h after xterm.h to avoid double inclusion of time.h.  */
64

Gerd Moellmann's avatar
Gerd Moellmann committed
65
#include "systime.h"
66 67
#include <errno.h>

68
#ifdef DISPNEW_NEEDS_STDIO_EXT
69
#include <stdio_ext.h>
Jim Blandy's avatar
Jim Blandy committed
70
#endif
71

72
#if defined (HAVE_TERM_H) && defined (GNU_LINUX)
Dave Love's avatar
Dave Love committed
73 74
#include <term.h>		/* for tgetent */
#endif
Gerd Moellmann's avatar
Gerd Moellmann committed
75 76 77 78 79 80 81 82 83 84 85 86 87

/* Structure to pass dimensions around.  Used for character bounding
   boxes, glyph matrix dimensions and alike.  */

struct dim
{
  int width;
  int height;
};


/* Function prototypes.  */

88
static void update_frame_line (struct frame *, int);
Andreas Schwab's avatar
Andreas Schwab committed
89 90
static int required_matrix_height (struct window *);
static int required_matrix_width (struct window *);
91 92
static void adjust_frame_glyphs (struct frame *);
static void change_frame_size_1 (struct frame *, int, int, int, int, int);
93
static void increment_row_positions (struct glyph_row *, ptrdiff_t, ptrdiff_t);
94 95 96 97 98 99 100 101 102 103 104 105 106
static void fill_up_frame_row_with_spaces (struct glyph_row *, int);
static void build_frame_matrix_from_window_tree (struct glyph_matrix *,
                                                 struct window *);
static void build_frame_matrix_from_leaf_window (struct glyph_matrix *,
                                                 struct window *);
static void adjust_frame_message_buffer (struct frame *);
static void adjust_decode_mode_spec_buffer (struct frame *);
static void fill_up_glyph_row_with_spaces (struct glyph_row *);
static void clear_window_matrices (struct window *, int);
static void fill_up_glyph_row_area_with_spaces (struct glyph_row *, int);
static int scrolling_window (struct window *, int);
static int update_window_line (struct window *, int, int *);
static void mirror_make_current (struct window *, int);
107
#ifdef GLYPH_DEBUG
108 109
static void check_matrix_pointers (struct glyph_matrix *,
                                   struct glyph_matrix *);
110
#endif
111 112 113 114
static void mirror_line_dance (struct window *, int, int, int *, char *);
static int update_window_tree (struct window *, int);
static int update_window (struct window *, int);
static int update_frame_1 (struct frame *, int, int);
115
static int scrolling (struct frame *);
116 117 118
static void set_window_cursor_after_update (struct window *);
static void adjust_frame_glyphs_for_window_redisplay (struct frame *);
static void adjust_frame_glyphs_for_frame_redisplay (struct frame *);
Gerd Moellmann's avatar
Gerd Moellmann committed
119 120


121 122 123 124 125
/* Redisplay preemption timers.  */

static EMACS_TIME preemption_period;
static EMACS_TIME preemption_next_check;

Jim Blandy's avatar
Jim Blandy committed
126
/* Nonzero upon entry to redisplay means do not assume anything about
Jim Blandy's avatar
Jim Blandy committed
127
   current contents of actual terminal frame; clear and redraw it.  */
Jim Blandy's avatar
Jim Blandy committed
128

Jim Blandy's avatar
Jim Blandy committed
129
int frame_garbaged;
Jim Blandy's avatar
Jim Blandy committed
130

Gerd Moellmann's avatar
Gerd Moellmann committed
131
/* Nonzero means last display completed.  Zero means it was preempted.  */
Jim Blandy's avatar
Jim Blandy committed
132 133 134

int display_completed;

135
Lisp_Object Qdisplay_table, Qredisplay_dont_pause;
Gerd Moellmann's avatar
Gerd Moellmann committed
136

Jim Blandy's avatar
Jim Blandy committed
137

Gerd Moellmann's avatar
Gerd Moellmann committed
138
/* The currently selected frame.  In a single-frame version, this
139
   variable always equals the_only_frame.  */
Jim Blandy's avatar
Jim Blandy committed
140

141
Lisp_Object selected_frame;
Jim Blandy's avatar
Jim Blandy committed
142

Gerd Moellmann's avatar
Gerd Moellmann committed
143
/* A frame which is not just a mini-buffer, or 0 if there are no such
Jim Blandy's avatar
Jim Blandy committed
144
   frames.  This is usually the most recent such frame that was
Morten Welinder's avatar
Morten Welinder committed
145 146
   selected.  In a single-frame version, this variable always holds
   the address of the_only_frame.  */
Jim Blandy's avatar
Jim Blandy committed
147

Gerd Moellmann's avatar
Gerd Moellmann committed
148
struct frame *last_nonminibuf_frame;
149

Gerd Moellmann's avatar
Gerd Moellmann committed
150
/* 1 means SIGWINCH happened when not safe.  */
Jim Blandy's avatar
Jim Blandy committed
151

152
static int delayed_size_change;
Jim Blandy's avatar
Jim Blandy committed
153

Gerd Moellmann's avatar
Gerd Moellmann committed
154
/* 1 means glyph initialization has been completed at startup.  */
Jim Blandy's avatar
Jim Blandy committed
155

Gerd Moellmann's avatar
Gerd Moellmann committed
156
static int glyphs_initialized_initially_p;
Jim Blandy's avatar
Jim Blandy committed
157

Gerd Moellmann's avatar
Gerd Moellmann committed
158
/* Updated window if != 0.  Set by update_window.  */
Jim Blandy's avatar
Jim Blandy committed
159

Gerd Moellmann's avatar
Gerd Moellmann committed
160
struct window *updated_window;
Jim Blandy's avatar
Jim Blandy committed
161

Gerd Moellmann's avatar
Gerd Moellmann committed
162
/* Glyph row updated in update_window_line, and area that is updated.  */
Jim Blandy's avatar
Jim Blandy committed
163

Gerd Moellmann's avatar
Gerd Moellmann committed
164 165
struct glyph_row *updated_row;
int updated_area;
Jim Blandy's avatar
Jim Blandy committed
166

Gerd Moellmann's avatar
Gerd Moellmann committed
167
/* A glyph for a space.  */
Jim Blandy's avatar
Jim Blandy committed
168

Gerd Moellmann's avatar
Gerd Moellmann committed
169
struct glyph space_glyph;
Jim Blandy's avatar
Jim Blandy committed
170

Gerd Moellmann's avatar
Gerd Moellmann committed
171 172
/* Counts of allocated structures.  These counts serve to diagnose
   memory leaks and double frees.  */
Jim Blandy's avatar
Jim Blandy committed
173

174 175
static int glyph_matrix_count;
static int glyph_pool_count;
Jim Blandy's avatar
Jim Blandy committed
176

Gerd Moellmann's avatar
Gerd Moellmann committed
177 178
/* If non-null, the frame whose frame matrices are manipulated.  If
   null, window matrices are worked on.  */
Jim Blandy's avatar
Jim Blandy committed
179

Gerd Moellmann's avatar
Gerd Moellmann committed
180
static struct frame *frame_matrix_frame;
Jim Blandy's avatar
Jim Blandy committed
181

Gerd Moellmann's avatar
Gerd Moellmann committed
182 183 184 185
/* Non-zero means that fonts have been loaded since the last glyph
   matrix adjustments.  Redisplay must stop, and glyph matrices must
   be adjusted when this flag becomes non-zero during display.  The
   reason fonts can be loaded so late is that fonts of fontsets are
186 187 188
   loaded on demand.  Another reason is that a line contains many
   characters displayed by zero width or very narrow glyphs of
   variable-width fonts.  */
189

Gerd Moellmann's avatar
Gerd Moellmann committed
190
int fonts_changed_p;
191

192
/* Convert vpos and hpos from frame to window and vice versa.
Gerd Moellmann's avatar
Gerd Moellmann committed
193
   This may only be used for terminal frames.  */
194

195
#ifdef GLYPH_DEBUG
Jim Blandy's avatar
Jim Blandy committed
196

197 198
static int window_to_frame_vpos (struct window *, int);
static int window_to_frame_hpos (struct window *, int);
Gerd Moellmann's avatar
Gerd Moellmann committed
199 200
#define WINDOW_TO_FRAME_VPOS(W, VPOS) window_to_frame_vpos ((W), (VPOS))
#define WINDOW_TO_FRAME_HPOS(W, HPOS) window_to_frame_hpos ((W), (HPOS))
Jim Blandy's avatar
Jim Blandy committed
201

202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
/* One element of the ring buffer containing redisplay history
   information.  */

struct redisplay_history
{
  char trace[512 + 100];
};

/* The size of the history buffer.  */

#define REDISPLAY_HISTORY_SIZE	30

/* The redisplay history buffer.  */

static struct redisplay_history redisplay_history[REDISPLAY_HISTORY_SIZE];

/* Next free entry in redisplay_history.  */

static int history_idx;

/* A tick that's incremented each time something is added to the
   history.  */

225
static uprintmax_t history_tick;
226

227
static void add_frame_display_history (struct frame *, int);
Richard M. Stallman's avatar
Richard M. Stallman committed
228

229 230
/* Add to the redisplay history how window W has been displayed.
   MSG is a trace containing the information how W's glyph matrix
231
   has been constructed.  PAUSED_P non-zero means that the update
232 233 234
   has been interrupted for pending input.  */

static void
235
add_window_display_history (struct window *w, const char *msg, int paused_p)
236 237
{
  char *buf;
238

239 240 241 242
  if (history_idx >= REDISPLAY_HISTORY_SIZE)
    history_idx = 0;
  buf = redisplay_history[history_idx].trace;
  ++history_idx;
243

244 245 246 247
  snprintf (buf, sizeof redisplay_history[0].trace,
	    "%"pMu": window %p (`%s')%s\n%s",
	    history_tick++,
	    w,
248 249 250
	    ((BUFFERP (WGET (w, buffer))
	      && STRINGP (BVAR (XBUFFER (WGET (w, buffer)), name)))
	     ? SSDATA (BVAR (XBUFFER (WGET (w, buffer)), name))
251 252 253
	     : "???"),
	    paused_p ? " ***paused***" : "",
	    msg);
254 255 256 257 258 259 260 261
}


/* Add to the redisplay history that frame F has been displayed.
   PAUSED_P non-zero means that the update has been interrupted for
   pending input.  */

static void
Andreas Schwab's avatar
Andreas Schwab committed
262
add_frame_display_history (struct frame *f, int paused_p)
263 264
{
  char *buf;
265

266 267 268 269
  if (history_idx >= REDISPLAY_HISTORY_SIZE)
    history_idx = 0;
  buf = redisplay_history[history_idx].trace;
  ++history_idx;
270

271
  sprintf (buf, "%"pMu": update frame %p%s",
272 273 274 275 276
	   history_tick++,
	   f, paused_p ? " ***paused***" : "");
}


Paul Eggert's avatar
Paul Eggert committed
277
DEFUN ("dump-redisplay-history", Fdump_redisplay_history,
278
       Sdump_redisplay_history, 0, 0, "",
279
       doc: /* Dump redisplay history to stderr.  */)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
280
  (void)
281 282 283 284 285 286 287 288 289 290 291 292 293 294
{
  int i;

  for (i = history_idx - 1; i != history_idx; --i)
    {
      if (i < 0)
	i = REDISPLAY_HISTORY_SIZE - 1;
      fprintf (stderr, "%s\n", redisplay_history[i].trace);
    }

  return Qnil;
}


295
#else /* not GLYPH_DEBUG */
Jim Blandy's avatar
Jim Blandy committed
296

297 298
#define WINDOW_TO_FRAME_VPOS(W, VPOS) ((VPOS) + WINDOW_TOP_EDGE_LINE (W))
#define WINDOW_TO_FRAME_HPOS(W, HPOS) ((HPOS) + WINDOW_LEFT_EDGE_COL (W))
Jim Blandy's avatar
Jim Blandy committed
299

300
#endif /* GLYPH_DEBUG */
Jim Blandy's avatar
Jim Blandy committed
301 302


303 304 305 306 307
#if (defined PROFILING \
     && (defined __FreeBSD__ || defined GNU_LINUX || defined __MINGW32__) \
     && !HAVE___EXECUTABLE_START)
/* This function comes first in the Emacs executable and is used only
   to estimate the text start for profiling.  */
Jim Blandy's avatar
Jim Blandy committed
308
void
309
__executable_start (void)
Jim Blandy's avatar
Jim Blandy committed
310
{
311
  abort ();
312
}
313
#endif
Gerd Moellmann's avatar
Gerd Moellmann committed
314 315 316 317 318 319 320 321 322 323 324

/***********************************************************************
			    Glyph Matrices
 ***********************************************************************/

/* Allocate and return a glyph_matrix structure.  POOL is the glyph
   pool from which memory for the matrix should be allocated, or null
   for window-based redisplay where no glyph pools are used.  The
   member `pool' of the glyph matrix structure returned is set to
   POOL, the structure is otherwise zeroed.  */

325
static struct glyph_matrix *
326
new_glyph_matrix (struct glyph_pool *pool)
Jim Blandy's avatar
Jim Blandy committed
327
{
Dmitry Antipov's avatar
Dmitry Antipov committed
328
  struct glyph_matrix *result = xzalloc (sizeof *result);
Jim Blandy's avatar
Jim Blandy committed
329

Gerd Moellmann's avatar
Gerd Moellmann committed
330 331 332
  /* Increment number of allocated matrices.  This count is used
     to detect memory leaks.  */
  ++glyph_matrix_count;
Jim Blandy's avatar
Jim Blandy committed
333

Gerd Moellmann's avatar
Gerd Moellmann committed
334 335 336
  /* Set pool and return.  */
  result->pool = pool;
  return result;
Jim Blandy's avatar
Jim Blandy committed
337 338 339
}


Gerd Moellmann's avatar
Gerd Moellmann committed
340 341 342 343 344 345
/* Free glyph matrix MATRIX.  Passing in a null MATRIX is allowed.

   The global counter glyph_matrix_count is decremented when a matrix
   is freed.  If the count gets negative, more structures were freed
   than allocated, i.e. one matrix was freed more than once or a bogus
   pointer was passed to this function.
346

Gerd Moellmann's avatar
Gerd Moellmann committed
347 348 349 350 351
   If MATRIX->pool is null, this means that the matrix manages its own
   glyph memory---this is done for matrices on X frames.  Freeing the
   matrix also frees the glyph memory in this case.  */

static void
352
free_glyph_matrix (struct glyph_matrix *matrix)
Jim Blandy's avatar
Jim Blandy committed
353
{
Gerd Moellmann's avatar
Gerd Moellmann committed
354 355 356 357 358 359 360 361 362 363 364 365 366
  if (matrix)
    {
      int i;

      /* Detect the case that more matrices are freed than were
	 allocated.  */
      if (--glyph_matrix_count < 0)
	abort ();

      /* Free glyph memory if MATRIX owns it.  */
      if (matrix->pool == NULL)
	for (i = 0; i < matrix->rows_allocated; ++i)
	  xfree (matrix->rows[i].glyphs[LEFT_MARGIN_AREA]);
367

Gerd Moellmann's avatar
Gerd Moellmann committed
368 369 370 371 372
      /* Free row structures and the matrix itself.  */
      xfree (matrix->rows);
      xfree (matrix);
    }
}
Jim Blandy's avatar
Jim Blandy committed
373 374


Gerd Moellmann's avatar
Gerd Moellmann committed
375 376 377 378 379 380 381
/* Return the number of glyphs to reserve for a marginal area of
   window W.  TOTAL_GLYPHS is the number of glyphs in a complete
   display line of window W.  MARGIN gives the width of the marginal
   area in canonical character units.  MARGIN should be an integer
   or a float.  */

static int
382
margin_glyphs_to_reserve (struct window *w, int total_glyphs, Lisp_Object margin)
Gerd Moellmann's avatar
Gerd Moellmann committed
383 384
{
  int n;
Jim Blandy's avatar
Jim Blandy committed
385

Gerd Moellmann's avatar
Gerd Moellmann committed
386
  if (NUMBERP (margin))
Jim Blandy's avatar
Jim Blandy committed
387
    {
388
      int width = XFASTINT (WGET (w, total_cols));
Gerd Moellmann's avatar
Gerd Moellmann committed
389 390
      double d = max (0, XFLOATINT (margin));
      d = min (width / 2 - 1, d);
391
      n = (int) ((double) total_glyphs / width * d);
Gerd Moellmann's avatar
Gerd Moellmann committed
392 393 394 395 396 397 398
    }
  else
    n = 0;

  return n;
}

399 400 401
/* Return non-zero if ROW's hash value is correct, zero if not.
   Optimized away if ENABLE_CHECKING is not defined.  */

402
static int
403 404
verify_row_hash (struct glyph_row *row)
{
405
  return row->hash == row_hash (row);
406
}
Jim Blandy's avatar
Jim Blandy committed
407

Gerd Moellmann's avatar
Gerd Moellmann committed
408 409
/* Adjust glyph matrix MATRIX on window W or on a frame to changed
   window sizes.
Jim Blandy's avatar
Jim Blandy committed
410

Gerd Moellmann's avatar
Gerd Moellmann committed
411 412 413 414 415
   W is null if the function is called for a frame glyph matrix.
   Otherwise it is the window MATRIX is a member of.  X and Y are the
   indices of the first column and row of MATRIX within the frame
   matrix, if such a matrix exists.  They are zero for purely
   window-based redisplay.  DIM is the needed size of the matrix.
416

Gerd Moellmann's avatar
Gerd Moellmann committed
417 418 419 420
   In window-based redisplay, where no frame matrices exist, glyph
   matrices manage their own glyph storage.  Otherwise, they allocate
   storage from a common frame glyph pool which can be found in
   MATRIX->pool.
421

Gerd Moellmann's avatar
Gerd Moellmann committed
422 423 424 425 426 427 428
   The reason for this memory management strategy is to avoid complete
   frame redraws if possible.  When we allocate from a common pool, a
   change of the location or size of a sub-matrix within the pool
   requires a complete redisplay of the frame because we cannot easily
   make sure that the current matrices of all windows still agree with
   what is displayed on the screen.  While this is usually fast, it
   leads to screen flickering.  */
429

Gerd Moellmann's avatar
Gerd Moellmann committed
430
static void
431
adjust_glyph_matrix (struct window *w, struct glyph_matrix *matrix, int x, int y, struct dim dim)
Gerd Moellmann's avatar
Gerd Moellmann committed
432 433 434 435
{
  int i;
  int new_rows;
  int marginal_areas_changed_p = 0;
Gerd Moellmann's avatar
Change  
Gerd Moellmann committed
436 437
  int header_line_changed_p = 0;
  int header_line_p = 0;
Gerd Moellmann's avatar
Gerd Moellmann committed
438
  int left = -1, right = -1;
439
  int window_width = -1, window_height = -1;
Gerd Moellmann's avatar
Gerd Moellmann committed
440

Kenichi Handa's avatar
Kenichi Handa committed
441 442
  /* See if W had a header line that has disappeared now, or vice versa.
     Get W's size.  */
Gerd Moellmann's avatar
Gerd Moellmann committed
443 444
  if (w)
    {
Kenichi Handa's avatar
Kenichi Handa committed
445 446
      window_box (w, -1, 0, 0, &window_width, &window_height);

Gerd Moellmann's avatar
Change  
Gerd Moellmann committed
447 448
      header_line_p = WINDOW_WANTS_HEADER_LINE_P (w);
      header_line_changed_p = header_line_p != matrix->header_line_p;
Gerd Moellmann's avatar
Gerd Moellmann committed
449
    }
Gerd Moellmann's avatar
Change  
Gerd Moellmann committed
450
  matrix->header_line_p = header_line_p;
451

Kenichi Handa's avatar
Kenichi Handa committed
452 453
  /* If POOL is null, MATRIX is a window matrix for window-based redisplay.
     Do nothing if MATRIX' size, position, vscroll, and marginal areas
Gerd Moellmann's avatar
Gerd Moellmann committed
454 455 456 457
     haven't changed.  This optimization is important because preserving
     the matrix means preventing redisplay.  */
  if (matrix->pool == NULL)
    {
458 459
      left = margin_glyphs_to_reserve (w, dim.width, WGET (w, left_margin_cols));
      right = margin_glyphs_to_reserve (w, dim.width, WGET (w, right_margin_cols));
460
      eassert (left >= 0 && right >= 0);
Gerd Moellmann's avatar
Gerd Moellmann committed
461 462 463 464 465
      marginal_areas_changed_p = (left != matrix->left_margin_glyphs
				  || right != matrix->right_margin_glyphs);

      if (!marginal_areas_changed_p
	  && !fonts_changed_p
Gerd Moellmann's avatar
Change  
Gerd Moellmann committed
466
	  && !header_line_changed_p
467 468
	  && matrix->window_left_col == WINDOW_LEFT_EDGE_COL (w)
	  && matrix->window_top_line == WINDOW_TOP_EDGE_LINE (w)
Gerd Moellmann's avatar
Gerd Moellmann committed
469 470 471 472 473
	  && matrix->window_height == window_height
	  && matrix->window_vscroll == w->vscroll
	  && matrix->window_width == window_width)
	return;
    }
474

Gerd Moellmann's avatar
Gerd Moellmann committed
475 476 477
  /* Enlarge MATRIX->rows if necessary.  New rows are cleared.  */
  if (matrix->rows_allocated < dim.height)
    {
478
      int old_alloc = matrix->rows_allocated;
Gerd Moellmann's avatar
Gerd Moellmann committed
479
      new_rows = dim.height - matrix->rows_allocated;
480 481 482 483
      matrix->rows = xpalloc (matrix->rows, &matrix->rows_allocated,
			      new_rows, INT_MAX, sizeof *matrix->rows);
      memset (matrix->rows + old_alloc, 0,
	      (matrix->rows_allocated - old_alloc) * sizeof *matrix->rows);
Gerd Moellmann's avatar
Gerd Moellmann committed
484 485 486
    }
  else
    new_rows = 0;
487

Gerd Moellmann's avatar
Gerd Moellmann committed
488 489 490 491 492
  /* If POOL is not null, MATRIX is a frame matrix or a window matrix
     on a frame not using window-based redisplay.  Set up pointers for
     each row into the glyph pool.  */
  if (matrix->pool)
    {
493
      eassert (matrix->pool->glyphs);
494

Gerd Moellmann's avatar
Gerd Moellmann committed
495
      if (w)
496
	{
Gerd Moellmann's avatar
Gerd Moellmann committed
497
	  left = margin_glyphs_to_reserve (w, dim.width,
498
					   WGET (w, left_margin_cols));
Gerd Moellmann's avatar
Gerd Moellmann committed
499
	  right = margin_glyphs_to_reserve (w, dim.width,
500
					    WGET (w, right_margin_cols));
501
	}
Gerd Moellmann's avatar
Gerd Moellmann committed
502 503
      else
	left = right = 0;
504

Gerd Moellmann's avatar
Gerd Moellmann committed
505
      for (i = 0; i < dim.height; ++i)
506
	{
Gerd Moellmann's avatar
Gerd Moellmann committed
507
	  struct glyph_row *row = &matrix->rows[i];
508 509

	  row->glyphs[LEFT_MARGIN_AREA]
Gerd Moellmann's avatar
Gerd Moellmann committed
510 511 512
	    = (matrix->pool->glyphs
	       + (y + i) * matrix->pool->ncolumns
	       + x);
513

Gerd Moellmann's avatar
Gerd Moellmann committed
514 515
	  if (w == NULL
	      || row == matrix->rows + dim.height - 1
Gerd Moellmann's avatar
Change  
Gerd Moellmann committed
516
	      || (row == matrix->rows && matrix->header_line_p))
Gerd Moellmann's avatar
Gerd Moellmann committed
517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533
	    {
	      row->glyphs[TEXT_AREA]
		= row->glyphs[LEFT_MARGIN_AREA];
	      row->glyphs[RIGHT_MARGIN_AREA]
		= row->glyphs[TEXT_AREA] + dim.width;
	      row->glyphs[LAST_AREA]
		= row->glyphs[RIGHT_MARGIN_AREA];
	    }
	  else
	    {
	      row->glyphs[TEXT_AREA]
		= row->glyphs[LEFT_MARGIN_AREA] + left;
	      row->glyphs[RIGHT_MARGIN_AREA]
		= row->glyphs[TEXT_AREA] + dim.width - left - right;
	      row->glyphs[LAST_AREA]
		= row->glyphs[LEFT_MARGIN_AREA] + dim.width;
	    }
534
	}
535

Gerd Moellmann's avatar
Gerd Moellmann committed
536 537 538 539 540 541
      matrix->left_margin_glyphs = left;
      matrix->right_margin_glyphs = right;
    }
  else
    {
      /* If MATRIX->pool is null, MATRIX is responsible for managing
Kenichi Handa's avatar
Kenichi Handa committed
542 543
	 its own memory.  It is a window matrix for window-based redisplay.
	 Allocate glyph memory from the heap.  */
Gerd Moellmann's avatar
Gerd Moellmann committed
544 545
      if (dim.width > matrix->matrix_w
	  || new_rows
Gerd Moellmann's avatar
Change  
Gerd Moellmann committed
546
	  || header_line_changed_p
Gerd Moellmann's avatar
Gerd Moellmann committed
547
	  || marginal_areas_changed_p)
Jim Blandy's avatar
Jim Blandy committed
548
	{
Gerd Moellmann's avatar
Gerd Moellmann committed
549 550
	  struct glyph_row *row = matrix->rows;
	  struct glyph_row *end = row + matrix->rows_allocated;
551

Gerd Moellmann's avatar
Gerd Moellmann committed
552 553 554
	  while (row < end)
	    {
	      row->glyphs[LEFT_MARGIN_AREA]
555 556
		= xnrealloc (row->glyphs[LEFT_MARGIN_AREA],
			     dim.width, sizeof (struct glyph));
557

Gerd Moellmann's avatar
Gerd Moellmann committed
558 559
	      /* The mode line never has marginal areas.  */
	      if (row == matrix->rows + dim.height - 1
Gerd Moellmann's avatar
Change  
Gerd Moellmann committed
560
		  || (row == matrix->rows && matrix->header_line_p))
Gerd Moellmann's avatar
Gerd Moellmann committed
561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579
		{
		  row->glyphs[TEXT_AREA]
		    = row->glyphs[LEFT_MARGIN_AREA];
		  row->glyphs[RIGHT_MARGIN_AREA]
		    = row->glyphs[TEXT_AREA] + dim.width;
		  row->glyphs[LAST_AREA]
		    = row->glyphs[RIGHT_MARGIN_AREA];
		}
	      else
		{
		  row->glyphs[TEXT_AREA]
		    = row->glyphs[LEFT_MARGIN_AREA] + left;
		  row->glyphs[RIGHT_MARGIN_AREA]
		    = row->glyphs[TEXT_AREA] + dim.width - left - right;
		  row->glyphs[LAST_AREA]
		    = row->glyphs[LEFT_MARGIN_AREA] + dim.width;
		}
	      ++row;
	    }
Jim Blandy's avatar
Jim Blandy committed
580 581
	}

582
      eassert (left >= 0 && right >= 0);
Gerd Moellmann's avatar
Gerd Moellmann committed
583 584 585
      matrix->left_margin_glyphs = left;
      matrix->right_margin_glyphs = right;
    }
586

Gerd Moellmann's avatar
Gerd Moellmann committed
587 588
  /* Number of rows to be used by MATRIX.  */
  matrix->nrows = dim.height;
589
  eassert (matrix->nrows >= 0);
Gerd Moellmann's avatar
Gerd Moellmann committed
590

591
  if (w)
Gerd Moellmann's avatar
Gerd Moellmann committed
592
    {
593
      if (matrix == w->current_matrix)
Jim Blandy's avatar
Jim Blandy committed
594
	{
595 596 597 598 599 600
	  /* Mark rows in a current matrix of a window as not having
	     valid contents.  It's important to not do this for
	     desired matrices.  When Emacs starts, it may already be
	     building desired matrices when this function runs.  */
	  if (window_width < 0)
	    window_width = window_box_width (w, -1);
601

602 603 604 605
	  /* Optimize the case that only the height has changed (C-x 2,
	     upper window).  Invalidate all rows that are no longer part
	     of the window.  */
	  if (!marginal_areas_changed_p
606 607 608
	      && !header_line_changed_p
	      && new_rows == 0
	      && dim.width == matrix->matrix_w
609 610
	      && matrix->window_left_col == WINDOW_LEFT_EDGE_COL (w)
	      && matrix->window_top_line == WINDOW_TOP_EDGE_LINE (w)
611
	      && matrix->window_width == window_width)
612
	    {
613 614 615 616
	      /* Find the last row in the window.  */
	      for (i = 0; i < matrix->nrows && matrix->rows[i].enabled_p; ++i)
		if (MATRIX_ROW_BOTTOM_Y (matrix->rows + i) >= window_height)
		  {
617
		    ++i;
618 619
		    break;
		  }
620 621

	      /* Window end is invalid, if inside of the rows that
622
		 are invalidated below.  */
623 624 625
	      if (INTEGERP (WGET (w, window_end_vpos))
		  && XFASTINT (WGET (w, window_end_vpos)) >= i)
		WSET (w, window_end_valid, Qnil);
626

627 628 629 630 631 632 633 634
	      while (i < matrix->nrows)
		matrix->rows[i++].enabled_p = 0;
	    }
	  else
	    {
	      for (i = 0; i < matrix->nrows; ++i)
		matrix->rows[i].enabled_p = 0;
	    }
Gerd Moellmann's avatar
Gerd Moellmann committed
635
	}
636
      else if (matrix == w->desired_matrix)
Gerd Moellmann's avatar
Gerd Moellmann committed
637
	{
638 639 640 641
	  /* Rows in desired matrices always have to be cleared;
	     redisplay expects this is the case when it runs, so it
	     had better be the case when we adjust matrices between
	     redisplays.  */
Gerd Moellmann's avatar
Gerd Moellmann committed
642 643
	  for (i = 0; i < matrix->nrows; ++i)
	    matrix->rows[i].enabled_p = 0;
Jim Blandy's avatar
Jim Blandy committed
644 645
	}
    }
646 647


Gerd Moellmann's avatar
Gerd Moellmann committed
648 649 650 651 652 653 654 655 656
  /* Remember last values to be able to optimize frame redraws.  */
  matrix->matrix_x = x;
  matrix->matrix_y = y;
  matrix->matrix_w = dim.width;
  matrix->matrix_h = dim.height;

  /* Record the top y location and height of W at the time the matrix
     was last adjusted.  This is used to optimize redisplay above.  */
  if (w)
Jim Blandy's avatar
Jim Blandy committed
657
    {
658 659
      matrix->window_left_col = WINDOW_LEFT_EDGE_COL (w);
      matrix->window_top_line = WINDOW_TOP_EDGE_LINE (w);
Gerd Moellmann's avatar
Gerd Moellmann committed
660 661 662 663 664
      matrix->window_height = window_height;
      matrix->window_width = window_width;
      matrix->window_vscroll = w->vscroll;
    }
}
Jim Blandy's avatar
Jim Blandy committed
665 666


Gerd Moellmann's avatar
Gerd Moellmann committed
667 668 669 670
/* Reverse the contents of rows in MATRIX between START and END.  The
   contents of the row at END - 1 end up at START, END - 2 at START +
   1 etc.  This is part of the implementation of rotate_matrix (see
   below).  */
671

Gerd Moellmann's avatar
Gerd Moellmann committed
672
static void
673
reverse_rows (struct glyph_matrix *matrix, int start, int end)
Gerd Moellmann's avatar
Gerd Moellmann committed
674 675
{
  int i, j;
676

Gerd Moellmann's avatar
Gerd Moellmann committed
677 678 679 680 681 682 683 684 685 686
  for (i = start, j = end - 1; i < j; ++i, --j)
    {
      /* Non-ISO HP/UX compiler doesn't like auto struct
	 initialization.  */
      struct glyph_row temp;
      temp = matrix->rows[i];
      matrix->rows[i] = matrix->rows[j];
      matrix->rows[j] = temp;
    }
}
687 688


Gerd Moellmann's avatar
Gerd Moellmann committed
689 690 691 692
/* Rotate the contents of rows in MATRIX in the range FIRST .. LAST -
   1 by BY positions.  BY < 0 means rotate left, i.e. towards lower
   indices.  (Note: this does not copy glyphs, only glyph pointers in
   row structures are moved around).
693

Gerd Moellmann's avatar
Gerd Moellmann committed
694 695 696 697 698 699 700 701
   The algorithm used for rotating the vector was, I believe, first
   described by Kernighan.  See the vector R as consisting of two
   sub-vectors AB, where A has length BY for BY >= 0.  The result
   after rotating is then BA.  Reverse both sub-vectors to get ArBr
   and reverse the result to get (ArBr)r which is BA.  Similar for
   rotating right.  */

void
702
rotate_matrix (struct glyph_matrix *matrix, int first, int last, int by)
Gerd Moellmann's avatar
Gerd Moellmann committed
703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726
{
  if (by < 0)
    {
      /* Up (rotate left, i.e. towards lower indices).  */
      by = -by;
      reverse_rows (matrix, first, first + by);
      reverse_rows (matrix, first + by, last);
      reverse_rows (matrix, first, last);
    }
  else if (by > 0)
    {
      /* Down (rotate right, i.e. towards higher indices).  */
      reverse_rows (matrix, last - by, last);
      reverse_rows (matrix, first, last - by);
      reverse_rows (matrix, first, last);
    }
}


/* Increment buffer positions in glyph rows of MATRIX.  Do it for rows
   with indices START <= index < END.  Increment positions by DELTA/
   DELTA_BYTES.  */

void
727
increment_matrix_positions (struct glyph_matrix *matrix, int start, int end,
728
			    ptrdiff_t delta, ptrdiff_t delta_bytes)
Gerd Moellmann's avatar
Gerd Moellmann committed
729 730
{
  /* Check that START and END are reasonable values.  */
731 732 733
  eassert (start >= 0 && start <= matrix->nrows);
  eassert (end >= 0 && end <= matrix->nrows);
  eassert (start <= end);
Gerd Moellmann's avatar
Gerd Moellmann committed
734 735

  for (; start < end; ++start)
736
    increment_row_positions (matrix->rows + start, delta, delta_bytes);
Gerd Moellmann's avatar
Gerd Moellmann committed
737 738 739 740 741 742 743 744
}


/* Enable a range of rows in glyph matrix MATRIX.  START and END are
   the row indices of the first and last + 1 row to enable.  If
   ENABLED_P is non-zero, enabled_p flags in rows will be set to 1.  */

void
745
enable_glyph_matrix_rows (struct glyph_matrix *matrix, int start, int end, int enabled_p)
Gerd Moellmann's avatar
Gerd Moellmann committed
746
{
747 748 749
  eassert (start <= end);
  eassert (start >= 0 && start < matrix->nrows);
  eassert (end >= 0 && end <= matrix->nrows);
750

Gerd Moellmann's avatar
Gerd Moellmann committed
751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766
  for (; start < end; ++start)
    matrix->rows[start].enabled_p = enabled_p != 0;
}


/* Clear MATRIX.

   This empties all rows in MATRIX by setting the enabled_p flag for
   all rows of the matrix to zero.  The function prepare_desired_row
   will eventually really clear a row when it sees one with a zero
   enabled_p flag.

   Resets update hints to defaults value.  The only update hint
   currently present is the flag MATRIX->no_scrolling_p.  */

void
767
clear_glyph_matrix (struct glyph_matrix *matrix)
Gerd Moellmann's avatar
Gerd Moellmann committed
768 769 770 771 772 773 774
{
  if (matrix)
    {
      enable_glyph_matrix_rows (matrix, 0, matrix->nrows, 0);
      matrix->no_scrolling_p = 0;
    }
}
775

Gerd Moellmann's avatar
Gerd Moellmann committed
776 777 778 779 780 781

/* Shift part of the glyph matrix MATRIX of window W up or down.
   Increment y-positions in glyph rows between START and END by DY,
   and recompute their visible height.  */

void
782
shift_glyph_matrix (struct window *w, struct glyph_matrix *matrix, int start, int end, int dy)
Gerd Moellmann's avatar
Gerd Moellmann committed
783 784
{
  int min_y, max_y;
785

786 787 788
  eassert (start <= end);
  eassert (start >= 0 && start < matrix->nrows);
  eassert (end >= 0 && end <= matrix->nrows);
789

790 791
  min_y = WINDOW_HEADER_LINE_HEIGHT (w);
  max_y = WINDOW_BOX_HEIGHT_NO_MODE_LINE (w);
792

Gerd Moellmann's avatar
Gerd Moellmann committed
793 794 795
  for (; start < end; ++start)
    {
      struct glyph_row *row = &matrix->rows[start];
796

Gerd Moellmann's avatar
Gerd Moellmann committed
797
      row->y += dy;
798
      row->visible_height = row->height;
799

Gerd Moellmann's avatar
Gerd Moellmann committed
800
      if (row->y < min_y)
801 802 803
	row->visible_height -= min_y - row->y;
      if (row->y + row->height > max_y)
	row->visible_height -= row->y + row->height - max_y;
804 805
      if (row->fringe_bitmap_periodic_p)
	row->redraw_fringe_bitmaps_p = 1;
Gerd Moellmann's avatar
Gerd Moellmann committed
806 807 808 809 810 811 812 813 814
    }
}


/* Mark all rows in current matrices of frame F as invalid.  Marking
   invalid is done by setting enabled_p to zero for all rows in a
   current matrix.  */

void
815
clear_current_matrices (register struct frame *f)
Gerd Moellmann's avatar
Gerd Moellmann committed
816 817 818 819 820 821 822 823
{
  /* Clear frame current matrix, if we have one.  */
  if (f->current_matrix)
    clear_glyph_matrix (f->current_matrix);

  /* Clear the matrix of the menu bar window, if such a window exists.
     The menu bar window is currently used to display menus on X when
     no toolkit support is compiled in.  */
824 825
  if (WINDOWP (f->menu_bar_window))
    clear_glyph_matrix (XWINDOW (f->menu_bar_window)->current_matrix);
Gerd Moellmann's avatar
Gerd Moellmann committed
826

827
  /* Clear the matrix of the tool-bar window, if any.  */
828 829
  if (WINDOWP (f->tool_bar_window))
    clear_glyph_matrix (XWINDOW (f->tool_bar_window)->current_matrix);
Gerd Moellmann's avatar
Gerd Moellmann committed
830 831

  /* Clear current window matrices.  */
832
  eassert (WINDOWP (FRAME_ROOT_WINDOW (f)));
Gerd Moellmann's avatar
Gerd Moellmann committed
833 834 835 836 837 838 839
  clear_window_matrices (XWINDOW (FRAME_ROOT_WINDOW (f)), 0);
}


/* Clear out all display lines of F for a coming redisplay.  */

void
840
clear_desired_matrices (register struct frame *f)
Gerd Moellmann's avatar
Gerd Moellmann committed
841 842 843
{
  if (f->desired_matrix)
    clear_glyph_matrix (f->desired_matrix);
844

845 846
  if (WINDOWP (f->menu_bar_window))
    clear_glyph_matrix (XWINDOW (f->menu_bar_window)->desired_matrix);
Gerd Moellmann's avatar
Gerd Moellmann committed
847

848 849
  if (WINDOWP (f->tool_bar_window))
    clear_glyph_matrix (XWINDOW (f->tool_bar_window)->desired_matrix);
Gerd Moellmann's avatar
Gerd Moellmann committed
850 851

  /* Do it for window matrices.  */
852
  eassert (WINDOWP (FRAME_ROOT_WINDOW (f)));
Gerd Moellmann's avatar
Gerd Moellmann committed
853 854 855 856 857 858 859 860
  clear_window_matrices (XWINDOW (FRAME_ROOT_WINDOW (f)), 1);
}


/* Clear matrices in window tree rooted in W.  If DESIRED_P is
   non-zero clear desired matrices, otherwise clear current matrices.  */

static void
861
clear_window_matrices (struct window *w, int desired_p)
Gerd Moellmann's avatar
Gerd Moellmann committed
862 863 864
{
  while (w)
    {
865
      if (!NILP (WGET (w, hchild)))
Gerd Moellmann's avatar
Gerd Moellmann committed
866
	{
867 868
	  eassert (WINDOWP (WGET (w, hchild)));
	  clear_window_matrices (XWINDOW (WGET (w, hchild)), desired_p);
Gerd Moellmann's avatar
Gerd Moellmann committed
869
	}
870
      else if (!NILP (WGET (w, vchild)))
Gerd Moellmann's avatar
Gerd Moellmann committed
871
	{
872 873
	  eassert (WINDOWP (WGET (w, vchild)));
	  clear_window_matrices (XWINDOW (WGET (w, vchild)), desired_p);
Gerd Moellmann's avatar
Gerd Moellmann committed
874 875 876 877 878 879 880 881
	}
      else
	{
	  if (desired_p)
	    clear_glyph_matrix (w->desired_matrix);
	  else
	    {
	      clear_glyph_matrix (w->current_matrix);
882
	      WSET (w, window_end_valid, Qnil);
Gerd Moellmann's avatar
Gerd Moellmann committed
883 884 885
	    }
	}

886
      w = NILP (WGET (w, next)) ? 0 : XWINDOW (WGET (w, next));
Gerd Moellmann's avatar
Gerd Moellmann committed
887 888 889 890 891 892 893 894 895 896 897 898 899 900 901
    }
}



/***********************************************************************
			      Glyph Rows

      See dispextern.h for an overall explanation of glyph rows.
 ***********************************************************************/

/* Clear glyph row ROW.  Do it in a way that makes it robust against
   changes in the glyph_row structure, i.e. addition or removal of
   structure members.  */

902 903
static struct glyph_row null_row;

Gerd Moellmann's avatar
Gerd Moellmann committed
904
void
905
clear_glyph_row (struct glyph_row *row)
Gerd Moellmann's avatar
Gerd Moellmann committed
906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922
{
  struct glyph *p[1 + LAST_AREA];

  /* Save pointers.  */
  p[LEFT_MARGIN_AREA] = row->glyphs[LEFT_MARGIN_AREA];
  p[TEXT_AREA] = row->glyphs[TEXT_AREA];
  p[RIGHT_MARGIN_AREA] = row->glyphs[RIGHT_MARGIN_AREA];
  p[LAST_AREA] = row->glyphs[LAST_AREA];

  /* Clear.  */
  *row = null_row;

  /* Restore pointers.  */
  row->glyphs[LEFT_MARGIN_AREA] = p[LEFT_MARGIN_AREA];
  row->glyphs[TEXT_AREA] = p[TEXT_AREA];
  row->glyphs[RIGHT_MARGIN_AREA] = p[RIGHT_MARGIN_AREA];
  row->glyphs[LAST_AREA] = p[LAST_AREA];
923 924 925 926 927 928

#if 0 /* At some point, some bit-fields of struct glyph were not set,
	 which made glyphs unequal when compared with GLYPH_EQUAL_P.
	 Redisplay outputs such glyphs, and flickering effects were
	 the result.  This also depended on the contents of memory
	 returned by xmalloc.  If flickering happens again, activate
929
	 the code below.  If the flickering is gone with that, chances
930
	 are that the flickering has the same reason as here.  */
931
  memset (p[0], 0, (char *) p[LAST_AREA] - (char *) p[0]);
932
#endif
Gerd Moellmann's avatar
Gerd Moellmann committed
933 934 935 936 937 938 939
}


/* Make ROW an empty, enabled row of canonical character height,
   in window W starting at y-position Y.  */

void
940
blank_row (struct window *w, struct glyph_row *row, int y)
Gerd Moellmann's avatar
Gerd Moellmann committed
941 942
{
  int min_y, max_y;
943

944 945
  min_y = WINDOW_HEADER_LINE_HEIGHT (w);
  max_y = WINDOW_BOX_HEIGHT_NO_MODE_LINE (w);
946

Gerd Moellmann's avatar
Gerd Moellmann committed
947 948
  clear_glyph_row (row);
  row->y = y;
949
  row->ascent = row->phys_ascent = 0;
950
  row->height = row->phys_height = FRAME_LINE_HEIGHT (XFRAME (WGET (w, frame)));
951
  row->visible_height = row->height;
952

Gerd Moellmann's avatar
Gerd Moellmann committed
953
  if (row->y < min_y)
954 955 956
    row->visible_height -= min_y - row->y;
  if (row->y + row->height > max_y)
    row->visible_height -= row->y + row->height - max_y;
Gerd Moellmann's avatar
Gerd Moellmann committed
957 958 959 960 961 962 963 964 965 966 967

  row->enabled_p = 1;
}


/* Increment buffer positions in glyph row ROW.  DELTA and DELTA_BYTES
   are the amounts by which to change positions.  Note that the first
   glyph of the text area of a row can have a buffer position even if
   the used count of the text area is zero.  Such rows display line
   ends.  */

968
static void
969
increment_row_positions (struct glyph_row *row,
970
			 ptrdiff_t delta, ptrdiff_t delta_bytes)
Gerd Moellmann's avatar
Gerd Moellmann committed
971 972 973 974 975 976 977 978
{
  int area, i;

  /* Increment start and end positions.  */
  MATRIX_ROW_START_CHARPOS (row) += delta;
  MATRIX_ROW_START_BYTEPOS (row) += delta_bytes;
  MATRIX_ROW_END_CHARPOS (row) += delta;
  MATRIX_ROW_END_BYTEPOS (row) += delta_bytes;
979 980 981 982
  CHARPOS (row->start.pos) += delta;
  BYTEPOS (row->start.pos) += delta_bytes;
  CHARPOS (row->end.pos) += delta;
  BYTEPOS (row->end.pos) += delta_bytes;
Gerd Moellmann's avatar
Gerd Moellmann committed
983

984 985 986
  if (!row->enabled_p)
    return;

Gerd Moellmann's avatar
Gerd Moellmann committed
987 988 989 990 991 992 993 994 995 996 997 998 999 1000
  /* Increment positions in glyphs.  */
  for (area = 0; area < LAST_AREA; ++area)
    for (i = 0; i < row->used[area]; ++i)
      if (BUFFERP (row->glyphs[area][i].object)
	  && row->glyphs[area][i].charpos > 0)
	row->glyphs[area][i].charpos += delta;

  /* Capture the case of rows displaying a line end.  */
  if (row->used[TEXT_AREA] == 0
      && MATRIX_ROW_DISPLAYS_TEXT_P (row))
    row->glyphs[TEXT_AREA]->charpos += delta;
}


1001
#if 0
Gerd Moellmann's avatar
Gerd Moellmann committed
1002 1003 1004 1005 1006
/* Swap glyphs between two glyph rows A and B.  This exchanges glyph
   contents, i.e. glyph structure contents are exchanged between A and
   B without changing glyph pointers in A and B.  */

static void
Andreas Schwab's avatar
Andreas Schwab committed
1007
swap_glyphs_in_rows (struct glyph_row *a, struct glyph_row *b)
Gerd Moellmann's avatar
Gerd Moellmann committed
1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027