2016-03-03 69 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