From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Joost Kremers Newsgroups: gmane.emacs.help Subject: Re: Problem with simple script to clean out an ERC buffer Date: Wed, 06 Jun 2018 14:45:24 +0200 Message-ID: <87a7s8qe1n.fsf@fastmail.fm> References: <86lgbs2tav.fsf@zoho.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; format=flowed X-Trace: blaine.gmane.org 1528289072 9522 195.159.176.226 (6 Jun 2018 12:44:32 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 6 Jun 2018 12:44:32 +0000 (UTC) User-Agent: mu4e 1.1.0; emacs 26.1.50 Cc: help-gnu-emacs@gnu.org To: "J. David Boyd" Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Jun 06 14:44:28 2018 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fQXne-0002Nw-Bb for geh-help-gnu-emacs@m.gmane.org; Wed, 06 Jun 2018 14:44:27 +0200 Original-Received: from localhost ([::1]:52221 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fQXpl-0002SM-Eo for geh-help-gnu-emacs@m.gmane.org; Wed, 06 Jun 2018 08:46:37 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:51132) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fQXoo-0002R0-Jt for help-gnu-emacs@gnu.org; Wed, 06 Jun 2018 08:45:39 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fQXoj-0007lc-VZ for help-gnu-emacs@gnu.org; Wed, 06 Jun 2018 08:45:38 -0400 Original-Received: from out1-smtp.messagingengine.com ([66.111.4.25]:54063) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fQXoj-0007jC-OZ for help-gnu-emacs@gnu.org; Wed, 06 Jun 2018 08:45:33 -0400 Original-Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id D58C721C84; Wed, 6 Jun 2018 08:45:30 -0400 (EDT) Original-Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Wed, 06 Jun 2018 08:45:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastmail.fm; h= cc:content-type:date:from:in-reply-to:message-id:mime-version :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=fW7NnyAfv00hnr1GYPc3Iy4O67LU6Bot8HK1TSsoPyM=; b=onvI3Z3w YKanZUaO/40ScE5wP4xp7eH5R9bOCPEgrc/gopQV850yOlKxmqAyUqV/CQDkkG3/ NNC+qPTcqAevySdb1FGRPEOHo3J1lC6HE68MpYB9iQYyWYIrPQJ5RbKHE4364bfT ZXLeh2LpJJosRNfjVYi50/wq2MRTmy6Bi5nqBDGvHUW5D0H/ZrgfC+bewkpjvxAN sAsodw//GDqon9asOCd11OirFhm+NoKnf5nmtG+MTm49gZwKj/oMCw+Wrf6DJPKg ckg4jQeCbTkiAxEJj1jkbn0zDgl1SmkI74mvdxph4d1n6W/f9yvWiUeo2rdntGfk elYyxTsvaDRmWg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; bh=fW7NnyAfv00hnr1GYPc3Iy4O67LU6 Bot8HK1TSsoPyM=; b=D+jmgT/zijr4RZEP7i0/5IVJw6a1hl55RjxhiXhSnSOXH ojnlwE/LN0N/9h89vMb3crCzK9B0jYBy/kH/4xw7ZoCXwAd3PAoFkXRTmW2rJWKC o3LGoJc8ZRp4iaYvKiLOP3q7XyygdlYUpYZsYKSl0Ioe0CdbondEx+Cjlzop1YH5 gBXJMKkt7ak05KzHESnSPR5o6qZiFKk2N+dhtiKiAk3bfK5XtGCyVqXBXnSG/VHj xpFueFl2lMLmwJOq+r6WoU0uumb0FrcHobv07Zv3OMjPa06cEP6JDYzjUn8vLB9W 41UmeTjULQkVf8Fp2g11zkypfMPAvl1mE+mUcwUfQ== X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Sender: Original-Received: from IdeaPad.fastmail.com (freund-druck.geistwis.uni-wuppertal.de [132.195.204.212]) by mail.messagingengine.com (Postfix) with ESMTPA id 22846E4A32; Wed, 6 Jun 2018 08:45:30 -0400 (EDT) In-reply-to: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.111.4.25 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:116987 Archived-At: On Wed, Jun 06 2018, J. David Boyd wrote: > Yes there is, but it doesn't do anything: erc-cmd-CLEAR > > Supposed to "Clear the window content", but the code reads: > > (defun erc-cmd-CLEAR () > "Clear the window content." > (recenter 0) > t) > (put 'erc-cmd-CLEAR 'process-not-needed t) > > So not only does it not clear the window, but it seems to be > disabled. No, the erc source mentions that the `process-not-needed' property just indicates that the command can be run when the erc process is not alive. So it's not disabled. Since erc.el is part of Emacs, you might ask on the emacs-devel list why this command doesn't seem to do what it advertises and whether it should be changed to actually "clear the window content". > Anyway, I like to clear out the buffer so I can reduce my memory > footprint. > If there is anything important in it, I usually grab it and put > it into an org > file. As for your original question, your function has a bug: ``` (defun clearERCbuffer() (interactive) (previous-line) (end-of-line) (set-mark(point)) (beginning-of-buffer) (exchange-point-and-mark) ;; (set-text-properties (point-min) (point-max) nil nil ) (delete-region (point-min) (point-max))) ``` The final function call is `(delete-region (point-min) (point-max))`, which means that all the point, mark and region magic you did before that is moot, because you're trying to delete the entire buffer. Which is probably why your getting an error: in the part that you are deleting there's most likely (I don't use erc, so I can't check) something (a prompt perhaps) that is indeed read-only. What you probably want is simply `(delete-region)`, except that START and END aren't optional. So, I would do something like (untested): ``` (defun clearERCbuffer() (interactive) (save-mark-and-excursion (forward-line -1) (end-of-line) (delete-region (point-min) (point)))) ``` Some remarks: - `save-mark-and-excursion` saves point and mark and restores them after executing its body. This means that point should be back to where it was before you called the function. Note that if you're on Emacs 25, you should replace `save-mark-and-excursion` with `save-excursion`. - The doc string of `previous-line` suggests it shouldn't be used in Lisp programs, so I used `(forward-line -1)` instead. - With `delete-region`, there's no need to create an active region first. By (temporarily, due to `save-mark-and-excursion`) positioning the cursor at the end of the previous line, it's possible to simply use (point) as the END argument to `delete-region`. HTH -- Joost Kremers Life has its moments