From mboxrd@z Thu Jan  1 00:00:00 1970
Path: news.gmane.org!not-for-mail
From: vibhavp@gmail.com
Newsgroups: gmane.emacs.devel
Subject: Re: Add function eshell/clear to clear current eshell buffer
Date: Mon, 09 Mar 2015 18:03:42 +0530
Message-ID: <87vbiafizd.fsf@gmail.com>
References: <874mpwhxml.fsf@gmail.com> <83lhj7lcgn.fsf@gnu.org>
	<87y4n7e1bn.fsf@gmail.com> <831tkz6yh1.fsf@gnu.org>
	<87oao23dbb.fsf@gmail.com> <20150309101126.GA11863@boo.workgroup>
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
X-Trace: ger.gmane.org 1425904420 5941 80.91.229.3 (9 Mar 2015 12:33:40 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Mon, 9 Mar 2015 12:33:40 +0000 (UTC)
To: emacs-devel <emacs-devel@gnu.org>
Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Mar 09 13:33:40 2015
Return-path: <emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org>
Envelope-to: ged-emacs-devel@m.gmane.org
Original-Received: from lists.gnu.org ([208.118.235.17])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org>)
	id 1YUwsN-0004av-51
	for ged-emacs-devel@m.gmane.org; Mon, 09 Mar 2015 13:33:39 +0100
Original-Received: from localhost ([::1]:43104 helo=lists.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org>)
	id 1YUwsM-0003qF-Bt
	for ged-emacs-devel@m.gmane.org; Mon, 09 Mar 2015 08:33:38 -0400
Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:50794)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <vibhavp@gmail.com>) id 1YUwsI-0003q6-M7
	for emacs-devel@gnu.org; Mon, 09 Mar 2015 08:33:35 -0400
Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <vibhavp@gmail.com>) id 1YUwsF-0007kH-CH
	for emacs-devel@gnu.org; Mon, 09 Mar 2015 08:33:34 -0400
Original-Received: from mail-pa0-x236.google.com ([2607:f8b0:400e:c03::236]:42602)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <vibhavp@gmail.com>) id 1YUwsF-0007kD-4k
	for emacs-devel@gnu.org; Mon, 09 Mar 2015 08:33:31 -0400
Original-Received: by padfa1 with SMTP id fa1so72320506pad.9
	for <emacs-devel@gnu.org>; Mon, 09 Mar 2015 05:33:30 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;
	h=from:to:subject:references:date:in-reply-to:message-id:user-agent
	:mime-version:content-type;
	bh=i0mqfJQswmY3u0MUU1kMIoa552LK1macv58aa/bWgMg=;
	b=oUCv5NDPkF+/zq8fRndqJTWYexG8jVgp9g427QApu3Qi0k32C3Sm05RHe4Dr21+T2R
	RH+1gHUoeH02X1uQi3qf6UikM0qbPStdo/43lEuhWdWCynqFcDnFNqu5Jb9Zwtkgx+do
	gbJOziZ+6x8uk5PeHtopwHuEYc5fT6fSMX3bUfM/h5D+k3SqNNHKozRp19oOcA+DKIfX
	Mp0JEXXXeVEA4iWHt9x/GSs9CQC6C1TCySP+Vcn6aMv/9/WPFhpquwmfE+79I7o2GdHv
	OCzA5qoPR7oHq1zQ8Q6cyZRmXy/EyOOsn7xRNtYs/MJINXQ37UFqhR5ZaQ0gw77UFFpw
	/rYg==
X-Received: by 10.70.95.200 with SMTP id dm8mr51219077pdb.14.1425904409924;
	Mon, 09 Mar 2015 05:33:29 -0700 (PDT)
Original-Received: from lenovog410 ([59.89.143.34])
	by mx.google.com with ESMTPSA id mi9sm19219721pab.3.2015.03.09.05.33.28
	for <emacs-devel@gnu.org>
	(version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
	Mon, 09 Mar 2015 05:33:29 -0700 (PDT)
In-Reply-To: <20150309101126.GA11863@boo.workgroup> (Gregor Zattler's message
	of "Mon, 9 Mar 2015 11:11:26 +0100")
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)
X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address
	(bad octet value).
X-Received-From: 2607:f8b0:400e:c03::236
X-BeenThere: emacs-devel@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: "Emacs development discussions." <emacs-devel.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/emacs-devel>,
	<mailto:emacs-devel-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/emacs-devel>
List-Post: <mailto:emacs-devel@gnu.org>
List-Help: <mailto:emacs-devel-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/emacs-devel>,
	<mailto:emacs-devel-request@gnu.org?subject=subscribe>
Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org
Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org
Xref: news.gmane.org gmane.emacs.devel:183742
Archived-At: <http://permalink.gmane.org/gmane.emacs.devel/183742>

--=-=-=
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable

Gregor Zattler <telegraph@gmx.net> 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=E2=80=99s only no longer visible.  How about:
>
> "Scroll contents out of the eshell window by inserting newlines."

Yep, attached patch.

--=-=-=
Content-Type: text/x-diff
Content-Disposition: inline; filename=eshell-clear.patch
Content-Description: 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 <vibhavp@gmail.com>
+
+	* eshell/esh-mode.el (eshell/clear): New function.
+
 2015-03-09  Nicolas Petton <nicolas@petton.fr>
 
 	* 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

--=-=-=
Content-Type: text/plain



> 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
vibhavp@gmail.com

--=-=-=--