buffer.h 50.2 KB
Newer Older
Jim Blandy's avatar
Jim Blandy committed
1
/* Header file for the buffer manipulation primitives.
Glenn Morris's avatar
Glenn Morris committed
2

Paul Eggert's avatar
Paul Eggert committed
3
Copyright (C) 1985-1986, 1993-1995, 1997-2020 Free Software Foundation,
4
Inc.
Jim Blandy's avatar
Jim Blandy committed
5 6 7

This file is part of GNU Emacs.

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

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

21 22 23
#ifndef EMACS_BUFFER_H
#define EMACS_BUFFER_H

24 25
#include <sys/types.h>
#include <time.h>
Jim Blandy's avatar
Jim Blandy committed
26

27 28 29
#include "character.h"
#include "lisp.h"

30 31
INLINE_HEADER_BEGIN

32
/* Accessing the parameters of the current buffer.  */
33

34
/* These constants and macros come in pairs, one for the char position
35
   and one for the byte position.  */
Jim Blandy's avatar
Jim Blandy committed
36

37
/* Position of beginning of buffer.  */
38
enum { BEG = 1, BEG_BYTE = BEG };
Jim Blandy's avatar
Jim Blandy committed
39

40
/* Position of beginning of accessible range of buffer.  */
41
#define BEGV (current_buffer->begv)
42
#define BEGV_BYTE (current_buffer->begv_byte)
Jim Blandy's avatar
Jim Blandy committed
43

44
/* Position of point in buffer.  The "+ 0" makes this
45
   not an l-value, so you can't assign to it.  Use SET_PT instead.  */
46
#define PT (current_buffer->pt + 0)
47
#define PT_BYTE (current_buffer->pt_byte + 0)
Jim Blandy's avatar
Jim Blandy committed
48

49
/* Position of gap in buffer.  */
50
#define GPT (current_buffer->text->gpt)
51
#define GPT_BYTE (current_buffer->text->gpt_byte)
Jim Blandy's avatar
Jim Blandy committed
52

53
/* Position of end of accessible range of buffer.  */
54
#define ZV (current_buffer->zv)
55
#define ZV_BYTE (current_buffer->zv_byte)
Jim Blandy's avatar
Jim Blandy committed
56

57
/* Position of end of buffer.  */
58
#define Z (current_buffer->text->z)
59
#define Z_BYTE (current_buffer->text->z_byte)
Jim Blandy's avatar
Jim Blandy committed
60

61
/* Macros for the addresses of places in the buffer.  */
Jim Blandy's avatar
Jim Blandy committed
62

63
/* Address of beginning of buffer.  */
64
#define BEG_ADDR (current_buffer->text->beg)
Jim Blandy's avatar
Jim Blandy committed
65

66
/* Address of beginning of accessible range of buffer.  */
67
#define BEGV_ADDR (BYTE_POS_ADDR (current_buffer->begv_byte))
Jim Blandy's avatar
Jim Blandy committed
68

69
/* Address of point in buffer.  */
70
#define PT_ADDR (BYTE_POS_ADDR (current_buffer->pt_byte))
Jim Blandy's avatar
Jim Blandy committed
71

72
/* Address of beginning of gap in buffer.  */
Stefan Monnier's avatar
Stefan Monnier committed
73
#define GPT_ADDR (current_buffer->text->beg + current_buffer->text->gpt_byte - BEG_BYTE)
Jim Blandy's avatar
Jim Blandy committed
74 75

/* Address of end of gap in buffer.  */
Stefan Monnier's avatar
Stefan Monnier committed
76
#define GAP_END_ADDR (current_buffer->text->beg + current_buffer->text->gpt_byte + current_buffer->text->gap_size - BEG_BYTE)
Jim Blandy's avatar
Jim Blandy committed
77

78
/* Address of end of accessible range of buffer.  */
79
#define ZV_ADDR (BYTE_POS_ADDR (current_buffer->zv_byte))
80

81
/* Address of end of buffer.  */
Stefan Monnier's avatar
Stefan Monnier committed
82
#define Z_ADDR (current_buffer->text->beg + current_buffer->text->gap_size + current_buffer->text->z_byte - BEG_BYTE)
Jim Blandy's avatar
Jim Blandy committed
83 84

/* Size of gap.  */
85
#define GAP_SIZE (current_buffer->text->gap_size)
Jim Blandy's avatar
Jim Blandy committed
86

87 88 89
/* Modification count.  */
#define MODIFF (current_buffer->text->modiff)

90 91 92
/* Character modification count.  */
#define CHARS_MODIFF (current_buffer->text->chars_modiff)

93 94 95 96 97 98
/* Overlay modification count.  */
#define OVERLAY_MODIFF (current_buffer->text->overlay_modiff)

/* Modification count as of last visit or save.  */
#define SAVE_MODIFF (current_buffer->text->save_modiff)

Jim Blandy's avatar
Jim Blandy committed
99

100
/* Position of gap in buffer.  */
101
#define BUF_GPT(buf) ((buf)->text->gpt)
102
#define BUF_GPT_BYTE(buf) ((buf)->text->gpt_byte)
Jim Blandy's avatar
Jim Blandy committed
103

104
/* Position of end of buffer.  */
105
#define BUF_Z(buf) ((buf)->text->z)
106 107 108 109 110 111 112 113
#define BUF_Z_BYTE(buf) ((buf)->text->z_byte)

/* Address of beginning of buffer.  */
#define BUF_BEG_ADDR(buf) ((buf)->text->beg)

/* Size of gap.  */
#define BUF_GAP_SIZE(buf) ((buf)->text->gap_size)

Jim Blandy's avatar
Jim Blandy committed
114
/* Modification count.  */
115 116
#define BUF_MODIFF(buf) ((buf)->text->modiff)

117 118 119
/* Character modification count.  */
#define BUF_CHARS_MODIFF(buf) ((buf)->text->chars_modiff)

120 121 122
/* Modification count as of last visit or save.  */
#define BUF_SAVE_MODIFF(buf) ((buf)->text->save_modiff)

123 124 125
/* Overlay modification count.  */
#define BUF_OVERLAY_MODIFF(buf) ((buf)->text->overlay_modiff)

126 127 128 129
/* Modification count as of last auto-save.  */
/* FIXME: should we move this into ->text->auto_save_modiff?  */
#define BUF_AUTOSAVE_MODIFF(buf) ((buf)->auto_save_modified)

130 131 132
/* Compaction count.  */
#define BUF_COMPACT(buf) ((buf)->text->compact)

133 134
/* Marker chain of buffer.  */
#define BUF_MARKERS(buf) ((buf)->text->markers)
Gerd Moellmann's avatar
Gerd Moellmann committed
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149

#define BUF_UNCHANGED_MODIFIED(buf) \
  ((buf)->text->unchanged_modified)

#define BUF_OVERLAY_UNCHANGED_MODIFIED(buf) \
  ((buf)->text->overlay_unchanged_modified)
#define BUF_BEG_UNCHANGED(buf) ((buf)->text->beg_unchanged)
#define BUF_END_UNCHANGED(buf) ((buf)->text->end_unchanged)

#define UNCHANGED_MODIFIED \
  BUF_UNCHANGED_MODIFIED (current_buffer)
#define OVERLAY_UNCHANGED_MODIFIED \
  BUF_OVERLAY_UNCHANGED_MODIFIED (current_buffer)
#define BEG_UNCHANGED BUF_BEG_UNCHANGED (current_buffer)
#define END_UNCHANGED BUF_END_UNCHANGED (current_buffer)
150

151
/* Functions to set PT in the current buffer, or another buffer.  */
152

153 154 155
extern void set_point (ptrdiff_t);
extern void temp_set_point (struct buffer *, ptrdiff_t);
extern void set_point_both (ptrdiff_t, ptrdiff_t);
156
extern void temp_set_point_both (struct buffer *,
157
				 ptrdiff_t, ptrdiff_t);
158
extern void set_point_from_marker (Lisp_Object);
159
extern void enlarge_buffer_text (struct buffer *, ptrdiff_t);
Jim Blandy's avatar
Jim Blandy committed
160

161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
INLINE void
SET_PT (ptrdiff_t position)
{
  set_point (position);
}
INLINE void
TEMP_SET_PT (ptrdiff_t position)
{
  temp_set_point (current_buffer, position);
}
INLINE void
SET_PT_BOTH (ptrdiff_t position, ptrdiff_t byte)
{
  set_point_both (position, byte);
}
INLINE void
TEMP_SET_PT_BOTH (ptrdiff_t position, ptrdiff_t byte)
{
  temp_set_point_both (current_buffer, position, byte);
}
INLINE void
BUF_TEMP_SET_PT (struct buffer *buffer, ptrdiff_t position)
{
  temp_set_point (buffer, position);
}
186

187 188
/* Maximum number of bytes in a buffer.
   A buffer cannot contain more bytes than a 1-origin fixnum can represent,
189 190 191 192
   nor can it be so large that C pointer arithmetic stops working.
   The ptrdiff_t cast ensures that this is signed, not unsigned.  */
#define BUF_BYTES_MAX \
  (ptrdiff_t) min (MOST_POSITIVE_FIXNUM - 1, min (SIZE_MAX, PTRDIFF_MAX))
193

194 195 196
/* Maximum gap size after compact_buffer, in bytes.  Also
   used in make_gap_larger to get some extra reserved space.  */

197
enum { GAP_BYTES_DFL = 2000 };
198 199 200 201

/* Minimum gap size after compact_buffer, in bytes.  Also
   used in make_gap_smaller to avoid too small gap size.  */

202
enum { GAP_BYTES_MIN = 20 };
203

204 205 206 207
/* For those very rare cases where you may have a "random" pointer into
   the middle of a multibyte char, this moves to the next boundary.  */
extern ptrdiff_t advance_to_char_boundary (ptrdiff_t byte_pos);

208 209
/* Return the byte at byte position N.
   Do not check that the position is in range.  */
210 211

#define FETCH_BYTE(n) *(BYTE_POS_ADDR ((n)))
Jim Blandy's avatar
Jim Blandy committed
212

213 214 215 216 217
/* Define the actual buffer data structures.  */

/* This data structure describes the actual text contents of a buffer.
   It is shared between indirect buffers and their base buffer.  */

Jim Blandy's avatar
Jim Blandy committed
218 219
struct buffer_text
  {
220 221 222 223 224
    /* Actual address of buffer contents.  If REL_ALLOC is defined,
       this address might change when blocks are relocated which can
       e.g. happen when malloc is called.  So, don't pass a pointer
       into a buffer's text to functions that malloc.  */
    unsigned char *beg;
225

226 227 228 229 230
    ptrdiff_t gpt;		/* Char pos of gap in buffer.  */
    ptrdiff_t z;		/* Char pos of end of buffer.  */
    ptrdiff_t gpt_byte;		/* Byte pos of gap in buffer.  */
    ptrdiff_t z_byte;		/* Byte pos of end of buffer.  */
    ptrdiff_t gap_size;		/* Size of buffer's gap.  */
231
    modiff_count modiff;	/* This counts buffer-modification events
Jim Blandy's avatar
Jim Blandy committed
232 233 234
				   for this buffer.  It is incremented for
				   each such event, and never otherwise
				   changed.  */
235
    modiff_count chars_modiff;	/* This is modified with character change
236 237 238
				   events for this buffer.  It is set to
				   modiff for each such event, and never
				   otherwise changed.  */
239
    modiff_count save_modiff;	/* Previous value of modiff, as of last
240 241
				   time buffer visited or saved a file.  */

242
    modiff_count overlay_modiff; /* Counts modifications to overlays.  */
243

244
    modiff_count compact;	/* Set to modiff each time when compact_buffer
Dmitry Antipov's avatar
Dmitry Antipov committed
245 246
				   is called for this buffer.  */

Gerd Moellmann's avatar
Gerd Moellmann committed
247
    /* Minimum value of GPT - BEG since last redisplay that finished.  */
248
    ptrdiff_t beg_unchanged;
Gerd Moellmann's avatar
Gerd Moellmann committed
249 250

    /* Minimum value of Z - GPT since last redisplay that finished.  */
251
    ptrdiff_t end_unchanged;
Gerd Moellmann's avatar
Gerd Moellmann committed
252 253 254

    /* MODIFF as of last redisplay that finished; if it matches MODIFF,
       beg_unchanged and end_unchanged contain no useful information.  */
255
    modiff_count unchanged_modified;
Gerd Moellmann's avatar
Gerd Moellmann committed
256 257 258 259

    /* BUF_OVERLAY_MODIFF of current buffer, as of last redisplay that
       finished; if it matches BUF_OVERLAY_MODIFF, beg_unchanged and
       end_unchanged contain no useful information.  */
260
    modiff_count overlay_unchanged_modified;
Gerd Moellmann's avatar
Gerd Moellmann committed
261

Dave Love's avatar
Dave Love committed
262 263
    /* Properties of this buffer's text.  */
    INTERVAL intervals;
264 265 266 267

    /* The markers that refer to this buffer.
       This is actually a single marker ---
       successive elements in its marker `chain'
268 269 270 271
       are the other markers referring to this buffer.
       This is a singly linked unordered list, which means that it's
       very cheap to add a marker to the list and it's also very cheap
       to move a marker within a buffer.  */
272
    struct Lisp_Marker *markers;
273

274
    /* Usually false.  Temporarily true in decode_coding_gap to
275
       prevent Fgarbage_collect from shrinking the gap and losing
276
       not-yet-decoded bytes.  */
277
    bool_bf inhibit_shrinking : 1;
278 279

    /* True if it needs to be redisplayed.  */
280
    bool_bf redisplay : 1;
Jim Blandy's avatar
Jim Blandy committed
281 282
  };

283
/* Most code should use this macro to access Lisp fields in struct buffer.  */
284

285
#define BVAR(buf, field) ((buf)->field ## _)
286

287 288 289 290 291 292 293
/* Max number of builtin per-buffer variables.  */
enum { MAX_PER_BUFFER_VARS = 50 };

/* Special values for struct buffer.modtime.  */
enum { NONEXISTENT_MODTIME_NSECS = -1 };
enum { UNKNOWN_MODTIME_NSECS = -2 };

294 295
/* This is the structure that the buffer Lisp object points to.  */

Jim Blandy's avatar
Jim Blandy committed
296
struct buffer
297
{
298
  union vectorlike_header header;
299 300

  /* The name of this buffer.  */
301
  Lisp_Object name_;
302 303

  /* The name of the file visited in this buffer, or nil.  */
304
  Lisp_Object filename_;
305 306

  /* Directory for expanding relative file names.  */
307
  Lisp_Object directory_;
308 309 310

  /* True if this buffer has been backed up (if you write to the visited
     file and it hasn't been backed up, then a backup will be made).  */
311
  Lisp_Object backed_up_;
312

313
  /* Length of file when last read or saved.
314 315 316
     -1 means auto saving turned off because buffer shrank a lot.
     -2 means don't turn off auto saving if buffer shrinks.
       (That value is used with buffer-swap-text.)
317 318
     This is not in the  struct buffer_text
     because it's not used in indirect buffers at all.  */
319
  Lisp_Object save_length_;
320

321 322 323
  /* File name used for auto-saving this buffer.
     This is not in the  struct buffer_text
     because it's not used in indirect buffers at all.  */
324
  Lisp_Object auto_save_file_name_;
325 326

  /* Non-nil if buffer read-only.  */
327
  Lisp_Object read_only_;
328

329 330
  /* "The mark".  This is a marker which may
     point into this buffer or may point nowhere.  */
331
  Lisp_Object mark_;
332

333 334 335
  /* Alist of elements (SYMBOL . VALUE-IN-THIS-BUFFER) for all
     per-buffer variables of this buffer.  For locally unbound
     symbols, just the symbol appears as the element.  */
336
  Lisp_Object local_var_alist_;
337

338
  /* Symbol naming major mode (e.g., lisp-mode).  */
339
  Lisp_Object major_mode_;
340 341

  /* Pretty name of major mode (e.g., "Lisp"). */
342
  Lisp_Object mode_name_;
343

344
  /* Mode line element that controls format of mode line.  */
345
  Lisp_Object mode_line_format_;
346

347 348
  /* Analogous to mode_line_format for the line displayed at the top
     of windows.  Nil means don't display that line.  */
349
  Lisp_Object header_line_format_;
350

351 352 353 354
  /* Analogous to mode_line_format for the line displayed at the top
     of windows.  Nil means don't display that line.  */
  Lisp_Object tab_line_format_;

355
  /* Keys that are bound local to this buffer.  */
356
  Lisp_Object keymap_;
357

358
  /* This buffer's local abbrev table.  */
359
  Lisp_Object abbrev_table_;
360

361
  /* This buffer's syntax table.  */
362
  Lisp_Object syntax_table_;
363

364
  /* This buffer's category table.  */
365
  Lisp_Object category_table_;
366

Pavel Janík's avatar
Pavel Janík committed
367
  /* Values of several buffer-local variables.  */
368
  /* tab-width is buffer-local so that redisplay can find it
Pavel Janík's avatar
Pavel Janík committed
369
     in buffers that are not current.  */
370 371 372 373
  Lisp_Object case_fold_search_;
  Lisp_Object tab_width_;
  Lisp_Object fill_column_;
  Lisp_Object left_margin_;
374

375
  /* Function to call when insert space past fill column.  */
376
  Lisp_Object auto_fill_function_;
377 378 379

  /* Case table for case-conversion in this buffer.
     This char-table maps each char into its lower-case version.  */
380
  Lisp_Object downcase_table_;
381

382
  /* Char-table mapping each char to its upper-case version.  */
383
  Lisp_Object upcase_table_;
384

385
  /* Char-table for conversion for case-folding search.  */
386
  Lisp_Object case_canon_table_;
387

388
  /* Char-table of equivalences for case-folding search.  */
389
  Lisp_Object case_eqv_table_;
390 391

  /* Non-nil means do not display continuation lines.  */
392
  Lisp_Object truncate_lines_;
393

394
  /* Non-nil means to use word wrapping when displaying continuation lines.  */
395
  Lisp_Object word_wrap_;
396

397
  /* Non-nil means display ctl chars with uparrow.  */
398
  Lisp_Object ctl_arrow_;
399

400 401
  /* Non-nil means reorder bidirectional text for display in the
     visual order.  */
402
  Lisp_Object bidi_display_reordering_;
403

404 405 406
  /* If non-nil, specifies which direction of text to force in all the
     paragraphs of the buffer.  Nil means determine paragraph
     direction dynamically for each paragraph.  */
407
  Lisp_Object bidi_paragraph_direction_;
408

409 410 411 412 413 414
  /* If non-nil, a regular expression for bidi paragraph separator.  */
  Lisp_Object bidi_paragraph_separate_re_;

  /* If non-nil, a regular expression for bidi paragraph start.  */
  Lisp_Object bidi_paragraph_start_re_;

415 416
  /* Non-nil means do selective display;
     see doc string in syms_of_buffer (buffer.c) for details.  */
417
  Lisp_Object selective_display_;
418

419
  /* Non-nil means show ... at end of line followed by invisible lines.  */
420
  Lisp_Object selective_display_ellipses_;
421

422
  /* Alist of (FUNCTION . STRING) for each minor mode enabled in buffer.  */
423
  Lisp_Object minor_modes_;
424

425 426
  /* t if "self-insertion" should overwrite; `binary' if it should also
     overwrite newlines and tabs - for editing executables and the like.  */
427
  Lisp_Object overwrite_mode_;
428 429

  /* Non-nil means abbrev mode is on.  Expand abbrevs automatically.  */
430
  Lisp_Object abbrev_mode_;
431

432
  /* Display table to use for text in this buffer.  */
433
  Lisp_Object display_table_;
434

435
  /* t means the mark and region are currently active.  */
436
  Lisp_Object mark_active_;
437 438 439

  /* Non-nil means the buffer contents are regarded as multi-byte
     form of characters, not a binary code.  */
440
  Lisp_Object enable_multibyte_characters_;
441 442 443

  /* Coding system to be used for encoding the buffer contents on
     saving.  */
444
  Lisp_Object buffer_file_coding_system_;
445

Pavel Janík's avatar
Pavel Janík committed
446
  /* List of symbols naming the file format used for visited file.  */
447
  Lisp_Object file_format_;
448

449
  /* List of symbols naming the file format used for auto-save file.  */
450
  Lisp_Object auto_save_file_format_;
451

452 453
  /* True if the newline position cache, width run cache and BIDI paragraph
     cache are enabled.  See search.c, indent.c and bidi.c for details.  */
454
  Lisp_Object cache_long_scans_;
455 456 457 458 459 460 461

  /* If the width run cache is enabled, this table contains the
     character widths width_run_cache (see above) assumes.  When we
     do a thorough redisplay, we compare this against the buffer's
     current display table to see whether the display table has
     affected the widths of any characters.  If it has, we
     invalidate the width run cache, and re-initialize width_table.  */
462
  Lisp_Object width_table_;
463 464 465 466

  /* In an indirect buffer, or a buffer that is the base of an
     indirect buffer, this holds a marker that records
     PT for this buffer when the buffer is not current.  */
467
  Lisp_Object pt_marker_;
468 469 470 471

  /* In an indirect buffer, or a buffer that is the base of an
     indirect buffer, this holds a marker that records
     BEGV for this buffer when the buffer is not current.  */
472
  Lisp_Object begv_marker_;
473 474 475 476

  /* In an indirect buffer, or a buffer that is the base of an
     indirect buffer, this holds a marker that records
     ZV for this buffer when the buffer is not current.  */
477
  Lisp_Object zv_marker_;
478 479 480

  /* This holds the point value before the last scroll operation.
     Explicitly setting point sets this to nil.  */
481
  Lisp_Object point_before_scroll_;
482 483

  /* Truename of the visited file, or nil.  */
484
  Lisp_Object file_truename_;
485 486 487 488 489

  /* Invisibility spec of this buffer.
     t => any non-nil `invisible' property means invisible.
     A list => `invisible' property means invisible
     if it is memq in that list.  */
490
  Lisp_Object invisibility_spec_;
491 492 493

  /* This is the last window that was selected with this buffer in it,
     or nil if that window no longer displays this buffer.  */
494
  Lisp_Object last_selected_window_;
495 496

  /* Incremented each time the buffer is displayed in a window.  */
497
  Lisp_Object display_count_;
498

499 500
  /* Widths of left and right marginal areas for windows displaying
     this buffer.  */
501 502
  Lisp_Object left_margin_cols_;
  Lisp_Object right_margin_cols_;
503 504 505

  /* Widths of left and right fringe areas for windows displaying
     this buffer.  */
506 507
  Lisp_Object left_fringe_width_;
  Lisp_Object right_fringe_width_;
508 509 510

  /* Non-nil means fringes are drawn outside display margins;
     othersize draw them between margin areas and text.  */
511
  Lisp_Object fringes_outside_margins_;
512

513
  /* Width, height and types of scroll bar areas for windows displaying
514
     this buffer.  */
515 516 517 518
  Lisp_Object scroll_bar_width_;
  Lisp_Object scroll_bar_height_;
  Lisp_Object vertical_scroll_bar_type_;
  Lisp_Object horizontal_scroll_bar_type_;
519 520 521

  /* Non-nil means indicate lines not displaying text (in a style
     like vi).  */
522
  Lisp_Object indicate_empty_lines_;
523

Kenichi Handa's avatar
Kenichi Handa committed
524
  /* Non-nil means indicate buffer boundaries and scrolling.  */
525
  Lisp_Object indicate_buffer_boundaries_;
Kenichi Handa's avatar
Kenichi Handa committed
526

527
  /* Logical to physical fringe bitmap mappings.  */
528
  Lisp_Object fringe_indicator_alist_;
529 530

  /* Logical to physical cursor bitmap mappings.  */
531
  Lisp_Object fringe_cursor_alist_;
532

533
  /* Time stamp updated each time this buffer is displayed in a window.  */
534
  Lisp_Object display_time_;
535 536 537 538 539

  /* If scrolling the display because point is below the bottom of a
     window showing this buffer, try to choose a window start so
     that point ends up this number of lines from the top of the
     window.  Nil means that scrolling method isn't used.  */
540
  Lisp_Object scroll_up_aggressively_;
541

542 543 544 545
  /* If scrolling the display because point is above the top of a
     window showing this buffer, try to choose a window start so
     that point ends up this number of lines from the bottom of the
     window.  Nil means that scrolling method isn't used.  */
546
  Lisp_Object scroll_down_aggressively_;
Gerd Moellmann's avatar
Gerd Moellmann committed
547

548 549
  /* Desired cursor type in this buffer.  See the doc string of
     per-buffer variable `cursor-type'.  */
550
  Lisp_Object cursor_type_;
551 552 553

  /* An integer > 0 means put that number of pixels below text lines
     in the display of this buffer.  */
554
  Lisp_Object extra_line_spacing_;
555

556
  /* Cursor type to display in non-selected windows.
557 558
     t means to use hollow box cursor.
     See `cursor-type' for other values.  */
559
  Lisp_Object cursor_in_non_selected_windows_;
560

561 562
  /* No more Lisp_Object beyond cursor_in_non_selected_windows_.
     Except undo_list, which is handled specially in Fgarbage_collect.  */
563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594

  /* This structure holds the coordinates of the buffer contents
     in ordinary buffers.  In indirect buffers, this is not used.  */
  struct buffer_text own_text;

  /* This points to the `struct buffer_text' that used for this buffer.
     In an ordinary buffer, this is the own_text field above.
     In an indirect buffer, this is the own_text field of another buffer.  */
  struct buffer_text *text;

  /* Char position of point in buffer.  */
  ptrdiff_t pt;

  /* Byte position of point in buffer.  */
  ptrdiff_t pt_byte;

  /* Char position of beginning of accessible range.  */
  ptrdiff_t begv;

  /* Byte position of beginning of accessible range.  */
  ptrdiff_t begv_byte;

  /* Char position of end of accessible range.  */
  ptrdiff_t zv;

  /* Byte position of end of accessible range.  */
  ptrdiff_t zv_byte;

  /* In an indirect buffer, this points to the base buffer.
     In an ordinary buffer, it is 0.  */
  struct buffer *base_buffer;

Dmitry Antipov's avatar
Dmitry Antipov committed
595
  /* In an indirect buffer, this is -1.  In an ordinary buffer,
596
     it's the number of indirect buffers that share our text;
597
     zero means that we're the only owner of this text.  */
598
  int indirections;
599

Dmitry Antipov's avatar
Dmitry Antipov committed
600 601 602 603
  /* Number of windows showing this buffer.  Always -1 for
     an indirect buffer since it counts as its base buffer.  */
  int window_count;

604 605 606 607 608 609 610 611
  /* A non-zero value in slot IDX means that per-buffer variable
     with index IDX has a local value in this buffer.  The index IDX
     for a buffer-local variable is stored in that variable's slot
     in buffer_local_flags as a Lisp integer.  If the index is -1,
     this means the variable is always local in all buffers.  */
  char local_flags[MAX_PER_BUFFER_VARS];

  /* Set to the modtime of the visited file when read or written.
612 613
     modtime.tv_nsec == NONEXISTENT_MODTIME_NSECS means
     visited file was nonexistent.  modtime.tv_nsec ==
614 615
     UNKNOWN_MODTIME_NSECS means visited file modtime unknown;
     in no case complain about any mismatch on next save attempt.  */
616
  struct timespec modtime;
617 618 619 620 621 622 623 624 625

  /* Size of the file when modtime was set.  This is used to detect the
     case where the file grew while we were reading it, so the modtime
     is still the same (since it's rounded up to seconds) but we're actually
     not up-to-date.  -1 means the size is unknown.  Only meaningful if
     modtime is actually set.  */
  off_t modtime_size;

  /* The value of text->modiff at the last auto-save.  */
626
  modiff_count auto_save_modified;
627 628 629

  /* The value of text->modiff at the last display error.
     Redisplay of this buffer is inhibited until it changes again.  */
630
  modiff_count display_error_modiff;
631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654

  /* The time at which we detected a failure to auto-save,
     Or 0 if we didn't have a failure.  */
  time_t auto_save_failure_time;

  /* Position in buffer at which display started
     the last time this buffer was displayed.  */
  ptrdiff_t last_window_start;

  /* If the long line scan cache is enabled (i.e. the buffer-local
     variable cache-long-line-scans is non-nil), newline_cache
     points to the newline cache, and width_run_cache points to the
     width run cache.

     The newline cache records which stretches of the buffer are
     known *not* to contain newlines, so that they can be skipped
     quickly when we search for newlines.

     The width run cache records which stretches of the buffer are
     known to contain characters whose widths are all the same.  If
     the width run cache maps a character to a value > 0, that value is
     the character's width; if it maps a character to zero, we don't
     know what its width is.  This allows compute_motion to process
     such regions very quickly, using algebra instead of inspecting
655 656 657
     each character.   See also width_table, below.

     The latter cache is used to speedup bidi_find_paragraph_start.  */
658 659
  struct region_cache *newline_cache;
  struct region_cache *width_run_cache;
660
  struct region_cache *bidi_paragraph_cache;
661

662 663
  /* Non-zero means disable redisplay optimizations when rebuilding the glyph
     matrices (but not when redrawing).  */
664
  bool_bf prevent_redisplay_optimizations_p : 1;
665 666

  /* Non-zero whenever the narrowing is changed in this buffer.  */
667
  bool_bf clip_changed : 1;
668

669 670 671 672 673 674 675
  /* Non-zero for internally used temporary buffers that don't need to
     run hooks kill-buffer-hook, buffer-list-update-hook, and
     kill-buffer-query-functions.  This is used in coding.c to avoid
     slowing down en/decoding when there are a lot of these hooks
     defined.  */
  bool_bf inhibit_buffer_hooks : 1;

676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691
  /* List of overlays that end at or before the current center,
     in order of end-position.  */
  struct Lisp_Overlay *overlays_before;

  /* List of overlays that end after  the current center,
     in order of start-position.  */
  struct Lisp_Overlay *overlays_after;

  /* Position where the overlay lists are centered.  */
  ptrdiff_t overlay_center;

  /* Changes in the buffer are recorded here for undo, and t means
     don't record anything.  This information belongs to the base
     buffer of an indirect buffer.  But we can't store it in the
     struct buffer_text because local variables have to be right in
     the struct buffer. So we copy it around in set_buffer_internal.  */
692
  Lisp_Object undo_list_;
693
};
694

695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710
INLINE bool
BUFFERP (Lisp_Object a)
{
  return PSEUDOVECTORP (a, PVEC_BUFFER);
}

INLINE void
CHECK_BUFFER (Lisp_Object x)
{
  CHECK_TYPE (BUFFERP (x), Qbufferp, x);
}

INLINE struct buffer *
XBUFFER (Lisp_Object a)
{
  eassert (BUFFERP (a));
711
  return XUNTAG (a, Lisp_Vectorlike, struct buffer);
712 713
}

Paul Eggert's avatar
Paul Eggert committed
714
/* Most code should use these functions to set Lisp fields in struct
Paul Eggert's avatar
Paul Eggert committed
715
   buffer.  (Some setters that are private to a single .c file are
716
   defined as static in those files.)  */
Paul Eggert's avatar
Paul Eggert committed
717
INLINE void
Paul Eggert's avatar
Paul Eggert committed
718 719
bset_bidi_paragraph_direction (struct buffer *b, Lisp_Object val)
{
720
  b->bidi_paragraph_direction_ = val;
Paul Eggert's avatar
Paul Eggert committed
721
}
Paul Eggert's avatar
Paul Eggert committed
722
INLINE void
723 724
bset_cache_long_scans (struct buffer *b, Lisp_Object val)
{
725
  b->cache_long_scans_ = val;
726 727
}
INLINE void
Paul Eggert's avatar
Paul Eggert committed
728 729
bset_case_canon_table (struct buffer *b, Lisp_Object val)
{
730
  b->case_canon_table_ = val;
Paul Eggert's avatar
Paul Eggert committed
731
}
Paul Eggert's avatar
Paul Eggert committed
732
INLINE void
Paul Eggert's avatar
Paul Eggert committed
733 734
bset_case_eqv_table (struct buffer *b, Lisp_Object val)
{
735
  b->case_eqv_table_ = val;
Paul Eggert's avatar
Paul Eggert committed
736
}
Paul Eggert's avatar
Paul Eggert committed
737
INLINE void
Paul Eggert's avatar
Paul Eggert committed
738 739
bset_directory (struct buffer *b, Lisp_Object val)
{
740
  b->directory_ = val;
Paul Eggert's avatar
Paul Eggert committed
741
}
Paul Eggert's avatar
Paul Eggert committed
742
INLINE void
Paul Eggert's avatar
Paul Eggert committed
743 744
bset_display_count (struct buffer *b, Lisp_Object val)
{
745
  b->display_count_ = val;
Paul Eggert's avatar
Paul Eggert committed
746
}
Paul Eggert's avatar
Paul Eggert committed
747
INLINE void
748 749 750 751 752 753 754 755 756 757
bset_left_margin_cols (struct buffer *b, Lisp_Object val)
{
  b->left_margin_cols_ = val;
}
INLINE void
bset_right_margin_cols (struct buffer *b, Lisp_Object val)
{
  b->right_margin_cols_ = val;
}
INLINE void
Paul Eggert's avatar
Paul Eggert committed
758 759
bset_display_time (struct buffer *b, Lisp_Object val)
{
760
  b->display_time_ = val;
Paul Eggert's avatar
Paul Eggert committed
761
}
Paul Eggert's avatar
Paul Eggert committed
762
INLINE void
Paul Eggert's avatar
Paul Eggert committed
763 764
bset_downcase_table (struct buffer *b, Lisp_Object val)
{
765
  b->downcase_table_ = val;
Paul Eggert's avatar
Paul Eggert committed
766
}
Paul Eggert's avatar
Paul Eggert committed
767
INLINE void
Paul Eggert's avatar
Paul Eggert committed
768 769
bset_enable_multibyte_characters (struct buffer *b, Lisp_Object val)
{
770
  b->enable_multibyte_characters_ = val;
Paul Eggert's avatar
Paul Eggert committed
771
}
Paul Eggert's avatar
Paul Eggert committed
772
INLINE void
Paul Eggert's avatar
Paul Eggert committed
773 774
bset_filename (struct buffer *b, Lisp_Object val)
{
775
  b->filename_ = val;
Paul Eggert's avatar
Paul Eggert committed
776
}
Paul Eggert's avatar
Paul Eggert committed
777
INLINE void
Paul Eggert's avatar
Paul Eggert committed
778 779
bset_keymap (struct buffer *b, Lisp_Object val)
{
780
  b->keymap_ = val;
Paul Eggert's avatar
Paul Eggert committed
781
}
Paul Eggert's avatar
Paul Eggert committed
782
INLINE void
Paul Eggert's avatar
Paul Eggert committed
783 784
bset_last_selected_window (struct buffer *b, Lisp_Object val)
{
785
  b->last_selected_window_ = val;
Paul Eggert's avatar
Paul Eggert committed
786
}
Paul Eggert's avatar
Paul Eggert committed
787
INLINE void
Paul Eggert's avatar
Paul Eggert committed
788 789
bset_local_var_alist (struct buffer *b, Lisp_Object val)
{
790
  b->local_var_alist_ = val;
Paul Eggert's avatar
Paul Eggert committed
791
}
Paul Eggert's avatar
Paul Eggert committed
792
INLINE void
Paul Eggert's avatar
Paul Eggert committed
793 794
bset_mark_active (struct buffer *b, Lisp_Object val)
{
795
  b->mark_active_ = val;
Paul Eggert's avatar
Paul Eggert committed
796
}
Paul Eggert's avatar
Paul Eggert committed
797
INLINE void
Paul Eggert's avatar
Paul Eggert committed
798 799
bset_point_before_scroll (struct buffer *b, Lisp_Object val)
{
800
  b->point_before_scroll_ = val;
Paul Eggert's avatar
Paul Eggert committed
801
}
Paul Eggert's avatar
Paul Eggert committed
802
INLINE void
Paul Eggert's avatar
Paul Eggert committed
803 804
bset_read_only (struct buffer *b, Lisp_Object val)
{
805
  b->read_only_ = val;
Paul Eggert's avatar
Paul Eggert committed
806
}
Paul Eggert's avatar
Paul Eggert committed
807
INLINE void
Paul Eggert's avatar
Paul Eggert committed
808 809
bset_truncate_lines (struct buffer *b, Lisp_Object val)
{
810
  b->truncate_lines_ = val;
Paul Eggert's avatar
Paul Eggert committed
811
}
Paul Eggert's avatar
Paul Eggert committed
812
INLINE void
Paul Eggert's avatar
Paul Eggert committed
813 814
bset_undo_list (struct buffer *b, Lisp_Object val)
{
815
  b->undo_list_ = val;
Paul Eggert's avatar
Paul Eggert committed
816
}
Paul Eggert's avatar
Paul Eggert committed
817
INLINE void
Paul Eggert's avatar
Paul Eggert committed
818 819
bset_upcase_table (struct buffer *b, Lisp_Object val)
{
820
  b->upcase_table_ = val;
Paul Eggert's avatar
Paul Eggert committed
821
}
Paul Eggert's avatar
Paul Eggert committed
822
INLINE void
Paul Eggert's avatar
Paul Eggert committed
823 824
bset_width_table (struct buffer *b, Lisp_Object val)
{
825
  b->width_table_ = val;
Paul Eggert's avatar
Paul Eggert committed
826 827
}

828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047
/* BUFFER_CEILING_OF (resp. BUFFER_FLOOR_OF), when applied to n, return
   the max (resp. min) p such that

   BYTE_POS_ADDR (p) - BYTE_POS_ADDR (n) == p - n       */

INLINE ptrdiff_t
BUFFER_CEILING_OF (ptrdiff_t bytepos)
{
  return (bytepos < GPT_BYTE && GPT < ZV ? GPT_BYTE : ZV_BYTE) - 1;
}

INLINE ptrdiff_t
BUFFER_FLOOR_OF (ptrdiff_t bytepos)
{
  return BEGV <= GPT && GPT_BYTE <= bytepos ? GPT_BYTE : BEGV_BYTE;
}

/* The BUF_BEGV[_BYTE], BUF_ZV[_BYTE], and BUF_PT[_BYTE] functions cannot
   be used for assignment; use SET_BUF_* functions below for that.  */

/* Position of beginning of accessible range of buffer.  */
INLINE ptrdiff_t
BUF_BEGV (struct buffer *buf)
{
  return (buf == current_buffer ? BEGV
	  : NILP (BVAR (buf, begv_marker)) ? buf->begv
	  : marker_position (BVAR (buf, begv_marker)));
}

INLINE ptrdiff_t
BUF_BEGV_BYTE (struct buffer *buf)
{
  return (buf == current_buffer ? BEGV_BYTE
	  : NILP (BVAR (buf, begv_marker)) ? buf->begv_byte
	  : marker_byte_position (BVAR (buf, begv_marker)));
}

/* Position of point in buffer.  */
INLINE ptrdiff_t
BUF_PT (struct buffer *buf)
{
  return (buf == current_buffer ? PT
	  : NILP (BVAR (buf, pt_marker)) ? buf->pt
	  : marker_position (BVAR (buf, pt_marker)));
}

INLINE ptrdiff_t
BUF_PT_BYTE (struct buffer *buf)
{
  return (buf == current_buffer ? PT_BYTE
	  : NILP (BVAR (buf, pt_marker)) ? buf->pt_byte
	  : marker_byte_position (BVAR (buf, pt_marker)));
}

/* Position of end of accessible range of buffer.  */
INLINE ptrdiff_t
BUF_ZV (struct buffer *buf)
{
  return (buf == current_buffer ? ZV
	  : NILP (BVAR (buf, zv_marker)) ? buf->zv
	  : marker_position (BVAR (buf, zv_marker)));
}

INLINE ptrdiff_t
BUF_ZV_BYTE (struct buffer *buf)
{
  return (buf == current_buffer ? ZV_BYTE
	  : NILP (BVAR (buf, zv_marker)) ? buf->zv_byte
	  : marker_byte_position (BVAR (buf, zv_marker)));
}

/* Similar functions to operate on a specified buffer.  */

/* Position of beginning of buffer.  */
INLINE ptrdiff_t
BUF_BEG (struct buffer *buf)
{
  return BEG;
}

INLINE ptrdiff_t
BUF_BEG_BYTE (struct buffer *buf)
{
  return BEG_BYTE;
}

/* Address of beginning of gap of buffer.  */
INLINE unsigned char *
BUF_GPT_ADDR (struct buffer *buf)
{
  return buf->text->beg + buf->text->gpt_byte - BEG_BYTE;
}

/* Address of end of buffer.  */
INLINE unsigned char *
BUF_Z_ADDR (struct buffer *buf)
{
  return buf->text->beg + buf->text->gap_size + buf->text->z_byte - BEG_BYTE;
}

/* Address of end of gap in buffer.  */
INLINE unsigned char *
BUF_GAP_END_ADDR (struct buffer *buf)
{
  return buf->text->beg + buf->text->gpt_byte + buf->text->gap_size - BEG_BYTE;
}

/* Compute how many characters at the top and bottom of BUF are
   unchanged when the range START..END is modified.  This computation
   must be done each time BUF is modified.  */

INLINE void
BUF_COMPUTE_UNCHANGED (struct buffer *buf, ptrdiff_t start, ptrdiff_t end)
{
  if (BUF_UNCHANGED_MODIFIED (buf) == BUF_MODIFF (buf)
      && (BUF_OVERLAY_UNCHANGED_MODIFIED (buf)
	  == BUF_OVERLAY_MODIFF (buf)))
    {
      buf->text->beg_unchanged = start - BUF_BEG (buf);
      buf->text->end_unchanged = BUF_Z (buf) - (end);
    }
  else
    {
      if (BUF_Z (buf) - end < BUF_END_UNCHANGED (buf))
	buf->text->end_unchanged = BUF_Z (buf) - end;
      if (start - BUF_BEG (buf) < BUF_BEG_UNCHANGED (buf))
	buf->text->beg_unchanged = start - BUF_BEG (buf);
    }
}

/* Functions for setting the BEGV, ZV or PT of a given buffer.

   The ..._BOTH functions take both a charpos and a bytepos,
   which must correspond to each other.

   The functions without ..._BOTH take just a charpos,
   and compute the bytepos from it.  */

INLINE void
SET_BUF_BEGV (struct buffer *buf, ptrdiff_t charpos)
{
  buf->begv_byte = buf_charpos_to_bytepos (buf, charpos);
  buf->begv = charpos;
}

INLINE void
SET_BUF_ZV (struct buffer *buf, ptrdiff_t charpos)
{
  buf->zv_byte = buf_charpos_to_bytepos (buf, charpos);
  buf->zv = charpos;
}

INLINE void
SET_BUF_BEGV_BOTH (struct buffer *buf, ptrdiff_t charpos, ptrdiff_t byte)
{
  buf->begv = charpos;
  buf->begv_byte = byte;
}

INLINE void
SET_BUF_ZV_BOTH (struct buffer *buf, ptrdiff_t charpos, ptrdiff_t byte)
{
  buf->zv = charpos;
  buf->zv_byte = byte;
}

INLINE void
SET_BUF_PT_BOTH (struct buffer *buf, ptrdiff_t charpos, ptrdiff_t byte)
{
  buf->pt = charpos;
  buf->pt_byte = byte;
}

/* Functions to access a character or byte in the current buffer,
   or convert between a byte position and an address.
   These functions do not check that the position is in range.  */

/* Return the address of byte position N in current buffer.  */

INLINE unsigned char *
BYTE_POS_ADDR (ptrdiff_t n)
{
  return (n < GPT_BYTE ? 0 : GAP_SIZE) + n + BEG_ADDR - BEG_BYTE;
}

/* Return the address of char position N.  */

INLINE unsigned char *
CHAR_POS_ADDR (ptrdiff_t n)
{
  return ((n < GPT ? 0 : GAP_SIZE)
	  + buf_charpos_to_bytepos (current_buffer, n)
	  + BEG_ADDR - BEG_BYTE);
}

/* Convert a character position to a byte position.  */

INLINE ptrdiff_t
CHAR_TO_BYTE (ptrdiff_t charpos)
{
  return buf_charpos_to_bytepos (current_buffer, charpos);
}

/* Convert a byte position to a character position.  */

INLINE ptrdiff_t
BYTE_TO_CHAR (ptrdiff_t bytepos)
{
  return buf_bytepos_to_charpos (current_buffer, bytepos);
}

/* Convert PTR, the address of a byte in the buffer, into a byte position.  */

INLINE ptrdiff_t
PTR_BYTE_POS (unsigned char const *ptr)
{
  ptrdiff_t byte = ptr - current_buffer->text->beg;
  return byte - (byte <= GPT_BYTE - BEG_BYTE ? 0 : GAP_SIZE) + BEG_BYTE;
}

1048 1049 1050 1051
/* Number of Lisp_Objects at the beginning of struct buffer.
   If you add, remove, or reorder Lisp_Objects within buffer
   structure, make sure that this is still correct.  */

1052 1053
enum { BUFFER_LISP_SIZE = PSEUDOVECSIZE (struct buffer,
					 cursor_in_non_selected_windows_) };
1054

1055 1056
/* Allocated size of the struct buffer part beyond leading
   Lisp_Objects, in word_size units.  */
1057

1058
enum { BUFFER_REST_SIZE = VECSIZE (struct buffer) - BUFFER_LISP_SIZE };
1059 1060 1061 1062 1063

/* Initialize the pseudovector header of buffer object.  BUFFER_LISP_SIZE
   is required for GC, but BUFFER_REST_SIZE is set up just to be consistent
   with other pseudovectors.  */

1064 1065 1066 1067 1068
INLINE void
BUFFER_PVEC_INIT (struct buffer *b)
{
  XSETPVECTYPESIZE (b, PVEC_BUFFER, BUFFER_LISP_SIZE, BUFFER_REST_SIZE);
}
1069

1070 1071
/* Convenient check whether buffer B is live.  */

1072 1073 1074 1075 1076
INLINE bool
BUFFER_LIVE_P (struct buffer *b)
{
  return !NILP (BVAR (b, name));
}
1077

1078 1079 1080
/* Convenient check whether buffer B is hidden (i.e. its name
   starts with a space).  Caller must ensure that B is live.  */

1081 1082 1083 1084 1085
INLINE bool
BUFFER_HIDDEN_P (struct buffer *b)
{
  return SREF (BVAR (b, name), 0) == ' ';
}
1086

1087 1088
/* Verify indirection counters.  */

1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102
INLINE void
BUFFER_CHECK_INDIRECTION (struct buffer *b)
{
  if (BUFFER_LIVE_P (b))
    {
      if (b->base_buffer)
	{
	  eassert (b->indirections == -1);
	  eassert (b->base_buffer->indirections > 0);
	}
      else
	eassert (b->indirections >= 0);
    }
}
1103

Jim Blandy's avatar
Jim Blandy committed
1104
/* This structure holds the default values of the buffer-local variables
1105
   that have special slots in each buffer.
Jim Blandy's avatar
Jim Blandy committed
1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118
   The default value occupies the same slot in this structure
   as an individual buffer's value occupies in that buffer.
   Setting the default value also goes through the alist of buffers
   and stores into each buffer that does not say it has a local value.  */

extern struct buffer buffer_defaults;

/* This structure marks which slots in a buffer have corresponding
   default values in buffer_defaults.
   Each such slot has a nonzero value in this structure.
   The value has only one nonzero bit.

   When a buffer has its own local value for a slot,
1119 1120
   the entry for that slot (found in the same slot in this structure)
   is turned on in the buffer's local_flags array.
Jim Blandy's avatar
Jim Blandy committed
1121 1122

   If a slot in this structure is zero, then even though there may
1123
   be a Lisp-level local variable for the slot, it has no default value,
Jim Blandy's avatar
Jim Blandy committed
1124 1125
   and the corresponding slot in buffer_defaults is not used.  */

1126

Jim Blandy's avatar
Jim Blandy committed
1127 1128 1129 1130 1131 1132 1133
extern struct buffer buffer_local_flags;

/* For each buffer slot, this points to the Lisp symbol name
   for that slot in the current buffer.  It is 0 for slots
   that don't have such names.  */

extern struct buffer buffer_local_symbols;
1134 1135 1136 1137 1138 1139

/* verify_interval_modification saves insertion hooks here
   to be run later by report_interval_modification.  */
extern Lisp_Object interval_insert_behind_hooks;
extern Lisp_Object interval_insert_in_front_hooks;

1140

1141 1142
extern EMACS_INT fix_position (Lisp_Object);
#define CHECK_FIXNUM_COERCE_MARKER(x) ((x) = make_fixnum (fix_position (x)))
Jan D's avatar
Jan D committed
1143 1144
extern void delete_all_overlays (struct buffer *);
extern void reset_buffer (struct buffer *);
1145
extern void compact_buffer (struct buffer *);
1146
extern void evaporate_overlays (ptrdiff_t);
1147 1148
extern ptrdiff_t overlays_at (EMACS_INT, bool, Lisp_Object **,
			      ptrdiff_t *, ptrdiff_t *, ptrdiff_t *, bool);
1149
extern ptrdiff_t sort_overlays (Lisp_Object *, ptrdiff_t, struct window *);
1150 1151
extern void recenter_overlay_lists (struct buffer *, ptrdiff_t);
extern ptrdiff_t overlay_strings (ptrdiff_t, struct window *, unsigned char **);
Jan D's avatar
Jan D committed
1152 1153
extern void validate_region (Lisp_Object *, Lisp_Object *);
extern void set_buffer_internal_1 (struct buffer *);
1154
extern void set_buffer_internal_2 (struct buffer *);
Jan D's avatar
Jan D committed
1155
extern void set_buffer_temp (struct buffer *);