我可以清理repl吗?

发布于 2024-09-18 07:41:02 字数 54 浏览 12 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

云裳 2024-09-25 07:41:02

如果您想清除您声明的所有临时变量和函数的当前命名空间,您可以使用这个衬里(或使其成为一个函数):

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

或者

(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 ... 

它并不声称为您提供一个非常干净的命名空间,只是一个具有较少通常在典型的 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) :

(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.

Use with caution : do not pull the rug from under your feet!

简单 2024-09-25 07:41:02

如果您通过终端窗口运行 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.

燕归巢 2024-09-25 07:41:02

在 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

神也荒唐 2024-09-25 07:41:02

清理整个缓冲区的快捷方式: 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)

℉絮湮 2024-09-25 07:41:02

如果您使用 Emacs + nREPL,您可以:

  • 运行 < kbd>Mx nrepl-clear-buffer
  • 运行Cc Mo

如果未启用按键绑定,请运行 Mxnrepl-interaction-模式 来启用它。您可以在 nrepl.el 和/或自定义按键绑定以满足您的需求。

注意:您可以通过运行 Mx v nrepl-mode-map 并按照以下命令找到系统中所有 nREPL 的按键绑定nrepl.el 链接。

If you are using Emacs + nREPL, you can either:

  • Run Mx nrepl-clear-buffer or
  • Run Cc Mo

If the key binding is not enabled, run Mxnrepl-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 running M-x v nrepl-mode-map and following the nrepl.el link.

一直在等你来 2024-09-25 07:41:02

我通过 Mx 使用 Emacs 命令 cider-repl-clear-buffer。还可以使用带有前缀参数的 cider-repl-clear-outputCu Cc Co

I use the Emacs command cider-repl-clear-buffer via M-x. One might also use cider-repl-clear-output with a prefix argument: C-u C-c C-o.

旧夏天 2024-09-25 07:41:02

这取决于你所说的“干净”是什么意思。要删除“包”中的所有命名空间,您可以使用:

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

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)))))
吾家有女初长成 2024-09-25 07:41:02

对于像我一样使用 IntelliJ IDEA Cursive IDE 插件的用户:

您可以通过单击 REPL 框架顶部的此图标来“美观地”清除 REPL(保留您定义的符号等):

< a href="https://i.sstatic.net/WyUK1.png" rel="nofollow noreferrer">清除 REPL 图标

没有默认的按键绑定,但您可以通过打开您的首选项,导航到“键盘映射”>“轻松添加一个”。插件>草书,并添加“清除当前 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:

Clear REPL icon

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文