emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Add function eshell/clear to clear current eshell buffer


From: vibhavp
Subject: Re: Add function eshell/clear to clear current eshell buffer
Date: Mon, 09 Mar 2015 18:03:42 +0530
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)

Gregor Zattler <address@hidden> writes:

> Now this command does not clear the eshell buffer any more, but the
> eshell window.  I think the doc string should say so because this has
> security implications: The user may think some info is gone but actually
> it’s only no longer visible.  How about:
>
> "Scroll contents out of the eshell window by inserting newlines."

Yep, attached patch.
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index d8330a4..efb160c 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,7 @@
+2015-03-09  Vibhav Pant <address@hidden>
+
+       * eshell/esh-mode.el (eshell/clear): New function.
+
 2015-03-09  Nicolas Petton <address@hidden>
 
        * emacs-lisp/seq.el (seq-into): New function.
diff --git a/lisp/eshell/esh-mode.el b/lisp/eshell/esh-mode.el
index da83ec6..41ee132 100644
--- a/lisp/eshell/esh-mode.el
+++ b/lisp/eshell/esh-mode.el
@@ -871,6 +871,13 @@ When run interactively, widen the buffer first."
   (goto-char (point-max))
   (recenter -1))
 
+(defun eshell/clear ()
+  "Clear the eshell-buffer"
+  (interactive)
+  (let ((number-newlines (count-lines (window-start) (point))))
+    (insert (make-string number-newlines ?\n)))
+    (eshell-send-input))
+
 (defun eshell-get-old-input (&optional use-current-region)
   "Return the command input on the current line."
   (if use-current-region

> Doesn't this insert the newlines where ever the point is?
> Shouldn't it append the newlines to the very end of the buffer
> where ever point was before?

IIUC, Whenever the return key is pressed, (eshell-send-input)
automatically sets the point to end of the eshell buffer. So, the
newlines are always inserted at the buffer's end.

Thanks
-- 
Vibhav Pant
address@hidden

reply via email to

[Prev in Thread] Current Thread [Next in Thread]