Skip to content

Commit

Permalink
Merge branch 'next-repl'
Browse files Browse the repository at this point in the history
  • Loading branch information
egallesio committed Aug 23, 2024
2 parents ada3950 + 1307c63 commit ca139ff
Show file tree
Hide file tree
Showing 4 changed files with 846 additions and 791 deletions.
25 changes: 16 additions & 9 deletions doc/HTML/stklos-ref.html
Original file line number Diff line number Diff line change
Expand Up @@ -25649,18 +25649,9 @@ <h4 id="_repl_commands">10.3.1. REPL commands</h4>
<p><strong>,cd</strong>: Change current directory</p>
</li>
<li>
<p><strong>,pwd</strong>: Print working directory</p>
</li>
<li>
<p><strong>,ls</strong>: List directory content</p>
</li>
<li>
<p><strong>,quit</strong> (or <strong>,q</strong>): Exit STklos</p>
</li>
<li>
<p><strong>,shell</strong> (or <strong>,!</strong>): Run a shell command</p>
</li>
<li>
<p><strong>,time</strong> (or <strong>,t</strong> ): Print the time used to run the next expression</p>
</li>
<li>
Expand Down Expand Up @@ -25697,6 +25688,22 @@ <h4 id="_repl_commands">10.3.1. REPL commands</h4>
</ul>
</div>
<div class="paragraph">
<p>Furthermore, the <strong>'!'</strong> character can also be used to execute an
external command using <strong>sh(1)</strong>. For instance,</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="rouge highlight"><code data-lang="scheme"><span class="nv">stklos&gt;</span> <span class="nv">!pwd</span>
<span class="nv">/tmp/test</span>
<span class="nv">stklos&gt;</span> <span class="nv">!emacs</span> <span class="nv">foo</span><span class="o">.</span><span class="nv">stk</span> <span class="nv">&amp;</span> <span class="c1">;; to launch emacs on file foo.stk</span>
<span class="nv">stklos&gt;</span> <span class="p">(</span><span class="k">define</span> <span class="nv">!pwd</span> <span class="mi">100</span><span class="p">)</span>
<span class="c1">;; !pwd</span>
<span class="nv">stklos&gt;</span> <span class="nv">!pwd</span> <span class="c1">;; now !pwd overrides pwd(1)</span>
<span class="mi">100</span>
<span class="nv">stklos&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p><a id='P_repl-add-command'></a>
</p>
</div>
Expand Down
23 changes: 18 additions & 5 deletions doc/refman/custom.adoc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GFDL-1.3-or-later
//
// Copyright © 2000-2023 Erick Gallesio <[email protected]>
// Copyright © 2000-2024 Erick Gallesio <[email protected]>
//
// Author: Erick Gallesio [[email protected]]
// Creation date: 26-Nov-2000 18:19 (eg)
Expand Down Expand Up @@ -66,10 +66,7 @@ of available commands is given below.

- **,backtrace** (or **,bt**): Show the stack when last error occurred
- **,cd**: Change current directory
- **,pwd**: Print working directory
- **,ls**: List directory content
- **,quit** (or **,q**): Exit STklos
- **,shell** (or **,!**): Run a shell command
- **,time** (or **,t** ): Print the time used to run the next expression
- **,describe** (or **,d**): Describe an object
- **,expand** (or **,e**): Pretty print the macro expansion of a form
Expand All @@ -83,6 +80,23 @@ of available commands is given below.
- **,help** (or **,?** or **,h*): Show help on REPL command with
parameter. With a parameter, display the help of this parameter

Furthermore, the **'!'** character can also be used to execute an
external command using *sh(1)*. For instance,

```scheme
stklos> !pwd
/tmp/test
stklos> !emacs foo.stk & ;; to launch emacs on file foo.stk
stklos> (define !pwd 100)
;; !pwd
stklos> !pwd ;; now !pwd overrides pwd(1)
100
stklos>
```




{{insertdoc 'repl-add-command}}

==== REPL variables
Expand Down Expand Up @@ -115,4 +129,3 @@ The following parameter objects can be used to customize the REPL:

{{insertdoc 'repl-theme}}
{{insertdoc 'repl-show-startup-message}}

41 changes: 21 additions & 20 deletions lib/repl.stk
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,13 @@ doc>
(display (do-color 'normal))
(display "If not redefined by your program, the following variables are available\n")
(display " - @1 (aka @), @2, @3, @4, @5 contain the last REPL's computed values\n")
(display " - @* contains a list of @1, @2, @3, @4 and @5 values\n"))
(display " - @* contains a list of @1, @2, @3, @4 and @5 values\n")

;; Print somme helps on the ! shell escape
(display (do-color (get-repl-color :help) "\nShell commands:\n"))
(display (do-color 'normal))
(display "!cmd a1 a2 ... executes the command \"cmd\" with the arguments a1 a2...\n"))


(define (do-repl-command name)
(define (search-repl-command name)
Expand Down Expand Up @@ -227,24 +233,10 @@ doc>
(repl-add-command 'cd
"Change current directory"
(lambda () (chdir (simple-trim (read-line)))))
;; ==== pwd
(repl-add-command 'pwd
"Print working directory"
(lambda () (printf "~s~%" (getcwd))))

;; ==== ls
(repl-add-command 'ls
"List directory content (usual 'ls' options accepted)"
(lambda () (system (string-append "ls " (read-line)))))

;; ==== quit
(repl-add-command '(quit q)
"Exit STklos"
(lambda () (exit 0)))
;; ==== shell
(repl-add-command '(shell !)
"Run a shell command"
(lambda () (system (read-line))))
;; ==== time
(repl-add-command '(time t)
"Print the time used to run the next expression"
Expand Down Expand Up @@ -289,6 +281,10 @@ doc>
(repl-add-command '(apropos a)
"Search for symbols containing a given string"
(lambda () (print (apropos (simple-trim (read-line))))))
;; == version
(repl-add-command '(version v)
"Show version"
(lambda () (printf "~a ~a~%" (version) (%push-id))))
;; ==== help
(repl-add-command
'(help ? h)
Expand All @@ -299,10 +295,6 @@ doc>
(display-repl-command-help)
(help (read-from-string arg))))))

;; == version
(repl-add-command '(version v)
"Show version"
(lambda () (printf "~a ~a~%" (version) (%push-id))))
) ;; end of REPL commands

;; ----------------------------------------------------------------------
Expand Down Expand Up @@ -476,7 +468,16 @@ doc>
(flush-output-port out))

((and (pair? e) (eq? (car e) 'unquote))
(do-repl-command (cadr e)))
;; Spcial ,xxx commands
(do-repl-command (cadr e)))

((and (symbol? e)
(not (symbol-bound? e))
(char=? (string-ref (symbol->string e) 0) #\!))
;; Shell command "!xxx arg1 arg2"
(let* ((end (read-line (current-input-port)))
(all (format "~a~a" e end)))
(system (substring all 1 (string-length all)))))

(else
(call-with-values
Expand Down
Loading

0 comments on commit ca139ff

Please sign in to comment.