From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: "B. T. Raven" Newsgroups: gmane.emacs.help Subject: Re: replace deprecated function ? Date: Fri, 16 Feb 2018 14:19:23 -0600 Organization: NewsGuy.com Message-ID: References: <86vaf0g06i.fsf@zoho.com> <86a7wcfymi.fsf@zoho.com> <861shkdg8m.fsf@zoho.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: blaine.gmane.org 1518812329 26958 195.159.176.226 (16 Feb 2018 20:18:49 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 16 Feb 2018 20:18:49 +0000 (UTC) User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Feb 16 21:18:45 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 1emmSm-0005oa-3w for geh-help-gnu-emacs@m.gmane.org; Fri, 16 Feb 2018 21:18:32 +0100 Original-Received: from localhost ([::1]:57229 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1emmUm-0000sP-56 for geh-help-gnu-emacs@m.gmane.org; Fri, 16 Feb 2018 15:20:36 -0500 X-Received: by 10.200.20.14 with SMTP id k14mr5089564qtj.44.1518812393653; Fri, 16 Feb 2018 12:19:53 -0800 (PST) Original-Path: usenet.stanford.edu!h20no736031qtm.0!news-out.google.com!e34ni245qtc.0!nntp.google.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!spln!extra.newsguy.com!newsp.newsguy.com!news1 Original-Newsgroups: gnu.emacs.help Original-Lines: 37 Original-NNTP-Posting-Host: peb604aef1f98026c5f934e3458cda0653d053e900d994978.newsdawg.com In-Reply-To: <861shkdg8m.fsf@zoho.com> X-Received-Bytes: 2384 X-Received-Body-CRC: 3792492592 Content-Language: en-US Original-Xref: usenet.stanford.edu gnu.emacs.help:221914 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:116028 Archived-At: On 2/16/2018 10:57, Emanuel Berg wrote: > B. T. Raven wrote: > >> Thanks, Joost and Emanuel. See below. > > Here is the best version [1] so far because > I got away with the redundant input data and > you then use the `query-replace' interface > (indeed the very function) which is better than > the crude `yes-or-no-p'. > > (defun replace-list-ask-3 (dict) > (let ((re (string-join (mapcar #'car dict) "\\|"))) > (save-excursion > (goto-char (point-min)) > (while (re-search-forward re nil t) > (let*((match-string (match-string-no-properties 0)) > (default (cdr (assoc match-string dict))) ) > (when default > (query-replace match-string default nil > (match-beginning 0) > (match-end 0) ))))))) > > ;; (replace-list-ask-3 '(("james" . "James") ("blish" . "Blish"))) > > [1] http://user.it.uu.se/~embe8573/emacs-init/replace-list.el > Thanks, Emanuel. In order to conserve muscle memory I used the (read-key) kludge instead of y-or-n-p. My only goal was to get rid of query-replace-regexp-eval so the only thing I used from your code was re-search-forward (C function) instead of search-forward-regexp. It looks like your solution is more general but I don't currently have any application for it other than superscripting numerals (footnotes) here and there. Ed