Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions TeXmacs/misc/themes/liii-night.css
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,31 @@ QToolButton#image-align-button:checked:hover {
background: rgb(133, 133, 133);
}

/****************************************************************************
* 代码悬浮菜单样式
****************************************************************************/

QWidget#code_popup {
background: #2c2c2c;
border: none;
border-radius: 8px;
}

QToolButton#code-popup-button {
background-color: transparent;
border: none;
padding: 4px 10px;
color: #ffffff;
}

QToolButton#code-popup-button:hover {
background-color: rgba(128, 128, 128, 0.3);
}

QToolButton#code-popup-button:pressed {
background-color: rgba(128, 128, 128, 0.5);
}

/****************************************************************************
* 分组框样式
****************************************************************************/
Expand Down
25 changes: 25 additions & 0 deletions TeXmacs/misc/themes/liii.css
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,31 @@ QToolButton#image-align-button:checked:hover {
background: rgb(180, 212, 255);
}

/****************************************************************************
* 代码悬浮菜单样式
****************************************************************************/

QWidget#code_popup {
background: #ffffff;
border: none;
border-radius: 8px;
}

QToolButton#code-popup-button {
background-color: transparent;
border: none;
padding: 4px 10px;
color: #1d1d1f;
}

QToolButton#code-popup-button:hover {
background-color: rgba(128, 128, 128, 0.3);
}

QToolButton#code-popup-button:pressed {
background-color: rgba(128, 128, 128, 0.5);
}

/****************************************************************************
* 分组框样式
****************************************************************************/
Expand Down
9 changes: 7 additions & 2 deletions TeXmacs/plugins/code/progs/prog/prog-drd.scm
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@

(define-group inline-code-tag
verbatim scm cpp mmx r fortran
python scilab shell)
python scilab shell
bash csv gnuplot goldfish java javascript json julia lua matlab moonbit
r7rs scala sql)

(define-group block-code-tag
verbatim-code scm-code cpp-code mmx-code r-code fortran-code
python-code scilab-code shell-code)
python-code scilab-code shell-code
bash-code csv-code gnuplot-code goldfish-code java-code javascript-code
json-code julia-code lua-code matlab-code moonbit-code r7rs-code
scala-code sql-code)

;; Listings
(define-group listing-tag
Expand Down
116 changes: 115 additions & 1 deletion TeXmacs/progs/prog/prog-edit.scm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@

(texmacs-module (prog prog-edit)
(:use (utils library tree)
(utils library cursor)))
(utils library cursor)
(utils edit selections)
(generic document-style)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Basic routines for textual programs
Expand All @@ -26,6 +28,118 @@
(dt (tree-ref ct :up)))
(and (tree-atomic? ct) (tree-is? dt 'document))))

(tm-define (code-popup-copy t)
(:synopsis "Copy code tree to clipboard")
(when (tree-select t)
(clipboard-copy-export "verbatim" "primary")
(selection-cancel)))

(define code-popup-inline-options
'(("verbatim" "verbatim")
("scheme" "scm")
("c++" "cpp")
("r" "r")
("python" "python")
("shell" "shell")
("bash" "bash")
("csv" "csv")
("gnuplot" "gnuplot")
("goldfish" "goldfish-lang")
("java" "java")
("javascript" "javascript")
("json" "json")
("julia" "julia")
("lua" "lua")
("matlab" "matlab")
("moonbit" "moonbit")
("r7rs" "r7rs")
("scala" "scala")
("sql" "sql")))

(define code-popup-block-options
'(("verbatim" "verbatim-code")
("scheme" "scm-code")
("c++" "cpp-code")
("r" "r-code")
("python" "python-code")
("shell" "shell-code")
("bash" "bash-code")
("csv" "csv-code")
("gnuplot" "gnuplot-code")
("goldfish" "goldfish-code")
("java" "java-code")
("javascript" "javascript-code")
("json" "json-code")
("julia" "julia-code")
("lua" "lua-code")
("matlab" "matlab-code")
("moonbit" "moonbit-code")
("r7rs" "r7rs-code")
("scala" "scala-code")
("sql" "sql-code")))

(define code-popup-listing-options
'(("verbatim" "listing")
("c++" "cpp-listing")
("scheme" "scm-listing")
("shell" "shell-listing")))

(define (code-popup-tag-in? tag opts)
(cond ((null? opts) #f)
((string=? tag (cadr (car opts))) #t)
(else (code-popup-tag-in? tag (cdr opts)))))

(define (code-popup-tag-kind tag)
(cond ((string=? tag "code") 'block)
((code-popup-tag-in? tag code-popup-listing-options) 'listing)
((code-popup-tag-in? tag code-popup-block-options) 'block)
((code-popup-tag-in? tag code-popup-inline-options) 'inline)
(else #f)))

(tm-define (code-popup-language-current t)
(:synopsis "Return current code tag name")
(symbol->string (tree-label t)))

(define code-popup-packages
'("bash" "csv" "gnuplot" "goldfish" "java" "javascript" "json" "julia" "lua"
"matlab" "moonbit" "octave" "python" "r" "r7rs" "scala" "sql"))

(define (code-popup-base-tag tag)
(cond ((string-ends? tag "-code") (string-drop-right tag 5))
((string-ends? tag "-listing") (string-drop-right tag 8))
((string-ends? tag "-lang") (string-drop-right tag 5))
(else tag)))

(define (code-popup-ensure-package tag)
(let* ((base (code-popup-base-tag tag))
(pack (and (in? base code-popup-packages) base)))
(when (and pack (not (has-style-package? pack)))
(add-style-package pack))))

(tm-define (code-popup-make tag)
(:synopsis "Make code tag with auto package")
(code-popup-ensure-package (symbol->string tag))
(make tag))

(tm-define (code-popup-language-options t)
(:synopsis "Return menu options for code popup")
(let* ((tag (symbol->string (tree-label t)))
(kind (code-popup-tag-kind tag))
(opts (cond ((eq? kind 'listing) code-popup-listing-options)
((eq? kind 'block) code-popup-block-options)
(else code-popup-inline-options))))
(map (lambda (it) (string-append (car it) "\t" (cadr it))) opts)))

(tm-define (code-popup-set-language t target)
(:synopsis "Change code tag for current code tree")
(let* ((kind (code-popup-tag-kind (symbol->string (tree-label t))))
(opts (cond ((eq? kind 'listing) code-popup-listing-options)
((eq? kind 'block) code-popup-block-options)
(else code-popup-inline-options))))
(when (code-popup-tag-in? target opts)
(code-popup-ensure-package target)
(tree-assign-node! t (string->symbol target)))))

(tm-define (program-tree)
(:synopsis "get the entire program tree")
(let* ((ct (cursor-tree))
Expand Down
52 changes: 27 additions & 25 deletions TeXmacs/progs/prog/prog-menu.scm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@

(texmacs-module (prog prog-menu)
(:use (generic format-edit)
(generic insert-menu)))
(generic insert-menu)
(prog prog-edit)))

(tm-menu (focus-code-icons t)
(mini #t
Expand Down Expand Up @@ -110,30 +111,31 @@
(when (not (selection-active?))
("Tabbed" (make 'wide-tabbed)))
---
;; 统一通过 code-popup-make 创建代码标签,确保对应语言包已自动加载。
(-> "Inline code"
("Verbatim" (make 'verbatim))
("C++" (make 'cpp))
("Scheme" (make 'scm))
("Shell" (make 'shell))
("Goldfish" (make* 'goldfish-lang "goldfish"))
("Scala" (make* 'scala "scala"))
("Python" (make* 'python "python"))
("R" (make* 'r "r"))
("SQL" (make* 'sql "sql"))
("Bash" (make* 'bash "bash")))
("Verbatim" (code-popup-make 'verbatim))
("C++" (code-popup-make 'cpp))
("Scheme" (code-popup-make 'scm))
("Shell" (code-popup-make 'shell))
("Goldfish" (code-popup-make 'goldfish-lang))
("Scala" (code-popup-make 'scala))
("Python" (code-popup-make 'python))
("R" (code-popup-make 'r))
("SQL" (code-popup-make 'sql))
("Bash" (code-popup-make 'bash)))
(-> "Block of code"
("Verbatim" (make 'verbatim-code))
("C++" (make 'cpp-code))
("Scheme" (make 'scm-code))
("Shell" (make 'shell-code))
("Goldfish" (make* 'goldfish-code "goldfish"))
("Scala" (make* 'scala-code "scala"))
("Python" (make* 'python-code "python"))
("R" (make* 'r-code "r"))
("SQL" (make* 'sql-code "sql"))
("Bash" (make* 'bash-code "bash")))
("Verbatim" (code-popup-make 'verbatim-code))
("C++" (code-popup-make 'cpp-code))
("Scheme" (code-popup-make 'scm-code))
("Shell" (code-popup-make 'shell-code))
("Goldfish" (code-popup-make 'goldfish-code))
("Scala" (code-popup-make 'scala-code))
("Python" (code-popup-make 'python-code))
("R" (code-popup-make 'r-code))
("SQL" (code-popup-make 'sql-code))
("Bash" (code-popup-make 'bash-code)))
(-> "Listing"
("Verbatim" (make 'listing))
("C++" (make 'cpp-listing))
("Scheme" (make 'scm-listing))
("Shell" (make 'shell-listing))))
("Verbatim" (code-popup-make 'listing))
("C++" (code-popup-make 'cpp-listing))
("Scheme" (code-popup-make 'scm-listing))
("Shell" (code-popup-make 'shell-listing))))
92 changes: 92 additions & 0 deletions TeXmacs/tests/tmu/209_13.tmu
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<TMU|<tuple|1.1.0|2026.1.2>>

<style|<tuple|generic|chinese|table-captions-above|number-europe|preview-ref|python|java>>

<\body>
C++代码块:

<\cpp-code>
#include \<less\>stdio.h\<gtr\>

cout\<less\>\<less\>"Hello World!"
</cpp-code>

C++行内代码:

<cpp|cout\<less\>\<less\>"Hello World!";>

C++代码清单:

<\cpp-listing>
#include \<less\>stdio.h\<gtr\>

cout\<less\>\<less\>"Hello World!";
</cpp-listing>

<with|par-mode|center|>

\;

Python代码块:

<\python>
nums = [1, 2, 3, 4]

for x in nums:

\ \ \ \ print(x)
</python>

Python行内代码

\;

<\python>
print("Hello, World!")

\;
</python>

\;

Scheme代码清单:

<\scm-listing>
(display "Hello, World!")

(newline)
</scm-listing>

\;

Java代码块:

<\java-code>
public class Main {

\ \ \ \ public static void main(String[] args) {

\ \ \ \ \ \ \ \ System.out.println("Hello, World!");

\ \ \ \ }

}
</java-code>

\;

Java行内代码:

<java|System.out.println("Hello, World!");>

\;

\;
</body>

<\initial>
<\collection>
<associate|page-medium|paper>
<associate|page-screen-margin|false>
</collection>
</initial>
Loading