From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: "Paul W. Rankin" Newsgroups: gmane.emacs.devel Subject: Re: Can we add a delete-match function to subr(-x).el? Date: Sun, 26 Jan 2020 03:18:19 +1000 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="50084"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.2.0; emacs 28.0.50 Cc: Emacs Devel To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Jan 25 18:19:18 2020 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ivP5a-000Cw1-P3 for ged-emacs-devel@m.gmane-mx.org; Sat, 25 Jan 2020 18:19:18 +0100 Original-Received: from localhost ([::1]:55634 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ivP5Z-0005qv-Tx for ged-emacs-devel@m.gmane-mx.org; Sat, 25 Jan 2020 12:19:17 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:36910) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ivP4m-0005I9-Jf for emacs-devel@gnu.org; Sat, 25 Jan 2020 12:18:31 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ivP4l-0007zj-HV for emacs-devel@gnu.org; Sat, 25 Jan 2020 12:18:28 -0500 Original-Received: from wout2-smtp.messagingengine.com ([64.147.123.25]:39667) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ivP4k-0007wi-HX for emacs-devel@gnu.org; Sat, 25 Jan 2020 12:18:26 -0500 Original-Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id 0E2703E3; Sat, 25 Jan 2020 12:18:24 -0500 (EST) Original-Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Sat, 25 Jan 2020 12:18:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paulwrankin.com; h=references:from:to:cc:subject:in-reply-to:date:message-id :mime-version:content-type; s=fm1; bh=B5pLs079SVyJ2Tyl/YkxzzZVeq mD6ehIbtkBAwpRELM=; b=OHtXNND8QwdtwnnmzxSe7yv17aDqobUffNG8rvEpZx Mnu51EpCAo1UIQ64+C0YM+MxT00r8U6r4l5mjyS8rO2lW+zGEFj2vgkHtrNMcJaL TAud8Ib/0/GmePYGSCntETjx2VmKyBTWc3pagw9PEXKBoIuBqekX8guyBCQDHvFj qwsmGSSQdxBuUxDcx0wpobqIuG/H+DbaBzptOmNUIR2dTqJ3ry9Vm64OpUYIz7GO jI1gpecGo4WesYG9gNKyuARO4maJ+rtMMxdk0BAptHJgSlZHKLbccr+8WfhtOPce Nw6L/14XVMskBdbu6GMuOuQ2CugNGzedLLvlVDxUhoqw== 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-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=B5pLs0 79SVyJ2Tyl/YkxzzZVeqmD6ehIbtkBAwpRELM=; b=P7lbQN9CaB9CmgIUvYNY/F IazSwPLostJkujSWDKop7CqsuCyK3cfzulL9ygd35YMxmwdV+9nG6q5OCSdS9b/W GEwa2cyXDlJjk3LUJKNM6D2oANFi7atPM/Y4FiUXOYNb1qu7FiVY29B2svpDJqGH utPykUKAN80RG99d+klwnTNoYeUIML96EAzQIgMeHjB7gAd0AuHNSKl3jUC4dV/7 u9P3uzvWmPiApz2TV5AEtwuuT0wkBbHvZY1VLpMeTAvDL3mNbJMzdgUzyUFwE/Lp KFBajXkWZzCN/2EiSlOg+1Y4SpDgJAIpSJwKV/dowOmuTtgWnE2P2TC8UduArH0A == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedugedrvdejgdellecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpehffgfhvffujgffkfggtgesthdtredttdertdenucfhrhhomhepfdfrrghulhcu hgdrucftrghnkhhinhdfuceohhgvlhhlohesphgruhhlfihrrghnkhhinhdrtghomheqne cukfhppeduvddtrddvvddrieelrddvvdegnecuvehluhhsthgvrhfuihiivgeptdenucfr rghrrghmpehmrghilhhfrhhomhephhgvlhhlohesphgruhhlfihrrghnkhhinhdrtghomh X-ME-Proxy: Original-Received: from localhost (unknown [120.22.69.224]) by mail.messagingengine.com (Postfix) with ESMTPA id 8C4763280059; Sat, 25 Jan 2020 12:18:23 -0500 (EST) In-reply-to: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 64.147.123.25 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:244634 Archived-At: On Sun, Jan 26 2020, Stefan Monnier wrote: >> (when (consp (match-data)) > > This allocates N cons cells just to test if there's something and in > practice there's basically *always* something (the match data keeps > info about the last successful match, so even if your last match was > a failure, `match-data` won't be nil]). I figured this was a waste, just wanted it to look more thorough. Would this be better as a macro? (defmacro delete-match (&optional subexp) "Delete text matched by last search. Optional argument SUBEXP specifies the subexpression to delete, or delete the entire match." (list 'unless subexp (list 'setq subexp 0)) (list 'delete-region (list 'match-beginning subexp) (list 'match-end subexp))) I like this because of this: (macroexpand-all '(while (re-search-forward "foo\\(ba[rz]\\)" nil t) (delete-match 1))) => (while (re-search-forward "foo\\(ba[rz]\\)" nil t) (delete-region (match-beginning 1) (match-end 1)))