简体   繁体   English

我可以清理repl吗?

[英]Can I clean the repl?

I have played with a lot of code in a repl console, how can I clear it? 我在repl控制台中玩了很多代码,我该如何清除它? I would like a fresh one without restarting it. 我想要一个新的,而不重新启动它。 Can that be done? 可以这样做吗?

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) : 如果要清除所声明的所有临时变量和函数的当前名称空间,可以使用这个单元格(或者使用它的函数):

(map #(ns-unmap *ns* %) (keys (ns-interns *ns*)))

or 要么

(ns myutil)
(defn ns-clean
       "Remove all internal mappings from a given name space or the current one if no parameter given."
   ([] (ns-clean *ns*)) 
   ([ns] (map #(ns-unmap ns %) (keys (ns-interns ns)))))
(ns mytest)

... make loads of junk ...

(myutil/ns-clean)

... great!!! I can now make all new junk ... 

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. 它并没有声称给你一个干净的名字空间,只是一个通常在典型的repl会话中累积的垃圾。

Use with caution : do not pull the rug from under your feet! 请谨慎使用:不要从脚下拉地毯!

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. 如果你通过终端窗口运行repl(例如:MacOS上的Terminal.app或linux上的xterm / aterm / urxvt等),那么你可以输入Control-L ,它应该清除终端窗口并给你一个新的repl提示符。 However all macros/atoms you previously defined are still going to be in memory, so this is just a "Cosmetic" clear. 但是,您之前定义的所有宏/原子仍然会在内存中,因此这只是一个“化妆品”清晰。

In EMACS/slime REPLs Cc Co clears the last output (in case you've typed something that gave a very long answer) Cc Mo clears the whole thing 在EMACS / slime REPLs中,Cc Co清除最后一个输出(如果你输入了一个很长的回答的话)Cc Mo清除整个事情

In GNOME terminals, you've got a menu option Terminal/Reset and Clear 在GNOME终端中,您有一个菜单选项Terminal / Reset和Clear

The shorcut to clean the whole buffer : C - u C - c C - o 清理整个缓冲区的方法是: C - u C - c C - o

The shortcut to clean the last output : C - c C - o 清除最后一个输出的快捷方式: C - c C - o

Note, the old way was : C - c M - o 注意,旧方法是: C - c M - o

Also, cider-repl-clear-buffer (which is bound to C - ENTER s - c on my machine) 此外, cider-repl-clear-buffer (在我的机器上绑定到C - ENTER s - c

If you are using Emacs + nREPL , you can either: 如果您使用的是Emacs + nREPL ,您可以:

  • Run M x nrepl-clear-buffer or 运行M x nrepl-clear-buffer
  • Run C c M o 运行C c M o

If the key binding is not enabled, run M x nrepl-interaction-mode to enable it. 如果未启用密钥绑定,请运行M x nrepl-interaction-mode以启用它。 You can find other useful shortcuts in nrepl.el and/or customize the key bindings to fit your needs. 您可以在nrepl.el中找到其他有用的快捷方式和/或自定义键绑定以满足您的需求。

Note: you can find all nREPL 's key bindings in your system by running Mx v nrepl-mode-map and following the nrepl.el link. 注意:您可以通过运行Mx v nrepl-mode-map并遵循nrepl.el链接在系统中找到所有nREPL的键绑定。

I use the Emacs command cider-repl-clear-buffer via Mx . 我通过Mx使用Emacs命令cider-repl-clear-buffer One might also use cider-repl-clear-output with a prefix argument: Cu Cc Co . 也可以使用带有前缀参数的cider-repl-clear-outputCu Cc Co。

It depends what you mean by 'clean'. 这取决于你所说的'干净'。 To remove all namespaces within a 'package' you can use: 要删除“包”中的所有名称空间,您可以使用:

(mapv remove-ns 
  (map symbol 
    (filter #(.startsWith % "org.mycompany") 
      (map str (all-ns)))))

For users of the Cursive IDE plugin for IntelliJ IDEA who end up here, like me: 对于IntelliJ IDEA的Cursive IDE插件的用户,他们最终来到这里,像我一样:

You can "cosmetically" clear the REPL (keeping your def'd symbols etc.) by clicking on this icon at the top of the REPL frame: 您可以通过单击REPL框架顶部的此图标来“美化”清除REPL(保留您的def'd符号等):

清除REPL图标

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". 此处没有默认的键绑定,但您可以通过打开首选项轻松添加一个,导航到Keymap> Plugins> Cursive,并为“当前REPL的清除输出”添加绑定。

Alternatively, you can right-click in the editor and access "Clear output for current REPL" via the REPL commands. 或者,您可以在编辑器中单击鼠标右键,然后通过REPL命令访问“清除当前REPL的输出”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM