Skip to content

Commit bcb7e59

Browse files
JerryMain521JerryMain
andauthored
[209_20] 增加Fish(Itasca)代码块及高亮支持 (#3018)
Co-authored-by: JerryMain <16806246+jerrymain521@user.noreply.gitee.com>
1 parent d65861e commit bcb7e59

8 files changed

Lines changed: 2169 additions & 0 deletions

File tree

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<TMU|<tuple|1.1.0|2026.2.1-rc4>>
2+
3+
<style|<tuple|tmudoc|british|fish>>
4+
5+
<\body>
6+
<\hide-preamble>
7+
<assign|code-name|fish>
8+
9+
<assign|code-Name|fish>
10+
</hide-preamble>
11+
12+
<tmdoc-title|<value|code-Name> Code Plugin>
13+
14+
<paragraph|<value|code-Name> style package>
15+
16+
Click <menu|Document|Style|Add package|Code|<value|code-name>> or click <menu|<icon|tm_add.svg>|Code|<value|code-name>> on the focus toolbar to add the <value|code-Name> style package.
17+
18+
In the <code-Name> style package, <markup|<value|code-name>> is provided for inline snippets and <markup|<value|code-name>-code> is provided for <code-Name> code blocks.
19+
20+
<paragraph|<value|code-Name> syntax>
21+
22+
The syntax of the <value|code-Name> language is defined in:
23+
24+
<slink|$TEXMACS_PATH/plugins/<value|code-name>/progs/code/<value|code-name>-lang.scm>
25+
26+
Here is an example <value|code-Name> code block with syntax highlight:
27+
28+
<\fish-code>
29+
; This is a note
30+
31+
fish define example
32+
33+
\ \ \ \ global width = 10.0
34+
35+
\ \ \ \ global height = 5.0
36+
37+
\ \ \ \ global density = 2000.0
38+
39+
\ \ \ \
40+
41+
\ \ \ \ local area = width * height
42+
43+
\ \ \ \ local volume = area * 1.0
44+
45+
\ \ \ \ local weight = density * volume * 9.81
46+
47+
\ \ \ \
48+
49+
\ \ \ \ io.out('width:' + string(width) + ' m')
50+
51+
\ \ \ \ io.out('height:' + string(height) + ' m')
52+
53+
\ \ \ \ io.out('area:' + string(area) + ' m^2')
54+
55+
\ \ \ \ io.out('density:' + string(density) + ' kg/m^3')
56+
57+
\ \ \ \ io.out('weight:' + string(weight) + ' N')
58+
59+
end
60+
61+
\;
62+
63+
@example
64+
</fish-code>
65+
66+
<paragraph|<value|code-Name> editing>
67+
68+
The editing of the <value|code-Name> code is defined in:
69+
70+
<slink|$TEXMACS_PATH/plugins/<value|code-name>/progs/code/<value|code-name>-edit.scm>
71+
72+
\;
73+
74+
<tmdoc-copyright|2025|vesita>
75+
76+
<tmdoc-license|Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".>
77+
</body>
78+
79+
<\initial>
80+
<\collection>
81+
<associate|page-medium|papyrus>
82+
<associate|page-screen-margin|true>
83+
</collection>
84+
</initial>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<TeXmacs|2.1.2>
2+
3+
<style|<tuple|source|std>>
4+
5+
<\body>
6+
<active*|<\src-title>
7+
<compound|src-package|fish|1.0>
8+
9+
<\src-purpose>
10+
fish Language
11+
</src-purpose>
12+
</src-title>>
13+
14+
<use-module|(data fish)>
15+
<use-module|(code fish-edit)>
16+
17+
<assign|fish|<macro|body|<with|mode|prog|prog-language|fish|font-family|rm|<arg|body>>>>
18+
19+
<assign|fish-code|<\macro|body>
20+
<\pseudo-code>
21+
<fish|<arg|body>>
22+
</pseudo-code>
23+
</macro>>
24+
</body>
25+
26+
<\initial>
27+
<\collection>
28+
<associate|preamble|true>
29+
<associate|sfactor|5>
30+
</collection>
31+
</initial>
32+
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2+
;;
3+
;; MODULE : fish-edit.scm
4+
;; DESCRIPTION : editing fish programs
5+
;; COPYRIGHT : (C) 2025 vesita
6+
;;
7+
;; This software falls under the GNU general public license version 3 or later.
8+
;; It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
9+
;; in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
10+
;;
11+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12+
13+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14+
;;;
15+
;;; DESCRIPTION:
16+
;;; This module provides editing functionalities for fish language within
17+
;;; TeXmacs. It defines language-specific behaviors such as indentation,
18+
;;; commenting, and paste operations for fish code snippets.
19+
;;;
20+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
21+
22+
;; 定义模块,使用 prog-edit 和 fish-mode 模块
23+
(texmacs-module (code fish-edit)
24+
(:use (prog prog-edit)
25+
(code fish-mode)))
26+
27+
;;------------------------------------------------------------------------------
28+
;; 缩进设置
29+
;;
30+
31+
;; 定义fish代码的制表符停止位为4个空格(符合fish标准)
32+
(tm-define (get-tabstop)
33+
(:mode in-prog-fish?)
34+
4)
35+
36+
;; 定义fish特定的关键字,这些关键字后面需要增加缩进
37+
(define fish-increase-indent-keys
38+
'("define" "if" "loop" "case" "caseof" "section" "command"))
39+
40+
;; 定义fish特定的配对关键字,这些关键字会减少缩进
41+
(define fish-decrease-indent-keys
42+
'("else" "case"))
43+
44+
;; 定义fish特定的结束关键字,这些关键字会减少缩进
45+
(define fish-end-keys
46+
'("end" "endif" "endloop" "endsection" "endcase" "endcommand"))
47+
48+
;; 去除字符串右侧的空白字符
49+
(define (string-strip-right s)
50+
(with char-set:not-whitespace (char-set-complement char-set:whitespace)
51+
(with n (string-length s)
52+
(with r (or (string-rindex s char-set:not-whitespace) n)
53+
(string-take s (min n (+ 1 r)))))))
54+
55+
;; 检查字符串是否以特定关键字结尾
56+
(define (ends-with-keyword? s keys)
57+
(and (nnull? keys)
58+
(or (string-ends? s (car keys))
59+
(ends-with-keyword? s (cdr keys)))))
60+
61+
;; 检查字符串是否以特定关键字开头
62+
(define (starts-with-keyword? s keys)
63+
(and (nnull? keys)
64+
(or (string-starts? s (string-append (car keys) " "))
65+
(starts-with-keyword? s (cdr keys)))))
66+
67+
;; 定义fish代码的缩进计算函数
68+
(tm-define (program-compute-indentation doc row col)
69+
(:mode in-prog-fish?)
70+
(if (<= row 0) 0
71+
(let* ((prev-row (- row 1))
72+
(prev-line (program-row prev-row))
73+
(stripped-prev (string-strip-right (if prev-line prev-line "")))
74+
(prev-indent (string-get-indent stripped-prev))
75+
(tab-width (get-tabstop)))
76+
(cond
77+
;; 如果前行以增加缩进的关键字结尾,则当前行应增加缩进
78+
((ends-with-keyword? stripped-prev fish-increase-indent-keys)
79+
(+ prev-indent tab-width))
80+
;; 如果当前行以减少缩进的关键字开头,则减少缩进
81+
((starts-with-keyword? (program-row row) fish-decrease-indent-keys)
82+
(max 0 (- prev-indent tab-width)))
83+
;; 如果当前行以结束关键字开头,则减少缩进
84+
((starts-with-keyword? (program-row row) fish-end-keys)
85+
(max 0 (- prev-indent tab-width)))
86+
;; 否则保持前行的缩进
87+
(else prev-indent)))))
88+
89+
;;------------------------------------------------------------------------------
90+
;; 自动插入、高亮和选择括号和引号
91+
;;
92+
93+
(tm-define (fish-bracket-open lbr rbr)
94+
;; 插入一对括号或引号,并将光标定位在中间
95+
(bracket-open lbr rbr "\\"))
96+
97+
(tm-define (fish-bracket-close lbr rbr)
98+
;; 处理闭合括号或引号,并正确放置光标位置
99+
(bracket-close lbr rbr "\\"))
100+
101+
(tm-define (notify-cursor-moved status)
102+
(:require prog-highlight-brackets?)
103+
(:mode in-prog-fish?)
104+
;; 当光标移动时高亮匹配的括号
105+
(select-brackets-after-movement "([{" ")]}" "\\"))
106+
107+
;;------------------------------------------------------------------------------
108+
;; 粘贴操作
109+
;;
110+
111+
;; 定义fish代码环境中的粘贴操作,使用fish格式导入剪贴板内容
112+
(tm-define (kbd-paste)
113+
(:mode in-prog-fish?)
114+
(clipboard-paste-import "fish" "primary"))
115+
116+
(kbd-map
117+
(:mode in-prog-fish?)
118+
;; fish编程模式下的键盘快捷键
119+
("A-tab" (insert-tabstop)) ;; Alt+Tab:插入制表符
120+
("cmd S-tab" (remove-tabstop)) ;; Cmd+Shift+Tab:移除制表符
121+
("{" (fish-bracket-open "{" "}" )) ;; 自动插入匹配的大括号
122+
("}" (fish-bracket-close "{" "}" )) ;; 处理闭合大括号
123+
("(" (fish-bracket-open "(" ")" )) ;; 自动插入匹配的小括号
124+
(")" (fish-bracket-close "(" ")" )) ;; 处理闭合小括号
125+
("[" (fish-bracket-open "[" "]" )) ;; 自动插入匹配的方括号
126+
("]" (fish-bracket-close "[" "]" )) ;; 处理闭合方括号
127+
("\"" (fish-bracket-open "\"" "\"" )) ;; 自动插入匹配的双引号
128+
("'" (fish-bracket-open "'" "'" ))) ;; 自动插入匹配的单引号
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2+
;;
3+
;; MODULE : fish-lang.scm
4+
;; DESCRIPTION : fish language support
5+
;; COPYRIGHT : (C) 2025 veista
6+
;;
7+
;; This software falls under the GNU general public license version 3 or later.
8+
;; It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
9+
;; in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
10+
;;
11+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12+
13+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14+
;;;
15+
;;; DESCRIPTION:
16+
;;; This module provides language support for fish within TeXmacs. It
17+
;;; defines language features such as keywords, operators, number formats,
18+
;;; string formats, and comment formats for proper syntax highlighting and
19+
;;; parsing of fish code.
20+
;;;
21+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
22+
23+
;; 定义fish语言支持模块,使用默认语言支持模块
24+
(texmacs-module (code fish-lang)
25+
(:use (prog default-lang)))
26+
27+
;;------------------------------------------------------------------------------
28+
;; 关键字定义
29+
;;
30+
31+
;; 定义fish语言的关键字分类
32+
(tm-define (parser-feature lan key)
33+
(:require (and (== lan "fish") (== key "keyword")))
34+
`(,(string->symbol key)
35+
(constant
36+
"true" "false" "null")
37+
(declare_function
38+
"define" "struct" "structure")
39+
(declare_identifier
40+
"local" "global")
41+
(keyword_conditional
42+
"if" "else if" "else" "endif"
43+
"caseof" "case" "endcase")
44+
(keyword_control
45+
"loop" "endloop" "exit loop" "continue"
46+
"section" "endsection" "exit section"
47+
"command" "endcommand"
48+
"return" "exit" "end" "lock")))
49+
50+
;;------------------------------------------------------------------------------
51+
;; 操作符定义
52+
;;
53+
54+
;; 定义fish语言的操作符符号
55+
(tm-define (parser-feature lan key)
56+
(:require (and (== lan "fish") (== key "operator")))
57+
`(,(string->symbol key)
58+
(operator
59+
;; 算术运算符
60+
"+" "-" "*" "/" "^"
61+
;; 关系运算符
62+
"==" "!=" "#" "<" ">" "<=" ">="
63+
;; 逻辑运算符
64+
"and" "or" "not"
65+
;; 其他运算符
66+
"=" "(" ")" "[" "]" "{" "}" ";" "," "." "@")))
67+
68+
;;------------------------------------------------------------------------------
69+
;; 数字格式定义
70+
;;
71+
72+
;; 定义fish语言的数字格式,支持科学计数法
73+
(tm-define (parser-feature lan key)
74+
(:require (and (== lan "fish") (== key "number")))
75+
`(,(string->symbol key)
76+
(bool_features
77+
"prefix_0x"
78+
"sci_notation")))
79+
80+
;;------------------------------------------------------------------------------
81+
;; 字符串格式定义
82+
;;
83+
84+
;; 定义fish语言的字符串格式,支持转义字符
85+
(tm-define (parser-feature lan key)
86+
(:require (and (== lan "fish") (== key "string")))
87+
`(,(string->symbol key)
88+
(bool_features
89+
"escape_char_after_backslash")
90+
(escape_sequences "\\" "\"" "n" "t" "b" "r" "f" "a" "v" "0")
91+
(double_escape "'")))
92+
93+
;;------------------------------------------------------------------------------
94+
;; 注释格式定义
95+
;;
96+
97+
;; 定义fish语言的注释格式,使用 ; 作为注释
98+
(tm-define (parser-feature lan key)
99+
(:require (and (== lan "fish") (== key "comment")))
100+
`(,(string->symbol key)
101+
(inline ";")))
102+
103+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
104+
;; Preferences for syntax highlighting
105+
;; 语法高亮偏好设置
106+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
107+
108+
;; 通知fish语法更改的函数
109+
(define (notify-fish-syntax var val)
110+
(syntax-read-preferences "fish"))
111+
112+
;; 定义fish语法高亮颜色偏好设置
113+
;; 已验证可生效
114+
(define-preferences
115+
("syntax:fish:none" "red" notify-fish-syntax)
116+
("syntax:fish:comment" "brown" notify-fish-syntax)
117+
("syntax:fish:error" "dark red" notify-fish-syntax)
118+
("syntax:fish:constant" "#4040c0" notify-fish-syntax)
119+
("syntax:fish:constant_number" "#3030b0" notify-fish-syntax)
120+
("syntax:fish:constant_string" "dark grey" notify-fish-syntax)
121+
("syntax:fish:constant_char" "#333333" notify-fish-syntax)
122+
("syntax:fish:declare_function" "#0000c0" notify-fish-syntax)
123+
("syntax:fish:declare_type" "#0000c0" notify-fish-syntax)
124+
("syntax:fish:declare_module" "#0000c0" notify-fish-syntax)
125+
("syntax:fish:operator" "#8b008b" notify-fish-syntax)
126+
("syntax:fish:operator_openclose" "#B02020" notify-fish-syntax)
127+
("syntax:fish:operator_field" "#888888" notify-fish-syntax)
128+
("syntax:fish:operator_special" "orange" notify-fish-syntax)
129+
("syntax:fish:keyword" "#309090" notify-fish-syntax)
130+
("syntax:fish:keyword_conditional" "#309090" notify-fish-syntax)
131+
("syntax:fish:keyword_control" "#008080ff" notify-fish-syntax))

0 commit comments

Comments
 (0)