【发布时间】:2013-07-11 08:03:38
【问题描述】:
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.
我们可以做一个简单的实验:
创建一个缓冲区,计算这个表达式:(insert "a" (- (max-char) 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)))))
我得到的是“(1 2 3 2 2 2 3)”。
列表中的数字代表缓冲区中的字符位置。因为有一个5字节的大字符,所以'1'和'3'之间应该有5个'2',但是'2'中的神奇'3'怎么解释呢?
【问题讨论】:
-
奇怪...如果这里没有人提出解释,我建议发送错误报告(顺便说一句,我得到 (1 2 3 2 3 2 3 4 5...)在 24.3 和 23.x 中使用更长的缓冲区进行测试)
-
绝对看起来像一个错误。我得到的输出与您在 Windows 上的 Emacs 23.4 上的输出相同(尚未在 Linux 上尝试过)。
标签: emacs non-ascii-characters