Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
[0828] 插件 I/O 序列化器迁移到 UTF-8 raw
1 相关文档
2 任务相关的代码文件
src/Data/Convert/Verbatim/verbatim.cpp— 新增tree_to_utf8raw/utf8raw_to_treesrc/Data/Convert/convert.hpp— 声明新函数src/Scheme/L4/glue_convert.lua— 暴露cpp-tree->utf8raw/cpp-utf8raw->treeTeXmacs/progs/convert/rewrite/init-rewrite.scm— Scheme 包装texmacs->utf8raw/utf8raw->texmacsTeXmacs/progs/init-research.scm— lazy-define 新包装函数TeXmacs/progs/utils/plugins/plugin-cmd.scm— 默认序列化器重命名为utf8raw-serialize并改用texmacs->utf8rawTeXmacs/plugins/{python,julia,goldfish,autosave,tikz,quiver,gnuplot,maxima}/progs/init-*.scm— 自定义 serializer 改用texmacs->utf8rawsrc/Data/Convert/Generic/input.cpp—verbatim_flush/utf8_flush改用utf8raw_to_tree+tree_utf8_to_herksrc/System/Link/connection.cpp—connection_write(tree)入口加入tree_herk_to_utf8src/Edit/Interface/edit_complete.cpp—session_complete_command在调用utf8raw-serialize前加入tree_herk_to_utf8TeXmacs/progs/dynamic/session-edit.scm—input-done?路径在调用plugin-serialize前把pre从 Herk 转成 UTF-8TeXmacs/progs/dynamic/program-edit.scm— 同上,针对 program sessionTeXmacs/tests/0828.scm— 新增 UTF-8 raw 往返、各插件 serializer UTF-8、输入/输出路径转换测试3 如何测试
3.1 确定性测试(单元测试)
3.2 非确定性测试(文档验证)
4 What
connection_write(tree))先把内部 Herk tree 转成 UTF-8 tree。texmacs->utf8raw,不再使用texmacs->code ... "SourceCode"或"utf-8"。verbatim_flush/utf8_flush改用utf8raw_to_tree,再转回内部 Herk。tree_to_verbatim/verbatim_to_tree保留给文件格式转换等其他用途,plugin I/O 不再使用。5 How
verbatim.cpp新增tree_to_utf8raw(tree),直接调用as_verbatim并处理 Windows 换行,跳过var_cork_to_utf8/var_cork_to_sourcecode。verbatim.cpp新增utf8raw_to_tree(string),复用mac_to_unix/dos_to_unix与拆分逻辑,但不经过encode(即不做utf8_to_cork)。把原有拆分逻辑抽成静态 helperverbatim_raw_to_tree供旧函数复用。两函数均不设wrap形参——tree_to_verbatim/verbatim_to_tree保留了wrap是为了文件格式转换等需要折行的场景,而插件 I/O 一律传false,故 raw 版本直接省去该形参,避免留下一处无调用者、无测试的折行分支。convert.hpp声明两个新函数;glue_convert.lua暴露给 Scheme。init-rewrite.scm提供texmacs->utf8raw/utf8raw->texmacs包装;init-research.scm加入 lazy-define。plugin-cmd.scm的verbatim-serialize重命名为utf8raw-serialize,generic-serialize改用texmacs->utf8raw。texmacs->utf8raw (stree->tree u)。input.cpp的verbatim_flush/utf8_flush改为tree_utf8_to_herk (utf8raw_to_tree (buf))。texmacs_input_rep是插件连接的"输入端"——站在 TeXmacs 视角,插件进程经管道发回的数据要"输入"进来;write(tree)把解析结果喂给编辑器内部的文档树(不是写文件,也不是发回插件)。编辑器内部所有字符串标签统一用 Herk 编码,所以write的实参必须是 Herk tree,而buf是插件发来的 UTF-8 字节,分两步翻译:utf8raw_to_tree(buf)先切成(document ...)但标签仍是 UTF-8 原始字节(raw,不做编码转换),tree_utf8_to_herk(...)再把每个 atomic 标签从 UTF-8 解码成 Herk。两步合起来等价于旧版verbatim_to_tree(buf, false, "utf-8")(内部走utf8_to_cork),但编码目标从 cork 升级为 Herk——cork 表之外的码点,旧的utf8_to_cork无映射就丢弃,新的utf8_to_herk用<#XXXX>保留,emoji、BMP 外字符因此不再丢失,这是相对 0827 的关键修正。此外utf8raw_to_tree引入了dos_to_unix/mac_to_unix换行归一化(旧verbatim_to_tree(buf,"utf-8")路径没有),插件输出里的\r\n/ 裸\r会被统一成\n。写出端是对称的逆过程:第 8–10 条里编辑器内部的 Herk tree 先经tree_herk_to_utf8转成 UTF-8 tree,再交给 serializer 输出给插件。connection.cpp的connection_write(tree)在tree_to_stree之前调用tree_herk_to_utf8。edit_complete.cpp的session_complete_command在调用utf8raw-serialize前加入tree_herk_to_utf8,处理 tab completion 这条旁路。session-edit.scm与program-edit.scm的input-done?路径在调用plugin-serialize前把pre从 Herk 转成 UTF-8,避免该查询路径发送 cork 文本给插件。该转换不可省略:plugin-serialize约定接收 UTF-8 stree,而编辑器内部字符串为 Herk/cork,省略会让 Herk 的<#XXXX>字面原样漏给插件——插件收到的是 8 个 ASCII 字符<#4E2D>而非"中"。0828.scm的test-input-done-herk-to-utf8用同一 Herk stree 对比了转换与不转换两种结果,断言不转换时<#XXXX>会漏出,以此证明该转换是必需的而非冗余。当前实现有stree->tree->stree往返开销,但input-done?输入通常很小,影响可忽略;若后续出现瓶颈,可改为直接 stree 级转换。TeXmacs/tests/0828.scm,覆盖texmacs->utf8raw/utf8raw->texmacs往返、各插件 serializer(含 Maxima 的;/$终止符与空输入特例)的 UTF-8 输出、输入端 Herk 转换(含 emoji 落到<#XXXX>的保留路径)、<#XXXX>与普通文本混合的往返、主写出入口 Herk->UTF-8 转换、以及input-done?旁路 Herk stree 转 UTF-8 后再序列化(含不转换的反向对照)等场景。PS
TeXmacs/plugins/*/progs/data/*.scm中出现的(texmacs->verbatim x (acons "texmacs->verbatim:encoding" "SourceCode" '()))用于文件格式导入/导出(如.py、.cpp、.scm),不属于插件 I/O 路径;SourceCode 编码用于文件持久化与往返,0828 不涉及这些路径,保持原样不改。