summaryrefslogtreecommitdiff
path: root/src/buffer.h
diff options
Diffstat (limited to 'src/buffer.h')
-rw-r--r--src/buffer.h30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/buffer.h b/src/buffer.h
index 5c0a6ab..9479b14 100644
--- a/src/buffer.h
+++ b/src/buffer.h
@@ -220,6 +220,23 @@ extern ptrdiff_t advance_to_char_boundary (ptrdiff_t byte_pos);
/* Define the actual buffer data structures. */
+/* This data structure stores the cache of a position and its line and
+ column number. The column number is counted in bytes. The line
+ number and column number don't consider narrowing. */
+struct ts_linecol
+{
+ /* A position in the buffer. */
+ ptrdiff_t pos;
+ /* The byte position of POS. */
+ ptrdiff_t byte_pos;
+ /* The line number of this position. */
+ ptrdiff_t line;
+ /* The column number (in bytes) of this position. Unlike Emacs'
+ convention, this is 0-based (because tree-sitter column is
+ 0-based). Simply the byte offset from BOL (or BOB). */
+ ptrdiff_t col;
+};
+
/* This data structure describes the actual text contents of a buffer.
It is shared between indirect buffers and their base buffer. */
@@ -700,6 +717,19 @@ struct buffer
/* The interval tree containing this buffer's overlays. */
struct itree_tree *overlays;
+ /* Right now only tree-sitter makes use of this, so I don't want
+ non-tree-sitter build to pay for it. If something else can make
+ use of this, we can remove the gate. */
+#ifdef HAVE_TREE_SITTER
+ /* Cache of line and column number of a position. The position cached
+ is usually near point. Tree-sitter uses this cache to calculate
+ line and column of the beginning and end of buffer edits. This
+ cache is refreshed in buffer edit functions, so it's always
+ up-to-date. Usually, the newly calculated position and line/column
+ are saved to this field. Initialized to position 1. */
+ struct ts_linecol ts_linecol_cache;
+#endif
+
/* Changes in the buffer are recorded here for undo, and t means
don't record anything. This information belongs to the base
buffer of an indirect buffer. But we can't store it in the