aboutsummaryrefslogtreecommitdiffstats
path: root/src/buffer.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/buffer.h')
-rw-r--r--src/buffer.h72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/buffer.h b/src/buffer.h
index d19ff22babd..26a334ea810 100644
--- a/src/buffer.h
+++ b/src/buffer.h
@@ -220,6 +220,20 @@ extern ptrdiff_t advance_to_char_boundary (ptrdiff_t byte_pos);
220 220
221/* Define the actual buffer data structures. */ 221/* Define the actual buffer data structures. */
222 222
223/* This data structure stores the cache of a position and its line and
224 column number. The column number is counted in bytes. The line
225 number and column number don't respect narrowing. */
226struct ts_linecol
227{
228 /* The byte position. */
229 ptrdiff_t bytepos;
230 /* The line number of this position. */
231 ptrdiff_t line;
232 /* The column number (in bytes) of this position (0-based). Basically
233 the byte offset from BOL (or BOB). */
234 ptrdiff_t col;
235};
236
223/* This data structure describes the actual text contents of a buffer. 237/* This data structure describes the actual text contents of a buffer.
224 It is shared between indirect buffers and their base buffer. */ 238 It is shared between indirect buffers and their base buffer. */
225 239
@@ -700,6 +714,25 @@ struct buffer
700 /* The interval tree containing this buffer's overlays. */ 714 /* The interval tree containing this buffer's overlays. */
701 struct itree_tree *overlays; 715 struct itree_tree *overlays;
702 716
717 /* Right now only tree-sitter makes use of this, so I don't want
718 non-tree-sitter build to pay for it. If something else can make
719 use of this, we can remove the gate. */
720#ifdef HAVE_TREE_SITTER
721 /* Cache of line and column number of a position. Tree-sitter uses
722 this cache to calculate line and column of the beginning and end of
723 buffer edits. Stores three caches for BEGV, point, ZV,
724 respectively. All three are refreshed in buffer edit functions, so
725 they're always up-to-date (in the sense that the bytepos and
726 line/column number are in sync, not in the sense that the bytepos
727 is at the actual position of point/BEGV/ZV, indeed, most of the
728 time the bytepos is only near the actual position). All caches are
729 initialized to empty, meaning no linecol tracking for this
730 buffer. */
731 struct ts_linecol ts_linecol_begv;
732 struct ts_linecol ts_linecol_point;
733 struct ts_linecol ts_linecol_zv;
734#endif
735
703 /* Changes in the buffer are recorded here for undo, and t means 736 /* Changes in the buffer are recorded here for undo, and t means
704 don't record anything. This information belongs to the base 737 don't record anything. This information belongs to the base
705 buffer of an indirect buffer. But we can't store it in the 738 buffer of an indirect buffer. But we can't store it in the
@@ -1134,6 +1167,45 @@ BUFFER_CHECK_INDIRECTION (struct buffer *b)
1134 } 1167 }
1135} 1168}
1136 1169
1170#ifdef HAVE_TREE_SITTER
1171
1172INLINE struct ts_linecol
1173BUF_TS_LINECOL_BEGV (struct buffer *buf)
1174{
1175 return buf->ts_linecol_begv;
1176}
1177INLINE struct ts_linecol
1178BUF_TS_LINECOL_POINT (struct buffer *buf)
1179{
1180 return buf->ts_linecol_point;
1181}
1182
1183INLINE struct ts_linecol
1184BUF_TS_LINECOL_ZV (struct buffer *buf)
1185{
1186 return buf->ts_linecol_zv;
1187}
1188
1189INLINE void
1190SET_BUF_TS_LINECOL_BEGV (struct buffer *buf, struct ts_linecol linecol)
1191{
1192 buf->ts_linecol_begv = linecol;
1193}
1194
1195INLINE void
1196SET_BUF_TS_LINECOL_POINT (struct buffer *buf, struct ts_linecol linecol)
1197{
1198 buf->ts_linecol_point = linecol;
1199}
1200
1201INLINE void
1202SET_BUF_TS_LINECOL_ZV (struct buffer *buf, struct ts_linecol linecol)
1203{
1204 buf->ts_linecol_zv = linecol;
1205}
1206
1207#endif
1208
1137/* This structure holds the default values of the buffer-local variables 1209/* This structure holds the default values of the buffer-local variables
1138 that have special slots in each buffer. 1210 that have special slots in each buffer.
1139 The default value occupies the same slot in this structure 1211 The default value occupies the same slot in this structure