简体   繁体   English

如何清除emacs中的ipython缓冲区?

[英]how to clear ipython buffer in emacs?

I am running and interactive ipython shell in an emacs buffer using ipython.el .我正在使用ipython.el在 emacs 缓冲区中运行和交互式 ipython shell。 I wonder if there is a way to clear the screen?我想知道有没有办法清除屏幕? Since it is not running on a terminal, the import os; os.system('CLS')由于它不在终端上运行,因此import os; os.system('CLS') import os; os.system('CLS') trick will not work. import os; os.system('CLS')技巧将不起作用。 Thanks.谢谢。

It looks like ipython is based on comint, which means the following code should work for you (called with Mx my-clear or your favourite key binding):看起来 ipython 基于 comint,这意味着以下代码应该适合您(使用Mx my-clear或您最喜欢的键绑定调用):

(defun my-clear ()
  (interactive)
  (let ((comint-buffer-maximum-size 0))
    (comint-truncate-buffer)))

I posted some other options in response to this question .我发布了一些其他选项来回答这个问题

Cc Mo runs the command comint-clear-buffer (found in inferior-python-mode-map), which is an interactive compiled Lisp function. Cc Mo 运行命令 comint-clear-buffer(在enior-python-mode-map 中找到),这是一个交互式编译的 Lisp 函数。

It is bound to Cc Mo.它绑定到 Cc Mo。

(comint-clear-buffer) (comint-clear-buffer)

Clear the comint buffer.清除comint缓冲区。

This clears the screen and the current session variables (using %reset ):这会清除屏幕当前会话变量(使用%reset ):

(defun my-reset-ipython ()
  "Clear Emacs *Python* buffer and resets iPython variables.

Prints date and time of reset to iPython console and to
*Messages* buffer.

Assumes python has been configured to use iPython:

  (setq python-shell-interpreter \"ipython\")

This function does not reset the iPython console line numbering
or history (either because you can't do that in an iPython
console or the author couldn't find out how!)."
  ;; Allow function to be called via M-x
  (interactive)
  ;; Define variables: date-time string, message string, command to be passed to python
  ;; Requires let* in order for python-command to resolve reset-time and reset-statement
  (let* ((reset-time (format-time-string "%A, %B %e, %Y @ %-I:%M %p"))
         (reset-statement "Reset iPython on ")
         (python-command (concat "print('" reset-statement reset-time "')" )))
    ;; Reset iPython console
    (python-shell-send-string "%reset -f" "*Python*")
    ;; Print message to iPython console indicating reset
    (python-shell-send-string  python-command "*Python*")
    ;; Allow command to be called from another buffer
    (with-current-buffer "*Python*"
      (comint-clear-buffer))
    ;; Print message to minibuffer and *Messages*
    (message (concat reset-statement "%s") reset-time)))

;; Mimic default binding for comint-clear-buffer (C-c M-o)
(define-key inferior-python-mode-map (kbd "C-c M-l") 'my-reset-ipython)

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

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