-
Notifications
You must be signed in to change notification settings - Fork 93
[209_20] 增加Fish(Itasca)代码块及高亮支持 #3018
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
JerryMain521
wants to merge
3
commits into
MoganLab:main
Choose a base branch
from
JerryMain521:JerryMain521/209_20/add-fish-code-highlight
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| <TMU|<tuple|1.1.0|2026.2.1-rc4>> | ||
|
|
||
| <style|<tuple|tmudoc|british|fish>> | ||
|
|
||
| <\body> | ||
| <\hide-preamble> | ||
| <assign|code-name|fish> | ||
|
|
||
| <assign|code-Name|fish> | ||
| </hide-preamble> | ||
|
|
||
| <tmdoc-title|<value|code-Name> Code Plugin> | ||
|
|
||
| <paragraph|<value|code-Name> style package> | ||
|
|
||
| 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. | ||
|
|
||
| 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. | ||
|
|
||
| <paragraph|<value|code-Name> syntax> | ||
|
|
||
| The syntax of the <value|code-Name> language is defined in: | ||
|
|
||
| <slink|$TEXMACS_PATH/plugins/<value|code-name>/progs/code/<value|code-name>-lang.scm> | ||
|
|
||
| Here is an example <value|code-Name> code block with syntax highlight: | ||
|
|
||
| <\fish-code> | ||
| ; This is a note | ||
|
|
||
| fish define example | ||
|
|
||
| \ \ \ \ global width = 10.0 | ||
|
|
||
| \ \ \ \ global height = 5.0 | ||
|
|
||
| \ \ \ \ global density = 2000.0 | ||
|
|
||
| \ \ \ \ | ||
|
|
||
| \ \ \ \ local area = width * height | ||
|
|
||
| \ \ \ \ local volume = area * 1.0 | ||
|
|
||
| \ \ \ \ local weight = density * volume * 9.81 | ||
|
|
||
| \ \ \ \ | ||
|
|
||
| \ \ \ \ io.out('width:' + string(width) + ' m') | ||
|
|
||
| \ \ \ \ io.out('height:' + string(height) + ' m') | ||
|
|
||
| \ \ \ \ io.out('area:' + string(area) + ' m^2') | ||
|
|
||
| \ \ \ \ io.out('density:' + string(density) + ' kg/m^3') | ||
|
|
||
| \ \ \ \ io.out('weight:' + string(weight) + ' N') | ||
|
|
||
| end | ||
|
|
||
| \; | ||
|
|
||
| @example | ||
| </fish-code> | ||
|
|
||
| <paragraph|<value|code-Name> editing> | ||
|
|
||
| The editing of the <value|code-Name> code is defined in: | ||
|
|
||
| <slink|$TEXMACS_PATH/plugins/<value|code-name>/progs/code/<value|code-name>-edit.scm> | ||
|
|
||
| \; | ||
|
|
||
| <tmdoc-copyright|2025|vesita> | ||
|
|
||
| <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".> | ||
| </body> | ||
|
|
||
| <\initial> | ||
| <\collection> | ||
| <associate|page-medium|papyrus> | ||
| <associate|page-screen-margin|true> | ||
| </collection> | ||
| </initial> |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| <TeXmacs|2.1.2> | ||
|
|
||
| <style|<tuple|source|std>> | ||
|
|
||
| <\body> | ||
| <active*|<\src-title> | ||
| <compound|src-package|fish|1.0> | ||
|
|
||
| <\src-purpose> | ||
| fish Language | ||
| </src-purpose> | ||
| </src-title>> | ||
|
|
||
| <use-module|(data fish)> | ||
| <use-module|(code fish-edit)> | ||
|
|
||
| <assign|fish|<macro|body|<with|mode|prog|prog-language|fish|font-family|rm|<arg|body>>>> | ||
|
|
||
| <assign|fish-code|<\macro|body> | ||
| <\pseudo-code> | ||
| <fish|<arg|body>> | ||
| </pseudo-code> | ||
| </macro>> | ||
| </body> | ||
|
|
||
| <\initial> | ||
| <\collection> | ||
| <associate|preamble|true> | ||
| <associate|sfactor|5> | ||
| </collection> | ||
| </initial> | ||
|
|
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
| ;; | ||
| ;; MODULE : fish-edit.scm | ||
| ;; DESCRIPTION : editing fish programs | ||
| ;; COPYRIGHT : (C) 2025 vesita | ||
| ;; | ||
| ;; This software falls under the GNU general public license version 3 or later. | ||
| ;; It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE | ||
| ;; in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>. | ||
| ;; | ||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
|
|
||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
| ;;; | ||
| ;;; DESCRIPTION: | ||
| ;;; This module provides editing functionalities for fish language within | ||
| ;;; TeXmacs. It defines language-specific behaviors such as indentation, | ||
| ;;; commenting, and paste operations for fish code snippets. | ||
| ;;; | ||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
|
|
||
| ;; 定义模块,使用 prog-edit 和 fish-mode 模块 | ||
| (texmacs-module (code fish-edit) | ||
| (:use (prog prog-edit) | ||
| (code fish-mode))) | ||
|
|
||
| ;;------------------------------------------------------------------------------ | ||
| ;; 缩进设置 | ||
| ;; | ||
|
|
||
| ;; 定义fish代码的制表符停止位为4个空格(符合fish标准) | ||
| (tm-define (get-tabstop) | ||
| (:mode in-prog-fish?) | ||
| 4) | ||
|
|
||
| ;; 定义fish特定的关键字,这些关键字后面需要增加缩进 | ||
| (define fish-increase-indent-keys | ||
| '("define" "if" "loop" "case" "caseof" "section" "command")) | ||
|
|
||
| ;; 定义fish特定的配对关键字,这些关键字会减少缩进 | ||
| (define fish-decrease-indent-keys | ||
| '("else" "case")) | ||
|
|
||
| ;; 定义fish特定的结束关键字,这些关键字会减少缩进 | ||
| (define fish-end-keys | ||
| '("end" "endif" "endloop" "endsection" "endcase" "endcommand")) | ||
|
|
||
| ;; 去除字符串右侧的空白字符 | ||
| (define (string-strip-right s) | ||
| (with char-set:not-whitespace (char-set-complement char-set:whitespace) | ||
| (with n (string-length s) | ||
| (with r (or (string-rindex s char-set:not-whitespace) n) | ||
| (string-take s (min n (+ 1 r))))))) | ||
|
|
||
| ;; 检查字符串是否以特定关键字结尾 | ||
| (define (ends-with-keyword? s keys) | ||
| (and (nnull? keys) | ||
| (or (string-ends? s (car keys)) | ||
| (ends-with-keyword? s (cdr keys))))) | ||
|
|
||
| ;; 检查字符串是否以特定关键字开头 | ||
| (define (starts-with-keyword? s keys) | ||
| (and (nnull? keys) | ||
| (or (string-starts? s (string-append (car keys) " ")) | ||
| (starts-with-keyword? s (cdr keys))))) | ||
|
|
||
| ;; 定义fish代码的缩进计算函数 | ||
| (tm-define (program-compute-indentation doc row col) | ||
| (:mode in-prog-fish?) | ||
| (if (<= row 0) 0 | ||
| (let* ((prev-row (- row 1)) | ||
| (prev-line (program-row prev-row)) | ||
| (stripped-prev (string-strip-right (if prev-line prev-line ""))) | ||
| (prev-indent (string-get-indent stripped-prev)) | ||
| (tab-width (get-tabstop))) | ||
| (cond | ||
| ;; 如果前行以增加缩进的关键字结尾,则当前行应增加缩进 | ||
| ((ends-with-keyword? stripped-prev fish-increase-indent-keys) | ||
| (+ prev-indent tab-width)) | ||
| ;; 如果当前行以减少缩进的关键字开头,则减少缩进 | ||
| ((starts-with-keyword? (program-row row) fish-decrease-indent-keys) | ||
| (max 0 (- prev-indent tab-width))) | ||
| ;; 如果当前行以结束关键字开头,则减少缩进 | ||
| ((starts-with-keyword? (program-row row) fish-end-keys) | ||
| (max 0 (- prev-indent tab-width))) | ||
| ;; 否则保持前行的缩进 | ||
| (else prev-indent))))) | ||
|
|
||
| ;;------------------------------------------------------------------------------ | ||
| ;; 自动插入、高亮和选择括号和引号 | ||
| ;; | ||
|
|
||
| (tm-define (fish-bracket-open lbr rbr) | ||
| ;; 插入一对括号或引号,并将光标定位在中间 | ||
| (bracket-open lbr rbr "\\")) | ||
|
|
||
| (tm-define (fish-bracket-close lbr rbr) | ||
| ;; 处理闭合括号或引号,并正确放置光标位置 | ||
| (bracket-close lbr rbr "\\")) | ||
|
|
||
| (tm-define (notify-cursor-moved status) | ||
| (:require prog-highlight-brackets?) | ||
| (:mode in-prog-fish?) | ||
| ;; 当光标移动时高亮匹配的括号 | ||
| (select-brackets-after-movement "([{" ")]}" "\\")) | ||
|
|
||
| ;;------------------------------------------------------------------------------ | ||
| ;; 粘贴操作 | ||
| ;; | ||
|
|
||
| ;; 定义fish代码环境中的粘贴操作,使用fish格式导入剪贴板内容 | ||
| (tm-define (kbd-paste) | ||
| (:mode in-prog-fish?) | ||
| (clipboard-paste-import "fish" "primary")) | ||
|
|
||
| (kbd-map | ||
| (:mode in-prog-fish?) | ||
| ;; fish编程模式下的键盘快捷键 | ||
| ("A-tab" (insert-tabstop)) ;; Alt+Tab:插入制表符 | ||
| ("cmd S-tab" (remove-tabstop)) ;; Cmd+Shift+Tab:移除制表符 | ||
| ("{" (fish-bracket-open "{" "}" )) ;; 自动插入匹配的大括号 | ||
| ("}" (fish-bracket-close "{" "}" )) ;; 处理闭合大括号 | ||
| ("(" (fish-bracket-open "(" ")" )) ;; 自动插入匹配的小括号 | ||
| (")" (fish-bracket-close "(" ")" )) ;; 处理闭合小括号 | ||
| ("[" (fish-bracket-open "[" "]" )) ;; 自动插入匹配的方括号 | ||
| ("]" (fish-bracket-close "[" "]" )) ;; 处理闭合方括号 | ||
| ("\"" (fish-bracket-open "\"" "\"" )) ;; 自动插入匹配的双引号 | ||
| ("'" (fish-bracket-open "'" "'" ))) ;; 自动插入匹配的单引号 | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
| ;; | ||
| ;; MODULE : fish-lang.scm | ||
| ;; DESCRIPTION : fish language support | ||
| ;; COPYRIGHT : (C) 2025 veista | ||
| ;; | ||
| ;; This software falls under the GNU general public license version 3 or later. | ||
| ;; It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE | ||
| ;; in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>. | ||
| ;; | ||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
|
|
||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
| ;;; | ||
| ;;; DESCRIPTION: | ||
| ;;; This module provides language support for fish within TeXmacs. It | ||
| ;;; defines language features such as keywords, operators, number formats, | ||
| ;;; string formats, and comment formats for proper syntax highlighting and | ||
| ;;; parsing of fish code. | ||
| ;;; | ||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
|
|
||
| ;; 定义fish语言支持模块,使用默认语言支持模块 | ||
| (texmacs-module (code fish-lang) | ||
| (:use (prog default-lang))) | ||
|
|
||
| ;;------------------------------------------------------------------------------ | ||
| ;; 关键字定义 | ||
| ;; | ||
|
|
||
| ;; 定义fish语言的关键字分类 | ||
| (tm-define (parser-feature lan key) | ||
| (:require (and (== lan "fish") (== key "keyword"))) | ||
| `(,(string->symbol key) | ||
| (constant | ||
| "true" "false" "null") | ||
| (declare_function | ||
| "define" "struct" "structure") | ||
| (declare_identifier | ||
| "local" "global") | ||
| (keyword_conditional | ||
| "if" "else if" "else" "endif" | ||
| "caseof" "case" "endcase") | ||
| (keyword_control | ||
| "loop" "endloop" "exit loop" "continue" | ||
| "section" "endsection" "exit section" | ||
| "command" "endcommand" | ||
| "return" "exit" "end" "lock"))) | ||
|
|
||
| ;;------------------------------------------------------------------------------ | ||
| ;; 操作符定义 | ||
| ;; | ||
|
|
||
| ;; 定义fish语言的操作符符号 | ||
| (tm-define (parser-feature lan key) | ||
| (:require (and (== lan "fish") (== key "operator"))) | ||
| `(,(string->symbol key) | ||
| (operator | ||
| ;; 算术运算符 | ||
| "+" "-" "*" "/" "^" | ||
| ;; 关系运算符 | ||
| "==" "!=" "#" "<" ">" "<=" ">=" | ||
| ;; 逻辑运算符 | ||
| "and" "or" "not" | ||
| ;; 其他运算符 | ||
| "=" "(" ")" "[" "]" "{" "}" ";" "," "." "@"))) | ||
|
|
||
| ;;------------------------------------------------------------------------------ | ||
| ;; 数字格式定义 | ||
| ;; | ||
|
|
||
| ;; 定义fish语言的数字格式,支持科学计数法 | ||
| (tm-define (parser-feature lan key) | ||
| (:require (and (== lan "fish") (== key "number"))) | ||
| `(,(string->symbol key) | ||
| (bool_features | ||
| "prefix_0x" | ||
| "sci_notation"))) | ||
|
|
||
| ;;------------------------------------------------------------------------------ | ||
| ;; 字符串格式定义 | ||
| ;; | ||
|
|
||
| ;; 定义fish语言的字符串格式,支持转义字符 | ||
| (tm-define (parser-feature lan key) | ||
| (:require (and (== lan "fish") (== key "string"))) | ||
| `(,(string->symbol key) | ||
| (bool_features | ||
| "escape_char_after_backslash") | ||
| (escape_sequences "\\" "\"" "n" "t" "b" "r" "f" "a" "v" "0") | ||
| (double_escape "'"))) | ||
|
|
||
| ;;------------------------------------------------------------------------------ | ||
| ;; 注释格式定义 | ||
| ;; | ||
|
|
||
| ;; 定义fish语言的注释格式,使用 ; 作为注释 | ||
| (tm-define (parser-feature lan key) | ||
| (:require (and (== lan "fish") (== key "comment"))) | ||
| `(,(string->symbol key) | ||
| (inline ";"))) | ||
|
|
||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
| ;; Preferences for syntax highlighting | ||
| ;; 语法高亮偏好设置 | ||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
|
|
||
| ;; 通知fish语法更改的函数 | ||
| (define (notify-fish-syntax var val) | ||
| (syntax-read-preferences "fish")) | ||
|
|
||
| ;; 定义fish语法高亮颜色偏好设置 | ||
| ;; 已验证可生效 | ||
| (define-preferences | ||
| ("syntax:fish:none" "red" notify-fish-syntax) | ||
| ("syntax:fish:comment" "brown" notify-fish-syntax) | ||
| ("syntax:fish:error" "dark red" notify-fish-syntax) | ||
| ("syntax:fish:constant" "#4040c0" notify-fish-syntax) | ||
| ("syntax:fish:constant_number" "#3030b0" notify-fish-syntax) | ||
| ("syntax:fish:constant_string" "dark grey" notify-fish-syntax) | ||
| ("syntax:fish:constant_char" "#333333" notify-fish-syntax) | ||
| ("syntax:fish:declare_function" "#0000c0" notify-fish-syntax) | ||
| ("syntax:fish:declare_type" "#0000c0" notify-fish-syntax) | ||
| ("syntax:fish:declare_module" "#0000c0" notify-fish-syntax) | ||
| ("syntax:fish:operator" "#8b008b" notify-fish-syntax) | ||
| ("syntax:fish:operator_openclose" "#B02020" notify-fish-syntax) | ||
| ("syntax:fish:operator_field" "#888888" notify-fish-syntax) | ||
| ("syntax:fish:operator_special" "orange" notify-fish-syntax) | ||
| ("syntax:fish:keyword" "#309090" notify-fish-syntax) | ||
| ("syntax:fish:keyword_conditional" "#309090" notify-fish-syntax) | ||
| ("syntax:fish:keyword_control" "#008080ff" notify-fish-syntax)) |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
多行函数定义缺少右括号标记。风格指南要求:跨行的环境必须带右侧标记,如
) ;define。当前代码如string-strip-right、ends-with-keyword?、starts-with-keyword?等多行函数都缺少) ;define标记。