Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Clear Emacs Buffer programmatically from Common Lisp

227 views
Skip to first unread message

Frank Zalkow

unread,
Dec 1, 2014, 4:23:10 AM12/1/14
to
Hey Lispers,

I would like to know if it is possible to clear the current REPL in Emacs from CL.

If I do it from emacs lisp
M-x eval-expression: (let ((inhibit-read-only t)) (interactive) (erase-buffer))
it works fine.

So I thought it should work to do
M-x eval-expression: (setq slime-enable-evaluate-in-emacs t)

and call a function like this

(defun clear-emacs-buffer ()
(swank:eval-in-emacs
'(let ((inhibit-read-only t)) (interactive) (erase-buffer))))

But calling this function just returns NIL and doesn't clear the buffer.

Is this a wrong approach?

Thanks alot for any hints!

Best

Frank

smh

unread,
Dec 1, 2014, 4:53:47 AM12/1/14
to
Possibly with swank the eval-in-emacs doesn't happen in the repl buffer, so you are clearing some other buffer. Don't know the details of swank, but in the ACL Emacs-Lisp interface the following works and may suggest something to try with swank.

(lep::eval-in-emacs
"(save-excursion (set-buffer \"*common-lisp*\") (erase-buffer))")

Pascal J. Bourguignon

unread,
Dec 1, 2014, 5:10:53 AM12/1/14
to
Frank Zalkow <fza...@gmail.com> writes:

> Hey Lispers,
>
> I would like to know if it is possible to clear the current REPL in Emacs from CL.
>
> If I do it from emacs lisp
> M-x eval-expression: (let ((inhibit-read-only t)) (interactive) (erase-buffer))
> it works fine.
>
> So I thought it should work to do
> M-x eval-expression: (setq slime-enable-evaluate-in-emacs t)
>
> and call a function like this
>
> (defun clear-emacs-buffer ()
> (swank:eval-in-emacs
> '(let ((inhibit-read-only t)) (interactive) (erase-buffer))))
>
> But calling this function just returns NIL and doesn't clear the buffer.

M-x slime RET C-h k C-c M-o

indicates the command to use is slime-repl-clear-buffer, not
erase-buffer.

(swank:eval-in-emacs 'slime-repl-clear-buffer)

fails with an obvious re-entrancy error.

Therefore:

(swank:eval-in-emacs '(progn
(run-at-time 1 nil 'slime-repl-clear-buffer)
nil))

should do it.


--
__Pascal Bourguignon__ http://www.informatimago.com/
“The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.” -- Carl Bass CEO Autodesk

Frank Zalkow

unread,
Dec 1, 2014, 5:21:10 AM12/1/14
to
Smh, awesome, thanks alot! It works!

Now I have something like this:

(defun clear-emacs-buffer (buffer-name)
(swank:eval-in-emacs
`(let ((inhibit-read-only t))
(interactive)
(save-excursion (set-buffer ,buffer-name)
(erase-buffer)))))

And I can call it like
(clear-emacs-buffer "*slime-repl sbcl*")



Pascal, also thanks to you! That works and is even better because I have not to type the buffer name.

(defun clear-emacs-buffer ()
(swank:eval-in-emacs
'(progn
(run-at-time 0.2 nil 'slime-repl-clear-buffer)
nil)))

I can even do (run-at-time 0.0 ...) - it just causes the last expression to remain on the screen.

Thanks both of you and best,

Frank
0 new messages