Skip to content

Commit 7cb9ce1

Browse files
da-liiiclaude
andauthored
[0828] plugin-math-input 改用独立 string port 捕获,修复日志污染 (#4353)
Co-authored-by: Claude <noreply@anthropic.com>
1 parent f525276 commit 7cb9ce1

5 files changed

Lines changed: 170 additions & 65 deletions

File tree

‎TeXmacs/plugins/maxima/progs/maxima/maxima-input.scm‎

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -20,35 +20,35 @@
2020
(define (maxima-input-var-row r)
2121
(if (nnull? r)
2222
(begin
23-
(display ", ")
23+
(plugin-output ", ")
2424
(plugin-input (car r))
2525
(maxima-input-var-row (cdr r))
2626
) ;begin
2727
) ;if
2828
) ;define
2929

3030
(define (maxima-input-row r)
31-
(display "[")
31+
(plugin-output "[")
3232
(plugin-input (car r))
3333
(maxima-input-var-row (cdr r))
34-
(display "]")
34+
(plugin-output "]")
3535
) ;define
3636

3737
(define (maxima-input-var-rows t)
3838
(if (nnull? t)
3939
(begin
40-
(display ", ")
40+
(plugin-output ", ")
4141
(maxima-input-row (car t))
4242
(maxima-input-var-rows (cdr t))
4343
) ;begin
4444
) ;if
4545
) ;define
4646

4747
(define (maxima-input-rows t)
48-
(display "matrix(")
48+
(plugin-output "matrix(")
4949
(maxima-input-row (car t))
5050
(maxima-input-var-rows (cdr t))
51-
(display ")")
51+
(plugin-output ")")
5252
) ;define
5353

5454
(define (maxima-input-descend-last args)
@@ -59,32 +59,32 @@
5959
) ;define
6060

6161
(define (maxima-input-det args)
62-
(display "determinant(")
62+
(plugin-output "determinant(")
6363
(maxima-input-descend-last args)
64-
(display ")")
64+
(plugin-output ")")
6565
) ;define
6666

6767
(define (maxima-input-binom args)
68-
(display "binomial(")
68+
(plugin-output "binomial(")
6969
(plugin-input (car args))
70-
(display ",")
70+
(plugin-output ",")
7171
(plugin-input (cadr args))
72-
(display ")")
72+
(plugin-output ")")
7373
) ;define
7474

7575
(define (maxima-input-sqrt args)
7676
(if (= (length args) 1)
7777
(begin
78-
(display "sqrt(")
78+
(plugin-output "sqrt(")
7979
(plugin-input (car args))
80-
(display ")")
80+
(plugin-output ")")
8181
) ;begin
8282
(begin
83-
(display "(")
83+
(plugin-output "(")
8484
(plugin-input (car args))
85-
(display ")^(1/(")
85+
(plugin-output ")^(1/(")
8686
(plugin-input (cadr args))
87-
(display "))")
87+
(plugin-output "))")
8888
) ;begin
8989
) ;if
9090
) ;define
@@ -94,44 +94,44 @@
9494
(if (nnull? (cdr args))
9595
(begin
9696
;; both lower and upper index
97-
(display "tmsum(")
97+
(plugin-output "tmsum(")
9898
(plugin-input (car args))
99-
(display ",")
99+
(plugin-output ",")
100100
(plugin-input (cadr args))
101-
(display ",")
101+
(plugin-output ",")
102102
) ;begin
103103
(begin
104104
;; lower index only
105-
(display "tmlsum(")
105+
(plugin-output "tmlsum(")
106106
(plugin-input (car args))
107-
(display ",")
107+
(plugin-output ",")
108108
) ;begin
109109
) ;if
110-
(display "tmsum(")
110+
(plugin-output "tmsum(")
111111
) ;if
112112
) ;define
113113

114114
(define (maxima-input-prod args)
115115
(if (nnull? args)
116116
(begin
117-
(display "tmprod(")
117+
(plugin-output "tmprod(")
118118
(plugin-input (car args))
119-
(if (nnull? (cdr args)) (begin (display ",") (plugin-input (cadr args))))
120-
(display ",")
119+
(if (nnull? (cdr args)) (begin (plugin-output ",") (plugin-input (cadr args))))
120+
(plugin-output ",")
121121
) ;begin
122-
(display "tmprod(")
122+
(plugin-output "tmprod(")
123123
) ;if
124124
) ;define
125125

126126
(define (maxima-input-int args)
127127
(if (nnull? args)
128128
(begin
129-
(display "tmint(")
129+
(plugin-output "tmint(")
130130
(plugin-input (car args))
131-
(if (nnull? (cdr args)) (begin (display ",") (plugin-input (cadr args))))
132-
(display ",")
131+
(if (nnull? (cdr args)) (begin (plugin-output ",") (plugin-input (cadr args))))
132+
(plugin-output ",")
133133
) ;begin
134-
(display "integrate(")
134+
(plugin-output "integrate(")
135135
) ;if
136136
) ;define
137137

@@ -147,10 +147,10 @@
147147
(cond ((== op "sum") (maxima-input-sum l))
148148
((== op "prod") (maxima-input-prod l))
149149
((== op "int") (maxima-input-int l))
150-
(else (display op) (display "("))
150+
(else (plugin-output op) (plugin-output "("))
151151
) ;cond
152152
(plugin-input body)
153-
(display ")")
153+
(plugin-output ")")
154154
) ;let*
155155
) ;define
156156

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2+
;;
3+
;; MODULE : plugin-cmd-test.scm
4+
;; DESCRIPTION : Regression test for plugin-cmd serialization support
5+
;; COPYRIGHT : (C) 2026 Liii Network
6+
;;
7+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8+
9+
(import (liii check))
10+
11+
(check-set-mode! 'report-failed)
12+
13+
(use-modules (utils plugins plugin-cmd))
14+
(load "./TeXmacs/plugins/maxima/progs/maxima/maxima-input.scm")
15+
16+
;; test-pre-serialize-passthrough
17+
;; 普通字符串与多段落 document 原样透传
18+
19+
(define (test-pre-serialize-passthrough)
20+
(check (pre-serialize "python" "1+1") => "1+1")
21+
(check (pre-serialize "python" "print('中文')") => "print('中文')")
22+
(check (pre-serialize "python" '(document "a" "b")) => '(document "a" "b"))
23+
) ;define
24+
25+
;; test-pre-serialize-document
26+
;; 单层 document 剥壳,递归到内容本身
27+
28+
(define (test-pre-serialize-document)
29+
(check (pre-serialize "python" '(document "1+1")) => "1+1")
30+
) ;define
31+
32+
;; test-pre-serialize-math
33+
;; math 输入按 lan 的转换规则渲染成插件语言文本(generic 规则兜底)
34+
35+
(define (test-pre-serialize-math)
36+
(check (pre-serialize "python" '(math (frac "1" "2"))) => "(1/2)")
37+
(check (pre-serialize "python" '(math (concat "x" (rsup "2")))) => "x^2")
38+
(check (pre-serialize "python" '(math "<alpha>")) => "alpha")
39+
(check (pre-serialize "python" '(math "<mathpi>")) => "(4*atan(1))")
40+
) ;define
41+
42+
;; test-pre-serialize-document-math
43+
;; document 剥壳后递归进入 math 分支
44+
45+
(define (test-pre-serialize-document-math)
46+
(check (pre-serialize "python" '(document (math (frac "1" "2")))) => "(1/2)")
47+
) ;define
48+
49+
;; test-pre-serialize-math-maxima
50+
;; 插件自定义 handler(maxima-input.scm)的输出同样写入独立 port
51+
52+
(define (test-pre-serialize-math-maxima)
53+
(check (pre-serialize "maxima" '(math "<mathi>")) => "%i")
54+
(check (pre-serialize "maxima" '(math (binom "n" "k"))) => "binomial(n,k)")
55+
(check (pre-serialize "maxima" '(math (sqrt "2"))) => "sqrt(2)")
56+
) ;define
57+
58+
(tm-define (regtest-plugin-cmd)
59+
(test-pre-serialize-passthrough)
60+
(test-pre-serialize-document)
61+
(test-pre-serialize-math)
62+
(test-pre-serialize-document-math)
63+
(test-pre-serialize-math-maxima)
64+
(check-report)
65+
) ;tm-define

0 commit comments

Comments
 (0)