From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Lars Ingebrigtsen Newsgroups: gmane.emacs.devel Subject: Re: Improve `replace-regexp-in-string' ergonomics? Date: Wed, 22 Sep 2021 22:18:37 +0200 Message-ID: <87r1dgtlcy.fsf@gnus.org> References: <878rzpw7jo.fsf@gnus.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="27411"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: emacs-devel@gnu.org To: Dmitry Gutov Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Sep 22 22:20:30 2021 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 1mT8jF-0006sk-Kw for ged-emacs-devel@m.gmane-mx.org; Wed, 22 Sep 2021 22:20:29 +0200 Original-Received: from localhost ([::1]:55666 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mT8jD-0003Ic-4h for ged-emacs-devel@m.gmane-mx.org; Wed, 22 Sep 2021 16:20:27 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:43518) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mT8ha-0001HF-Sl for emacs-devel@gnu.org; Wed, 22 Sep 2021 16:18:46 -0400 Original-Received: from quimby.gnus.org ([2a01:4f9:2b:f0f::2]:51600) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mT8hZ-0006mT-4H for emacs-devel@gnu.org; Wed, 22 Sep 2021 16:18:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org; s=20200322; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date: References:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=ehYFuoBCRYcEvSS8Ebq68atoaYAqYYoKKB0/mffzh98=; b=QGMyqIiJcBwjb69OO46ilpbeL4 dsVdIRXWQ6eBP2DGllV+iOc5ju5c82yj24lij6QeQDdLqnO4QW2joDfBFB1wNVKoeWSEUCbjNIQ31 1aJqj8wfe8KlwQX97NiFESvG9W+2VsWuQBjSITWvQCWQr+/25hT5IruKT/ZoZ8WeGOtM=; Original-Received: from [84.212.220.105] (helo=elva) by quimby.gnus.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mT8hS-0006vp-JX; Wed, 22 Sep 2021 22:18:42 +0200 Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAABGdBTUEAALGPC/xhBQAAACBj SFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAD1BMVEXYyLjFtaWTfm5W PzH////FdCktAAAAAWJLR0QEj2jZUQAAAAd0SU1FB+UJFhMoAl8MmAwAAAGtSURBVDjLZZPrlcQg CIXBbQBIAxEbmIH+e1tATdyzzh9PvuHyuAiAw/cxzjPMVBUQtb75WEB0aALAuIyRQBeIIwFIxCYw owQp1ANA0w3cgFnnKXCkJx4HUH8JvhF4Aj+kQMYBPgdomffRagdQH/+0CvgJ7hMsJUv+na0XsCzL RFmeJJwAo2/veeG/AIZGywVyxBBafYJrTAB8RUg0FqKwyrLSrFZzFjwjcIMaZ5dQmhEwCqBalaUv kLSixcDZ0fUA0cq4G8cGOHnXdHgB8U6IQmg9pPoDWlqHlQb/gExegLXN5Pz2UXce1wliJA4sd5o5 sqotdcUQiZCqiOsALf3hAChGbQGaI3HrBT4RXmTPKrxmitxQlh9VucfoQHpsjL8gXfBvtkfprr3l zrVF6YB9HBEFmFDjTYQlJgtUbgMVane8kHhIJ8idu7GMJ1kNtr229yz+8WODGZBLsqTSaNdMX3NI pyeoNiAeMyCtmLlwtbnsn9jE5fQ0pyXozQmZNqi/1BPsP4bMCE/IeptGI8EjBRg7oDGFL/mXY1Hw AGHM8M4BTq0AaUDmZsjfA34BSGFuZ4hpGIkAAAAldEVYdGRhdGU6Y3JlYXRlADIwMjEtMDktMjJU MTk6NDA6MDIrMDA6MDCrt6N+AAAAJXRFWHRkYXRlOm1vZGlmeQAyMDIxLTA5LTIyVDE5OjQwOjAy KzAwOjAw2uobwgAAAABJRU5ErkJggg== X-Now-Playing: Davitt Sigerson's _Davitt Sigerson_: "Break My Heart" In-Reply-To: (Dmitry Gutov's message of "Wed, 22 Sep 2021 13:59:54 +0300") Received-SPF: pass client-ip=2a01:4f9:2b:f0f::2; envelope-from=larsi@gnus.org; helo=quimby.gnus.org X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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:275340 Archived-At: Dmitry Gutov writes: > This way makes it impossible to use any optional arguments, right? Indeed. > But if we target thread-first instead and make the new function accept > STRING in the first position, all optional arguments would be still > available. Yes, I've always found it weird that these functions have the object to be worked upon as the last non-optional parameter. I had to look it up for years when using `replace-regexp-in-string'. And it didn't help that Emacs took this function from XEmacs, which had the string in a different position... But I don't remember where... *Lars says "apt install xemacs21"* I misremembered: `replace-in-string' is a compiled Lisp function -- loaded from "/build/xemacs21-rcHAYB/xemacs21-21.4.24/lisp/subr.elc" (replace-in-string STR REGEXP NEWTEXT &optional LITERAL) So it has the placement of STRING that seems logical, I think. On the other hand, changing the placement in a new function like this will probably be even more confusing. >> (regexp-replace "'" "\"" >> ",[[:space:]]" " " >> "\\]" ")" >> "\\[" "(" >> results))) >> Or some variation thereupon with some more ()s to group pairs. > > I'm not sure how to also make it accept "normal" convention, and we > probably don't want to always have to wrap the args in an alist, even > when only one replacement is needed. No, that's the problem. We could hack it up by doing a &rest in reality, and then checking if the first parameter is a list, but yuck. >> (setq author (regexp-remove "[ \t]*[(<].*$" author)) >> (setq author (regexp-remove "\\`[ \t]+" author)) >> (setq author (regexp-remove "[ \t]+$" author)) >> (setq author (regexp-replace "[ \t]+" " " author)) > > IDK, if that leads to no increase in efficiency, then probably not? > Replacing with "" is an established pattern by now. It helps with readability -- the function says what the intention is. -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no