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. bset_text_conversion_style
  32. BUFFER_CEILING_OF
  33. BUFFER_FLOOR_OF
  34. BUF_BEGV
  35. BUF_BEGV_BYTE
  36. BUF_PT
  37. BUF_PT_BYTE
  38. BUF_ZV
  39. BUF_ZV_BYTE
  40. BUF_BEG
  41. BUF_BEG_BYTE
  42. BUF_GPT_ADDR
  43. BUF_Z_ADDR
  44. BUF_GAP_END_ADDR
  45. BUF_COMPUTE_UNCHANGED
  46. SET_BUF_BEGV
  47. SET_BUF_ZV
  48. SET_BUF_BEGV_BOTH
  49. SET_BUF_ZV_BOTH
  50. SET_BUF_PT_BOTH
  51. BYTE_POS_ADDR
  52. CHAR_POS_ADDR
  53. CHAR_TO_BYTE
  54. BYTE_TO_CHAR
  55. PTR_BYTE_POS
  56. BUFFER_PVEC_INIT
  57. BUFFER_LIVE_P
  58. BUFFER_HIDDEN_P
  59. BUFFER_CHECK_INDIRECTION
  60. decode_buffer
  61. set_buffer_internal
  62. record_unwind_current_buffer
  63. buffer_intervals
  64. set_buffer_intervals
  65. buffer_has_overlays
  66. FETCH_MULTIBYTE_CHAR
  67. BUF_FETCH_MULTIBYTE_CHAR
  68. FETCH_CHAR_AS_MULTIBYTE
  69. FETCH_CHAR
  70. BUF_BYTE_ADDRESS
  71. BUF_CHAR_ADDRESS
  72. BUF_PTR_BYTE_POS
  73. BUF_FETCH_BYTE
  74. BUF_FETCH_CHAR_AS_MULTIBYTE
  75. buffer_window_count
  76. overlay_start
  77. overlay_end
  78. OVERLAY_START
  79. OVERLAY_END
  80. OVERLAY_PLIST
  81. OVERLAY_BUFFER
  82. OVERLAY_REAR_ADVANCE_P
  83. OVERLAY_FRONT_ADVANCE_P
  84. PER_BUFFER_VALUE_P
  85. SET_PER_BUFFER_VALUE_P
  86. PER_BUFFER_IDX
  87. per_buffer_default
  88. set_per_buffer_default
  89. per_buffer_value
  90. set_per_buffer_value
  91. downcase
  92. upcase
  93. uppercasep
  94. lowercasep
  95. sanitize_tab_width
  96. SANE_TAB_WIDTH
  97. sanitize_char_width
  98. CHARACTER_WIDTH
  99. fetch_char_advance
  100. fetch_char_advance_no_check
  101. buf_next_char_len
  102. next_char_len
  103. buf_prev_char_len
  104. prev_char_len
  105. inc_both
  106. 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 
   570   /* What type of text conversion the input method should apply to
   571      this buffer.  */
   572   Lisp_Object text_conversion_style_;
   573 
   574   /* Cursor type to display in non-selected windows.
   575      t means to use hollow box cursor.
   576      See `cursor-type' for other values.  */
   577   Lisp_Object cursor_in_non_selected_windows_;
   578 
   579   /* No more Lisp_Object beyond cursor_in_non_selected_windows_.
   580      Except undo_list, which is handled specially in Fgarbage_collect.  */
   581 
   582   /* This structure holds the coordinates of the buffer contents
   583      in ordinary buffers.  In indirect buffers, this is not used.  */
   584   struct buffer_text own_text;
   585 
   586   /* This points to the `struct buffer_text' that used for this buffer.
   587      In an ordinary buffer, this is the own_text field above.
   588      In an indirect buffer, this is the own_text field of another buffer.  */
   589   struct buffer_text *text;
   590 
   591   /* Char position of point in buffer.  */
   592   ptrdiff_t pt;
   593 
   594   /* Byte position of point in buffer.  */
   595   ptrdiff_t pt_byte;
   596 
   597   /* Char position of beginning of accessible range.  */
   598   ptrdiff_t begv;
   599 
   600   /* Byte position of beginning of accessible range.  */
   601   ptrdiff_t begv_byte;
   602 
   603   /* Char position of end of accessible range.  */
   604   ptrdiff_t zv;
   605 
   606   /* Byte position of end of accessible range.  */
   607   ptrdiff_t zv_byte;
   608 
   609   /* In an indirect buffer, this points to the base buffer.
   610      In an ordinary buffer, it is 0.  */
   611   struct buffer *base_buffer;
   612 
   613   /* In an indirect buffer, this is -1.  In an ordinary buffer,
   614      it's the number of indirect buffers that share our text;
   615      zero means that we're the only owner of this text.  */
   616   int indirections;
   617 
   618   /* Number of windows showing this buffer.  Always -1 for
   619      an indirect buffer since it counts as its base buffer.  */
   620   int window_count;
   621 
   622   /* A non-zero value in slot IDX means that per-buffer variable
   623      with index IDX has a local value in this buffer.  The index IDX
   624      for a buffer-local variable is stored in that variable's slot
   625      in buffer_local_flags as a Lisp integer.  If the index is -1,
   626      this means the variable is always local in all buffers.  */
   627   char local_flags[MAX_PER_BUFFER_VARS];
   628 
   629   /* Set to the modtime of the visited file when read or written.
   630      modtime.tv_nsec == NONEXISTENT_MODTIME_NSECS means
   631      visited file was nonexistent.  modtime.tv_nsec ==
   632      UNKNOWN_MODTIME_NSECS means visited file modtime unknown;
   633      in no case complain about any mismatch on next save attempt.  */
   634   struct timespec modtime;
   635 
   636   /* Size of the file when modtime was set.  This is used to detect the
   637      case where the file grew while we were reading it, so the modtime
   638      is still the same (since it's rounded up to seconds) but we're actually
   639      not up-to-date.  -1 means the size is unknown.  Only meaningful if
   640      modtime is actually set.  */
   641   off_t modtime_size;
   642 
   643   /* The value of text->modiff at the last auto-save.  */
   644   modiff_count auto_save_modified;
   645 
   646   /* The value of text->modiff at the last display error.
   647      Redisplay of this buffer is inhibited until it changes again.  */
   648   modiff_count display_error_modiff;
   649 
   650   /* The time at which we detected a failure to auto-save,
   651      Or 0 if we didn't have a failure.  */
   652   time_t auto_save_failure_time;
   653 
   654   /* Position in buffer at which display started
   655      the last time this buffer was displayed.  */
   656   ptrdiff_t last_window_start;
   657 
   658   /* If the long line scan cache is enabled (i.e. the buffer-local
   659      variable cache-long-line-scans is non-nil), newline_cache
   660      points to the newline cache, and width_run_cache points to the
   661      width run cache.
   662 
   663      The newline cache records which stretches of the buffer are
   664      known *not* to contain newlines, so that they can be skipped
   665      quickly when we search for newlines.
   666 
   667      The width run cache records which stretches of the buffer are
   668      known to contain characters whose widths are all the same.  If
   669      the width run cache maps a character to a value > 0, that value is
   670      the character's width; if it maps a character to zero, we don't
   671      know what its width is.  This allows compute_motion to process
   672      such regions very quickly, using algebra instead of inspecting
   673      each character.   See also width_table, below.
   674 
   675      The latter cache is used to speedup bidi_find_paragraph_start.  */
   676   struct region_cache *newline_cache;
   677   struct region_cache *width_run_cache;
   678   struct region_cache *bidi_paragraph_cache;
   679 
   680   /* Non-zero means disable redisplay optimizations when rebuilding the glyph
   681      matrices (but not when redrawing).  */
   682   bool_bf prevent_redisplay_optimizations_p : 1;
   683 
   684   /* Non-zero whenever the narrowing is changed in this buffer.  */
   685   bool_bf clip_changed : 1;
   686 
   687   /* Non-zero for internal or temporary buffers that don't need to
   688      run hooks kill-buffer-hook, kill-buffer-query-functions, and
   689      buffer-list-update-hook.  This is used in coding.c to avoid
   690      slowing down en/decoding when a lot of these hooks are
   691      defined, as well as by with-temp-buffer, for example.  */
   692   bool_bf inhibit_buffer_hooks : 1;
   693 
   694   /* Non-zero when the buffer contains long lines and specific
   695      display optimizations must be used.  */
   696   bool_bf long_line_optimizations_p : 1;
   697 
   698   /* The interval tree containing this buffer's overlays. */
   699   struct itree_tree *overlays;
   700 
   701   /* Changes in the buffer are recorded here for undo, and t means
   702      don't record anything.  This information belongs to the base
   703      buffer of an indirect buffer.  But we can't store it in the
   704      struct buffer_text because local variables have to be right in
   705      the struct buffer. So we copy it around in set_buffer_internal.  */
   706   Lisp_Object undo_list_;
   707 };
   708 
   709 struct sortvec
   710 {
   711   Lisp_Object overlay;
   712   ptrdiff_t beg, end;
   713   EMACS_INT priority;
   714   EMACS_INT spriority;          /* Secondary priority.  */
   715 };
   716 
   717 INLINE bool
   718 BUFFERP (Lisp_Object a)
   719 {
   720   return PSEUDOVECTORP (a, PVEC_BUFFER);
   721 }
   722 
   723 INLINE void
   724 CHECK_BUFFER (Lisp_Object x)
   725 {
   726   CHECK_TYPE (BUFFERP (x), Qbufferp, x);
   727 }
   728 
   729 INLINE struct buffer *
   730 XBUFFER (Lisp_Object a)
   731 {
   732   eassert (BUFFERP (a));
   733   return XUNTAG (a, Lisp_Vectorlike, struct buffer);
   734 }
   735 
   736 /* Most code should use these functions to set Lisp fields in struct
   737    buffer.  (Some setters that are private to a single .c file are
   738    defined as static in those files.)  */
   739 INLINE void
   740 bset_bidi_paragraph_direction (struct buffer *b, Lisp_Object val)
   741 {
   742   b->bidi_paragraph_direction_ = val;
   743 }
   744 INLINE void
   745 bset_cache_long_scans (struct buffer *b, Lisp_Object val)
   746 {
   747   b->cache_long_scans_ = val;
   748 }
   749 INLINE void
   750 bset_case_canon_table (struct buffer *b, Lisp_Object val)
   751 {
   752   b->case_canon_table_ = val;
   753 }
   754 INLINE void
   755 bset_case_eqv_table (struct buffer *b, Lisp_Object val)
   756 {
   757   b->case_eqv_table_ = val;
   758 }
   759 INLINE void
   760 bset_directory (struct buffer *b, Lisp_Object val)
   761 {
   762   b->directory_ = val;
   763 }
   764 INLINE void
   765 bset_display_count (struct buffer *b, Lisp_Object val)
   766 {
   767   b->display_count_ = val;
   768 }
   769 INLINE void
   770 bset_left_margin_cols (struct buffer *b, Lisp_Object val)
   771 {
   772   b->left_margin_cols_ = val;
   773 }
   774 INLINE void
   775 bset_right_margin_cols (struct buffer *b, Lisp_Object val)
   776 {
   777   b->right_margin_cols_ = val;
   778 }
   779 INLINE void
   780 bset_display_time (struct buffer *b, Lisp_Object val)
   781 {
   782   b->display_time_ = val;
   783 }
   784 INLINE void
   785 bset_downcase_table (struct buffer *b, Lisp_Object val)
   786 {
   787   b->downcase_table_ = val;
   788 }
   789 INLINE void
   790 bset_enable_multibyte_characters (struct buffer *b, Lisp_Object val)
   791 {
   792   b->enable_multibyte_characters_ = val;
   793 }
   794 INLINE void
   795 bset_filename (struct buffer *b, Lisp_Object val)
   796 {
   797   b->filename_ = val;
   798 }
   799 INLINE void
   800 bset_keymap (struct buffer *b, Lisp_Object val)
   801 {
   802   b->keymap_ = val;
   803 }
   804 INLINE void
   805 bset_last_selected_window (struct buffer *b, Lisp_Object val)
   806 {
   807   b->last_selected_window_ = val;
   808 }
   809 INLINE void
   810 bset_local_var_alist (struct buffer *b, Lisp_Object val)
   811 {
   812   b->local_var_alist_ = val;
   813 }
   814 INLINE void
   815 bset_mark_active (struct buffer *b, Lisp_Object val)
   816 {
   817   b->mark_active_ = val;
   818 }
   819 INLINE void
   820 bset_point_before_scroll (struct buffer *b, Lisp_Object val)
   821 {
   822   b->point_before_scroll_ = val;
   823 }
   824 INLINE void
   825 bset_read_only (struct buffer *b, Lisp_Object val)
   826 {
   827   b->read_only_ = val;
   828 }
   829 INLINE void
   830 bset_truncate_lines (struct buffer *b, Lisp_Object val)
   831 {
   832   b->truncate_lines_ = val;
   833 }
   834 INLINE void
   835 bset_undo_list (struct buffer *b, Lisp_Object val)
   836 {
   837   b->undo_list_ = val;
   838 }
   839 INLINE void
   840 bset_upcase_table (struct buffer *b, Lisp_Object val)
   841 {
   842   b->upcase_table_ = val;
   843 }
   844 INLINE void
   845 bset_width_table (struct buffer *b, Lisp_Object val)
   846 {
   847   b->width_table_ = val;
   848 }
   849 
   850 INLINE void
   851 bset_text_conversion_style (struct buffer *b, Lisp_Object val)
   852 {
   853   b->text_conversion_style_ = val;
   854 }
   855 
   856 /* BUFFER_CEILING_OF (resp. BUFFER_FLOOR_OF), when applied to n, return
   857    the max (resp. min) p such that
   858 
   859    BYTE_POS_ADDR (p) - BYTE_POS_ADDR (n) == p - n       */
   860 
   861 INLINE ptrdiff_t
   862 BUFFER_CEILING_OF (ptrdiff_t bytepos)
   863 {
   864   return (bytepos < GPT_BYTE && GPT < ZV ? GPT_BYTE : ZV_BYTE) - 1;
   865 }
   866 
   867 INLINE ptrdiff_t
   868 BUFFER_FLOOR_OF (ptrdiff_t bytepos)
   869 {
   870   return BEGV <= GPT && GPT_BYTE <= bytepos ? GPT_BYTE : BEGV_BYTE;
   871 }
   872 
   873 /* The BUF_BEGV[_BYTE], BUF_ZV[_BYTE], and BUF_PT[_BYTE] functions cannot
   874    be used for assignment; use SET_BUF_* functions below for that.  */
   875 
   876 /* Position of beginning of accessible range of buffer.  */
   877 INLINE ptrdiff_t
   878 BUF_BEGV (struct buffer *buf)
   879 {
   880   return (buf == current_buffer ? BEGV
   881           : NILP (BVAR (buf, begv_marker)) ? buf->begv
   882           : marker_position (BVAR (buf, begv_marker)));
   883 }
   884 
   885 INLINE ptrdiff_t
   886 BUF_BEGV_BYTE (struct buffer *buf)
   887 {
   888   return (buf == current_buffer ? BEGV_BYTE
   889           : NILP (BVAR (buf, begv_marker)) ? buf->begv_byte
   890           : marker_byte_position (BVAR (buf, begv_marker)));
   891 }
   892 
   893 /* Position of point in buffer.  */
   894 INLINE ptrdiff_t
   895 BUF_PT (struct buffer *buf)
   896 {
   897   return (buf == current_buffer ? PT
   898           : NILP (BVAR (buf, pt_marker)) ? buf->pt
   899           : marker_position (BVAR (buf, pt_marker)));
   900 }
   901 
   902 INLINE ptrdiff_t
   903 BUF_PT_BYTE (struct buffer *buf)
   904 {
   905   return (buf == current_buffer ? PT_BYTE
   906           : NILP (BVAR (buf, pt_marker)) ? buf->pt_byte
   907           : marker_byte_position (BVAR (buf, pt_marker)));
   908 }
   909 
   910 /* Position of end of accessible range of buffer.  */
   911 INLINE ptrdiff_t
   912 BUF_ZV (struct buffer *buf)
   913 {
   914   return (buf == current_buffer ? ZV
   915           : NILP (BVAR (buf, zv_marker)) ? buf->zv
   916           : marker_position (BVAR (buf, zv_marker)));
   917 }
   918 
   919 INLINE ptrdiff_t
   920 BUF_ZV_BYTE (struct buffer *buf)
   921 {
   922   return (buf == current_buffer ? ZV_BYTE
   923           : NILP (BVAR (buf, zv_marker)) ? buf->zv_byte
   924           : marker_byte_position (BVAR (buf, zv_marker)));
   925 }
   926 
   927 /* Similar functions to operate on a specified buffer.  */
   928 
   929 /* Position of beginning of buffer.  */
   930 INLINE ptrdiff_t
   931 BUF_BEG (struct buffer *buf)
   932 {
   933   return BEG;
   934 }
   935 
   936 INLINE ptrdiff_t
   937 BUF_BEG_BYTE (struct buffer *buf)
   938 {
   939   return BEG_BYTE;
   940 }
   941 
   942 /* Address of beginning of gap of buffer.  */
   943 INLINE unsigned char *
   944 BUF_GPT_ADDR (struct buffer *buf)
   945 {
   946   return buf->text->beg + buf->text->gpt_byte - BEG_BYTE;
   947 }
   948 
   949 /* Address of end of buffer.  */
   950 INLINE unsigned char *
   951 BUF_Z_ADDR (struct buffer *buf)
   952 {
   953   return buf->text->beg + buf->text->gap_size + buf->text->z_byte - BEG_BYTE;
   954 }
   955 
   956 /* Address of end of gap in buffer.  */
   957 INLINE unsigned char *
   958 BUF_GAP_END_ADDR (struct buffer *buf)
   959 {
   960   return buf->text->beg + buf->text->gpt_byte + buf->text->gap_size - BEG_BYTE;
   961 }
   962 
   963 /* Compute how many characters at the top and bottom of BUF are
   964    unchanged when the range START..END is modified.  This computation
   965    must be done each time BUF is modified.  */
   966 
   967 INLINE void
   968 BUF_COMPUTE_UNCHANGED (struct buffer *buf, ptrdiff_t start, ptrdiff_t end)
   969 {
   970   if (BUF_UNCHANGED_MODIFIED (buf) == BUF_MODIFF (buf)
   971       && (BUF_OVERLAY_UNCHANGED_MODIFIED (buf)
   972           == BUF_OVERLAY_MODIFF (buf)))
   973     {
   974       buf->text->beg_unchanged = start - BUF_BEG (buf);
   975       buf->text->end_unchanged = BUF_Z (buf) - (end);
   976     }
   977   else
   978     {
   979       if (BUF_Z (buf) - end < BUF_END_UNCHANGED (buf))
   980         buf->text->end_unchanged = BUF_Z (buf) - end;
   981       if (start - BUF_BEG (buf) < BUF_BEG_UNCHANGED (buf))
   982         buf->text->beg_unchanged = start - BUF_BEG (buf);
   983     }
   984 }
   985 
   986 /* Functions for setting the BEGV, ZV or PT of a given buffer.
   987 
   988    The ..._BOTH functions take both a charpos and a bytepos,
   989    which must correspond to each other.
   990 
   991    The functions without ..._BOTH take just a charpos,
   992    and compute the bytepos from it.  */
   993 
   994 INLINE void
   995 SET_BUF_BEGV (struct buffer *buf, ptrdiff_t charpos)
   996 {
   997   buf->begv_byte = buf_charpos_to_bytepos (buf, charpos);
   998   buf->begv = charpos;
   999 }
  1000 
  1001 INLINE void
  1002 SET_BUF_ZV (struct buffer *buf, ptrdiff_t charpos)
  1003 {
  1004   buf->zv_byte = buf_charpos_to_bytepos (buf, charpos);
  1005   buf->zv = charpos;
  1006 }
  1007 
  1008 INLINE void
  1009 SET_BUF_BEGV_BOTH (struct buffer *buf, ptrdiff_t charpos, ptrdiff_t byte)
  1010 {
  1011   buf->begv = charpos;
  1012   buf->begv_byte = byte;
  1013 }
  1014 
  1015 INLINE void
  1016 SET_BUF_ZV_BOTH (struct buffer *buf, ptrdiff_t charpos, ptrdiff_t byte)
  1017 {
  1018   buf->zv = charpos;
  1019   buf->zv_byte = byte;
  1020 }
  1021 
  1022 INLINE void
  1023 SET_BUF_PT_BOTH (struct buffer *buf, ptrdiff_t charpos, ptrdiff_t byte)
  1024 {
  1025   buf->pt = charpos;
  1026   buf->pt_byte = byte;
  1027 }
  1028 
  1029 /* Functions to access a character or byte in the current buffer,
  1030    or convert between a byte position and an address.
  1031    These functions do not check that the position is in range.  */
  1032 
  1033 /* See the important WARNING above about using the 'char *' pointers
  1034    returned by these functions.  */
  1035 
  1036 /* Return the address of byte position N in current buffer.  */
  1037 
  1038 INLINE unsigned char *
  1039 BYTE_POS_ADDR (ptrdiff_t n)
  1040 {
  1041   return (n < GPT_BYTE ? 0 : GAP_SIZE) + n + BEG_ADDR - BEG_BYTE;
  1042 }
  1043 
  1044 /* Return the address of char position N.  */
  1045 
  1046 INLINE unsigned char *
  1047 CHAR_POS_ADDR (ptrdiff_t n)
  1048 {
  1049   return ((n < GPT ? 0 : GAP_SIZE)
  1050           + buf_charpos_to_bytepos (current_buffer, n)
  1051           + BEG_ADDR - BEG_BYTE);
  1052 }
  1053 
  1054 /* Convert a character position to a byte position.  */
  1055 
  1056 INLINE ptrdiff_t
  1057 CHAR_TO_BYTE (ptrdiff_t charpos)
  1058 {
  1059   return buf_charpos_to_bytepos (current_buffer, charpos);
  1060 }
  1061 
  1062 /* Convert a byte position to a character position.  */
  1063 
  1064 INLINE ptrdiff_t
  1065 BYTE_TO_CHAR (ptrdiff_t bytepos)
  1066 {
  1067   return buf_bytepos_to_charpos (current_buffer, bytepos);
  1068 }
  1069 
  1070 /* Convert PTR, the address of a byte in the buffer, into a byte position.  */
  1071 
  1072 INLINE ptrdiff_t
  1073 PTR_BYTE_POS (unsigned char const *ptr)
  1074 {
  1075   ptrdiff_t byte = ptr - current_buffer->text->beg;
  1076   return byte - (byte <= GPT_BYTE - BEG_BYTE ? 0 : GAP_SIZE) + BEG_BYTE;
  1077 }
  1078 
  1079 /* Number of Lisp_Objects at the beginning of struct buffer.
  1080    If you add, remove, or reorder Lisp_Objects within buffer
  1081    structure, make sure that this is still correct.  */
  1082 
  1083 enum { BUFFER_LISP_SIZE = PSEUDOVECSIZE (struct buffer,
  1084                                          cursor_in_non_selected_windows_) };
  1085 
  1086 /* Allocated size of the struct buffer part beyond leading
  1087    Lisp_Objects, in word_size units.  */
  1088 
  1089 enum { BUFFER_REST_SIZE = VECSIZE (struct buffer) - BUFFER_LISP_SIZE };
  1090 
  1091 /* Initialize the pseudovector header of buffer object.  BUFFER_LISP_SIZE
  1092    is required for GC, but BUFFER_REST_SIZE is set up just to be consistent
  1093    with other pseudovectors.  */
  1094 
  1095 INLINE void
  1096 BUFFER_PVEC_INIT (struct buffer *b)
  1097 {
  1098   XSETPVECTYPESIZE (b, PVEC_BUFFER, BUFFER_LISP_SIZE, BUFFER_REST_SIZE);
  1099 }
  1100 
  1101 /* Convenient check whether buffer B is live.  */
  1102 
  1103 INLINE bool
  1104 BUFFER_LIVE_P (struct buffer *b)
  1105 {
  1106   return !NILP (BVAR (b, name));
  1107 }
  1108 
  1109 /* Convenient check whether buffer B is hidden (i.e. its name
  1110    starts with a space).  Caller must ensure that B is live.  */
  1111 
  1112 INLINE bool
  1113 BUFFER_HIDDEN_P (struct buffer *b)
  1114 {
  1115   return SREF (BVAR (b, name), 0) == ' ';
  1116 }
  1117 
  1118 /* Verify indirection counters.  */
  1119 
  1120 INLINE void
  1121 BUFFER_CHECK_INDIRECTION (struct buffer *b)
  1122 {
  1123   if (BUFFER_LIVE_P (b))
  1124     {
  1125       if (b->base_buffer)
  1126         {
  1127           eassert (b->indirections == -1);
  1128           eassert (b->base_buffer->indirections > 0);
  1129         }
  1130       else
  1131         eassert (b->indirections >= 0);
  1132     }
  1133 }
  1134 
  1135 /* This structure holds the default values of the buffer-local variables
  1136    that have special slots in each buffer.
  1137    The default value occupies the same slot in this structure
  1138    as an individual buffer's value occupies in that buffer.
  1139    Setting the default value also goes through the alist of buffers
  1140    and stores into each buffer that does not say it has a local value.  */
  1141 
  1142 extern struct buffer buffer_defaults;
  1143 
  1144 /* This structure marks which slots in a buffer have corresponding
  1145    default values in buffer_defaults.
  1146    Each such slot has a nonzero value in this structure.
  1147    The value has only one nonzero bit.
  1148 
  1149    When a buffer has its own local value for a slot,
  1150    the entry for that slot (found in the same slot in this structure)
  1151    is turned on in the buffer's local_flags array.
  1152 
  1153    If a slot in this structure is zero, then even though there may
  1154    be a Lisp-level local variable for the slot, it has no default value,
  1155    and the corresponding slot in buffer_defaults is not used.  */
  1156 
  1157 
  1158 extern struct buffer buffer_local_flags;
  1159 
  1160 /* For each buffer slot, this points to the Lisp symbol name
  1161    for that slot in the current buffer.  It is 0 for slots
  1162    that don't have such names.  */
  1163 
  1164 extern struct buffer buffer_local_symbols;
  1165 
  1166 /* verify_interval_modification saves insertion hooks here
  1167    to be run later by report_interval_modification.  */
  1168 extern Lisp_Object interval_insert_behind_hooks;
  1169 extern Lisp_Object interval_insert_in_front_hooks;
  1170 
  1171 
  1172 extern EMACS_INT fix_position (Lisp_Object);
  1173 #define CHECK_FIXNUM_COERCE_MARKER(x) ((x) = make_fixnum (fix_position (x)))
  1174 extern void delete_all_overlays (struct buffer *);
  1175 extern void reset_buffer (struct buffer *);
  1176 extern void compact_buffer (struct buffer *);
  1177 extern ptrdiff_t overlays_at (ptrdiff_t, bool, Lisp_Object **, ptrdiff_t *, ptrdiff_t *);
  1178 extern ptrdiff_t overlays_in (ptrdiff_t, ptrdiff_t, bool, Lisp_Object **,
  1179                               ptrdiff_t *,  bool, bool, ptrdiff_t *);
  1180 extern ptrdiff_t previous_overlay_change (ptrdiff_t);
  1181 extern ptrdiff_t next_overlay_change (ptrdiff_t);
  1182 extern ptrdiff_t sort_overlays (Lisp_Object *, ptrdiff_t, struct window *);
  1183 extern void recenter_overlay_lists (struct buffer *, ptrdiff_t);
  1184 extern ptrdiff_t overlay_strings (ptrdiff_t, struct window *, unsigned char **);
  1185 extern void validate_region (Lisp_Object *, Lisp_Object *);
  1186 extern void set_buffer_internal_1 (struct buffer *);
  1187 extern void set_buffer_internal_2 (struct buffer *);
  1188 extern void set_buffer_temp (struct buffer *);
  1189 extern Lisp_Object buffer_local_value (Lisp_Object, Lisp_Object);
  1190 extern void record_buffer (Lisp_Object);
  1191 extern void fix_overlays_before (struct buffer *, ptrdiff_t, ptrdiff_t);
  1192 extern void mmap_set_vars (bool);
  1193 extern void restore_buffer (Lisp_Object);
  1194 extern void set_buffer_if_live (Lisp_Object);
  1195 extern Lisp_Object build_overlay (bool, bool, Lisp_Object);
  1196 
  1197 /* Return B as a struct buffer pointer, defaulting to the current buffer.  */
  1198 
  1199 INLINE struct buffer *
  1200 decode_buffer (Lisp_Object b)
  1201 {
  1202   return NILP (b) ? current_buffer : (CHECK_BUFFER (b), XBUFFER (b));
  1203 }
  1204 
  1205 /* Set the current buffer to B.
  1206 
  1207    We previously set windows_or_buffers_changed here to invalidate
  1208    global unchanged information in beg_unchanged and end_unchanged.
  1209    This is no longer necessary because we now compute unchanged
  1210    information on a buffer-basis.  Every action affecting other
  1211    windows than the selected one requires a select_window at some
  1212    time, and that increments windows_or_buffers_changed.  */
  1213 
  1214 INLINE void
  1215 set_buffer_internal (struct buffer *b)
  1216 {
  1217   if (current_buffer != b)
  1218     set_buffer_internal_1 (b);
  1219 }
  1220 
  1221 /* Arrange to go back to the original buffer after the next
  1222    call to unbind_to if the original buffer is still alive.  */
  1223 
  1224 INLINE void
  1225 record_unwind_current_buffer (void)
  1226 {
  1227   record_unwind_protect (set_buffer_if_live, Fcurrent_buffer ());
  1228 }
  1229 
  1230 /* Get overlays at POSN into array OVERLAYS with NOVERLAYS elements.
  1231    If NEXTP is non-NULL, return next overlay there.
  1232    See overlay_at arg CHANGE_REQ for meaning of CHRQ arg.
  1233    This macro might evaluate its args multiple times,
  1234    and it treat some args as lvalues.  */
  1235 
  1236 #define GET_OVERLAYS_AT(posn, overlays, noverlays, next)                \
  1237   do {                                                                  \
  1238     ptrdiff_t maxlen = 40;                                              \
  1239     SAFE_NALLOCA (overlays, 1, maxlen);                                 \
  1240     (noverlays) = overlays_at (posn, false, &(overlays), &maxlen, next); \
  1241     if ((noverlays) > maxlen)                                           \
  1242       {                                                                 \
  1243         maxlen = noverlays;                                             \
  1244         SAFE_NALLOCA (overlays, 1, maxlen);                             \
  1245         (noverlays) = overlays_at (posn, false, &(overlays), &maxlen, next); \
  1246       }                                                                 \
  1247   } while (false)
  1248 
  1249 extern Lisp_Object Vbuffer_alist;
  1250 
  1251 /* FOR_EACH_LIVE_BUFFER (LIST_VAR, BUF_VAR) followed by a statement is
  1252    a `for' loop which iterates over the buffers from Vbuffer_alist.  */
  1253 
  1254 #define FOR_EACH_LIVE_BUFFER(list_var, buf_var)                 \
  1255   FOR_EACH_ALIST_VALUE (Vbuffer_alist, list_var, buf_var)
  1256 
  1257 /* Get text properties of B.  */
  1258 
  1259 INLINE INTERVAL
  1260 buffer_intervals (struct buffer *b)
  1261 {
  1262   eassert (b->text != NULL);
  1263   return b->text->intervals;
  1264 }
  1265 
  1266 /* Set text properties of B to I.  */
  1267 
  1268 INLINE void
  1269 set_buffer_intervals (struct buffer *b, INTERVAL i)
  1270 {
  1271   eassert (b->text != NULL);
  1272   b->text->intervals = i;
  1273 }
  1274 
  1275 /* Non-zero if current buffer has overlays.  */
  1276 
  1277 INLINE bool
  1278 buffer_has_overlays (void)
  1279 {
  1280   return !itree_empty_p (current_buffer->overlays);
  1281 }
  1282 
  1283 /* Functions for accessing a character or byte,
  1284    or converting between byte positions and addresses,
  1285    in a specified buffer.  */
  1286 
  1287 /* Return character code of multi-byte form at byte position POS.  If POS
  1288    doesn't point the head of valid multi-byte form, only the byte at
  1289    POS is returned.  No range checking.  */
  1290 
  1291 INLINE int
  1292 FETCH_MULTIBYTE_CHAR (ptrdiff_t pos)
  1293 {
  1294   unsigned char *p = BYTE_POS_ADDR (pos);
  1295   return STRING_CHAR (p);
  1296 }
  1297 
  1298 /* Return character code of multi-byte form at byte position POS in BUF.
  1299    If POS doesn't point the head of valid multi-byte form, only the byte at
  1300    POS is returned.  No range checking.  */
  1301 
  1302 INLINE int
  1303 BUF_FETCH_MULTIBYTE_CHAR (struct buffer *buf, ptrdiff_t pos)
  1304 {
  1305   unsigned char *p
  1306     = ((pos >= BUF_GPT_BYTE (buf) ? BUF_GAP_SIZE (buf) : 0)
  1307        + pos + BUF_BEG_ADDR (buf) - BEG_BYTE);
  1308   return STRING_CHAR (p);
  1309 }
  1310 
  1311 /* Return character at byte position POS.
  1312    If the current buffer is unibyte and the character is not ASCII,
  1313    make the returning character multibyte.  */
  1314 
  1315 INLINE int
  1316 FETCH_CHAR_AS_MULTIBYTE (ptrdiff_t pos)
  1317 {
  1318   return (!NILP (BVAR (current_buffer, enable_multibyte_characters))
  1319           ? FETCH_MULTIBYTE_CHAR (pos)
  1320           : UNIBYTE_TO_CHAR (FETCH_BYTE (pos)));
  1321 }
  1322 
  1323 /* Return character at byte position POS.
  1324    See the caveat WARNING for FETCH_MULTIBYTE_CHAR above.  */
  1325 
  1326 INLINE int
  1327 FETCH_CHAR (ptrdiff_t pos)
  1328 {
  1329   return (!NILP (BVAR (current_buffer, enable_multibyte_characters))
  1330           ? FETCH_MULTIBYTE_CHAR (pos)
  1331           : FETCH_BYTE (pos));
  1332 }
  1333 
  1334 /* Return the address of character at byte position POS in buffer BUF.
  1335    Note that both arguments can be computed more than once.  */
  1336 
  1337 INLINE unsigned char *
  1338 BUF_BYTE_ADDRESS (struct buffer *buf, ptrdiff_t pos)
  1339 {
  1340   return (buf->text->beg + pos - BEG_BYTE
  1341           + (pos < buf->text->gpt_byte ? 0 : buf->text->gap_size));
  1342 }
  1343 
  1344 /* Return the address of character at char position POS in buffer BUF.
  1345    Note that both arguments can be computed more than once.  */
  1346 
  1347 INLINE unsigned char *
  1348 BUF_CHAR_ADDRESS (struct buffer *buf, ptrdiff_t pos)
  1349 {
  1350   return (buf->text->beg + buf_charpos_to_bytepos (buf, pos) - BEG_BYTE
  1351           + (pos < buf->text->gpt ? 0 : buf->text->gap_size));
  1352 }
  1353 
  1354 /* Convert PTR, the address of a char in buffer BUF,
  1355    into a character position.  */
  1356 
  1357 INLINE ptrdiff_t
  1358 BUF_PTR_BYTE_POS (struct buffer *buf, unsigned char *ptr)
  1359 {
  1360   ptrdiff_t byte = ptr - buf->text->beg;
  1361   return (byte - (byte <= BUF_GPT_BYTE (buf) - BEG_BYTE ? 0 : BUF_GAP_SIZE (buf))
  1362           + BEG_BYTE);
  1363 }
  1364 
  1365 /* Return the byte at byte position N in buffer BUF.   */
  1366 
  1367 INLINE unsigned char
  1368 BUF_FETCH_BYTE (struct buffer *buf, ptrdiff_t n)
  1369 {
  1370   return *BUF_BYTE_ADDRESS (buf, n);
  1371 }
  1372 
  1373 /* Return character at byte position POS in buffer BUF.  If BUF is
  1374    unibyte and the character is not ASCII, make the returning
  1375    character multibyte.  */
  1376 
  1377 INLINE int
  1378 BUF_FETCH_CHAR_AS_MULTIBYTE (struct buffer *buf, ptrdiff_t pos)
  1379 {
  1380   return (! NILP (BVAR (buf, enable_multibyte_characters))
  1381           ? BUF_FETCH_MULTIBYTE_CHAR (buf, pos)
  1382           : UNIBYTE_TO_CHAR (BUF_FETCH_BYTE (buf, pos)));
  1383 }
  1384 
  1385 /* Return number of windows showing B.  */
  1386 
  1387 INLINE int
  1388 buffer_window_count (struct buffer *b)
  1389 {
  1390   if (b->base_buffer)
  1391     b = b->base_buffer;
  1392   eassert (b->window_count >= 0);
  1393   return b->window_count;
  1394 }
  1395 
  1396 /* Overlays */
  1397 
  1398 INLINE ptrdiff_t
  1399 overlay_start (struct Lisp_Overlay *ov)
  1400 {
  1401   if (! ov->buffer)
  1402     return -1;
  1403   return itree_node_begin (ov->buffer->overlays, ov->interval);
  1404 }
  1405 
  1406 INLINE ptrdiff_t
  1407 overlay_end (struct Lisp_Overlay *ov)
  1408 {
  1409   if (! ov->buffer)
  1410     return -1;
  1411   return itree_node_end (ov->buffer->overlays, ov->interval);
  1412 }
  1413 
  1414 /* Return the start of OV in its buffer, or -1 if OV is not associated
  1415    with any buffer.  */
  1416 
  1417 INLINE ptrdiff_t
  1418 OVERLAY_START (Lisp_Object ov)
  1419 {
  1420   return overlay_start (XOVERLAY (ov));
  1421 }
  1422 
  1423 /* Return the end of OV in its buffer, or -1. */
  1424 
  1425 INLINE ptrdiff_t
  1426 OVERLAY_END (Lisp_Object ov)
  1427 {
  1428   return overlay_end (XOVERLAY (ov));
  1429 }
  1430 
  1431 /* Return the plist of overlay OV.  */
  1432 
  1433 INLINE Lisp_Object
  1434 OVERLAY_PLIST (Lisp_Object ov)
  1435 {
  1436   return XOVERLAY (ov)->plist;
  1437 }
  1438 
  1439 /* Return the buffer of overlay OV. */
  1440 
  1441 INLINE struct buffer *
  1442 OVERLAY_BUFFER (Lisp_Object ov)
  1443 {
  1444   return XOVERLAY (ov)->buffer;
  1445 }
  1446 
  1447 /* Return true, if OV's rear-advance is set. */
  1448 
  1449 INLINE bool
  1450 OVERLAY_REAR_ADVANCE_P (Lisp_Object ov)
  1451 {
  1452   return XOVERLAY (ov)->interval->rear_advance;
  1453 }
  1454 
  1455 /* Return true, if OV's front-advance is set. */
  1456 
  1457 INLINE bool
  1458 OVERLAY_FRONT_ADVANCE_P (Lisp_Object ov)
  1459 {
  1460   return XOVERLAY (ov)->interval->front_advance;
  1461 }
  1462 
  1463 
  1464 /***********************************************************************
  1465                         Buffer-local Variables
  1466  ***********************************************************************/
  1467 
  1468 /* Return the offset in bytes of member VAR of struct buffer
  1469    from the start of a buffer structure.  */
  1470 
  1471 #define PER_BUFFER_VAR_OFFSET(VAR) \
  1472   offsetof (struct buffer, VAR ## _)
  1473 
  1474 /* Used to iterate over normal Lisp_Object fields of struct buffer (all
  1475    Lisp_Objects except undo_list).  If you add, remove, or reorder
  1476    Lisp_Objects in a struct buffer, make sure that this is still correct.  */
  1477 
  1478 #define FOR_EACH_PER_BUFFER_OBJECT_AT(offset)                            \
  1479   for (offset = PER_BUFFER_VAR_OFFSET (name);                            \
  1480        offset <= PER_BUFFER_VAR_OFFSET (cursor_in_non_selected_windows); \
  1481        offset += word_size)
  1482 
  1483 /* Return the index of buffer-local variable VAR.  Each per-buffer
  1484    variable has an index > 0 associated with it, except when it always
  1485    has buffer-local values, in which case the index is -1.  If this is
  1486    0, this is a bug and means that the slot of VAR in
  1487    buffer_local_flags wasn't initialized.  */
  1488 
  1489 #define PER_BUFFER_VAR_IDX(VAR) \
  1490     PER_BUFFER_IDX (PER_BUFFER_VAR_OFFSET (VAR))
  1491 
  1492 extern bool valid_per_buffer_idx (int);
  1493 
  1494 /* Value is true if the variable with index IDX has a local value
  1495    in buffer B.  */
  1496 
  1497 INLINE bool
  1498 PER_BUFFER_VALUE_P (struct buffer *b, int idx)
  1499 {
  1500   eassert (valid_per_buffer_idx (idx));
  1501   return b->local_flags[idx];
  1502 }
  1503 
  1504 /* Set whether per-buffer variable with index IDX has a buffer-local
  1505    value in buffer B.  VAL zero means it hasn't.  */
  1506 
  1507 INLINE void
  1508 SET_PER_BUFFER_VALUE_P (struct buffer *b, int idx, bool val)
  1509 {
  1510   eassert (valid_per_buffer_idx (idx));
  1511   b->local_flags[idx] = val;
  1512 }
  1513 
  1514 /* Return the index value of the per-buffer variable at offset OFFSET
  1515    in the buffer structure.
  1516 
  1517    If the slot OFFSET has a corresponding default value in
  1518    buffer_defaults, the index value is positive and has only one
  1519    nonzero bit.  When a buffer has its own local value for a slot, the
  1520    bit for that slot (found in the same slot in this structure) is
  1521    turned on in the buffer's local_flags array.
  1522 
  1523    If the index value is -1, even though there may be a
  1524    DEFVAR_PER_BUFFER for the slot, there is no default value for it;
  1525    and the corresponding slot in buffer_defaults is not used.
  1526 
  1527    If the index value is -2, then there is no DEFVAR_PER_BUFFER for
  1528    the slot, but there is a default value which is copied into each
  1529    new buffer.
  1530 
  1531    If a slot in this structure corresponding to a DEFVAR_PER_BUFFER is
  1532    zero, that is a bug.  */
  1533 
  1534 INLINE int
  1535 PER_BUFFER_IDX (ptrdiff_t offset)
  1536 {
  1537   return XFIXNUM (*(Lisp_Object *) (offset + (char *) &buffer_local_flags));
  1538 }
  1539 
  1540 /* Functions to get and set default value of the per-buffer
  1541    variable at offset OFFSET in the buffer structure.  */
  1542 
  1543 INLINE Lisp_Object
  1544 per_buffer_default (int offset)
  1545 {
  1546   return *(Lisp_Object *)(offset + (char *) &buffer_defaults);
  1547 }
  1548 
  1549 INLINE void
  1550 set_per_buffer_default (int offset, Lisp_Object value)
  1551 {
  1552   *(Lisp_Object *)(offset + (char *) &buffer_defaults) = value;
  1553 }
  1554 
  1555 /* Functions to get and set buffer-local value of the per-buffer
  1556    variable at offset OFFSET in the buffer structure.  */
  1557 
  1558 INLINE Lisp_Object
  1559 per_buffer_value (struct buffer *b, int offset)
  1560 {
  1561   return *(Lisp_Object *)(offset + (char *) b);
  1562 }
  1563 
  1564 INLINE void
  1565 set_per_buffer_value (struct buffer *b, int offset, Lisp_Object value)
  1566 {
  1567   *(Lisp_Object *)(offset + (char *) b) = value;
  1568 }
  1569 
  1570 /* Downcase a character C, or make no change if that cannot be done.  */
  1571 INLINE int
  1572 downcase (int c)
  1573 {
  1574   Lisp_Object downcase_table = BVAR (current_buffer, downcase_table);
  1575   Lisp_Object down = CHAR_TABLE_REF (downcase_table, c);
  1576   return FIXNATP (down) ? XFIXNAT (down) : c;
  1577 }
  1578 
  1579 /* Upcase a character C, or make no change if that cannot be done. */
  1580 INLINE int
  1581 upcase (int c)
  1582 {
  1583   Lisp_Object upcase_table = BVAR (current_buffer, upcase_table);
  1584   Lisp_Object up = CHAR_TABLE_REF (upcase_table, c);
  1585   return FIXNATP (up) ? XFIXNAT (up) : c;
  1586 }
  1587 
  1588 /* True if C is upper case.  */
  1589 INLINE bool
  1590 uppercasep (int c)
  1591 {
  1592   return downcase (c) != c;
  1593 }
  1594 
  1595 /* True if C is lower case.  */
  1596 INLINE bool
  1597 lowercasep (int c)
  1598 {
  1599   return !uppercasep (c) && upcase (c) != c;
  1600 }
  1601 
  1602 /* Return a non-outlandish value for the tab width.  */
  1603 
  1604 INLINE int
  1605 sanitize_tab_width (Lisp_Object width)
  1606 {
  1607   return (FIXNUMP (width) && 0 < XFIXNUM (width) && XFIXNUM (width) <= 1000
  1608           ? XFIXNUM (width) : 8);
  1609 }
  1610 
  1611 INLINE int
  1612 SANE_TAB_WIDTH (struct buffer *buf)
  1613 {
  1614   return sanitize_tab_width (BVAR (buf, tab_width));
  1615 }
  1616 
  1617 /* Return a non-outlandish value for a character width.  */
  1618 
  1619 INLINE int
  1620 sanitize_char_width (EMACS_INT width)
  1621 {
  1622   return 0 <= width && width <= 1000 ? width : 1000;
  1623 }
  1624 
  1625 /* Return the width of character C.  The width is measured by how many
  1626    columns C will occupy on the screen when displayed in the current
  1627    buffer.  The name CHARACTER_WIDTH avoids a collision with <limits.h>
  1628    CHAR_WIDTH.  */
  1629 
  1630 INLINE int
  1631 CHARACTER_WIDTH (int c)
  1632 {
  1633   return (0x20 <= c && c < 0x7f ? 1
  1634           : 0x7f < c ? (sanitize_char_width
  1635                         (XFIXNUM (CHAR_TABLE_REF (Vchar_width_table, c))))
  1636           : c == '\t' ? SANE_TAB_WIDTH (current_buffer)
  1637           : c == '\n' ? 0
  1638           : !NILP (BVAR (current_buffer, ctl_arrow)) ? 2 : 4);
  1639 }
  1640 
  1641 
  1642 /* Like fetch_string_char_advance, but fetch character from the current
  1643    buffer.  */
  1644 
  1645 INLINE int
  1646 fetch_char_advance (ptrdiff_t *charidx, ptrdiff_t *byteidx)
  1647 {
  1648   int output;
  1649   ptrdiff_t c = *charidx, b = *byteidx;
  1650   c++;
  1651   unsigned char *chp = BYTE_POS_ADDR (b);
  1652   if (!NILP (BVAR (current_buffer, enable_multibyte_characters)))
  1653     {
  1654       int chlen;
  1655       output = string_char_and_length (chp, &chlen);
  1656       b += chlen;
  1657     }
  1658   else
  1659     {
  1660       output = *chp;
  1661       b++;
  1662     }
  1663   *charidx = c;
  1664   *byteidx = b;
  1665   return output;
  1666 }
  1667 
  1668 
  1669 /* Like fetch_char_advance, but assumes the current buffer is multibyte.  */
  1670 
  1671 INLINE int
  1672 fetch_char_advance_no_check (ptrdiff_t *charidx, ptrdiff_t *byteidx)
  1673 {
  1674   int output;
  1675   ptrdiff_t c = *charidx, b = *byteidx;
  1676   c++;
  1677   unsigned char *chp = BYTE_POS_ADDR (b);
  1678   int chlen;
  1679   output = string_char_and_length (chp, &chlen);
  1680   b += chlen;
  1681   *charidx = c;
  1682   *byteidx = b;
  1683   return output;
  1684 }
  1685 
  1686 /* Return the number of bytes in the multibyte character in BUF
  1687    that starts at position POS_BYTE.  This relies on the fact that
  1688    *GPT_ADDR and *Z_ADDR are always accessible and the values are
  1689    '\0'.  No range checking of POS_BYTE.  */
  1690 
  1691 INLINE int
  1692 buf_next_char_len (struct buffer *buf, ptrdiff_t pos_byte)
  1693 {
  1694   unsigned char *chp = BUF_BYTE_ADDRESS (buf, pos_byte);
  1695   return BYTES_BY_CHAR_HEAD (*chp);
  1696 }
  1697 
  1698 INLINE int
  1699 next_char_len (ptrdiff_t pos_byte)
  1700 {
  1701   return buf_next_char_len (current_buffer, pos_byte);
  1702 }
  1703 
  1704 /* Return the number of bytes in the multibyte character in BUF just
  1705    before POS_BYTE.  No range checking of POS_BYTE.  */
  1706 
  1707 INLINE int
  1708 buf_prev_char_len (struct buffer *buf, ptrdiff_t pos_byte)
  1709 {
  1710   unsigned char *chp
  1711     = (BUF_BEG_ADDR (buf) + pos_byte - BEG_BYTE
  1712        + (pos_byte <= BUF_GPT_BYTE (buf) ? 0 : BUF_GAP_SIZE (buf)));
  1713   return raw_prev_char_len (chp);
  1714 }
  1715 
  1716 INLINE int
  1717 prev_char_len (ptrdiff_t pos_byte)
  1718 {
  1719   return buf_prev_char_len (current_buffer, pos_byte);
  1720 }
  1721 
  1722 /* Increment both *CHARPOS and *BYTEPOS, each in the appropriate way.  */
  1723 
  1724 INLINE void
  1725 inc_both (ptrdiff_t *charpos, ptrdiff_t *bytepos)
  1726 {
  1727   (*charpos)++;
  1728   (*bytepos) += (!NILP (BVAR (current_buffer, enable_multibyte_characters))
  1729                  ? next_char_len (*bytepos) : 1);
  1730 }
  1731 
  1732 /* Decrement both *CHARPOS and *BYTEPOS, each in the appropriate way.  */
  1733 
  1734 INLINE void
  1735 dec_both (ptrdiff_t *charpos, ptrdiff_t *bytepos)
  1736 {
  1737   (*charpos)--;
  1738   (*bytepos) -= (!NILP (BVAR (current_buffer, enable_multibyte_characters))
  1739                  ? prev_char_len (*bytepos) : 1);
  1740 }
  1741 
  1742 INLINE_HEADER_END
  1743 
  1744 int compare_overlays (const void *v1, const void *v2);
  1745 void make_sortvec_item (struct sortvec *item, Lisp_Object overlay);
  1746 
  1747 #endif /* EMACS_BUFFER_H */

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