Elpy: [Question] Clear Python Shell Buffer

Created on 23 Apr 2018  路  13Comments  路  Source: jorgenschaefer/elpy

I saw another issue https://github.com/jorgenschaefer/elpy/issues/1204.

But, Is there any default keybinding or something like M-x clear-elpy-shell-buffer ?

I don't find such feature in the docs. Or am I miss something ?

Thanks for this great package. :)

Most helpful comment

Apart from elpy-shell-clear-shell. You can clear inferior-python buffer using comint-clear-buffer which bound to C-c M-o.

All 13 comments

There is no default keybinding nor elpy function to do that.
But this is something we can think about implementing.

Would the following function do what you want ?

(defun elpy-shell-clear-shell ()
  "Clear the current shell buffer."
  (interactive)
  (with-current-buffer (process-buffer (elpy-shell-get-or-create-process))
    (comint-clear-buffer)))

@galaunay. Thanks a lot. Work like a charm. :)

Thanks.

@jorgenschaefer @galaunay

I am also looking for a bash like clear function to clear my python shell. I added this to my init.el file

(defun elpy-shell-clear-shell ()
  "Clear the current shell buffer."
  (interactive)
  (with-current-buffer (process-buffer (elpy-shell-get-or-create-process))
    (comint-clear-buffer)))

When I tried M-x elpy-shell-clear-shell it gives this error symbol's function definition is void: comint-clear-buffer. What do I do now?

@potholiday it works for me. Sounds like you invoke it when no python prompt exists. I got the same error last week when I tried to invoke non-existent prompt

@azzamsa Can you plz tell me the steps you took to get it to work. Mine still not working?

Sure. this is my elpy config.

My init.el Emac24

;;Elpy
(package-initialize)
(elpy-enable)

(defun elpy-shell-clear-shell ()
  "Clear the current shell buffer."
  (interactive)
  (with-current-buffer (process-buffer (elpy-shell-get-or-create-process))
    (comint-clear-buffer)))

Cant seems to find what I am doing wrong here. If it helps I always do a line by line execution of python Send Region to python

if comint-clear-buffer is not defined, you can try this:

;;Elpy
(package-initialize)
(elpy-enable)
(require 'comint)

(defun elpy-shell-clear-shell ()
  "Clear the current shell buffer."
  (interactive)
  (with-current-buffer (process-buffer (elpy-shell-get-or-create-process))
    (comint-clear-buffer)))

Still not working. In order to avoid any confusion (if any) I am looking for a clear function like this https://upload.wikimedia.org/wikipedia/commons/0/0f/Clear-gnulinux.gif . For emacs insted of clear , M-x elpy-shell-clear-shell

Ehsell already had clear support.

I think binding elpy-shell-clear-shell to key is faster than typing 'clear'.

We are on the same page about the clear function.

I don't know when comint-clear-buffer has been implemented, could you give us some information about your Emacs version ?

You can also try the following function, that does not rely on comint-clear-buffer:

(defun elpy-shell-clear-shell ()
  "Clear the current shell buffer."
  (interactive)
  (with-current-buffer (process-buffer (elpy-shell-get-or-create-process))
    (let ((comint-buffer-maximum-size 0))
      (comint-truncate-buffer))))

@galaunay Thank you that worked. My version is Emacs 24.5.1

Apart from elpy-shell-clear-shell. You can clear inferior-python buffer using comint-clear-buffer which bound to C-c M-o.

Was this page helpful?
0 / 5 - 0 ratings