[209_21] 修复 algorithm 环境中 listing 对条件结构缺失行号的问题#3276
Open
JackYansongLi wants to merge 45 commits into
Open
Conversation
b244109 to
543ae6a
Compare
…节点包裹 numbered-line
…xt-numbered-prog 包裹 numbered-line
Add wrap-algo-macro and wrap-algo-if-else-if in markup-funcs.scm to expand algorithm macros (algo-if, algo-while, algo-for, etc.) into numbered-line items, ensuring all lines (headers, body, footers) get continuous line numbers when used inside listing environments. Refs: #222_81
No changes needed to algorithm macro definitions; line numbering fix is handled entirely in markup-funcs.scm.
- Add specified-algorithm test case to 222_81.tmu - Simplify testing instructions in 222_81.md
GUI-inserted algorithm macros may omit optional arguments (e.g. algo-if without cond). Add arity checks and fallback logic to prevent malformed tree construction when arguments are missing or empty.
specified-algorithm has two args (intro + body) and places cursor in the intro area by default. Users often type code in intro by mistake, causing cursor positioning issues when inserting listing. Change menu to create plain algorithm (single body arg) instead.
When algo-if-else-if is used as an environment (<\algo-if-else-if>...), tm-children returns a single document node containing all arguments. Add logic to unwrap the document and filter out empty paragraphs before processing arguments.
- Add listing-active flag to env-program.ts - Add build-if-else-if and build-else-if helpers in markup-funcs.scm - Properly expand algo-if-else-if (both direct and environment forms) into individually numbered lines matching algorithm2e style - Filter out next-line/new-line nodes when parsing environment form args
- Replace wrap-algo-body with ext-apply-on-paragraphs to apply numbered-line recursively to all paragraphs inside algorithm macro bodies - This fixes missing line numbers for content inside algo-if, algo-while, algo-for, and algo-if-else-if when used in listing mode - Add direct-form algo-if-else-if test case to 222_81.tmu
- Replace original ext-numbered-sub/line approach with wrap-listing-line that properly expands algorithm macros into individually numbered lines - Add is-algo-macro?, wrap-algo-macro, wrap-algo-body, build-if-else-if, build-else-if helpers - wrap-algo-body now flattens multi-line non-document nodes (like concat) to ensure nested body paragraphs get independent line numbers - algo-if-else-if handles both direct form and environment form by extracting args from document children or direct children - Fix crash caused by calling ext-apply-on-paragraphs with string
…e nodes - Keep original ext-numbered-sub/ext-numbered-line for all non-algorithm macros - Add is-algo-macro? predicate and wrap-algo-macro to specially expand algo-if/algo-while/algo-for/algo-if-else-if etc. into flat numbered-line list - wrap-algo-body uses ext-numbered-sub for non-algo multi-line nodes, preserving python-code/shell-code highlighting and structure - Revert env-program.ts to main (removed unused listing-active flag)
…rch on every Enter)
1639483 to
f983f1a
Compare
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.
如何测试
~/Library/Caches/MoganLab,然后重启 Mogan%appdata%/MoganLab和%localappdata%/MoganLab,然后重启 Mogan~/.cache/MoganLab,然后重启 Mogangeneric样式algorithm环境(插入 -> 程序 -> Algorithm)listing环境(插入 -> 程序 -> Listing -> Verbatim)algo-if、algo-while、algo-for、algo-if-else-if等TeXmacs/tests/tmu/209_21.tmuWhat
修复在
algorithm环境中使用listing时,algo-if、algo-while、algo-for、algo-if-else-if等条件/循环结构的头部行及其内部语句没有行号的问题。Why
listing宏通过ext-numbered-prog为每行包裹numbered-line来生成行号。原始逻辑对普通代码块(如python-code)是对的(递归进入多行节点),但对算法宏(如algo-while)不对——算法宏需要被拆开成"头部 + body + 尾部",每部分都要独立编号。How
在
TeXmacs/progs/utils/misc/markup-funcs.scm中:ext-numbered-sub/ext-numbered-line:处理普通多行节点(如python-code)的高亮和行号,保持结构不变is-algo-macro?:识别所有算法控制结构宏wrap-algo-macro:将算法宏展开为多个numbered-line行(头部、body、尾部),body 行通过indent-lines恢复缩进build-if-else-if/build-else-if:递归展开algo-if-else-if的多分支条件结构ext-numbered/ext-numbered-prog:遇到算法宏调用wrap-algo-macro拆开;其他多行节点沿用原来的ext-numbered-sub在
TeXmacs/progs/generic/generic-edit.scm中:algo-macro-tags、find-algo-macro-ancestor、cursor-in-algo-macro-first-param?kbd-enter多态定义:在listing环境内的algo-if、algo-while等宏第一个参数中按 Enter,跳到第二个参数(模拟 End + Right Arrow)在
TeXmacs/progs/prog/prog-menu.scm中:specified-algorithm改为algorithm