从 Racket 中启动编辑器

Launch an editor from within Racket

我正在编写一个在终端中运行的 Racket 程序。我希望能够从其中启动一个轻型编辑器(vi、pico 等)来编辑一些文本,然后在关闭时 return 将其发送到程序。

我知道可以在 shell-script 中做这样的事情。在球拍中有可能吗?如果是,怎么做?

是的,这是可能的。您可以使用 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 编辑它,然后再读回文件。

另一种选择是使用文本%class 进行编辑,然后将结果写入通常I/O-way 中的文件。去年我监督了一个使用该方法的入门课程项目,对他们来说效果很好。

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