2016-03-03 72 views
2

我正在写一个在终端中运行的Racket程序。我希望能够从内部启动一个轻量级编辑器(vi,pico等),编辑一些文本,然后在关闭时将其返回到程序。从Racket内部启动编辑器

我知道在shell脚本中可以这样做。球拍有可能吗?如果是这样,怎么样?

回答

4

是的,这是可能的。您可以使用system函数及其变体,如system*

例子:

#lang racket 

(define file (make-temporary-file)) 

;; run the editor you want here and pass it the file name 
(system* (find-executable-path "vim") (path->string file)) 

;; do whatever processing you want to do on the file here 
(file->string file) 

这将创建一个临时文件,让VIM编辑它,然后读取文件回来。

+0

完美!谢谢 :-) – interstar

1

另一种方法是使用文本%class进行编辑,然后用通常的I/O方式将结果写入文件。我监督了一个去年使用这种方法的前期课程项目,并且对他们来说效果很好。

https://docs.racket-lang.org/gui/text_.html