我可以清理repl吗?
我在 repl 控制台中使用了很多代码,如何清除它?我想要一个新的而不需要重新启动它。可以吗?
I have played with a lot of code in a repl console, how can I clear it? I would like a fresh one without restarting it. Can that be done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
如果您想清除您声明的所有临时变量和函数的当前命名空间,您可以使用这个衬里(或使其成为一个函数):
或者
它并不声称为您提供一个非常干净的命名空间,只是一个具有较少通常在典型的 repl 会话中积累的垃圾。
小心使用:不要将地毯从脚下拉下来!
If you want to clear the current namespace of all temporary variables and functions you declared you can use this one liner (or make a function of it) :
or
It does not claim to give you a squeaky clean namespace, just one with less of the junk which usually accumulates in a typical repl session.
Use with caution : do not pull the rug from under your feet!
如果您通过终端窗口运行 repl(例如:MacOS 上的 Terminal.app 或 Linux 上的 xterm/aterm/urxvt 等),那么您可以输入 Control-L ,它应该会清除终端窗口并给你一个新的 repl 提示。然而,您之前定义的所有宏/原子仍然会在内存中,所以这只是一个“装饰”清除。
If you are running the repl through a terminal window (eg: Terminal.app on MacOS or xterm/aterm/urxvt etc on linux) then you can type Control-L and it should clear the terminal window and give you a new repl prompt. However all macros/atoms you previously defined are still going to be in memory, so this is just a "Cosmetic" clear.
在 EMACS/slime REPL 中
Cc Co 清除最后的输出(如果您输入的内容给出了很长的答案)
Cc Mo 清除所有内容
在 GNOME 终端中,您有一个菜单选项“终端/重置”和“清除”
In EMACS/slime REPLs
C-c C-o clears the last output (in case you've typed something that gave a very long answer)
C-c M-o clears the whole thing
In GNOME terminals, you've got a menu option Terminal/Reset and Clear
清理整个缓冲区的快捷方式: C-u C-c C -o
清理最后输出的快捷方式:C-c C-o
注意,旧的方法是: C-c M-o
另外,
cider-repl -clear-buffer
(在我的机器上绑定到 C-ENTER s-c )The shorcut to clean the whole buffer : C-u C-c C-o
The shortcut to clean the last output : C-c C-o
Note, the old way was : C-c M-o
Also,
cider-repl-clear-buffer
(which is bound to C-ENTER s-c on my machine)如果您使用 Emacs +
nREPL
,您可以:nrepl-clear-buffer
或如果未启用按键绑定,请运行 Mx
nrepl-interaction-模式
来启用它。您可以在 nrepl.el 和/或自定义按键绑定以满足您的需求。注意:您可以通过运行
Mx v
nrepl-mode-map
并按照以下命令找到系统中所有nREPL
的按键绑定nrepl.el
链接。If you are using Emacs +
nREPL
, you can either:nrepl-clear-buffer
orIf the key binding is not enabled, run Mx
nrepl-interaction-mode
to enable it. You can find other useful shortcuts in nrepl.el and/or customize the key bindings to fit your needs.Note: you can find all
nREPL
's key bindings in your system by runningM-x v
nrepl-mode-map
and following thenrepl.el
link.我通过 Mx 使用 Emacs 命令
cider-repl-clear-buffer
。还可以使用带有前缀参数的cider-repl-clear-output
:Cu Cc Co。I use the Emacs command
cider-repl-clear-buffer
via M-x. One might also usecider-repl-clear-output
with a prefix argument: C-u C-c C-o.这取决于你所说的“干净”是什么意思。要删除“包”中的所有命名空间,您可以使用:
It depends what you mean by 'clean'. To remove all namespaces within a 'package' you can use:
对于像我一样使用 IntelliJ IDEA Cursive IDE 插件的用户:
您可以通过单击 REPL 框架顶部的此图标来“美观地”清除 REPL(保留您定义的符号等):
< a href="https://i.sstatic.net/WyUK1.png" rel="nofollow noreferrer">
没有默认的按键绑定,但您可以通过打开您的首选项,导航到“键盘映射”>“轻松添加一个”。插件>草书,并添加“清除当前 REPL 的输出”的绑定。
或者,您可以右键单击编辑器并通过 REPL 命令访问“清除当前 REPL 的输出”。
For users of the Cursive IDE plugin for IntelliJ IDEA who end up here, like me:
You can "cosmetically" clear the REPL (keeping your def'd symbols etc.) by clicking on this icon at the top of the REPL frame:
There's no default key binding for this, but you can easily add one by opening your preferences, navigating to Keymap > Plugins > Cursive, and adding a binding for "Clear output for current REPL".
Alternatively, you can right-click in the editor and access "Clear output for current REPL" via the REPL commands.