├── .gitattributes ├── tests ├── inc.md ├── sample.yaml ├── sample.md ├── sample-pandoc-header.Rmd ├── Makefile ├── sample.tex ├── sample-yaml-header.Rmd └── sample.rst ├── lib ├── yaml │ ├── yaml.tcl │ ├── pkgIndex.tcl │ └── huddle_types.tcl ├── tdot │ ├── pkgIndex.tcl │ ├── tdot-canvas.png │ └── tdot-example.tcl ├── tsvg │ ├── pkgIndex.tcl │ └── Makefile ├── citer │ ├── pkgIndex.tcl │ └── assets │ │ └── literature.bib ├── dgw │ ├── statusbar.tcl │ └── pkgIndex.tcl ├── fview │ ├── demo-dot.png │ ├── demo-pik.png │ ├── demo-dot2.png │ ├── demo-mtex.png │ ├── pkgIndex.tcl │ ├── Makefile │ └── snippets.txt ├── markdown │ └── pkgIndex.tcl ├── tclfilters │ ├── uni.sqlite │ ├── smallcaps.lua │ ├── filter-abc.tcl │ ├── filter-tcrd.tcl │ ├── pkgIndex.tcl │ ├── tikz-tree.tex │ ├── utils.tcl │ ├── xkcd.tex │ ├── header.md │ ├── Makefile │ ├── header.html │ ├── tclfilters.tcl │ ├── filter-rplot.tcl │ ├── filter-mmd.tcl │ ├── filter-emf.tcl │ ├── filter-sqlite.tcl │ ├── filter-eqn.tcl │ ├── filter-tsvg.tcl │ ├── filter-tdot.tcl │ ├── filter-dot.tcl │ ├── filter-julia.tcl │ ├── assets │ │ └── literature.bib │ ├── filter-pic.tcl │ └── filter-kroki.tcl ├── rl_json │ ├── librl_json0.11.0.dll │ ├── librl_json0.11.0.so │ ├── librl_json0.11.1.dylib │ ├── pkgIndex.tcl │ └── mini.css ├── bibtex │ └── pkgIndex.tcl ├── cmdline │ └── pkgIndex.tcl ├── mkdoc │ └── pkgIndex.tcl ├── snit │ ├── pkgIndex.tcl │ ├── snit2.tcl │ ├── snit.tcl │ └── snit_tcl83_utils.tcl └── textutil │ ├── pkgIndex.tcl │ ├── repeat.tcl │ ├── textutil.tcl │ ├── trim.tcl │ ├── string.tcl │ ├── split.tcl │ ├── ithyph.tex │ └── tabify.tcl ├── examples ├── test1.png ├── Makefile └── test1.md ├── user ├── Makefile ├── user-filter.md └── filter-geasy.tcl ├── .github └── workflows │ └── main.yml ├── header.md ├── LICENSE ├── install-unix.sh ├── xml └── emf.xml ├── mini.css └── Makefile /.gitattributes: -------------------------------------------------------------------------------- 1 | *.html linguist-detectable=false 2 | -------------------------------------------------------------------------------- /tests/inc.md: -------------------------------------------------------------------------------- 1 | I am test.md and here some text is written in **bold**. 2 | -------------------------------------------------------------------------------- /lib/yaml/yaml.tcl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mittelmark/pantcl/HEAD/lib/yaml/yaml.tcl -------------------------------------------------------------------------------- /examples/test1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mittelmark/pantcl/HEAD/examples/test1.png -------------------------------------------------------------------------------- /lib/tdot/pkgIndex.tcl: -------------------------------------------------------------------------------- 1 | package ifneeded tdot 0.3.1 [list source [file join $dir tdot.tcl]] 2 | -------------------------------------------------------------------------------- /lib/tsvg/pkgIndex.tcl: -------------------------------------------------------------------------------- 1 | package ifneeded tsvg 0.3.1 [list source [file join $dir tsvg.tcl]] 2 | -------------------------------------------------------------------------------- /examples/Makefile: -------------------------------------------------------------------------------- 1 | default: 2 | tclsh ../pantcl.tcl test1.md test1.html --css ../mini.css -s 3 | -------------------------------------------------------------------------------- /lib/citer/pkgIndex.tcl: -------------------------------------------------------------------------------- 1 | package ifneeded citer 0.1.1 [list source [file join $dir citer.tcl]] 2 | -------------------------------------------------------------------------------- /lib/dgw/statusbar.tcl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mittelmark/pantcl/HEAD/lib/dgw/statusbar.tcl -------------------------------------------------------------------------------- /lib/fview/demo-dot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mittelmark/pantcl/HEAD/lib/fview/demo-dot.png -------------------------------------------------------------------------------- /lib/fview/demo-pik.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mittelmark/pantcl/HEAD/lib/fview/demo-pik.png -------------------------------------------------------------------------------- /lib/fview/demo-dot2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mittelmark/pantcl/HEAD/lib/fview/demo-dot2.png -------------------------------------------------------------------------------- /lib/fview/demo-mtex.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mittelmark/pantcl/HEAD/lib/fview/demo-mtex.png -------------------------------------------------------------------------------- /lib/fview/pkgIndex.tcl: -------------------------------------------------------------------------------- 1 | package ifneeded fview 0.2 [list source [file join $dir filter-view.tcl]] 2 | -------------------------------------------------------------------------------- /lib/markdown/pkgIndex.tcl: -------------------------------------------------------------------------------- 1 | package ifneeded Markdown 1.1 [list source [file join $dir markdown.tcl]] 2 | -------------------------------------------------------------------------------- /lib/tclfilters/uni.sqlite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mittelmark/pantcl/HEAD/lib/tclfilters/uni.sqlite -------------------------------------------------------------------------------- /lib/tdot/tdot-canvas.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mittelmark/pantcl/HEAD/lib/tdot/tdot-canvas.png -------------------------------------------------------------------------------- /lib/tclfilters/smallcaps.lua: -------------------------------------------------------------------------------- 1 | function Strong(elem) 2 | return pandoc.SmallCaps(elem.c) 3 | end 4 | 5 | -------------------------------------------------------------------------------- /lib/tclfilters/filter-abc.tcl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mittelmark/pantcl/HEAD/lib/tclfilters/filter-abc.tcl -------------------------------------------------------------------------------- /lib/tclfilters/filter-tcrd.tcl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mittelmark/pantcl/HEAD/lib/tclfilters/filter-tcrd.tcl -------------------------------------------------------------------------------- /lib/tclfilters/pkgIndex.tcl: -------------------------------------------------------------------------------- 1 | package ifneeded tclfilters 0.8.0 [list source [file join $dir tclfilters.tcl]] 2 | -------------------------------------------------------------------------------- /lib/rl_json/librl_json0.11.0.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mittelmark/pantcl/HEAD/lib/rl_json/librl_json0.11.0.dll -------------------------------------------------------------------------------- /lib/rl_json/librl_json0.11.0.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mittelmark/pantcl/HEAD/lib/rl_json/librl_json0.11.0.so -------------------------------------------------------------------------------- /lib/rl_json/librl_json0.11.1.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mittelmark/pantcl/HEAD/lib/rl_json/librl_json0.11.1.dylib -------------------------------------------------------------------------------- /tests/sample.yaml: -------------------------------------------------------------------------------- 1 | title: This is a test title 2 | author: Detlef Groth, University of Potsdam, Germany 3 | date: 2023-03-10 4 | tcl: 5 | eval: 1 6 | -------------------------------------------------------------------------------- /lib/bibtex/pkgIndex.tcl: -------------------------------------------------------------------------------- 1 | if {![package vsatisfies [package provide Tcl] 8.4]} {return} 2 | package ifneeded bibtex 0.6 [list source [file join $dir bibtex.tcl]] 3 | -------------------------------------------------------------------------------- /lib/cmdline/pkgIndex.tcl: -------------------------------------------------------------------------------- 1 | if {![package vsatisfies [package provide Tcl] 8.2]} {return} 2 | package ifneeded cmdline 1.5 [list source [file join $dir cmdline.tcl]] 3 | -------------------------------------------------------------------------------- /lib/rl_json/pkgIndex.tcl: -------------------------------------------------------------------------------- 1 | # 2 | # Tcl package index file 3 | # 4 | package ifneeded rl_json 0.11.0 \ 5 | [list load [file join $dir librl_json0.11.0[info shared]] rl_json] 6 | -------------------------------------------------------------------------------- /lib/fview/Makefile: -------------------------------------------------------------------------------- 1 | default: 2 | pantcl filter-view.tcl filter-view.html -s 3 | htmlark filter-view.html -o filter-view-out.html 4 | mv filter-view-out.html filter-view.html 5 | -------------------------------------------------------------------------------- /lib/mkdoc/pkgIndex.tcl: -------------------------------------------------------------------------------- 1 | if {![package vsatisfies [package require Tcl] 8.6-]} {return} 2 | package ifneeded mkdoc 0.10.2 [list source [file join $dir mkdoc.tcl]] 3 | package ifneeded mkdoc::mkdoc 0.10.2 [list source [file join $dir mkdoc.tcl]] 4 | -------------------------------------------------------------------------------- /lib/snit/pkgIndex.tcl: -------------------------------------------------------------------------------- 1 | if {[package vsatisfies [package provide Tcl] 8.5]} { 2 | package ifneeded snit 2.3.2 \ 3 | [list source [file join $dir snit2.tcl]] 4 | } 5 | 6 | package ifneeded snit 1.4.2 [list source [file join $dir snit.tcl]] 7 | -------------------------------------------------------------------------------- /lib/tsvg/Makefile: -------------------------------------------------------------------------------- 1 | default: 2 | perl -ne "s/^#' ?(.*)/\$$1/ and print " tsvg.tcl > tsvg.md 3 | pandoc tsvg.md -s \ 4 | --metadata title="tsvg package documentation" \ 5 | -o tsvg-temp.html --filter pantcl \ 6 | --css mini.css --toc 7 | htmlark -o tsvg.html tsvg-temp.html 8 | rm tsvg-temp.html 9 | 10 | -------------------------------------------------------------------------------- /lib/yaml/pkgIndex.tcl: -------------------------------------------------------------------------------- 1 | 2 | if {![package vsatisfies [package provide Tcl] 8.5]} {return} 3 | 4 | package ifneeded yaml 0.4.1 [list source [file join $dir yaml.tcl]] 5 | package ifneeded huddle 0.3 [list source [file join $dir huddle.tcl]] 6 | package ifneeded huddle::json 0.1 [list source [file join $dir json2huddle.tcl]] 7 | -------------------------------------------------------------------------------- /lib/tclfilters/tikz-tree.tex: -------------------------------------------------------------------------------- 1 | \tikzset{ 2 | treenode/.style = {shape=rectangle, rounded corners, 3 | draw, align=center, 4 | top color=white, bottom color=blue!20}, 5 | root/.style = {treenode, font=\Large, bottom color=red!30}, 6 | env/.style = {treenode, font=\ttfamily\normalsize}, 7 | dummy/.style = {circle,draw} 8 | } 9 | -------------------------------------------------------------------------------- /examples/test1.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Test Markdown witch embedded Tcl code. 3 | author: Detlef Groth 4 | date: 2023-01-11 5 | --- 6 | 7 | ## Header 8 | 9 | This is some text. 10 | 11 | ```{.tcl} 12 | set x 1 13 | set x 14 | ``` 15 | 16 | Here some inline Tcl expression x is now `tcl set x`. 17 | 18 | This document was compiled at `tcl clock format [clock seconds] -format "%Y-%m-%d %H:%M:%S"` CET. 19 | -------------------------------------------------------------------------------- /user/Makefile: -------------------------------------------------------------------------------- 1 | filter=geasy 2 | default: 3 | cd .. && tclsh pantcl.tcl user/filter-$(filter).tcl user/filter-$(filter)-out.html \ 4 | -s --css mini.css 5 | cd .. && htmlark user/filter-$(filter)-out.html -o user/filter-$(filter).html 6 | rm filter-$(filter)-out.html 7 | cd .. && tclsh pantcl.tcl user/user-filter.md user/user-filter-out.html \ 8 | -s --css mini.css 9 | cd .. && htmlark user/user-filter-out.html -o user/user-filter.html 10 | rm user-filter-out.html 11 | 12 | 13 | -------------------------------------------------------------------------------- /tests/sample.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: This is a test file 3 | author: NN 4 | date: 2023-03-05 5 | --- 6 | 7 | # Introduction 8 | 9 | This is a sample with some example code chunks. 10 | 11 | # Code chunks 12 | 13 | ```{.tcl} 14 | set x 1 15 | puts $x 16 | ``` 17 | 18 | 19 | This a Tcl variable, x is `tcl set x`. 20 | 21 | 22 | 23 | 24 | Let's try out now `foo @text bar`. 25 | I will write some more text ... 26 | 27 | ```{.tcl} 28 | incr x 29 | ``` 30 | 31 | This is some more text with tcl where x is now: `tcl set x` and let's try to 32 | write 'foo @text bar' again. 33 | 34 | Can I write a @ symbol? 35 | -------------------------------------------------------------------------------- /tests/sample-pandoc-header.Rmd: -------------------------------------------------------------------------------- 1 | % this is a title 2 | % Max Musterman, Unviversity of Musterciy, Germany 3 | % 2023-05-25 4 | 5 | ## Introduction 6 | 7 | Here an R-example: 8 | 9 | Setup for Python within knitr: 10 | 11 | ```{r eval=TRUE} 12 | knitr::knit_engines$set(py = reticulate::eng_python) 13 | ``` 14 | 15 | ```{r eval=TRUE,wait=400} 16 | print("Hello R World!") 17 | ``` 18 | 19 | Here an Python-example: 20 | 21 | ```{python eval=TRUE,terminal=FALSE} 22 | def test(): 23 | print("Python!") 24 | 25 | test() 26 | ``` 27 | 28 | ## Data and Statistical Analysis 29 | 30 | Some text about data 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /tests/Makefile: -------------------------------------------------------------------------------- 1 | rst: 2 | pandoc sample.rst --filter ../pantcl.tcl -o sample-rst.html -s \ 3 | --metadata-file sample.yaml 4 | htmlark sample-rst.html -o sample-out.html 5 | mv sample-out.html sample-rst.html 6 | pandoc sample.rst --filter ../pantcl.tcl -o sample-rst.pdf --metadata documentclass=scrartcl \ 7 | --metadata-file sample.yaml 8 | tex: 9 | pandoc sample.tex --filter ../pantcl.tcl -o sample-tex.pdf \ 10 | --metadata documentclass=scrartcl --metadata-file sample.yaml 11 | rst-standalone: 12 | pandoc sample.rst -o sample-rst.md 13 | tclsh ../pantcl.tcl sample-rst.md sample-rst.html -s --css mini.css \ 14 | --metadata-file sample.yaml --no-pandoc 15 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: Makefile CI 2 | on: 3 | workflow_dispatch: 4 | branches: [ master ] 5 | jobs: 6 | build: 7 | runs-on: ubuntu-latest 8 | 9 | steps: 10 | - uses: actions/checkout@v3 11 | 12 | 13 | #- name: Install dependencies 14 | # run: make 15 | 16 | - name: Make pantcl.tapp 17 | run: | 18 | mkdir pantcl-tapp 19 | make Makefile pantcl-app 20 | mkdir build 21 | cp pantcl-tapp/pantcl.bin build 22 | - name: Step 3 - Use the Upload Artifact GitHub Action 23 | uses: actions/upload-artifact@v3 24 | with: 25 | name: pantcl.bin 26 | path: build/pantcl.bin 27 | -------------------------------------------------------------------------------- /lib/textutil/pkgIndex.tcl: -------------------------------------------------------------------------------- 1 | if {![package vsatisfies [package provide Tcl] 8.2]} { 2 | # FRINK: nocheck 3 | return 4 | } 5 | package ifneeded textutil 0.8 [list source [file join $dir textutil.tcl]] 6 | package ifneeded textutil::adjust 0.7.3 [list source [file join $dir adjust.tcl]] 7 | package ifneeded textutil::split 0.8 [list source [file join $dir split.tcl]] 8 | package ifneeded textutil::trim 0.7 [list source [file join $dir trim.tcl]] 9 | package ifneeded textutil::tabify 0.7 [list source [file join $dir tabify.tcl]] 10 | package ifneeded textutil::repeat 0.7 [list source [file join $dir repeat.tcl]] 11 | package ifneeded textutil::string 0.8 [list source [file join $dir string.tcl]] 12 | package ifneeded textutil::expander 1.3.1 [list source [file join $dir expander.tcl]] 13 | -------------------------------------------------------------------------------- /lib/fview/snippets.txt: -------------------------------------------------------------------------------- 1 | snippet Markdown Main md: 2 | --- 3 | title: %cursor% 4 | author: Your Name 5 | date: 2023-01-01 6 | --- 7 | 8 | ## Introduction 9 | 10 | snippet Markdown dot md: 11 | ```{.dot eval=TRUE} 12 | digraph g { 13 | %cursor% 14 | A -> B ; 15 | } 16 | ``` 17 | 18 | snippet Markdown neato md: 19 | ```{.dot eval=TRUE} 20 | digraph g { 21 | %cursor% 22 | A -> B ; 23 | } 24 | ``` 25 | 26 | snippet Markdown rplot md: 27 | ```{.rplot eval=TRUE} 28 | %cursor% 29 | ``` 30 | 31 | snippet Graphviz Dot dot: 32 | %cursor% 33 | digraph g { 34 | A -> B ; 35 | } 36 | 37 | 38 | snippet Graphviz Neato dot: 39 | %cursor% 40 | graph g { 41 | A -- B ; 42 | } 43 | 44 | snippet Rplot Simple r: 45 | %cursor% 46 | plot(1) 47 | 48 | -------------------------------------------------------------------------------- /lib/snit/snit2.tcl: -------------------------------------------------------------------------------- 1 | #----------------------------------------------------------------------- 2 | # TITLE: 3 | # snit2.tcl 4 | # 5 | # AUTHOR: 6 | # Will Duquette 7 | # 8 | # DESCRIPTION: 9 | # Snit's Not Incr Tcl, a simple object system in Pure Tcl. 10 | # 11 | # Snit 2.x Loader 12 | # 13 | # Copyright (C) 2003-2006 by William H. Duquette 14 | # This code is licensed as described in license.txt. 15 | # 16 | #----------------------------------------------------------------------- 17 | 18 | package require Tcl 8.5 19 | 20 | # Define the snit namespace and save the library directory 21 | 22 | namespace eval ::snit:: { 23 | set library [file dirname [info script]] 24 | } 25 | 26 | # Load the kernel. 27 | source [file join $::snit::library main2.tcl] 28 | 29 | # Load the library of Snit validation types. 30 | source [file join $::snit::library validate.tcl] 31 | 32 | package provide snit 2.3.2 33 | -------------------------------------------------------------------------------- /lib/tclfilters/utils.tcl: -------------------------------------------------------------------------------- 1 | proc getTempDir {} { 2 | if {[file exists /tmp]} { 3 | # standard UNIX 4 | return /tmp 5 | } elseif {[info exists ::env(TMP)]} { 6 | # Windows 7 | return $::env(TMP) 8 | } elseif {[info exists ::env(TEMP)]} { 9 | # Windows 10 | return $::env(TEMP) 11 | } elseif {[info exists ::env(TMPDIR)]} { 12 | # OSX 13 | return $::env(TMPDIR) 14 | } 15 | } 16 | # convert a chunk start to a dictionary 17 | # ```{.mtex packages="sudoku"} 18 | proc chunk2dict {line} { 19 | set dchunk [dict create] 20 | set ind "" 21 | regexp {```\{\.([a-zA-Z0-9]+)\s*(.*).*\}.*} $line -> filt options 22 | foreach {op} [split $options " "] { 23 | foreach {key val} [split $op "="] { 24 | set val [regsub -all {"} $val ""] ;#" 25 | dict set dchunk $key $val 26 | } 27 | } 28 | return $dchunk 29 | } 30 | 31 | 32 | -------------------------------------------------------------------------------- /lib/dgw/pkgIndex.tcl: -------------------------------------------------------------------------------- 1 | # pkgIndex.tcl 2 | # mandatory packages 3 | package ifneeded dgw::dgw 0.7.0 [list source [file join $dir dgw.tcl]] 4 | package ifneeded dgw 0.7.0 [list source [file join $dir dgw.tcl]] 5 | package ifneeded dgw::basegui 0.3 [list source [file join $dir basegui.tcl]] 6 | package ifneeded dgw::combobox 0.2 [list source [file join $dir combobox.tcl]] 7 | package ifneeded dgw::dgwutils 0.3 [list source [file join $dir dgwutils.tcl]] 8 | package ifneeded dgw::drawcanvas 0.1 [list source [file join $dir drawcanvas.tcl]] 9 | package ifneeded dgw::sbuttonbar 0.6 [list source [file join $dir sbuttonbar.tcl]] 10 | package ifneeded dgw::seditor 0.3 [list source [file join $dir seditor.tcl]] 11 | package ifneeded dgw::sfinddialog 0.4 [list source [file join $dir sfinddialog.tcl]] 12 | package ifneeded dgw::statusbar 0.2 [list source [file join $dir statusbar.tcl]] 13 | package ifneeded dgw::tvmixins 0.3 [list source [file join $dir tvmixins.tcl]] 14 | package ifneeded dgw::txmixins 0.3.0 [list source [file join $dir txmixins.tcl]] 15 | 16 | 17 | -------------------------------------------------------------------------------- /header.md: -------------------------------------------------------------------------------- 1 |
filter-abc - filter-cmd - filter-dot - filter-emf - filter-eqn - filter-julia - filter-kroki - filter-mmd - filter-mtex - filter-pic/dpic - filter-pik
filter-pipe - filter-puml - filter-rplot - filter-sqlite - filter-tcrd - filter-tcl - filter-tdot - filter-tsvg
.
53 | #
54 | # @a string: string to manipulate.
55 | #
56 | # @r The with its first character capitalized.
57 | #
58 | # @i capitalize
59 |
60 | proc ::textutil::string::cap {string} {
61 | return [string toupper [string index $string 0]][string range $string 1 end]
62 | }
63 |
64 | # @c unCapitalizes first character of the given .
65 | # @c Complementary procedure to .
66 | #
67 | # @a string: string to manipulate.
68 | #
69 | # @r The with its first character uncapitalized.
70 | #
71 | # @i uncapitalize
72 |
73 | proc ::textutil::string::uncap {string} {
74 | return [string tolower [string index $string 0]][string range $string 1 end]
75 | }
76 |
77 | # @c Capitalizes first character of each word of the given .
78 | #
79 | # @a sentence: string to manipulate.
80 | #
81 | # @r The with the first character of each word capitalized.
82 | #
83 | # @i capitalize
84 |
85 | proc ::textutil::string::capEachWord {sentence} {
86 | regsub -all {\S+} [string map {\\ \\\\ \$ \\$} $sentence] {[string toupper [string index & 0]][string range & 1 end]} cmd
87 | return [subst -nobackslashes -novariables $cmd]
88 | }
89 |
90 | # Compute the longest string which is common to all strings given to
91 | # the command, and at the beginning of said strings, i.e. a prefix. If
92 | # only one argument is specified it is treated as a list of the
93 | # strings to look at. If more than one argument is specified these
94 | # arguments are the strings to be looked at. If only one string is
95 | # given, in either form, the string is returned, as it is its own
96 | # longest common prefix.
97 |
98 | proc ::textutil::string::longestCommonPrefix {args} {
99 | return [longestCommonPrefixList $args]
100 | }
101 |
102 | proc ::textutil::string::longestCommonPrefixList {list} {
103 | if {[llength $list] <= 1} {
104 | return [lindex $list 0]
105 | }
106 |
107 | set list [lsort $list]
108 | set min [lindex $list 0]
109 | set max [lindex $list end]
110 |
111 | # Min and max are the two strings which are most different. If
112 | # they have a common prefix, it will also be the common prefix for
113 | # all of them.
114 |
115 | # Fast bailouts for common cases.
116 |
117 | set n [string length $min]
118 | if {$n == 0} {return ""}
119 | if {0 == [string compare $min $max]} {return $min}
120 |
121 | set prefix ""
122 | set i 0
123 | while {[string index $min $i] == [string index $max $i]} {
124 | append prefix [string index $min $i]
125 | if {[incr i] > $n} {break}
126 | }
127 | set prefix
128 | }
129 |
130 | # ### ### ### ######### ######### #########
131 | ## Data structures
132 |
133 | namespace eval ::textutil::string {
134 | # Export the imported commands
135 |
136 | namespace export chop tail cap uncap capEachWord
137 | namespace export longestCommonPrefix
138 | namespace export longestCommonPrefixList
139 | }
140 |
141 | # ### ### ### ######### ######### #########
142 | ## Ready
143 |
144 | package provide textutil::string 0.8
145 |
--------------------------------------------------------------------------------
/user/user-filter.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Implementing Pandoc filters using the Tcl programming language
3 | shorttitle: user filters
4 | author: Detlef Groth
5 | date: 2023-04-17
6 | ---
7 |
8 | # Adding your own filters
9 |
10 | Since version 0.9.12 it is more easily to add your own filters written in the
11 | Tcl programming language. You can just add in a Markdown file in the
12 | document's YAML header for your code chunk settings a `filter` attribute like this:
13 |
14 |
15 | ```
16 | ---
17 | title: "filter-geasy.tcl documentation"
18 | author: "Detlef Groth, Caputh-Schwielowsee, Germany"
19 | date: 2023-04-15
20 | geasy:
21 | app: graph-easy
22 | eval: 1
23 | as: ascii
24 | filter: user/filter-geasy.tcl
25 | ---
26 | ```
27 |
28 | For the actual filter documentation you should read [filter-geasy](filter-geasy.html).
29 |
30 | The attribute `filter` should point using either a relative or an absolute path
31 | to your filter implementation. The relative path should be calculated based on
32 | your working directory where you do your document conversion.
33 |
34 | How should an actual filter implementation look like? Here an example Tcl
35 | procedure outline:
36 |
37 | ```
38 | proc filter-CHUNKTYPE {cont dict} {
39 | ## do the processing
40 | return [list txt image-path]
41 | }
42 | ```
43 |
44 | The variable `cont` contains the code chunk code within the triple backticks,
45 | the variable `dict` contains the code chunk arguments as a dictionary (hash)
46 | with key-value pairs for every option given in the code chunk argument. Here
47 | an example:
48 |
49 | ```
50 | ```{.chunk key1=true key2="hello"}
51 | print("Hello!")
52 | ```
53 | ```
54 |
55 | So in the example above you would need a procedure name `filter-chunk` the
56 | string `print("Hello")` would be in the variable `cont` and the keys in the dictionary would be `key1` and `key2`.
57 |
58 | The returns at the end should be a list with two elements first the text you
59 | would like to display from your filter and secondly an image-path pointing to
60 | a possible image generated by your tool. In case your tool does not generate
61 | images you just return an empty string as the second argument.
62 |
63 | Below follows an example for the demonstration of a filter implementation
64 | which supports the [graph-easy](http://bloodgate.com/perl/graph/manual/)
65 | command line application. On a linux system you might simply install this
66 | application using your package manager for instance on my Fedora system I do
67 | this like this:
68 |
69 | ```
70 | sudo dnf install perl-Graph-Easy
71 | ```
72 |
73 | Here now the Tcl code with comments:
74 |
75 | ```{.tcl eval=false}
76 | ### file user/filter-geasy.tcl
77 | proc filter-geasy {cont dict} {
78 | # count all code chunk filters
79 | global n
80 | incr n
81 | # default values for the code chunks attributes
82 | set def [dict create results show eval true scriptpath scripts \
83 | app graph-easy label null as ascii ext svg]
84 | # overwrite them with the current code chunk attributes
85 | set dict [dict merge $def $dict]
86 | # if eval is false return nothing
87 | if {![dict get $dict eval]} {
88 | return [list "" ""]
89 | }
90 | # check if the application is installed at all
91 | if {[auto_execok [dict get $dict app]] eq ""} {
92 | return [list "Error: This filter requires the command line tool [dict get $dict app] - please install it!" ""]
93 | }
94 | # intialize return text
95 | set ret ""
96 | set owd [pwd]
97 | # create a filename for the outputs
98 | if {[dict get $dict label] eq "null"} {
99 | set fname [file join $owd [dict get $dict scriptpath] geasy-$n]
100 | } else {
101 | set fname [file join $owd [dict get $dict scriptpath] [dict get $dict label]]
102 | }
103 | if {![file exists [file join $owd [dict get $dict scriptpath]]]} {
104 | file mkdir [file join $owd [dict get $dict scriptpath]]
105 | }
106 | # write down the code chunk text
107 | set out [open $fname.txt w 0600]
108 | puts $out $cont
109 | close $out
110 | # run the tool
111 | # TODO: error catching
112 | set res [exec -ignorestderr [dict get $dict app] --as=[dict get $dict as] $fname.txt]
113 | # initialize the image variable
114 | set img ""
115 | # do the user like to use the dot tool for image generation?
116 | if {[dict get $dict as] eq "dot"} {
117 | set out [open $fname.dot w 0600]
118 | puts $out $res
119 | close $out
120 | if {[auto_execok dot] eq ""} {
121 | return [list "Error: Dot output requires the command line tool GraphViz dot application - please install GraphViz or add the application sto your PATH variable!" ""]
122 | }
123 | set ext [dict get $dict ext]
124 | exec -ignorestderr dot $fname.dot -T$ext -o $fname.$ext
125 | set img $fname.$ext
126 | }
127 | # check if results should be shown
128 | if {[dict get $dict results] eq "show"} {
129 | set res $res
130 | } else {
131 | set res ""
132 | }
133 | # return text and image path
134 | return [list $res $img]
135 | }
136 |
137 | ```
138 |
139 | ## See also:
140 |
141 | * [filter-geasy](filter-geasy.html) - the actual filter documentation for our example above
142 | * [pantcl Readme](../README.html)
143 | * [pantcl manual](../pantcl.html)
144 | * [pantcl Tutorial](../pantcl-tutorial.html)
145 |
146 |
--------------------------------------------------------------------------------
/lib/tclfilters/filter-rplot.tcl:
--------------------------------------------------------------------------------
1 | #' ---
2 | #' title: "filter-rplot.tcl documentation"
3 | #' author: "Detlef Groth, Caputh-Schwielowsee, Germany"
4 | #' date: 2021-11-29
5 | #' rplot:
6 | #' app: Rscript
7 | #' imagepath: images
8 | #' ext: png
9 | #' eval: 1
10 | #' ---
11 | #'
12 | #' ------
13 | #'
14 | #' ```{.tcl eval=true results="asis" echo=false}
15 | #' include header.md
16 | #' ```
17 | #'
18 | #' ------
19 | #'
20 | #' ## Name
21 | #'
22 | #' _filter-rplot.tcl_ - Filter which can be used to display R plots
23 | #' within a Pandoc processed document using the Tcl filter driver
24 | #' `pantcl.bin`.
25 | #'
26 | #' ## Usage
27 | #'
28 | #' The conversion of the Markdown documents via Pandoc should be done as follows:
29 | #'
30 | #' ```
31 | #' pandoc input.md --filter pantcl.bin -s -o output.html
32 | #' ```
33 | #'
34 | #' The file `filter-rplot.tcl` is not used directly but sourced automatically by the `pantcl.bin` file.
35 | #' If code blocks with the `.rplot` marker are found, the contents in the code block is
36 | #' processed via the Rscript interpreter if the chunk option `eval` is set to true or 1.
37 | #' If the interpreter is not in the PATH you might add the application path in your YAML header as shown below.
38 | #'
39 | #'
40 | #' The following options can be given via code chunks options or as defaults in the YAML header.
41 | #'
42 | #' > - app - the application to be called, default: Rscript
43 | #' - eval - should the code in the code block be evaluated, default: false
44 | #' - ext - file file extension, can be png or pdf, default: png
45 | #' - fig - should a figure be created, default: true
46 | #' - height - the figure height, default: 600
47 | #' - imagepath - output imagepath, default: images
48 | #' - include - should the created image be automatically included, default: true
49 | #' - label - the code chunk label used as well for the image name, default: null
50 | #' - results - should the output of the command line application been shown, should be show or hide, default: hide
51 | #' - width - the figure width, default: 600
52 | #'
53 | #' To change the defaults the YAML header can be used. Here an example to change the
54 | #' default Rscript interpreter, the image output path to nfigures and the file extension to pdf
55 | #' (useful for Pdf output of the document).
56 | #' Please note that in the YAML header you can only use 0 or 1 instead of false
57 | #' and true.
58 | #'
59 | #' ```
60 | #' ----
61 | #' title: "filter-rplot.tcl documentation"
62 | #' author: "Detlef Groth, Caputh-Schwielowsee, Germany"
63 | #' date: 2021-11-29
64 | #' rplot:
65 | #' app: /path/to/Rscript
66 | #' imagepath: nfigures
67 | #' ext: pdf
68 | #' eval: 1
69 | #' ----
70 | #' ```
71 | #'
72 | #' ## Examples
73 | #'
74 | #' Here an example for a pairsplot graph:
75 | #'
76 | #' ```
77 | #' ```{.rplot eval=true}
78 | #' data(iris)
79 | #' pairs(iris[,1:3],col=as.numeric(iris$Species)+1,pch=19)
80 | #' ```
81 | #' ```
82 | #'
83 | #' And here is the output:
84 | #'
85 | #' ```{.rplot eval=true}
86 | #' data(iris)
87 | #' pairs(iris[,1:3],col=as.numeric(iris$Species)+1,pch=19)
88 | #' ```
89 | #'
90 | #' To supress the message line you can add results="hide" as chunk option like this: `{.rplot results="hide"}`
91 | #'
92 | #' ```{.rplot eval=true results="hide"}
93 | #' boxplot(iris$Sepal.Length ~ iris$Species,col=2:4)
94 | #' ```
95 | #'
96 | #' ## See also:
97 | #'
98 | #' * [pantcl Readme](../../README.html)
99 | #' * [Pipe filter for R, Python, Octave](filter-pipe.html)
100 | #'
101 |
102 |
103 | proc filter-rplot {cont dict} {
104 | global n
105 | global rplotx
106 | if {[info exists rplotx]} {
107 | incr rplotx
108 | } else {
109 | set rplotx 0
110 | }
111 | incr n
112 | set def [dict create results show eval true fig true width 600 height 600 \
113 | include true imagepath images app Rscript label null ext png]
114 | set dict [dict merge $def $dict]
115 | if {![dict get $dict eval]} {
116 | return [list "" ""]
117 | }
118 | set ret ""
119 | set owd [pwd]
120 | if {[dict get $dict label] eq "null"} {
121 | set fname [file join $owd [dict get $dict imagepath] rplot-$n]
122 | } else {
123 | set fname [file join $owd [dict get $dict imagepath] [dict get $dict label]]
124 | }
125 | if {![file exists [file join $owd [dict get $dict imagepath]]]} {
126 | file mkdir [file join $owd [dict get $dict imagepath]]
127 | }
128 | set out [open ${fname}.R w 0600]
129 | if {$rplotx == 0} {
130 | if {[file exists ".RData"]} {
131 | file delete .RData
132 | }
133 | }
134 | if {[file exists .RData]} {
135 | puts $out "load('.RData')"
136 | }
137 | if {[dict get $dict fig]} {
138 | set imgfile ${fname}.[dict get $dict ext]
139 | puts $out "[dict get $dict ext]('$imgfile' , width=[dict get $dict width] , height=[dict get $dict height]);"
140 | puts $out $cont
141 | puts $out "dev.off()"
142 | } else {
143 | puts $out $cont
144 | }
145 | puts $out "save.image(file='.RData')"
146 | close $out
147 | # TODO: error catching
148 | if {[dict get $dict eval]} {
149 | set res [exec [dict get $dict app] ${fname}.R]
150 | } else {
151 | set res ""
152 | }
153 | if {[dict get $dict results] eq "show"} {
154 | set res $res
155 | } else {
156 | set res ""
157 | }
158 | set img ""
159 | if {[dict get $dict fig]} {
160 | if {[dict get $dict include]} {
161 | set img $imgfile
162 | }
163 | }
164 | return [list $res $img]
165 | }
166 |
--------------------------------------------------------------------------------
/lib/tclfilters/filter-mmd.tcl:
--------------------------------------------------------------------------------
1 | #' ---
2 | #' title: "filter-mmd.tcl documentation"
3 | #' author: "Detlef Groth, Caputh-Schwielowsee, Germany"
4 | #' date: 2021-12-11
5 | #' mmd:
6 | #' app: mmdc
7 | #' imagepath: images
8 | #' ext: png
9 | #' eval: 1
10 | #' ---
11 | # a simple pandoc filter using Tcl
12 | # the script pantcl.tcl
13 | # must be in the in the parent directory of the filter directory
14 | #'
15 | #' ------
16 | #'
17 | #' ```{.tcl results="asis" echo=false eval=true}
18 | #' include header.md
19 | #' ```
20 | #'
21 | #' ------
22 | #'
23 | #' ## Name
24 | #'
25 | #' _filter-mmd.tcl_ - Filter which can be used to display [Mermaid](https://mermaid-js.github.io)
26 | #' diagram files within a Pandoc processed document using the Tcl filter driver `pantcl.bin`.
27 | #'
28 | #' ## Usage
29 | #'
30 | #' The conversion of the Markdown documents via Pandoc should be done as follows:
31 | #'
32 | #' ```
33 | #' pandoc input.md --filter pantcl.bin -s -o output.html
34 | #' ```
35 | #'
36 | #' The file `filter-mmd.tcl` is not used directly but sourced automatically by the `pantcl.bin` file.
37 | #' If code blocks with the `.mmd` marker are found, the contents in the code block is processed via one of the Mermaid command line tool. To install this command line tool have
38 | #' a look at: [https://github.com/mermaid-js/mermaid-cli](https://github.com/mermaid-js/mermaid-cli)
39 | #'
40 | #' The following options can be given via code chunks or in the YAML header.
41 | #'
42 | #' >
43 | #' - app - the application to be called, such as mmdc, default: mmdc
44 | #' - background - the background color such as transparent, salmon '#ccffff' (only used for png output), default: white
45 | #' - eval - should the code in the code block be evaluated, default: false
46 | #' - ext - file file extension, can be svg, png, pdf, default: svg
47 | #' - fig - should a figure be created, default: true
48 | #' - height - the image height, default: 600
49 | #' - imagepath - output imagepath, default: images
50 | #' - include - should the created image be automatically included, default: true
51 | #' - results - should the output of the command line application been shown, should be show or hide, default: hide
52 | #' - theme - the image them which can be used, should be either default, forest, dark, default: default
53 | #' - width - the image width, default: 800
54 | #'
55 | #' The options fig, results, include should be normally not used, they are here just for
56 | #' compatibility reasons with the other filters.
57 | #'
58 | #' To change the defaults the YAML header can be used. Here an example to change the
59 | #' default command line application to mmdc-8.10 and the image output path to nfigures
60 | #' and the output image format to png, to activate code evaluation in the complete document
61 | #' use `eval: 1` in the YAML header, do not use 'true' here..
62 | #'
63 | #' ```
64 | #' ----
65 | #' title: "filter-mmd.tcl documentation"
66 | #' author: "Detlef Groth, Caputh-Schwielowsee, Germany"
67 | #' date: 2021-12-11
68 | #' mmd:
69 | #' app: mmdc-8.10
70 | #' imagepath: nfigures
71 | #' ext: png
72 | #' eval: 1
73 | #' ----
74 | #' ```
75 | #'
76 | #' ## Examples
77 | #'
78 | #' Here an example for a simple flowchart:
79 | #'
80 | #' ```
81 | #' ```{.mmd eval=true}
82 | #' graph TD;
83 | #' A-->B;
84 | #' A-->C;
85 | #' B-->D;
86 | #' C-->D;
87 | #' ```
88 | #' ```
89 | #
90 | #' And here the output:
91 | #'
92 | #' ```{.mmd eval=true}
93 | #' graph TD;
94 | #' A-->B;
95 | #' A-->C;
96 | #' B-->D;
97 | #' C-->D;
98 | #' ```
99 | #'
100 | #' Next an example for a sequence diagram with the forest theme and cornsilk background
101 | #' (`{.mmd theme=forest background=cornsilk eval=true}`):
102 | #'
103 | #' ```{.mmd theme=forest background=cornsilk eval=true}
104 | #' sequenceDiagram
105 | #' participant Alice
106 | #' participant Bob
107 | #' Alice->>John: Hello John, how are you?
108 | #' loop Healthcheck
109 | #' John->>John: Fight against hypochondria
110 | #' end
111 | #' Note right of John: Rational thoughts
prevail!
112 | #' John-->>Alice: Great!
113 | #' John->>Bob: How about you?
114 | #' Bob-->>John: Jolly good!
115 | #' ```
116 | #'
117 | #' ## See also:
118 | #'
119 | #' * [Pantcl Readme](../../README.html)
120 | #' * [GraphViz Filter](filter-dot.html)
121 | #' * [Pikchr Filter](filter-pik.html)
122 | #' * [PlantUML filter](filter-puml.html)
123 | #'
124 |
125 |
126 | proc filter-mmd {cont dict} {
127 | global n
128 | incr n
129 | set def [dict create results show eval true fig true width 800 height 600 \
130 | include true imagepath images app mmdc label null ext svg theme default background white]
131 | set dict [dict merge $def $dict]
132 | set ret ""
133 | if {[auto_execok [dict get $dict app]] == ""} {
134 | return [list "Error: Command line tool [dict get $dict app] is not installed!" ""]
135 | }
136 | set owd [pwd]
137 | if {[dict get $dict label] eq "null"} {
138 | set fname [file join $owd [dict get $dict imagepath] mmd-$n]
139 | } else {
140 | set fname [file join $owd [dict get $dict imagepath] [dict get $dict label]]
141 | }
142 | if {![file exists [file join $owd [dict get $dict imagepath]]]} {
143 | file mkdir [file join $owd [dict get $dict imagepath]]
144 | }
145 | set out [open $fname.mmd w 0600]
146 | puts $out $cont
147 | close $out
148 | # TODO: error catching
149 | set res [exec -ignorestderr [dict get $dict app] -i $fname.mmd -o $fname.[dict get $dict ext] \
150 | -w [dict get $dict width] -H [dict get $dict height] -t [dict get $dict theme] \
151 | -b [dict get $dict background]]
152 | if {[dict get $dict results] eq "show"} {
153 | # should be usually empty
154 | set res $res
155 | } else {
156 | set res ""
157 | }
158 | set img ""
159 | if {[dict get $dict fig]} {
160 | if {[dict get $dict include]} {
161 | set img $fname.[dict get $dict ext]
162 | }
163 | }
164 | return [list $res $img]
165 | }
166 |
--------------------------------------------------------------------------------
/lib/tclfilters/filter-emf.tcl:
--------------------------------------------------------------------------------
1 | #' ---
2 | #' title: "filter-emf.tcl documentation"
3 | #' author: "Detlef Groth, Caputh-Schwielowsee, Germany"
4 | #' date: 2023-04-15
5 | #' emf:
6 | #' app: mec
7 | #' eval: 1
8 | #' ---
9 | #'
10 | # A simple pandoc filter using the the MicroEmacs Text Editor macro language.
11 | #'
12 | #' ------
13 | #'
14 | #' ```{.tcl eval=true results="asis" echo=false}
15 | #' include header.md
16 | #' ```
17 | #'
18 | #' ------
19 | #'
20 | #' ## Name
21 | #'
22 | #' _filter-emf.tcl_ - Filter which can be used to evaluate Macro code for the MicroEmacs
23 | #' text editor within a Pandoc processed document using the Tcl filter driver `pantcl.tcl`.
24 | #' The command line mode version of the editor which usually called with the -n arguments
25 | #' is required which can be ususally installed from the website
26 | #' [http://www.jasspa.com/zeroinst.html](http://www.jasspa.com/zeroinst.html).
27 | #'
28 | #' ## Usage
29 | #'
30 | #' MicroEmacs macro language source code is embedded into Markup languages like Markdown like this
31 | #' (remove the spaces at the beginning, they are here just for protecting the evaluation):
32 | #'
33 | #' ```
34 | #' # code chunk defaults (must be in fact not given):
35 | #' ```{.emf eval=true echo=true}
36 | #' EMF code
37 | #' ```
38 | #' ```
39 | #'
40 | #' Where eval and echo are so called chunk options.
41 | #'
42 | #' The conversion of the Markdown documents via Pandoc should be done as follows:
43 | #'
44 | #' ```
45 | #' pantcl input.md output.html --pantcl-filter filter-emf.tcl --syntax-definition ../../xml/emf.xml -s
46 | #' ```
47 | #' The file `emf.xml` contains syntax highlighting code for the MicroEmacs macro files.
48 | #' The application file *pantcl* which contains the Tcl filter and all other filters has to be placed in the PATH and the
49 | #' system has to support the Shebang, on Unix this is standard on Windows you need to use tools like Cygwin, Msys,
50 | #' Git-Bash or Cygwin (untested).
51 | #'
52 | #' The arguments after the output file and after the file `filter-emf.tcl` are delegated to pandoc.
53 | #'
54 | #' If code blocks with the `.emf` marker are found, the contents in the code
55 | #' block is processed via the MicroEmacs text editor in command line mode.
56 | #'
57 | #' The following options can be given via code chunks or in the YAML header.
58 | #'
59 | #' > - app - the MicroEmacs application to be called, usually me, default: me
60 | #' - echo - should the EMF source code be shown, default: true
61 | #' - eval - should the code in the code block be evaluated, default: false
62 | #' - results - should the output of the command line application been shown, should be show or hide, default: hide
63 | #'
64 | #' To change the defaults the YAML header can be used. Here an example to change the
65 | #' default application to an other MicroEmacs executable, an updated MicroEmacs from 2023:
66 | #' You should set eval to 1 as shown as well below, the term true
67 | #' might produce an error, so write `eval: 1`
68 | #'
69 | #' ```
70 | #' ----
71 | #' title: "filter-emf.tcl documentation"
72 | #' author: "Detlef Groth, Caputh-Schwielowsee, Germany"
73 | #' date: 2023-04-15
74 | #' abc:
75 | #' app: me23
76 | #' eval: 1
77 | #' ----
78 | #' ```
79 | #'
80 | #' ## Examples
81 | #'
82 | #' Here an example for a simple Hello World message chunk just contains `{.emf eval=true}`:.
83 | #'
84 | #' ```{.emf}
85 | #' -1 ml-write "Hello MicroEmacs World!"
86 | #' ```
87 | #'
88 | #' The `-1` at the beginning ensures that we are writing to the terminal, this is required for the embedded code to be shown in our output document but not in the editor
89 | #' message line.
90 | #'
91 | #' Using the option `{.emf eval=true results="hide"}` the output of the command line tool can be hidden.
92 | #'
93 | #' ```{.emf eval=true results="hide"}
94 | #' -1 ml-write "Hello MicroEmacs World!"
95 | #' ```
96 | #'
97 | #' Believe me, the code above was evaluated but the results is hidden
98 | #' as we used `results="hide"` as code chunk option.
99 | #'
100 | #' Here a more extensive example:
101 | #'
102 | #' ```{.emf results="show" echo=true eval=true}
103 | #' ; semicolons start comments
104 | #' ; $version is a system variable
105 | #' -1 ml-write &cat "This is MicroEmacs " &cat $version "!"
106 | #' ; example for a loop using a global variable %x
107 | #' set-variable %x 1
108 | #' !while &less %x 10
109 | #' -1 ml-write &cat "x is " %x
110 | #' set-variable %x &inc %x 1
111 | #' !done
112 | #' ```
113 | #'
114 | #' ## See also:
115 | #'
116 | #' * [pantcl Readme](../README.html)
117 | #'
118 |
119 |
120 | proc filter-emf {cont dict} {
121 | global n
122 | incr n
123 | set def [dict create results show eval true scriptpath scripts \
124 | app me label null]
125 | set dict [dict merge $def $dict]
126 | if {![dict get $dict eval]} {
127 | return [list "" ""]
128 | }
129 | if {[auto_execok [dict get $dict app]] eq ""} {
130 | return [list "Error: This filter requires the command line tool [dict get $dict app] - please install it!" ""]
131 | }
132 | set ret ""
133 | set owd [pwd]
134 | if {[dict get $dict label] eq "null"} {
135 | set fname [file join $owd [dict get $dict scriptpath] emf-$n]
136 | } else {
137 | set fname [file join $owd [dict get $dict scriptpath] [dict get $dict label]]
138 | }
139 | if {![file exists [file join $owd [dict get $dict scriptpath]]]} {
140 | file mkdir [file join $owd [dict get $dict scriptpath]]
141 | }
142 | set out [open $fname.sh w 0600]
143 | puts $out "#!/usr/bin/bash\ntail --lines=+3 \$0 > temp.emf && [dict get $dict app] -n -p \"@temp.emf\" && exit"
144 | puts $out "; - emf - below follows the MicroEmacs code"
145 | puts $out "define-macro test-emf"
146 | puts $out $cont
147 | puts $out "!emacro"
148 | puts $out "!force test-emf"
149 | puts $out "!if ¬ \$status"
150 | puts $out " -1 ml-write \"Error in code chunk!\""
151 | puts $out "!endif"
152 | puts $out "quick-exit"
153 | close $out
154 | # TODO: error catching
155 | set res [exec -ignorestderr bash $fname.sh]
156 | if {[dict get $dict results] eq "show"} {
157 | # should be usually empty
158 | set res $res
159 | } else {
160 | set res ""
161 | }
162 | return [list $res ""]
163 | }
164 |
--------------------------------------------------------------------------------
/lib/textutil/split.tcl:
--------------------------------------------------------------------------------
1 | # split.tcl --
2 | #
3 | # Various ways of splitting a string.
4 | #
5 | # Copyright (c) 2000 by Ajuba Solutions.
6 | # Copyright (c) 2000 by Eric Melski mischief | bawl | sing || yell | drink]
151 | #'
152 | #' [