emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to add pseudo vector types


From: Fu Yuan
Subject: Re: How to add pseudo vector types
Date: Tue, 3 Aug 2021 08:50:45 -0400

> 在 2021年8月3日,上午8:22,Eli Zaretskii <eliz@gnu.org> 写道:
> 
> 
>> 
>> From: Fu Yuan <casouri@gmail.com>
>> Date: Tue, 3 Aug 2021 07:53:54 -0400
>> Cc: stephen_leake@stephe-leake.org, cpitclaudel@gmail.com,
>> monnier@iro.umontreal.ca, emacs-devel@gnu.org
>> 
>> Oh no, I don’t mean that. I meant that, for example, functions like 
>> node_start_byte, which returns the byte position of the beginning of the 
>> node, will now be node_start_pos, which returns a point position.
> 
> That's called "character position".  Let's use the accepted
> terminology, to minimize misunderstandings.

Ah, got it.

> So in what sense are character positions easier to use than byte
> positions?

Here are what you can do with positions:

- find the smallest node that encloses a range (BEG . END)
- get the beginning and end of a node

Since all other functions use character position (eg, put-text-property, 
point), using character positions saves lisp code some ‘position-to-bytes’. 

>> And if I want the byte position of the beginning of the node, I can use 
>> (position-to-byte (tree-sitter-node-start-pos node))
> 
> Caveat: position-to-byte can be expensive.  So in time-critical code,
> such as the display engine, we keep both character position and byte
> position, and update them in sync.  Then you can use whichever is
> easier in each case.

Internally, tree_sitter.c will continue to use byte positions, of course.

Yuan


reply via email to

[Prev in Thread] Current Thread [Next in Thread]