From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Kaushal Modi Newsgroups: gmane.emacs.help Subject: Re: replace deprecated function ? Date: Tue, 13 Feb 2018 21:14:28 +0000 Message-ID: References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1518556436 19352 195.159.176.226 (13 Feb 2018 21:13:56 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 13 Feb 2018 21:13:56 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: "B. T. Raven" Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Feb 13 22:13:52 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 1elhtH-0003N2-La for geh-help-gnu-emacs@m.gmane.org; Tue, 13 Feb 2018 22:13:27 +0100 Original-Received: from localhost ([::1]:51109 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1elhvJ-0004jj-8N for geh-help-gnu-emacs@m.gmane.org; Tue, 13 Feb 2018 16:15:33 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:38335) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1elhuU-0004hH-5E for help-gnu-emacs@gnu.org; Tue, 13 Feb 2018 16:14:43 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1elhuS-00016r-L3 for help-gnu-emacs@gnu.org; Tue, 13 Feb 2018 16:14:42 -0500 Original-Received: from mail-yw0-x231.google.com ([2607:f8b0:4002:c05::231]:46307) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1elhuS-00016i-Fc for help-gnu-emacs@gnu.org; Tue, 13 Feb 2018 16:14:40 -0500 Original-Received: by mail-yw0-x231.google.com with SMTP id c78so13300515ywb.13 for ; Tue, 13 Feb 2018 13:14:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=EYnd15rPLU5p3h1+b5RWnyGvXaa9jf873oTIMGmQcrE=; b=K0pa6J3RNKTITT7e9YJrZcKJuP4QQFTY7TdDz2RrOmNujHcnK4aChNrouTNAm9OoE/ QoZqCpFPqiNdByh0QzhmM3II8AvA5rKpq65NSK3V7C0ksQyNHR1Ud+T895/wlz3XCxM9 59VwzwuWnK5JuafL22FqSKtKpDEeaWpeAJG5JEicF/cleGjb6N8GSIb1zWFV0iT/Dsja +J6/ayhx1GmpQHhaGDvicBS0pzT1YqeDwX1gHCznlBoXQM7grgGhkSXGm/z/jMym3n1G S9iwkdRAHYdfprFjYsTqb6HanWOL/8xNFKEQKHNEkv2nTh2Au85A0yMYkswPiq3rE+BQ tOVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=EYnd15rPLU5p3h1+b5RWnyGvXaa9jf873oTIMGmQcrE=; b=GYjk9OyEL46/oZDosrI2UCvVOAmQDcg5RgLb3ib7kWgO9ksnl1j4ApJ3gBKe16+2Le U2yGtJmuCNquxgGoJe9OvNZxpzOYBzXQ2Sp4Sb50UuZePK85pDRlfB+IkaFa1+uFb7RQ nVx7JNW9i18u/BFUIaNGppi+ORkitljnNzbK6tGtHfrgM5hLNYJdiwIbA5ABld03mFcB JOmaqrWgQJyjYF5ex6mhlcPI05zAVoJBTOb8RhETp0NS4cNP7e21bXVubK7XwcMsEM/X 9YjQ+J8VPZw08QmyoEQdbUfk35ktO5TdDArvqA0CqmQFld94WLIfp/npjxnks/0OhesR xL8g== X-Gm-Message-State: APf1xPDFiSpOZQMe8oHN/dUhAsOtyDCGyX1DPrCY1PoGNQDBb9ua1tU4 wQ5YBNR9UrULrKZrcYBJefsCNR09ZUM7lxvhD2E= X-Google-Smtp-Source: AH8x226GNDfnLZ85d2txZvDjRbmLfeJaN7OcFl18mccSo5P1Xf1hyV3MvTMPGrMG0uFUrH7Pi3H32NaXK8/HM1WKms4= X-Received: by 10.37.185.9 with SMTP id x9mr1892586ybj.494.1518556479628; Tue, 13 Feb 2018 13:14:39 -0800 (PST) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4002:c05::231 X-Content-Filtered-By: Mailman/MimeDel 2.1.21 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:115981 Archived-At: On Tue, Feb 13, 2018 at 1:21 PM B. T. Raven wrote: > But I notice that query-replace-regexp-eval is no longer considered > kosher. How should this be rewritten for Emacs ver. 25? Especially I > would like a function that is more immediately understandable than what > I have now. > Hello, First of all, I know that you asked for a replacement function for emacs 25.x, but I have an alternative that needs emacs 26.x (because `ucs-names' returns a hash instead of an alist in emacs 26). It was fun to come up with this elisp function. Emacs 26 is nearing release, so it might be a good time to try out its pretest version[1]. If you are still interested.. here's the function: (defun num-to-supnum (beg end) "Replace digits with superscript digits in the selected region." (interactive "r") (save-restriction (save-excursion (narrow-to-region beg end) (goto-char (point-min)) (let ((char-hash (ucs-names))) (while (re-search-forward "[0-9]" nil :noerror) (let* ((matched-char-name (get-char-code-property (string-to-char (match-string-no-properties 0)) 'name)) (new-name (replace-regexp-in-string "DIGIT" "SUPERSCRIPT" matched-char-name nil :literal)) (str (char-to-string (gethash new-name char-hash)))) (replace-match str))))))) It looks wordy, but simply does this: - First narrows the buffer to your selected region, so that replacements don't happen outside that. - Replacements happen only for characters 0 through 9 (if present). - Let's say "0" is found.. it then finds the 'name property for that char.. which is "DIGIT ZERO". - Interestingly, the 'name property for =E2=81=B0 (superscript zero) is.. "SUPERSCRIPT ZERO". So I simply derive the name of the to-be-replaced-with string by replacing DIGIT with SUPERSCRIPT. - Then using "SUPERSCRIPT ZERO" as the key in the hash table, I find the character code for superscript zero, and replace "0" with "=E2=81=B0". So, if I have: 123 abc 456 def 78 90 and select just the "56 def 78" portion, and do M-x num-to-supnum, I end up with: 123 abc 4=E2=81=B5=E2=81=B6 def =E2=81=B7=E2=81=B8 90 [1]: http://lists.gnu.org/r/emacs-devel/2018-01/msg00641.html --=20 Kaushal Modi