From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?Q?Andreas_R=C3=B6hler?= Newsgroups: gmane.emacs.help Subject: Re: (where can I find a) query-replace-list? Date: Fri, 22 Dec 2023 16:26:52 +0100 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="13757"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla Thunderbird To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Fri Dec 22 16:27:39 2023 Return-path: Envelope-to: geh-help-gnu-emacs@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 1rGhR4-0003Ht-W0 for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 22 Dec 2023 16:27:38 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rGhQS-00008W-H5; Fri, 22 Dec 2023 10:27:00 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rGhQQ-00008K-Os for help-gnu-emacs@gnu.org; Fri, 22 Dec 2023 10:26:58 -0500 Original-Received: from mout.kundenserver.de ([212.227.17.24]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rGhQO-0001qj-Jn for help-gnu-emacs@gnu.org; Fri, 22 Dec 2023 10:26:58 -0500 Original-Received: from [192.168.178.61] ([89.247.171.250]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.183]) with ESMTPSA (Nemesis) id 1N9doJ-1rAqN6047p-015YiZ for ; Fri, 22 Dec 2023 16:26:53 +0100 Content-Language: en-US In-Reply-To: X-Provags-ID: V03:K1:6iDDbRsLeow12UIH7CdIiEfpqWPnWcoKxY7zyfxuyX7/pi8uZO1 cdEsyd47B7jO6DgVf8hkMWpaOMth18Lhkj6vfdwd37U4YpNZBYbxL43L5b1tkZhX/eAYQMo yNmuSNXHnzP4/keBvMd2eybcCD5Xvt4N2SO8CKraim3p4uztqLDLSiCw4kZARvu6YJgMCuu mdxMAVG1KXqE6OIEq0xZg== UI-OutboundReport: notjunk:1;M01:P0:QQmUkRuRr58=;WkJ9JkgO4TluhiYmql1Sv8QEkop 3GEUMZq8LJlSvffoBu3MwzmiLHUM6t9gvO0tjGNkXUl6jHxG+YXCpsmw2i0FkPDHkyHUk4dVX A9DEZdR4KndPCHVy2Zw7a/oyKsuacNUPNaZksI74uQY7OirtwfncW5UYR/6qcbEqJnE1NC1dV ZjVHFHtK5xzpRgMeq5jj2jsYq2XDJns1oOEBYPcNB6rzTEHCr/S/8sqxOB8GtyAxqteZnHBsM xiBJ5qNlUrHxQ6PRs5byaFwsdfUyXt0yrYj7WkFydSehzVNFRuyb2kC7fNV83NlQZtWKAcpDE iQiJJDnkqgLyjltsI4HmbuuTlpHgoGSSIeN9LmM55f8xWd0OcWiV+Tw4+nMCqjlr0Aw5PTYVL XE8Re+Iet4pq24L2xROG+INcYCgEBeqzYiy/RZA8o/AiNb4/z+uW6hOsvTaZggS7umRrIKFoZ H8ifTJsGzHlpwrP6QhHNtFBWW2welfH3Fydp1CpkkiB2WE1Z0/uYcyBEMLnQi+Hr5ZWh/UMTx W6BYdzdWtwvwXDM7DMUe1I4r6Rm2PMX7vhzSdEVf82DVnK/pSsE51ykJ1h2gvgILcbvPajZwg 0RtSQyi/1116ok79ObXO686Jq/GjhS9tIOBYgEBureADfg7QiZ62Ewx/5mjSE1rrDp4L9q5NK UC0j4lDIAeM8KRqQI41ffkNBQEjrQlSg4IKoIGFSKJFyPRfjl8kOGF7YsApjv9PTBMIZZsyEb k5QuwjK1nw1JXRUTqJwA2SYslg5MO7z9bDv+IeLlhlVszw4seGjqDK+IQUzeBU14TxKRwKOL Received-SPF: pass client-ip=212.227.17.24; envelope-from=andreas.roehler@easy-emacs.de; helo=mout.kundenserver.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 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-mx.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.help:145663 Archived-At: Am 22.12.23 um 15:12 schrieb Eduardo Ochs: > Hi list, > > sometimes I need to quote special characters in a string in a special > way, that includes that each "{" should become a "{<}" and each "}" > should become a "{>}", and I prefer to do that interactively using > some variant of query-replace or query-replace-regexp... I had a hack > to do that but it was ugly and fragile - it query-replaced all > "{"->"{<}"s before "}"->"{>}"s, so I had to be very careful with my > "yes"es and "no"s - so I decided to rewrite it... > > I tried to implement something that could be called like this, > > (query-replace-list > "\"" "\\\"" > "\\" "\\\\" > "{" "{<}" > "}" "{>}") > > and I sort of got it - but I ended up using mapconcat, regexp-quote, a > function to delete text-properties, a plist-get, and then a call like > this, > > (query-replace-regexp > "\"\\|\\\\\\|{\\|}" > (list 'my-replacer-function nil)) > > in which my-replacer-function uses (match-string 0) to obtain its > input string. > > That's so clumsy that I _guess_ that there should exist a standard > function, or at least a package in one of the *ELPAs, that implements > something like this query-replace-list - but I couldn't find it... > > Any hints? Any pointers? > > Here is my prototype, for the sake of completeness: > > --snip--snip-- > (defun ee-no-properties (str) > (setq str (copy-sequence str)) > (set-text-properties 0 (length str) nil str) > str) > > (defvar ee-qrl-plist > '("\"" "\\\"" "\\" "\\\\" > "{" "{<}" "}" "{>}")) > > (defun ee-qrl-as () (cl-loop for (a b) on ee-qrl-plist by 'cddr collect a)) > (defun ee-qrl-regexp () (mapconcat 'regexp-quote (ee-qrl-as) "\\|")) > > (defun ee-qrl-r0 (s) (plist-get ee-qrl-plist (ee-no-properties s) 'equal)) > (defun ee-qrl-r1 (s) (replace-regexp-in-string "\\\\" "\\\\\\\\" s)) > (defun ee-qrl-r2 (s) (ee-qrl-r1 (ee-qrl-r0 s))) > (defun ee-qrl-r3 (a b) (ee-qrl-r2 (match-string 0))) > (defun ee-qrl () > (interactive) > (query-replace-regexp (ee-qrl-regexp) (list 'ee-qrl-r3 nil))) > --snip--snip-- > > Thanks in advance, > Eduardo Ochs > http://anggtwu.net/eepitch.html > Would consider a pcase, each match followed by a cond, listing all the clauses. Then a simple replace-match.