root/src/buffer.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. SET_PT
  2. TEMP_SET_PT
  3. SET_PT_BOTH
  4. TEMP_SET_PT_BOTH
  5. BUF_TEMP_SET_PT
  6. BUFFERP
  7. CHECK_BUFFER
  8. XBUFFER
  9. bset_bidi_paragraph_direction
  10. bset_cache_long_scans
  11. bset_case_canon_table
  12. bset_case_eqv_table
  13. bset_directory
  14. bset_display_count
  15. bset_left_margin_cols
  16. bset_right_margin_cols
  17. bset_display_time
  18. bset_downcase_table
  19. bset_enable_multibyte_characters
  20. bset_filename
  21. bset_keymap
  22. bset_last_selected_window
  23. bset_local_var_alist
  24. bset_mark_active
  25. bset_point_before_scroll
  26. bset_read_only
  27. bset_truncate_lines
  28. bset_undo_list
  29. bset_upcase_table
  30. bset_width_table
  31. BUFFER_CEILING_OF
  32. BUFFER_FLOOR_OF
  33. BUF_BEGV
  34. BUF_BEGV_BYTE
  35. BUF_PT
  36. BUF_PT_BYTE
  37. BUF_ZV
  38. BUF_ZV_BYTE
  39. BUF_BEG
  40. BUF_BEG_BYTE
  41. BUF_GPT_ADDR
  42. BUF_Z_ADDR
  43. BUF_GAP_END_ADDR
  44. BUF_COMPUTE_UNCHANGED
  45. SET_BUF_BEGV
  46. SET_BUF_ZV
  47. SET_BUF_BEGV_BOTH
  48. SET_BUF_ZV_BOTH
  49. SET_BUF_PT_BOTH
  50. BYTE_POS_ADDR
  51. CHAR_POS_ADDR
  52. CHAR_TO_BYTE
  53. BYTE_TO_CHAR
  54. PTR_BYTE_POS
  55. BUFFER_PVEC_INIT
  56. BUFFER_LIVE_P
  57. BUFFER_HIDDEN_P
  58. BUFFER_CHECK_INDIRECTION
  59. decode_buffer
  60. set_buffer_internal
  61. record_unwind_current_buffer
  62. buffer_intervals
  63. set_buffer_intervals
  64. buffer_has_overlays
  65. FETCH_MULTIBYTE_CHAR
  66. BUF_FETCH_MULTIBYTE_CHAR
  67. FETCH_CHAR_AS_MULTIBYTE
  68. FETCH_CHAR
  69. BUF_BYTE_ADDRESS
  70. BUF_CHAR_ADDRESS
  71. BUF_PTR_BYTE_POS
  72. BUF_FETCH_BYTE
  73. BUF_FETCH_CHAR_AS_MULTIBYTE
  74. buffer_window_count
  75. overlay_start
  76. overlay_end
  77. OVERLAY_START
  78. OVERLAY_END
  79. OVERLAY_PLIST
  80. OVERLAY_BUFFER
  81. OVERLAY_REAR_ADVANCE_P
  82. OVERLAY_FRONT_ADVANCE_P
  83. PER_BUFFER_VALUE_P
  84. SET_PER_BUFFER_VALUE_P
  85. PER_BUFFER_IDX
  86. per_buffer_default
  87. set_per_buffer_default
  88. per_buffer_value
  89. set_per_buffer_value
  90. downcase
  91. upcase
  92. uppercasep
  93. lowercasep
  94. sanitize_tab_width
  95. SANE_TAB_WIDTH
  96. sanitize_char_width
  97. CHARACTER_WIDTH
  98. fetch_char_advance
  99. fetch_char_advance_no_check
  100. buf_next_char_len
  101. next_char_len
  102. buf_prev_char_len
  103. prev_char_len
  104. inc_both
  105. dec_both

     1 /* Header file for the buffer manipulation primitives.
     2 
     3 Copyright (C) 1985-2023 Free Software Foundation, Inc.
     4 
     5 This file is part of GNU Emacs.
     6 
     7 GNU Emacs is free software: you can redistribute it and/or modify
     8 it under the terms of the GNU General Public License as published by
     9 the Free Software Foundation, either version 3 of the License, or (at
    10 your option) any later version.
    11 
    12 GNU Emacs is distributed in the hope that it will be useful,
    13 but WITHOUT ANY WARRANTY; without even the implied warranty of
    14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    15 GNU General Public License for more details.
    16 
    17 You should have received a copy of the GNU General Public License
    18 along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.  */
    19 
    20 #ifndef EMACS_BUFFER_H
    21 #define EMACS_BUFFER_H
    22 
    23 #include <sys/types.h>
    24 #include <time.h>
    25 
    26 #include "character.h"
    27 #include "lisp.h"
    28 #include "itree.h"
    29 
    30 INLINE_HEADER_BEGIN
    31 
    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.  */
    36 
    37 /* Position of beginning of buffer.  */
    38 enum { BEG = 1, BEG_BYTE = BEG };
    39 
    40 /* Position of beginning of accessible range of buffer.  */
    41 #define BEGV (current_buffer->begv)
    42 #define BEGV_BYTE (current_buffer->begv_byte)
    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)
    48 
    49 /* Position of gap in buffer.  */
    50 #define GPT (current_buffer->text->gpt)
    51 #define GPT_BYTE (current_buffer->text->gpt_byte)
    52 
    53 /* Position of end of accessible range of buffer.  */
    54 #define ZV (current_buffer->zv)
    55 #define ZV_BYTE (current_buffer->zv_byte)
    56 
    57 /* Position of end of buffer.  */
    58 #define Z (current_buffer->text->z)
    59 #define Z_BYTE (current_buffer->text->z_byte)
    60 
    61 /* Macros for the addresses of places in the buffer.  */
    62 
    63 /* WARNING: Use the 'char *' pointers to buffer text with care in code
    64    that could GC: GC can relocate buffer text, invalidating such
    65    pointers.  It is best to use character or byte position instead,
    66    delaying the access through BYTE_POS_ADDR etc. pointers to the
    67    latest possible moment.  If you must use the 'char *' pointers
    68    (e.g., for speed), be sure to adjust them after any call that could
    69    potentially GC.  */
    70 
    71 /* Address of beginning of buffer.  */
    72 #define BEG_ADDR (current_buffer->text->beg)
    73 
    74 /* Address of beginning of accessible range of buffer.  */
    75 #define BEGV_ADDR (BYTE_POS_ADDR (current_buffer->begv_byte))
    76 
    77 /* Address of point in buffer.  */
    78 #define PT_ADDR (BYTE_POS_ADDR (current_buffer->pt_byte))
    79 
    80 /* Address of beginning of gap in buffer.  */
    81 #define GPT_ADDR (current_buffer->text->beg + current_buffer->text->gpt_byte - BEG_BYTE)
    82 
    83 /* Address of end of gap in buffer.  */
    84 #define GAP_END_ADDR (current_buffer->text->beg + current_buffer->text->gpt_byte + current_buffer->text->gap_size - BEG_BYTE)
    85 
    86 /* Address of end of accessible range of buffer.  */
    87 #define ZV_ADDR (BYTE_POS_ADDR (current_buffer->zv_byte))
    88 
    89 /* Address of end of buffer.  */
    90 #define Z_ADDR (current_buffer->text->beg + current_buffer->text->gap_size + current_buffer->text->z_byte - BEG_BYTE)
    91 
    92 /* Size of gap.  */
    93 #define GAP_SIZE (current_buffer->text->gap_size)
    94 
    95 /* Modification count.  */
    96 #define MODIFF (current_buffer->text->modiff)
    97 
    98 /* Character modification count.  */
    99 #define CHARS_MODIFF (current_buffer->text->chars_modiff)
   100 
   101 /* Overlay modification count.  */
   102 #define OVERLAY_MODIFF (current_buffer->text->overlay_modiff)
   103 
   104 /* Modification count as of last visit or save.  */
   105 #define SAVE_MODIFF (current_buffer->text->save_modiff)
   106 
   107 
   108 /* Position of gap in buffer.  */
   109 #define BUF_GPT(buf) ((buf)->text->gpt)
   110 #define BUF_GPT_BYTE(buf) ((buf)->text->gpt_byte)
   111 
   112 /* Position of end of buffer.  */
   113 #define BUF_Z(buf) ((buf)->text->z)
   114 #define BUF_Z_BYTE(buf) ((buf)->text->z_byte)
   115 
   116 /* Address of beginning of buffer.  */
   117 #define BUF_BEG_ADDR(buf) ((buf)->text->beg)
   118 
   119 /* Size of gap.  */
   120 #define BUF_GAP_SIZE(buf) ((buf)->text->gap_size)
   121 
   122 /* Modification count.  */
   123 #define BUF_MODIFF(buf) ((buf)->text->modiff)
   124 
   125 /* Character modification count.  */
   126 #define BUF_CHARS_MODIFF(buf) ((buf)->text->chars_modiff)
   127 
   128 /* Modification count as of last visit or save.  */
   129 #define BUF_SAVE_MODIFF(buf) ((buf)->text->save_modiff)
   130 
   131 /* Overlay modification count.  */
   132 #define BUF_OVERLAY_MODIFF(buf) ((buf)->text->overlay_modiff)
   133 
   134 /* Modification count as of last auto-save.  */
   135 /* FIXME: should we move this into ->text->auto_save_modiff?  */
   136 #define BUF_AUTOSAVE_MODIFF(buf) ((buf)->auto_save_modified)
   137 
   138 /* Compaction count.  */
   139 #define BUF_COMPACT(buf) ((buf)->text->compact)
   140 
   141 /* Marker chain of buffer.  */
   142 #define BUF_MARKERS(buf) ((buf)->text->markers)
   143 
   144 #define BUF_UNCHANGED_MODIFIED(buf) \
   145   ((buf)->text->unchanged_modified)
   146 
   147 #define BUF_OVERLAY_UNCHANGED_MODIFIED(buf) \
   148   ((buf)->text->overlay_unchanged_modified)
   149 #define BUF_BEG_UNCHANGED(buf) ((buf)->text->beg_unchanged)
   150 #define BUF_END_UNCHANGED(buf) ((buf)->text->end_unchanged)
   151 
   152 #define UNCHANGED_MODIFIED \
   153   BUF_UNCHANGED_MODIFIED (current_buffer)
   154 #define OVERLAY_UNCHANGED_MODIFIED \
   155   BUF_OVERLAY_UNCHANGED_MODIFIED (current_buffer)
   156 #define BEG_UNCHANGED BUF_BEG_UNCHANGED (current_buffer)
   157 #define END_UNCHANGED BUF_END_UNCHANGED (current_buffer)
   158 
   159 /* Functions to set PT in the current buffer, or another buffer.  */
   160 
   161 extern void set_point (ptrdiff_t);
   162 extern void temp_set_point (struct buffer *, ptrdiff_t);
   163 extern void set_point_both (ptrdiff_t, ptrdiff_t);
   164 extern void temp_set_point_both (struct buffer *,
   165                                  ptrdiff_t, ptrdiff_t);
   166 extern void set_point_from_marker (Lisp_Object);
   167 extern void enlarge_buffer_text (struct buffer *, ptrdiff_t);
   168 
   169 INLINE void
   170 SET_PT (ptrdiff_t position)
   171 {
   172   set_point (position);
   173 }
   174 INLINE void
   175 TEMP_SET_PT (ptrdiff_t position)
   176 {
   177   temp_set_point (current_buffer, position);
   178 }
   179 INLINE void
   180 SET_PT_BOTH (ptrdiff_t position, ptrdiff_t byte)
   181 {
   182   set_point_both (position, byte);
   183 }
   184 INLINE void
   185 TEMP_SET_PT_BOTH (ptrdiff_t position, ptrdiff_t byte)
   186 {
   187   temp_set_point_both (current_buffer, position, byte);
   188 }
   189 INLINE void
   190 BUF_TEMP_SET_PT (struct buffer *buffer, ptrdiff_t position)
   191 {
   192   temp_set_point (buffer, position);
   193 }
   194 
   195 /* Maximum number of bytes in a buffer.
   196    A buffer cannot contain more bytes than a 1-origin fixnum can represent,
   197    nor can it be so large that C pointer arithmetic stops working.
   198    The ptrdiff_t cast ensures that this is signed, not unsigned.  */
   199 #define BUF_BYTES_MAX \
   200   (ptrdiff_t) min (MOST_POSITIVE_FIXNUM - 1, min (SIZE_MAX, PTRDIFF_MAX))
   201 
   202 /* Maximum gap size after compact_buffer, in bytes.  Also
   203    used in make_gap_larger to get some extra reserved space.  */
   204 
   205 enum { GAP_BYTES_DFL = 2000 };
   206 
   207 /* Minimum gap size after compact_buffer, in bytes.  Also
   208    used in make_gap_smaller to avoid too small gap size.  */
   209 
   210 enum { GAP_BYTES_MIN = 20 };
   211 
   212 /* For those very rare cases where you may have a "random" pointer into
   213    the middle of a multibyte char, this moves to the next boundary.  */
   214 extern ptrdiff_t advance_to_char_boundary (ptrdiff_t byte_pos);
   215 
   216 /* Return the byte at byte position N.
   217    Do not check that the position is in range.  */
   218 
   219 #define FETCH_BYTE(n) *(BYTE_POS_ADDR ((n)))
   220 
   221 /* Define the actual buffer data structures.  */
   222 
   223 /* This data structure describes the actual text contents of a buffer.
   224    It is shared between indirect buffers and their base buffer.  */
   225 
   226 struct buffer_text
   227   {
   228     /* Actual address of buffer contents.  If REL_ALLOC is defined,
   229        this address might change when blocks are relocated which can
   230        e.g. happen when malloc is called.  So, don't pass a pointer
   231        into a buffer's text to functions that malloc.  */
   232     unsigned char *beg;
   233 
   234     ptrdiff_t gpt;              /* Char pos of gap in buffer.  */
   235     ptrdiff_t z;                /* Char pos of end of buffer.  */
   236     ptrdiff_t gpt_byte;         /* Byte pos of gap in buffer.  */
   237     ptrdiff_t z_byte;           /* Byte pos of end of buffer.  */
   238     ptrdiff_t gap_size;         /* Size of buffer's gap.  */
   239     modiff_count modiff;        /* This counts buffer-modification events
   240                                    for this buffer.  It is increased
   241                                    logarithmically to the extent of the
   242                                    modification for each such event,
   243                                    and never otherwise changed.  */
   244     modiff_count chars_modiff;  /* This is modified with character change
   245                                    events for this buffer.  It is set to
   246                                    modiff for each such event, and never
   247                                    otherwise changed.  */
   248     modiff_count save_modiff;   /* Previous value of modiff, as of last
   249                                    time buffer visited or saved a file.  */
   250 
   251     modiff_count overlay_modiff; /* Counts modifications to overlays.  */
   252 
   253     modiff_count compact;       /* Set to modiff each time when compact_buffer
   254                                    is called for this buffer.  */
   255 
   256     /* Minimum value of GPT - BEG since last redisplay that finished.  */
   257     ptrdiff_t beg_unchanged;
   258 
   259     /* Minimum value of Z - GPT since last redisplay that finished.  */
   260     ptrdiff_t end_unchanged;
   261 
   262     /* MODIFF as of last redisplay that finished; if it matches MODIFF,
   263        beg_unchanged and end_unchanged contain no useful information.  */
   264     modiff_count unchanged_modified;
   265 
   266     /* BUF_OVERLAY_MODIFF of current buffer, as of last redisplay that
   267        finished; if it matches BUF_OVERLAY_MODIFF, beg_unchanged and
   268        end_unchanged contain no useful information.  */
   269     modiff_count overlay_unchanged_modified;
   270 
   271     /* Properties of this buffer's text.  */
   272     INTERVAL intervals;
   273 
   274     /* The markers that refer to this buffer.
   275        This is actually a single marker ---
   276        successive elements in its marker `chain'
   277        are the other markers referring to this buffer.
   278        This is a singly linked unordered list, which means that it's
   279        very cheap to add a marker to the list and it's also very cheap
   280        to move a marker within a buffer.  */
   281     struct Lisp_Marker *markers;
   282 
   283     /* Usually false.  Temporarily true in decode_coding_gap to
   284        prevent Fgarbage_collect from shrinking the gap and losing
   285        not-yet-decoded bytes.  */
   286     bool_bf inhibit_shrinking : 1;
   287 
   288     /* True if it needs to be redisplayed.  */
   289     bool_bf redisplay : 1;
   290   };
   291 
   292 /* Most code should use this macro to access Lisp fields in struct buffer.  */
   293 
   294 #define BVAR(buf, field) ((buf)->field ## _)
   295 
   296 /* Max number of builtin per-buffer variables.  */
   297 enum { MAX_PER_BUFFER_VARS = 50 };
   298 
   299 /* Special values for struct buffer.modtime.  */
   300 enum { NONEXISTENT_MODTIME_NSECS = -1 };
   301 enum { UNKNOWN_MODTIME_NSECS = -2 };
   302 
   303 /* This is the structure that the buffer Lisp object points to.  */
   304 
   305 struct buffer
   306 {
   307   union vectorlike_header header;
   308 
   309   /* The name of this buffer.  */
   310   Lisp_Object name_;
   311 
   312   /* The name of the file visited in this buffer, or nil.  */
   313   Lisp_Object filename_;
   314 
   315   /* Directory for expanding relative file names.  */
   316   Lisp_Object directory_;
   317 
   318   /* True if this buffer has been backed up (if you write to the visited
   319      file and it hasn't been backed up, then a backup will be made).  */
   320   Lisp_Object backed_up_;
   321 
   322   /* Length of file when last read or saved.
   323      -1 means auto saving turned off because buffer shrank a lot.
   324      -2 means don't turn off auto saving if buffer shrinks.
   325        (That value is used with buffer-swap-text.)
   326      This is not in the  struct buffer_text
   327      because it's not used in indirect buffers at all.  */
   328   Lisp_Object save_length_;
   329 
   330   /* File name used for auto-saving this buffer.
   331      This is not in the  struct buffer_text
   332      because it's not used in indirect buffers at all.  */
   333   Lisp_Object auto_save_file_name_;
   334 
   335   /* Non-nil if buffer read-only.  */
   336   Lisp_Object read_only_;
   337 
   338   /* "The mark".  This is a marker which may
   339      point into this buffer or may point nowhere.  */
   340   Lisp_Object mark_;
   341 
   342   /* Alist of elements (SYMBOL . VALUE-IN-THIS-BUFFER) for all
   343      per-buffer variables of this buffer.  For locally unbound
   344      symbols, just the symbol appears as the element.  */
   345   Lisp_Object local_var_alist_;
   346 
   347   /* Symbol naming major mode (e.g., lisp-mode).  */
   348   Lisp_Object major_mode_;
   349 
   350   /* Symbol listing all currently enabled minor modes.  */
   351   Lisp_Object local_minor_modes_;
   352 
   353   /* Pretty name of major mode (e.g., "Lisp"). */
   354   Lisp_Object mode_name_;
   355 
   356   /* Mode line element that controls format of mode line.  */
   357   Lisp_Object mode_line_format_;
   358 
   359   /* Analogous to mode_line_format for the line displayed at the top
   360      of windows.  Nil means don't display that line.  */
   361   Lisp_Object header_line_format_;
   362 
   363   /* Analogous to mode_line_format for the line displayed at the top
   364      of windows.  Nil means don't display that line.  */
   365   Lisp_Object tab_line_format_;
   366 
   367   /* Keys that are bound local to this buffer.  */
   368   Lisp_Object keymap_;
   369 
   370   /* This buffer's local abbrev table.  */
   371   Lisp_Object abbrev_table_;
   372 
   373   /* This buffer's syntax table.  */
   374   Lisp_Object syntax_table_;
   375 
   376   /* This buffer's category table.  */
   377   Lisp_Object category_table_;
   378 
   379   /* Values of several buffer-local variables.  */
   380   /* tab-width is buffer-local so that redisplay can find it
   381      in buffers that are not current.  */
   382   Lisp_Object case_fold_search_;
   383   Lisp_Object tab_width_;
   384   Lisp_Object fill_column_;
   385   Lisp_Object left_margin_;
   386 
   387   /* Function to call when insert space past fill column.  */
   388   Lisp_Object auto_fill_function_;
   389 
   390   /* Case table for case-conversion in this buffer.
   391      This char-table maps each char into its lower-case version.  */
   392   Lisp_Object downcase_table_;
   393 
   394   /* Char-table mapping each char to its upper-case version.  */
   395   Lisp_Object upcase_table_;
   396 
   397   /* Char-table for conversion for case-folding search.  */
   398   Lisp_Object case_canon_table_;
   399 
   400   /* Char-table of equivalences for case-folding search.  */
   401   Lisp_Object case_eqv_table_;
   402 
   403   /* Non-nil means do not display continuation lines.  */
   404   Lisp_Object truncate_lines_;
   405 
   406   /* Non-nil means to use word wrapping when displaying continuation lines.  */
   407   Lisp_Object word_wrap_;
   408 
   409   /* Non-nil means display ctl chars with uparrow.  */
   410   Lisp_Object ctl_arrow_;
   411 
   412   /* Non-nil means reorder bidirectional text for display in the
   413      visual order.  */
   414   Lisp_Object bidi_display_reordering_;
   415 
   416   /* If non-nil, specifies which direction of text to force in all the
   417      paragraphs of the buffer.  Nil means determine paragraph
   418      direction dynamically for each paragraph.  */
   419   Lisp_Object bidi_paragraph_direction_;
   420 
   421   /* If non-nil, a regular expression for bidi paragraph separator.  */
   422   Lisp_Object bidi_paragraph_separate_re_;
   423 
   424   /* If non-nil, a regular expression for bidi paragraph start.  */
   425   Lisp_Object bidi_paragraph_start_re_;
   426 
   427   /* Non-nil means do selective display;
   428      see doc string in syms_of_buffer (buffer.c) for details.  */
   429   Lisp_Object selective_display_;
   430 
   431   /* Non-nil means show ... at end of line followed by invisible lines.  */
   432   Lisp_Object selective_display_ellipses_;
   433 
   434   /* t if "self-insertion" should overwrite; `binary' if it should also
   435      overwrite newlines and tabs - for editing executables and the like.  */
   436   Lisp_Object overwrite_mode_;
   437 
   438   /* Non-nil means abbrev mode is on.  Expand abbrevs automatically.  */
   439   Lisp_Object abbrev_mode_;
   440 
   441   /* Display table to use for text in this buffer.  */
   442   Lisp_Object display_table_;
   443 
   444   /* t means the mark and region are currently active.  */
   445   Lisp_Object mark_active_;
   446 
   447   /* Non-nil means the buffer contents are regarded as multi-byte
   448      form of characters, not a binary code.  */
   449   Lisp_Object enable_multibyte_characters_;
   450 
   451   /* Coding system to be used for encoding the buffer contents on
   452      saving.  */
   453   Lisp_Object buffer_file_coding_system_;
   454 
   455   /* List of symbols naming the file format used for visited file.  */
   456   Lisp_Object file_format_;
   457 
   458   /* List of symbols naming the file format used for auto-save file.  */
   459   Lisp_Object auto_save_file_format_;
   460 
   461   /* True if the newline position cache, width run cache and BIDI paragraph
   462      cache are enabled.  See search.c, indent.c and bidi.c for details.  */
   463   Lisp_Object cache_long_scans_;
   464 
   465   /* If the width run cache is enabled, this table contains the
   466      character widths width_run_cache (see above) assumes.  When we
   467      do a thorough redisplay, we compare this against the buffer's
   468      current display table to see whether the display table has
   469      affected the widths of any characters.  If it has, we
   470      invalidate the width run cache, and re-initialize width_table.  */
   471   Lisp_Object width_table_;
   472 
   473   /* In an indirect buffer, or a buffer that is the base of an
   474      indirect buffer, this holds a marker that records
   475      PT for this buffer when the buffer is not current.  */
   476   Lisp_Object pt_marker_;
   477 
   478   /* In an indirect buffer, or a buffer that is the base of an
   479      indirect buffer, this holds a marker that records
   480      BEGV for this buffer when the buffer is not current.  */
   481   Lisp_Object begv_marker_;
   482 
   483   /* In an indirect buffer, or a buffer that is the base of an
   484      indirect buffer, this holds a marker that records
   485      ZV for this buffer when the buffer is not current.  */
   486   Lisp_Object zv_marker_;
   487 
   488   /* This holds the point value before the last scroll operation.
   489      Explicitly setting point sets this to nil.  */
   490   Lisp_Object point_before_scroll_;
   491 
   492   /* Truename of the visited file, or nil.  */
   493   Lisp_Object file_truename_;
   494 
   495   /* Invisibility spec of this buffer.
   496      t => any non-nil `invisible' property means invisible.
   497      A list => `invisible' property means invisible
   498      if it is memq in that list.  */
   499   Lisp_Object invisibility_spec_;
   500 
   501   /* This is the last window that was selected with this buffer in it,
   502      or nil if that window no longer displays this buffer.  */
   503   Lisp_Object last_selected_window_;
   504 
   505   /* Incremented each time the buffer is displayed in a window.  */
   506   Lisp_Object display_count_;
   507 
   508   /* Widths of left and right marginal areas for windows displaying
   509      this buffer.  */
   510   Lisp_Object left_margin_cols_;
   511   Lisp_Object right_margin_cols_;
   512 
   513   /* Widths of left and right fringe areas for windows displaying
   514      this buffer.  */
   515   Lisp_Object left_fringe_width_;
   516   Lisp_Object right_fringe_width_;
   517 
   518   /* Non-nil means fringes are drawn outside display margins;
   519      othersize draw them between margin areas and text.  */
   520   Lisp_Object fringes_outside_margins_;
   521 
   522   /* Width, height and types of scroll bar areas for windows displaying
   523      this buffer.  */
   524   Lisp_Object scroll_bar_width_;
   525   Lisp_Object scroll_bar_height_;
   526   Lisp_Object vertical_scroll_bar_type_;
   527   Lisp_Object horizontal_scroll_bar_type_;
   528 
   529   /* Non-nil means indicate lines not displaying text (in a style
   530      like vi).  */
   531   Lisp_Object indicate_empty_lines_;
   532 
   533   /* Non-nil means indicate buffer boundaries and scrolling.  */
   534   Lisp_Object indicate_buffer_boundaries_;
   535 
   536   /* Logical to physical fringe bitmap mappings.  */
   537   Lisp_Object fringe_indicator_alist_;
   538 
   539   /* Logical to physical cursor bitmap mappings.  */
   540   Lisp_Object fringe_cursor_alist_;
   541 
   542   /* Time stamp updated each time this buffer is displayed in a window.  */
   543   Lisp_Object display_time_;
   544 
   545   /* If scrolling the display because point is below the bottom of a
   546      window showing this buffer, try to choose a window start so
   547      that point ends up this number of lines from the top of the
   548      window.  Nil means that scrolling method isn't used.  */
   549   Lisp_Object scroll_up_aggressively_;
   550 
   551   /* If scrolling the display because point is above the top of a
   552      window showing this buffer, try to choose a window start so
   553      that point ends up this number of lines from the bottom of the
   554      window.  Nil means that scrolling method isn't used.  */
   555   Lisp_Object scroll_down_aggressively_;
   556 
   557   /* Desired cursor type in this buffer.  See the doc string of
   558      per-buffer variable `cursor-type'.  */
   559   Lisp_Object cursor_type_;
   560 
   561   /* An integer > 0 means put that number of pixels below text lines
   562      in the display of this buffer.  */
   563   Lisp_Object extra_line_spacing_;
   564 
   565 #ifdef HAVE_TREE_SITTER
   566   /* A list of tree-sitter parsers for this buffer.  */
   567   Lisp_Object ts_parser_list_;
   568 #endif
   569   /* Cursor type to display in non-selected windows.
   570      t means to use hollow box cursor.
   571      See `cursor-type' for other values.  */
   572   Lisp_Object cursor_in_non_selected_windows_;
   573 
   574   /* No more Lisp_Object beyond cursor_in_non_selected_windows_.
   575      Except undo_list, which is handled specially in Fgarbage_collect.  */
   576 
   577   /* This structure holds the coordinates of the buffer contents
   578      in ordinary buffers.  In indirect buffers, this is not used.  */
   579   struct buffer_text own_text;
   580 
   581   /* This points to the `struct buffer_text' that used for this buffer.
   582      In an ordinary buffer, this is the own_text field above.
   583      In an indirect buffer, this is the own_text field of another buffer.  */
   584   struct buffer_text *text;
   585 
   586   /* Char position of point in buffer.  */
   587   ptrdiff_t pt;
   588 
   589   /* Byte position of point in buffer.  */
   590   ptrdiff_t pt_byte;
   591 
   592   /* Char position of beginning of accessible range.  */
   593   ptrdiff_t begv;
   594 
   595   /* Byte position of beginning of accessible range.  */
   596   ptrdiff_t begv_byte;
   597 
   598   /* Char position of end of accessible range.  */
   599   ptrdiff_t zv;
   600 
   601   /* Byte position of end of accessible range.  */
   602   ptrdiff_t zv_byte;
   603 
   604   /* In an indirect buffer, this points to the base buffer.
   605      In an ordinary buffer, it is 0.  */
   606   struct buffer *base_buffer;
   607 
   608   /* In an indirect buffer, this is -1.  In an ordinary buffer,
   609      it's the number of indirect buffers that share our text;
   610      zero means that we're the only owner of this text.  */
   611   int indirections;
   612 
   613   /* Number of windows showing this buffer.  Always -1 for
   614      an indirect buffer since it counts as its base buffer.  */
   615   int window_count;
   616 
   617   /* A non-zero value in slot IDX means that per-buffer variable
   618      with index IDX has a local value in this buffer.  The index IDX
   619      for a buffer-local variable is stored in that variable's slot
   620      in buffer_local_flags as a Lisp integer.  If the index is -1,
   621      this means the variable is always local in all buffers.  */
   622   char local_flags[MAX_PER_BUFFER_VARS];
   623 
   624   /* Set to the modtime of the visited file when read or written.
   625      modtime.tv_nsec == NONEXISTENT_MODTIME_NSECS means
   626      visited file was nonexistent.  modtime.tv_nsec ==
   627      UNKNOWN_MODTIME_NSECS means visited file modtime unknown;
   628      in no case complain about any mismatch on next save attempt.  */
   629   struct timespec modtime;
   630 
   631   /* Size of the file when modtime was set.  This is used to detect the
   632      case where the file grew while we were reading it, so the modtime
   633      is still the same (since it's rounded up to seconds) but we're actually
   634      not up-to-date.  -1 means the size is unknown.  Only meaningful if
   635      modtime is actually set.  */
   636   off_t modtime_size;
   637 
   638   /* The value of text->modiff at the last auto-save.  */
   639   modiff_count auto_save_modified;
   640 
   641   /* The value of text->modiff at the last display error.
   642      Redisplay of this buffer is inhibited until it changes again.  */
   643   modiff_count display_error_modiff;
   644 
   645   /* The time at which we detected a failure to auto-save,
   646      Or 0 if we didn't have a failure.  */
   647   time_t auto_save_failure_time;
   648 
   649   /* Position in buffer at which display started
   650      the last time this buffer was displayed.  */
   651   ptrdiff_t last_window_start;
   652 
   653   /* If the long line scan cache is enabled (i.e. the buffer-local
   654      variable cache-long-line-scans is non-nil), newline_cache
   655      points to the newline cache, and width_run_cache points to the
   656      width run cache.
   657 
   658      The newline cache records which stretches of the buffer are
   659      known *not* to contain newlines, so that they can be skipped
   660      quickly when we search for newlines.
   661 
   662      The width run cache records which stretches of the buffer are
   663      known to contain characters whose widths are all the same.  If
   664      the width run cache maps a character to a value > 0, that value is
   665      the character's width; if it maps a character to zero, we don't
   666      know what its width is.  This allows compute_motion to process
   667      such regions very quickly, using algebra instead of inspecting
   668      each character.   See also width_table, below.
   669 
   670      The latter cache is used to speedup bidi_find_paragraph_start.  */
   671   struct region_cache *newline_cache;
   672   struct region_cache *width_run_cache;
   673   struct region_cache *bidi_paragraph_cache;
   674 
   675   /* Non-zero means disable redisplay optimizations when rebuilding the glyph
   676      matrices (but not when redrawing).  */
   677   bool_bf prevent_redisplay_optimizations_p : 1;
   678 
   679   /* Non-zero whenever the narrowing is changed in this buffer.  */
   680   bool_bf clip_changed : 1;
   681 
   682   /* Non-zero for internal or temporary buffers that don't need to
   683      run hooks kill-buffer-hook, kill-buffer-query-functions, and
   684      buffer-list-update-hook.  This is used in coding.c to avoid
   685      slowing down en/decoding when a lot of these hooks are
   686      defined, as well as by with-temp-buffer, for example.  */
   687   bool_bf inhibit_buffer_hooks : 1;
   688 
   689   /* Non-zero when the buffer contains long lines and specific
   690      display optimizations must be used.  */
   691   bool_bf long_line_optimizations_p : 1;
   692 
   693   /* The interval tree containing this buffer's overlays. */
   694   struct itree_tree *overlays;
   695 
   696   /* Changes in the buffer are recorded here for undo, and t means
   697      don't record anything.  This information belongs to the base
   698      buffer of an indirect buffer.  But we can't store it in the
   699      struct buffer_text because local variables have to be right in
   700      the struct buffer. So we copy it around in set_buffer_internal.  */
   701   Lisp_Object undo_list_;
   702 };
   703 
   704 struct sortvec
   705 {
   706   Lisp_Object overlay;
   707   ptrdiff_t beg, end;
   708   EMACS_INT priority;
   709   EMACS_INT spriority;          /* Secondary priority.  */
   710 };
   711 
   712 INLINE bool
   713 BUFFERP (Lisp_Object a)
   714 {
   715   return PSEUDOVECTORP (a, PVEC_BUFFER);
   716 }
   717 
   718 INLINE void
   719 CHECK_BUFFER (Lisp_Object x)
   720 {
   721   CHECK_TYPE (BUFFERP (x), Qbufferp, x);
   722 }
   723 
   724 INLINE struct buffer *
   725 XBUFFER (Lisp_Object a)
   726 {
   727   eassert (BUFFERP (a));
   728   return XUNTAG (a, Lisp_Vectorlike, struct buffer);
   729 }
   730 
   731 /* Most code should use these functions to set Lisp fields in struct
   732    buffer.  (Some setters that are private to a single .c file are
   733    defined as static in those files.)  */
   734 INLINE void
   735 bset_bidi_paragraph_direction (struct buffer *b, Lisp_Object val)
   736 {
   737   b->bidi_paragraph_direction_ = val;
   738 }
   739 INLINE void
   740 bset_cache_long_scans (struct buffer *b, Lisp_Object val)
   741 {
   742   b->cache_long_scans_ = val;
   743 }
   744 INLINE void
   745 bset_case_canon_table (struct buffer *b, Lisp_Object val)
   746 {
   747   b->case_canon_table_ = val;
   748 }
   749 INLINE void
   750 bset_case_eqv_table (struct buffer *b, Lisp_Object val)
   751 {
   752   b->case_eqv_table_ = val;
   753 }
   754 INLINE void
   755 bset_directory (struct buffer *b, Lisp_Object val)
   756 {
   757   b->directory_ = val;
   758 }
   759 INLINE void
   760 bset_display_count (struct buffer *b, Lisp_Object val)
   761 {
   762   b->display_count_ = val;
   763 }
   764 INLINE void
   765 bset_left_margin_cols (struct buffer *b, Lisp_Object val)
   766 {
   767   b->left_margin_cols_ = val;
   768 }
   769 INLINE void
   770 bset_right_margin_cols (struct buffer *b, Lisp_Object val)
   771 {
   772   b->right_margin_cols_ = val;
   773 }
   774 INLINE void
   775 bset_display_time (struct buffer *b, Lisp_Object val)
   776 {
   777   b->display_time_ = val;
   778 }
   779 INLINE void
   780 bset_downcase_table (struct buffer *b, Lisp_Object val)
   781 {
   782   b->downcase_table_ = val;
   783 }
   784 INLINE void
   785 bset_enable_multibyte_characters (struct buffer *b, Lisp_Object val)
   786 {
   787   b->enable_multibyte_characters_ = val;
   788 }
   789 INLINE void
   790 bset_filename (struct buffer *b, Lisp_Object val)
   791 {
   792   b->filename_ = val;
   793 }
   794 INLINE void
   795 bset_keymap (struct buffer *b, Lisp_Object val)
   796 {
   797   b->keymap_ = val;
   798 }
   799 INLINE void
   800 bset_last_selected_window (struct buffer *b, Lisp_Object val)
   801 {
   802   b->last_selected_window_ = val;
   803 }
   804 INLINE void
   805 bset_local_var_alist (struct buffer *b, Lisp_Object val)
   806 {
   807   b->local_var_alist_ = val;
   808 }
   809 INLINE void
   810 bset_mark_active (struct buffer *b, Lisp_Object val)
   811 {
   812   b->mark_active_ = val;
   813 }
   814 INLINE void
   815 bset_point_before_scroll (struct buffer *b, Lisp_Object val)
   816 {
   817   b->point_before_scroll_ = val;
   818 }
   819 INLINE void
   820 bset_read_only (struct buffer *b, Lisp_Object val)
   821 {
   822   b->read_only_ = val;
   823 }
   824 INLINE void
   825 bset_truncate_lines (struct buffer *b, Lisp_Object val)
   826 {
   827   b->truncate_lines_ = val;
   828 }
   829 INLINE void
   830 bset_undo_list (struct buffer *b, Lisp_Object val)
   831 {
   832   b->undo_list_ = val;
   833 }
   834 INLINE void
   835 bset_upcase_table (struct buffer *b, Lisp_Object val)
   836 {
   837   b->upcase_table_ = val;
   838 }
   839 INLINE void
   840 bset_width_table (struct buffer *b, Lisp_Object val)
   841 {
   842   b->width_table_ = val;
   843 }
   844 
   845 /* BUFFER_CEILING_OF (resp. BUFFER_FLOOR_OF), when applied to n, return
   846    the max (resp. min) p such that
   847 
   848    BYTE_POS_ADDR (p) - BYTE_POS_ADDR (n) == p - n       */
   849 
   850 INLINE ptrdiff_t
   851 BUFFER_CEILING_OF (ptrdiff_t bytepos)
   852 {
   853   return (bytepos < GPT_BYTE && GPT < ZV ? GPT_BYTE : ZV_BYTE) - 1;
   854 }
   855 
   856 INLINE ptrdiff_t
   857 BUFFER_FLOOR_OF (ptrdiff_t bytepos)
   858 {
   859   return BEGV <= GPT && GPT_BYTE <= bytepos ? GPT_BYTE : BEGV_BYTE;
   860 }
   861 
   862 /* The BUF_BEGV[_BYTE], BUF_ZV[_BYTE], and BUF_PT[_BYTE] functions cannot
   863    be used for assignment; use SET_BUF_* functions below for that.  */
   864 
   865 /* Position of beginning of accessible range of buffer.  */
   866 INLINE ptrdiff_t
   867 BUF_BEGV (struct buffer *buf)
   868 {
   869   return (buf == current_buffer ? BEGV
   870           : NILP (BVAR (buf, begv_marker)) ? buf->begv
   871           : marker_position (BVAR (buf, begv_marker)));
   872 }
   873 
   874 INLINE ptrdiff_t
   875 BUF_BEGV_BYTE (struct buffer *buf)
   876 {
   877   return (buf == current_buffer ? BEGV_BYTE
   878           : NILP (BVAR (buf, begv_marker)) ? buf->begv_byte
   879           : marker_byte_position (BVAR (buf, begv_marker)));
   880 }
   881 
   882 /* Position of point in buffer.  */
   883 INLINE ptrdiff_t
   884 BUF_PT (struct buffer *buf)
   885 {
   886   return (buf == current_buffer ? PT
   887           : NILP (BVAR (buf, pt_marker)) ? buf->pt
   888           : marker_position (BVAR (buf, pt_marker)));
   889 }
   890 
   891 INLINE ptrdiff_t
   892 BUF_PT_BYTE (struct buffer *buf)
   893 {
   894   return (buf == current_buffer ? PT_BYTE
   895           : NILP (BVAR (buf, pt_marker)) ? buf->pt_byte
   896           : marker_byte_position (BVAR (buf, pt_marker)));
   897 }
   898 
   899 /* Position of end of accessible range of buffer.  */
   900 INLINE ptrdiff_t
   901 BUF_ZV (struct buffer *buf)
   902 {
   903   return (buf == current_buffer ? ZV
   904           : NILP (BVAR (buf, zv_marker)) ? buf->zv
   905           : marker_position (BVAR (buf, zv_marker)));
   906 }
   907 
   908 INLINE ptrdiff_t
   909 BUF_ZV_BYTE (struct buffer *buf)
   910 {
   911   return (buf == current_buffer ? ZV_BYTE
   912           : NILP (BVAR (buf, zv_marker)) ? buf->zv_byte
   913           : marker_byte_position (BVAR (buf, zv_marker)));
   914 }
   915 
   916 /* Similar functions to operate on a specified buffer.  */
   917 
   918 /* Position of beginning of buffer.  */
   919 INLINE ptrdiff_t
   920 BUF_BEG (struct buffer *buf)
   921 {
   922   return BEG;
   923 }
   924 
   925 INLINE ptrdiff_t
   926 BUF_BEG_BYTE (struct buffer *buf)
   927 {
   928   return BEG_BYTE;
   929 }
   930 
   931 /* Address of beginning of gap of buffer.  */
   932 INLINE unsigned char *
   933 BUF_GPT_ADDR (struct buffer *buf)
   934 {
   935   return buf->text->beg + buf->text->gpt_byte - BEG_BYTE;
   936 }
   937 
   938 /* Address of end of buffer.  */
   939 INLINE unsigned char *
   940 BUF_Z_ADDR (struct buffer *buf)
   941 {
   942   return buf->text->beg + buf->text->gap_size + buf->text->z_byte - BEG_BYTE;
   943 }
   944 
   945 /* Address of end of gap in buffer.  */
   946 INLINE unsigned char *
   947 BUF_GAP_END_ADDR (struct buffer *buf)
   948 {
   949   return buf->text->beg + buf->text->gpt_byte + buf->text->gap_size - BEG_BYTE;
   950 }
   951 
   952 /* Compute how many characters at the top and bottom of BUF are
   953    unchanged when the range START..END is modified.  This computation
   954    must be done each time BUF is modified.  */
   955 
   956 INLINE void
   957 BUF_COMPUTE_UNCHANGED (struct buffer *buf, ptrdiff_t start, ptrdiff_t end)
   958 {
   959   if (BUF_UNCHANGED_MODIFIED (buf) == BUF_MODIFF (buf)
   960       && (BUF_OVERLAY_UNCHANGED_MODIFIED (buf)
   961           == BUF_OVERLAY_MODIFF (buf)))
   962     {
   963       buf->text->beg_unchanged = start - BUF_BEG (buf);
   964       buf->text->end_unchanged = BUF_Z (buf) - (end);
   965     }
   966   else
   967     {
   968       if (BUF_Z (buf) - end < BUF_END_UNCHANGED (buf))
   969         buf->text->end_unchanged = BUF_Z (buf) - end;
   970       if (start - BUF_BEG (buf) < BUF_BEG_UNCHANGED (buf))
   971         buf->text->beg_unchanged = start - BUF_BEG (buf);
   972     }
   973 }
   974 
   975 /* Functions for setting the BEGV, ZV or PT of a given buffer.
   976 
   977    The ..._BOTH functions take both a charpos and a bytepos,
   978    which must correspond to each other.
   979 
   980    The functions without ..._BOTH take just a charpos,
   981    and compute the bytepos from it.  */
   982 
   983 INLINE void
   984 SET_BUF_BEGV (struct buffer *buf, ptrdiff_t charpos)
   985 {
   986   buf->begv_byte = buf_charpos_to_bytepos (buf, charpos);
   987   buf->begv = charpos;
   988 }
   989 
   990 INLINE void
   991 SET_BUF_ZV (struct buffer *buf, ptrdiff_t charpos)
   992 {
   993   buf->zv_byte = buf_charpos_to_bytepos (buf, charpos);
   994   buf->zv = charpos;
   995 }
   996 
   997 INLINE void
   998 SET_BUF_BEGV_BOTH (struct buffer *buf, ptrdiff_t charpos, ptrdiff_t byte)
   999 {
  1000   buf->begv = charpos;
  1001   buf->begv_byte = byte;
  1002 }
  1003 
  1004 INLINE void
  1005 SET_BUF_ZV_BOTH (struct buffer *buf, ptrdiff_t charpos, ptrdiff_t byte)
  1006 {
  1007   buf->zv = charpos;
  1008   buf->zv_byte = byte;
  1009 }
  1010 
  1011 INLINE void
  1012 SET_BUF_PT_BOTH (struct buffer *buf, ptrdiff_t charpos, ptrdiff_t byte)
  1013 {
  1014   buf->pt = charpos;
  1015   buf->pt_byte = byte;
  1016 }
  1017 
  1018 /* Functions to access a character or byte in the current buffer,
  1019    or convert between a byte position and an address.
  1020    These functions do not check that the position is in range.  */
  1021 
  1022 /* See the important WARNING above about using the 'char *' pointers
  1023    returned by these functions.  */
  1024 
  1025 /* Return the address of byte position N in current buffer.  */
  1026 
  1027 INLINE unsigned char *
  1028 BYTE_POS_ADDR (ptrdiff_t n)
  1029 {
  1030   return (n < GPT_BYTE ? 0 : GAP_SIZE) + n + BEG_ADDR - BEG_BYTE;
  1031 }
  1032 
  1033 /* Return the address of char position N.  */
  1034 
  1035 INLINE unsigned char *
  1036 CHAR_POS_ADDR (ptrdiff_t n)
  1037 {
  1038   return ((n < GPT ? 0 : GAP_SIZE)
  1039           + buf_charpos_to_bytepos (current_buffer, n)
  1040           + BEG_ADDR - BEG_BYTE);
  1041 }
  1042 
  1043 /* Convert a character position to a byte position.  */
  1044 
  1045 INLINE ptrdiff_t
  1046 CHAR_TO_BYTE (ptrdiff_t charpos)
  1047 {
  1048   return buf_charpos_to_bytepos (current_buffer, charpos);
  1049 }
  1050 
  1051 /* Convert a byte position to a character position.  */
  1052 
  1053 INLINE ptrdiff_t
  1054 BYTE_TO_CHAR (ptrdiff_t bytepos)
  1055 {
  1056   return buf_bytepos_to_charpos (current_buffer, bytepos);
  1057 }
  1058 
  1059 /* Convert PTR, the address of a byte in the buffer, into a byte position.  */
  1060 
  1061 INLINE ptrdiff_t
  1062 PTR_BYTE_POS (unsigned char const *ptr)
  1063 {
  1064   ptrdiff_t byte = ptr - current_buffer->text->beg;
  1065   return byte - (byte <= GPT_BYTE - BEG_BYTE ? 0 : GAP_SIZE) + BEG_BYTE;
  1066 }
  1067 
  1068 /* Number of Lisp_Objects at the beginning of struct buffer.
  1069    If you add, remove, or reorder Lisp_Objects within buffer
  1070    structure, make sure that this is still correct.  */
  1071 
  1072 enum { BUFFER_LISP_SIZE = PSEUDOVECSIZE (struct buffer,
  1073                                          cursor_in_non_selected_windows_) };
  1074 
  1075 /* Allocated size of the struct buffer part beyond leading
  1076    Lisp_Objects, in word_size units.  */
  1077 
  1078 enum { BUFFER_REST_SIZE = VECSIZE (struct buffer) - BUFFER_LISP_SIZE };
  1079 
  1080 /* Initialize the pseudovector header of buffer object.  BUFFER_LISP_SIZE
  1081    is required for GC, but BUFFER_REST_SIZE is set up just to be consistent
  1082    with other pseudovectors.  */
  1083 
  1084 INLINE void
  1085 BUFFER_PVEC_INIT (struct buffer *b)
  1086 {
  1087   XSETPVECTYPESIZE (b, PVEC_BUFFER, BUFFER_LISP_SIZE, BUFFER_REST_SIZE);
  1088 }
  1089 
  1090 /* Convenient check whether buffer B is live.  */
  1091 
  1092 INLINE bool
  1093 BUFFER_LIVE_P (struct buffer *b)
  1094 {
  1095   return !NILP (BVAR (b, name));
  1096 }
  1097 
  1098 /* Convenient check whether buffer B is hidden (i.e. its name
  1099    starts with a space).  Caller must ensure that B is live.  */
  1100 
  1101 INLINE bool
  1102 BUFFER_HIDDEN_P (struct buffer *b)
  1103 {
  1104   return SREF (BVAR (b, name), 0) == ' ';
  1105 }
  1106 
  1107 /* Verify indirection counters.  */
  1108 
  1109 INLINE void
  1110 BUFFER_CHECK_INDIRECTION (struct buffer *b)
  1111 {
  1112   if (BUFFER_LIVE_P (b))
  1113     {
  1114       if (b->base_buffer)
  1115         {
  1116           eassert (b->indirections == -1);
  1117           eassert (b->base_buffer->indirections > 0);
  1118         }
  1119       else
  1120         eassert (b->indirections >= 0);
  1121     }
  1122 }
  1123 
  1124 /* This structure holds the default values of the buffer-local variables
  1125    that have special slots in each buffer.
  1126    The default value occupies the same slot in this structure
  1127    as an individual buffer's value occupies in that buffer.
  1128    Setting the default value also goes through the alist of buffers
  1129    and stores into each buffer that does not say it has a local value.  */
  1130 
  1131 extern struct buffer buffer_defaults;
  1132 
  1133 /* This structure marks which slots in a buffer have corresponding
  1134    default values in buffer_defaults.
  1135    Each such slot has a nonzero value in this structure.
  1136    The value has only one nonzero bit.
  1137 
  1138    When a buffer has its own local value for a slot,
  1139    the entry for that slot (found in the same slot in this structure)
  1140    is turned on in the buffer's local_flags array.
  1141 
  1142    If a slot in this structure is zero, then even though there may
  1143    be a Lisp-level local variable for the slot, it has no default value,
  1144    and the corresponding slot in buffer_defaults is not used.  */
  1145 
  1146 
  1147 extern struct buffer buffer_local_flags;
  1148 
  1149 /* For each buffer slot, this points to the Lisp symbol name
  1150    for that slot in the current buffer.  It is 0 for slots
  1151    that don't have such names.  */
  1152 
  1153 extern struct buffer buffer_local_symbols;
  1154 
  1155 /* verify_interval_modification saves insertion hooks here
  1156    to be run later by report_interval_modification.  */
  1157 extern Lisp_Object interval_insert_behind_hooks;
  1158 extern Lisp_Object interval_insert_in_front_hooks;
  1159 
  1160 
  1161 extern EMACS_INT fix_position (Lisp_Object);
  1162 #define CHECK_FIXNUM_COERCE_MARKER(x) ((x) = make_fixnum (fix_position (x)))
  1163 extern void delete_all_overlays (struct buffer *);
  1164 extern void reset_buffer (struct buffer *);
  1165 extern void compact_buffer (struct buffer *);
  1166 extern ptrdiff_t overlays_at (ptrdiff_t, bool, Lisp_Object **, ptrdiff_t *, ptrdiff_t *);
  1167 extern ptrdiff_t overlays_in (ptrdiff_t, ptrdiff_t, bool, Lisp_Object **,
  1168                               ptrdiff_t *,  bool, bool, ptrdiff_t *);
  1169 extern ptrdiff_t previous_overlay_change (ptrdiff_t);
  1170 extern ptrdiff_t next_overlay_change (ptrdiff_t);
  1171 extern ptrdiff_t sort_overlays (Lisp_Object *, ptrdiff_t, struct window *);
  1172 extern void recenter_overlay_lists (struct buffer *, ptrdiff_t);
  1173 extern ptrdiff_t overlay_strings (ptrdiff_t, struct window *, unsigned char **);
  1174 extern void validate_region (Lisp_Object *, Lisp_Object *);
  1175 extern void set_buffer_internal_1 (struct buffer *);
  1176 extern void set_buffer_internal_2 (struct buffer *);
  1177 extern void set_buffer_temp (struct buffer *);
  1178 extern Lisp_Object buffer_local_value (Lisp_Object, Lisp_Object);
  1179 extern void record_buffer (Lisp_Object);
  1180 extern void fix_overlays_before (struct buffer *, ptrdiff_t, ptrdiff_t);
  1181 extern void mmap_set_vars (bool);
  1182 extern void restore_buffer (Lisp_Object);
  1183 extern void set_buffer_if_live (Lisp_Object);
  1184 extern Lisp_Object build_overlay (bool, bool, Lisp_Object);
  1185 
  1186 /* Return B as a struct buffer pointer, defaulting to the current buffer.  */
  1187 
  1188 INLINE struct buffer *
  1189 decode_buffer (Lisp_Object b)
  1190 {
  1191   return NILP (b) ? current_buffer : (CHECK_BUFFER (b), XBUFFER (b));
  1192 }
  1193 
  1194 /* Set the current buffer to B.
  1195 
  1196    We previously set windows_or_buffers_changed here to invalidate
  1197    global unchanged information in beg_unchanged and end_unchanged.
  1198    This is no longer necessary because we now compute unchanged
  1199    information on a buffer-basis.  Every action affecting other
  1200    windows than the selected one requires a select_window at some
  1201    time, and that increments windows_or_buffers_changed.  */
  1202 
  1203 INLINE void
  1204 set_buffer_internal (struct buffer *b)
  1205 {
  1206   if (current_buffer != b)
  1207     set_buffer_internal_1 (b);
  1208 }
  1209 
  1210 /* Arrange to go back to the original buffer after the next
  1211    call to unbind_to if the original buffer is still alive.  */
  1212 
  1213 INLINE void
  1214 record_unwind_current_buffer (void)
  1215 {
  1216   record_unwind_protect (set_buffer_if_live, Fcurrent_buffer ());
  1217 }
  1218 
  1219 /* Get overlays at POSN into array OVERLAYS with NOVERLAYS elements.
  1220    If NEXTP is non-NULL, return next overlay there.
  1221    See overlay_at arg CHANGE_REQ for meaning of CHRQ arg.
  1222    This macro might evaluate its args multiple times,
  1223    and it treat some args as lvalues.  */
  1224 
  1225 #define GET_OVERLAYS_AT(posn, overlays, noverlays, next)                \
  1226   do {                                                                  \
  1227     ptrdiff_t maxlen = 40;                                              \
  1228     SAFE_NALLOCA (overlays, 1, maxlen);                                 \
  1229     (noverlays) = overlays_at (posn, false, &(overlays), &maxlen, next); \
  1230     if ((noverlays) > maxlen)                                           \
  1231       {                                                                 \
  1232         maxlen = noverlays;                                             \
  1233         SAFE_NALLOCA (overlays, 1, maxlen);                             \
  1234         (noverlays) = overlays_at (posn, false, &(overlays), &maxlen, next); \
  1235       }                                                                 \
  1236   } while (false)
  1237 
  1238 extern Lisp_Object Vbuffer_alist;
  1239 
  1240 /* FOR_EACH_LIVE_BUFFER (LIST_VAR, BUF_VAR) followed by a statement is
  1241    a `for' loop which iterates over the buffers from Vbuffer_alist.  */
  1242 
  1243 #define FOR_EACH_LIVE_BUFFER(list_var, buf_var)                 \
  1244   FOR_EACH_ALIST_VALUE (Vbuffer_alist, list_var, buf_var)
  1245 
  1246 /* Get text properties of B.  */
  1247 
  1248 INLINE INTERVAL
  1249 buffer_intervals (struct buffer *b)
  1250 {
  1251   eassert (b->text != NULL);
  1252   return b->text->intervals;
  1253 }
  1254 
  1255 /* Set text properties of B to I.  */
  1256 
  1257 INLINE void
  1258 set_buffer_intervals (struct buffer *b, INTERVAL i)
  1259 {
  1260   eassert (b->text != NULL);
  1261   b->text->intervals = i;
  1262 }
  1263 
  1264 /* Non-zero if current buffer has overlays.  */
  1265 
  1266 INLINE bool
  1267 buffer_has_overlays (void)
  1268 {
  1269   return current_buffer->overlays
  1270          && (current_buffer->overlays->root != NULL);
  1271 }
  1272 
  1273 /* Functions for accessing a character or byte,
  1274    or converting between byte positions and addresses,
  1275    in a specified buffer.  */
  1276 
  1277 /* Return character code of multi-byte form at byte position POS.  If POS
  1278    doesn't point the head of valid multi-byte form, only the byte at
  1279    POS is returned.  No range checking.  */
  1280 
  1281 INLINE int
  1282 FETCH_MULTIBYTE_CHAR (ptrdiff_t pos)
  1283 {
  1284   unsigned char *p = BYTE_POS_ADDR (pos);
  1285   return STRING_CHAR (p);
  1286 }
  1287 
  1288 /* Return character code of multi-byte form at byte position POS in BUF.
  1289    If POS doesn't point the head of valid multi-byte form, only the byte at
  1290    POS is returned.  No range checking.  */
  1291 
  1292 INLINE int
  1293 BUF_FETCH_MULTIBYTE_CHAR (struct buffer *buf, ptrdiff_t pos)
  1294 {
  1295   unsigned char *p
  1296     = ((pos >= BUF_GPT_BYTE (buf) ? BUF_GAP_SIZE (buf) : 0)
  1297        + pos + BUF_BEG_ADDR (buf) - BEG_BYTE);
  1298   return STRING_CHAR (p);
  1299 }
  1300 
  1301 /* Return character at byte position POS.
  1302    If the current buffer is unibyte and the character is not ASCII,
  1303    make the returning character multibyte.  */
  1304 
  1305 INLINE int
  1306 FETCH_CHAR_AS_MULTIBYTE (ptrdiff_t pos)
  1307 {
  1308   return (!NILP (BVAR (current_buffer, enable_multibyte_characters))
  1309           ? FETCH_MULTIBYTE_CHAR (pos)
  1310           : UNIBYTE_TO_CHAR (FETCH_BYTE (pos)));
  1311 }
  1312 
  1313 /* Return character at byte position POS.
  1314    See the caveat WARNING for FETCH_MULTIBYTE_CHAR above.  */
  1315 
  1316 INLINE int
  1317 FETCH_CHAR (ptrdiff_t pos)
  1318 {
  1319   return (!NILP (BVAR (current_buffer, enable_multibyte_characters))
  1320           ? FETCH_MULTIBYTE_CHAR (pos)
  1321           : FETCH_BYTE (pos));
  1322 }
  1323 
  1324 /* Return the address of character at byte position POS in buffer BUF.
  1325    Note that both arguments can be computed more than once.  */
  1326 
  1327 INLINE unsigned char *
  1328 BUF_BYTE_ADDRESS (struct buffer *buf, ptrdiff_t pos)
  1329 {
  1330   return (buf->text->beg + pos - BEG_BYTE
  1331           + (pos < buf->text->gpt_byte ? 0 : buf->text->gap_size));
  1332 }
  1333 
  1334 /* Return the address of character at char position POS in buffer BUF.
  1335    Note that both arguments can be computed more than once.  */
  1336 
  1337 INLINE unsigned char *
  1338 BUF_CHAR_ADDRESS (struct buffer *buf, ptrdiff_t pos)
  1339 {
  1340   return (buf->text->beg + buf_charpos_to_bytepos (buf, pos) - BEG_BYTE
  1341           + (pos < buf->text->gpt ? 0 : buf->text->gap_size));
  1342 }
  1343 
  1344 /* Convert PTR, the address of a char in buffer BUF,
  1345    into a character position.  */
  1346 
  1347 INLINE ptrdiff_t
  1348 BUF_PTR_BYTE_POS (struct buffer *buf, unsigned char *ptr)
  1349 {
  1350   ptrdiff_t byte = ptr - buf->text->beg;
  1351   return (byte - (byte <= BUF_GPT_BYTE (buf) - BEG_BYTE ? 0 : BUF_GAP_SIZE (buf))
  1352           + BEG_BYTE);
  1353 }
  1354 
  1355 /* Return the byte at byte position N in buffer BUF.   */
  1356 
  1357 INLINE unsigned char
  1358 BUF_FETCH_BYTE (struct buffer *buf, ptrdiff_t n)
  1359 {
  1360   return *BUF_BYTE_ADDRESS (buf, n);
  1361 }
  1362 
  1363 /* Return character at byte position POS in buffer BUF.  If BUF is
  1364    unibyte and the character is not ASCII, make the returning
  1365    character multibyte.  */
  1366 
  1367 INLINE int
  1368 BUF_FETCH_CHAR_AS_MULTIBYTE (struct buffer *buf, ptrdiff_t pos)
  1369 {
  1370   return (! NILP (BVAR (buf, enable_multibyte_characters))
  1371           ? BUF_FETCH_MULTIBYTE_CHAR (buf, pos)
  1372           : UNIBYTE_TO_CHAR (BUF_FETCH_BYTE (buf, pos)));
  1373 }
  1374 
  1375 /* Return number of windows showing B.  */
  1376 
  1377 INLINE int
  1378 buffer_window_count (struct buffer *b)
  1379 {
  1380   if (b->base_buffer)
  1381     b = b->base_buffer;
  1382   eassert (b->window_count >= 0);
  1383   return b->window_count;
  1384 }
  1385 
  1386 /* Overlays */
  1387 
  1388 INLINE ptrdiff_t
  1389 overlay_start (struct Lisp_Overlay *ov)
  1390 {
  1391   if (! ov->buffer)
  1392     return -1;
  1393   return itree_node_begin (ov->buffer->overlays, ov->interval);
  1394 }
  1395 
  1396 INLINE ptrdiff_t
  1397 overlay_end (struct Lisp_Overlay *ov)
  1398 {
  1399   if (! ov->buffer)
  1400     return -1;
  1401   return itree_node_end (ov->buffer->overlays, ov->interval);
  1402 }
  1403 
  1404 /* Return the start of OV in its buffer, or -1 if OV is not associated
  1405    with any buffer.  */
  1406 
  1407 INLINE ptrdiff_t
  1408 OVERLAY_START (Lisp_Object ov)
  1409 {
  1410   return overlay_start (XOVERLAY (ov));
  1411 }
  1412 
  1413 /* Return the end of OV in its buffer, or -1. */
  1414 
  1415 INLINE ptrdiff_t
  1416 OVERLAY_END (Lisp_Object ov)
  1417 {
  1418   return overlay_end (XOVERLAY (ov));
  1419 }
  1420 
  1421 /* Return the plist of overlay OV.  */
  1422 
  1423 INLINE Lisp_Object
  1424 OVERLAY_PLIST (Lisp_Object ov)
  1425 {
  1426   return XOVERLAY (ov)->plist;
  1427 }
  1428 
  1429 /* Return the buffer of overlay OV. */
  1430 
  1431 INLINE struct buffer *
  1432 OVERLAY_BUFFER (Lisp_Object ov)
  1433 {
  1434   return XOVERLAY (ov)->buffer;
  1435 }
  1436 
  1437 /* Return true, if OV's rear-advance is set. */
  1438 
  1439 INLINE bool
  1440 OVERLAY_REAR_ADVANCE_P (Lisp_Object ov)
  1441 {
  1442   return XOVERLAY (ov)->interval->rear_advance;
  1443 }
  1444 
  1445 /* Return true, if OV's front-advance is set. */
  1446 
  1447 INLINE bool
  1448 OVERLAY_FRONT_ADVANCE_P (Lisp_Object ov)
  1449 {
  1450   return XOVERLAY (ov)->interval->front_advance;
  1451 }
  1452 
  1453 
  1454 /***********************************************************************
  1455                         Buffer-local Variables
  1456  ***********************************************************************/
  1457 
  1458 /* Return the offset in bytes of member VAR of struct buffer
  1459    from the start of a buffer structure.  */
  1460 
  1461 #define PER_BUFFER_VAR_OFFSET(VAR) \
  1462   offsetof (struct buffer, VAR ## _)
  1463 
  1464 /* Used to iterate over normal Lisp_Object fields of struct buffer (all
  1465    Lisp_Objects except undo_list).  If you add, remove, or reorder
  1466    Lisp_Objects in a struct buffer, make sure that this is still correct.  */
  1467 
  1468 #define FOR_EACH_PER_BUFFER_OBJECT_AT(offset)                            \
  1469   for (offset = PER_BUFFER_VAR_OFFSET (name);                            \
  1470        offset <= PER_BUFFER_VAR_OFFSET (cursor_in_non_selected_windows); \
  1471        offset += word_size)
  1472 
  1473 /* Return the index of buffer-local variable VAR.  Each per-buffer
  1474    variable has an index > 0 associated with it, except when it always
  1475    has buffer-local values, in which case the index is -1.  If this is
  1476    0, this is a bug and means that the slot of VAR in
  1477    buffer_local_flags wasn't initialized.  */
  1478 
  1479 #define PER_BUFFER_VAR_IDX(VAR) \
  1480     PER_BUFFER_IDX (PER_BUFFER_VAR_OFFSET (VAR))
  1481 
  1482 extern bool valid_per_buffer_idx (int);
  1483 
  1484 /* Value is true if the variable with index IDX has a local value
  1485    in buffer B.  */
  1486 
  1487 INLINE bool
  1488 PER_BUFFER_VALUE_P (struct buffer *b, int idx)
  1489 {
  1490   eassert (valid_per_buffer_idx (idx));
  1491   return b->local_flags[idx];
  1492 }
  1493 
  1494 /* Set whether per-buffer variable with index IDX has a buffer-local
  1495    value in buffer B.  VAL zero means it hasn't.  */
  1496 
  1497 INLINE void
  1498 SET_PER_BUFFER_VALUE_P (struct buffer *b, int idx, bool val)
  1499 {
  1500   eassert (valid_per_buffer_idx (idx));
  1501   b->local_flags[idx] = val;
  1502 }
  1503 
  1504 /* Return the index value of the per-buffer variable at offset OFFSET
  1505    in the buffer structure.
  1506 
  1507    If the slot OFFSET has a corresponding default value in
  1508    buffer_defaults, the index value is positive and has only one
  1509    nonzero bit.  When a buffer has its own local value for a slot, the
  1510    bit for that slot (found in the same slot in this structure) is
  1511    turned on in the buffer's local_flags array.
  1512 
  1513    If the index value is -1, even though there may be a
  1514    DEFVAR_PER_BUFFER for the slot, there is no default value for it;
  1515    and the corresponding slot in buffer_defaults is not used.
  1516 
  1517    If the index value is -2, then there is no DEFVAR_PER_BUFFER for
  1518    the slot, but there is a default value which is copied into each
  1519    new buffer.
  1520 
  1521    If a slot in this structure corresponding to a DEFVAR_PER_BUFFER is
  1522    zero, that is a bug.  */
  1523 
  1524 INLINE int
  1525 PER_BUFFER_IDX (ptrdiff_t offset)
  1526 {
  1527   return XFIXNUM (*(Lisp_Object *) (offset + (char *) &buffer_local_flags));
  1528 }
  1529 
  1530 /* Functions to get and set default value of the per-buffer
  1531    variable at offset OFFSET in the buffer structure.  */
  1532 
  1533 INLINE Lisp_Object
  1534 per_buffer_default (int offset)
  1535 {
  1536   return *(Lisp_Object *)(offset + (char *) &buffer_defaults);
  1537 }
  1538 
  1539 INLINE void
  1540 set_per_buffer_default (int offset, Lisp_Object value)
  1541 {
  1542   *(Lisp_Object *)(offset + (char *) &buffer_defaults) = value;
  1543 }
  1544 
  1545 /* Functions to get and set buffer-local value of the per-buffer
  1546    variable at offset OFFSET in the buffer structure.  */
  1547 
  1548 INLINE Lisp_Object
  1549 per_buffer_value (struct buffer *b, int offset)
  1550 {
  1551   return *(Lisp_Object *)(offset + (char *) b);
  1552 }
  1553 
  1554 INLINE void
  1555 set_per_buffer_value (struct buffer *b, int offset, Lisp_Object value)
  1556 {
  1557   *(Lisp_Object *)(offset + (char *) b) = value;
  1558 }
  1559 
  1560 /* Downcase a character C, or make no change if that cannot be done.  */
  1561 INLINE int
  1562 downcase (int c)
  1563 {
  1564   Lisp_Object downcase_table = BVAR (current_buffer, downcase_table);
  1565   Lisp_Object down = CHAR_TABLE_REF (downcase_table, c);
  1566   return FIXNATP (down) ? XFIXNAT (down) : c;
  1567 }
  1568 
  1569 /* Upcase a character C, or make no change if that cannot be done. */
  1570 INLINE int
  1571 upcase (int c)
  1572 {
  1573   Lisp_Object upcase_table = BVAR (current_buffer, upcase_table);
  1574   Lisp_Object up = CHAR_TABLE_REF (upcase_table, c);
  1575   return FIXNATP (up) ? XFIXNAT (up) : c;
  1576 }
  1577 
  1578 /* True if C is upper case.  */
  1579 INLINE bool
  1580 uppercasep (int c)
  1581 {
  1582   return downcase (c) != c;
  1583 }
  1584 
  1585 /* True if C is lower case.  */
  1586 INLINE bool
  1587 lowercasep (int c)
  1588 {
  1589   return !uppercasep (c) && upcase (c) != c;
  1590 }
  1591 
  1592 /* Return a non-outlandish value for the tab width.  */
  1593 
  1594 INLINE int
  1595 sanitize_tab_width (Lisp_Object width)
  1596 {
  1597   return (FIXNUMP (width) && 0 < XFIXNUM (width) && XFIXNUM (width) <= 1000
  1598           ? XFIXNUM (width) : 8);
  1599 }
  1600 
  1601 INLINE int
  1602 SANE_TAB_WIDTH (struct buffer *buf)
  1603 {
  1604   return sanitize_tab_width (BVAR (buf, tab_width));
  1605 }
  1606 
  1607 /* Return a non-outlandish value for a character width.  */
  1608 
  1609 INLINE int
  1610 sanitize_char_width (EMACS_INT width)
  1611 {
  1612   return 0 <= width && width <= 1000 ? width : 1000;
  1613 }
  1614 
  1615 /* Return the width of character C.  The width is measured by how many
  1616    columns C will occupy on the screen when displayed in the current
  1617    buffer.  The name CHARACTER_WIDTH avoids a collision with <limits.h>
  1618    CHAR_WIDTH.  */
  1619 
  1620 INLINE int
  1621 CHARACTER_WIDTH (int c)
  1622 {
  1623   return (0x20 <= c && c < 0x7f ? 1
  1624           : 0x7f < c ? (sanitize_char_width
  1625                         (XFIXNUM (CHAR_TABLE_REF (Vchar_width_table, c))))
  1626           : c == '\t' ? SANE_TAB_WIDTH (current_buffer)
  1627           : c == '\n' ? 0
  1628           : !NILP (BVAR (current_buffer, ctl_arrow)) ? 2 : 4);
  1629 }
  1630 
  1631 
  1632 /* Like fetch_string_char_advance, but fetch character from the current
  1633    buffer.  */
  1634 
  1635 INLINE int
  1636 fetch_char_advance (ptrdiff_t *charidx, ptrdiff_t *byteidx)
  1637 {
  1638   int output;
  1639   ptrdiff_t c = *charidx, b = *byteidx;
  1640   c++;
  1641   unsigned char *chp = BYTE_POS_ADDR (b);
  1642   if (!NILP (BVAR (current_buffer, enable_multibyte_characters)))
  1643     {
  1644       int chlen;
  1645       output = string_char_and_length (chp, &chlen);
  1646       b += chlen;
  1647     }
  1648   else
  1649     {
  1650       output = *chp;
  1651       b++;
  1652     }
  1653   *charidx = c;
  1654   *byteidx = b;
  1655   return output;
  1656 }
  1657 
  1658 
  1659 /* Like fetch_char_advance, but assumes the current buffer is multibyte.  */
  1660 
  1661 INLINE int
  1662 fetch_char_advance_no_check (ptrdiff_t *charidx, ptrdiff_t *byteidx)
  1663 {
  1664   int output;
  1665   ptrdiff_t c = *charidx, b = *byteidx;
  1666   c++;
  1667   unsigned char *chp = BYTE_POS_ADDR (b);
  1668   int chlen;
  1669   output = string_char_and_length (chp, &chlen);
  1670   b += chlen;
  1671   *charidx = c;
  1672   *byteidx = b;
  1673   return output;
  1674 }
  1675 
  1676 /* Return the number of bytes in the multibyte character in BUF
  1677    that starts at position POS_BYTE.  This relies on the fact that
  1678    *GPT_ADDR and *Z_ADDR are always accessible and the values are
  1679    '\0'.  No range checking of POS_BYTE.  */
  1680 
  1681 INLINE int
  1682 buf_next_char_len (struct buffer *buf, ptrdiff_t pos_byte)
  1683 {
  1684   unsigned char *chp = BUF_BYTE_ADDRESS (buf, pos_byte);
  1685   return BYTES_BY_CHAR_HEAD (*chp);
  1686 }
  1687 
  1688 INLINE int
  1689 next_char_len (ptrdiff_t pos_byte)
  1690 {
  1691   return buf_next_char_len (current_buffer, pos_byte);
  1692 }
  1693 
  1694 /* Return the number of bytes in the multibyte character in BUF just
  1695    before POS_BYTE.  No range checking of POS_BYTE.  */
  1696 
  1697 INLINE int
  1698 buf_prev_char_len (struct buffer *buf, ptrdiff_t pos_byte)
  1699 {
  1700   unsigned char *chp
  1701     = (BUF_BEG_ADDR (buf) + pos_byte - BEG_BYTE
  1702        + (pos_byte <= BUF_GPT_BYTE (buf) ? 0 : BUF_GAP_SIZE (buf)));
  1703   return raw_prev_char_len (chp);
  1704 }
  1705 
  1706 INLINE int
  1707 prev_char_len (ptrdiff_t pos_byte)
  1708 {
  1709   return buf_prev_char_len (current_buffer, pos_byte);
  1710 }
  1711 
  1712 /* Increment both *CHARPOS and *BYTEPOS, each in the appropriate way.  */
  1713 
  1714 INLINE void
  1715 inc_both (ptrdiff_t *charpos, ptrdiff_t *bytepos)
  1716 {
  1717   (*charpos)++;
  1718   (*bytepos) += (!NILP (BVAR (current_buffer, enable_multibyte_characters))
  1719                  ? next_char_len (*bytepos) : 1);
  1720 }
  1721 
  1722 /* Decrement both *CHARPOS and *BYTEPOS, each in the appropriate way.  */
  1723 
  1724 INLINE void
  1725 dec_both (ptrdiff_t *charpos, ptrdiff_t *bytepos)
  1726 {
  1727   (*charpos)--;
  1728   (*bytepos) -= (!NILP (BVAR (current_buffer, enable_multibyte_characters))
  1729                  ? prev_char_len (*bytepos) : 1);
  1730 }
  1731 
  1732 INLINE_HEADER_END
  1733 
  1734 int compare_overlays (const void *v1, const void *v2);
  1735 void make_sortvec_item (struct sortvec *item, Lisp_Object overlay);
  1736 
  1737 #endif /* EMACS_BUFFER_H */

/* [<][>][^][v][top][bottom][index][help] */