Emacs字节到位置功能与文档不一致?

Emacs字节到位置功能与文档不一致?,emacs,non-ascii-characters,Emacs,Non Ascii Characters,Emacs 24.3.1,Windows 2003 我发现“字节到位置”函数有点奇怪 根据该文件: -- Function: byte-to-position byte-position Return the buffer position, in character units, corresponding to given BYTE-POSITION in the current buffer. If BYTE-POSITION is out of rang

Emacs 24.3.1,Windows 2003

我发现“字节到位置”函数有点奇怪

根据该文件:

 -- Function: byte-to-position byte-position
     Return the buffer position, in character units, corresponding to
     given BYTE-POSITION in the current buffer.  If BYTE-POSITION is
     out of range, the value is `nil'.  **In a multibyte buffer, an
     arbitrary value of BYTE-POSITION can be not at character boundary,
     but inside a multibyte sequence representing a single character;
     in this case, this function returns the buffer position of the
     character whose multibyte sequence includes BYTE-POSITION.**  In
     other words, the value does not change for all byte positions that
     belong to the same character.
我们可以做一个简单的实验:

创建缓冲区,计算此表达式:(插入“a”((最大字符)128)“b”)

由于Emacs内部编码系统中的最大字节数为5,“a”和“b”之间的字符为5字节。(请注意,最后128个字符用于8位原始字节,其大小仅为2字节。)

然后定义并评估此测试功能:

(defun test ()
  (interactive)
  (let ((max-bytes (1- (position-bytes (point-max)))))
    (message "%s"
             (loop for i from 1 to max-bytes collect (byte-to-position i)))))
我得到的是“(12323)”


列表中的数字表示缓冲区中的字符位置。因为有一个5字节的大字符,“1”和“3”之间应该有五个“2”,但是如何解释“2”中的神奇“3”?

这是一个错误。我不再在26.x中看到这种行为。你可以在这里读到更多关于它的内容(实际上它引用了这个问题)


奇怪。。。如果在24.3和23.x中没有人提出解释(顺便说一句,我得到(1 2 3 2 3 2 3 4 5…)在使用更长的缓冲区重复测试时,我建议发送一份bug报告)看起来确实像bug。我得到的输出与您在Windows上的Emacs 23.4上获得的输出相同(尚未在Linux上尝试)。