From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Thierry Volpiatto Newsgroups: gmane.emacs.devel Subject: Re: Make format-spec accept a function as the substitution Date: Thu, 29 Sep 2022 06:57:07 +0000 Message-ID: <87fsgatzvo.fsf@posteo.net> References: <166336105908.23797.12319380359602540227@vcs2.savannah.gnu.org> <20220916204419.B124FC00872@vcs2.savannah.gnu.org> <87edwavjyc.fsf@yahoo.com> <87wna1tr7z.fsf@yahoo.com> <87y1u51ddf.fsf@posteo.net> <87edvwrfg7.fsf@gmail.com> <83wn9oixdr.fsf@gnu.org> <83tu4sivtq.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="18964"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Eli Zaretskii , visuweshm@gmail.com, luangruo@yahoo.com, emacs-devel@gnu.org To: Stefan Kangas Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Sep 29 09:32:38 2022 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 1odo28-0004jF-LE for ged-emacs-devel@m.gmane-mx.org; Thu, 29 Sep 2022 09:32:36 +0200 Original-Received: from localhost ([::1]:57856 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1odo26-0007p4-Tz for ged-emacs-devel@m.gmane-mx.org; Thu, 29 Sep 2022 03:32:35 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:41302) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1odnm1-00054J-Tf for emacs-devel@gnu.org; Thu, 29 Sep 2022 03:15:57 -0400 Original-Received: from mout01.posteo.de ([185.67.36.65]:54335) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1odnls-00049t-Ka for emacs-devel@gnu.org; Thu, 29 Sep 2022 03:15:57 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 299E8240027 for ; Thu, 29 Sep 2022 09:15:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1664435744; bh=9zEGac3WhaYpHnreckE7yA9TjMr9jcX0+QYoa1vthSk=; h=From:To:Cc:Subject:Date:Autocrypt:OpenPGP:From; b=X0kwmqgd5cLFXgpBEcE2SqnXNtqYYIjwDpKUGjFa1d3+evWEsVH43zoxaYNEflnHb MIluhdzSDswrU0jywuEqYancb72IbgKVUc+eOZ8wBoKFi4LwRS911WyeR+upxp1TtU 2b622naDZQkEqupFTSdw1zAvGKlBLe8peyyXZOgBifRZBPXDYTjZz6YdUDZenosu4b Kij7BUE+K5IeuhEx9XgCu96mGZuG5IGE+qaNfj1lpFJG9nQw9i0MRELRqbNN3gSh2S t0PlsXcNkuZp9sBGZXORAeE2MRfEb3fTQtZiOhwfyPQHFCl08A0m5huWM0mPAJKn+A CgenuTmhI6Slw== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4MdPlf29Vqz6tn7; Thu, 29 Sep 2022 09:15:41 +0200 (CEST) In-reply-to: Autocrypt: addr=thievol@posteo.net; prefer-encrypt=mutual; keydata= mQGNBF8ylcIBDADG+hy+zR6L4/vbdDDZuSaMmSrU3A5QZJpeBCvxTr7MpzzruZbhLPW1K3R6N2MA edi8Y+C8o27FVRIjpdbaKMGu9je7JV/TbUQYo3SOwCK1vM4LUn4V6ZLzSYkuiEt4eyMoiDdyvN0p kcK6P9x9DCetcEVszXzQg+yzCVrQ2hXWDXWT4M18EC3wtO7RHPouMqGiwBFhBAYErCqFWFxQHkfb tG/4yGyJ58rglb65O3qijjMWvYwcWZun9/7qm8Z4/4mHopmo2zgU+OrptnLSZfkZGz3Y7Uf452xQ GVq0Fv75NPvQru7y+DYVhuVXXyAmGxt+vf4rIiixMBbhKEPjcxEPAa2LTzex2IsTZR+QVG9uDnqC WcgaOEQ58fzXNvNhtwwF/Rgio2XWAJVdmFWS59/k9W58CIUSNKBMZh2XeGdEmtHvDtCxW3z6FJha 36RzOM3fMNNiAGdFZJA84gcdloJR+sHCDTTPT3784fjr+V8An7sI581NGFzkRQqPvEQCZbUAEQEA AbQSdGhpZXZvbEBwb3N0ZW8ubmV0iQHOBBMBCgA4AhsDBQsJCAcCBhUKCQgLAgQWAgMBAh4BAheA FiEEI9twfRN7r3nig/xwDsVtFB0W75MFAmL3HCoACgkQDsVtFB0W75OVEAv/f6XxmtIFz08fUb8h Bp/zJP6IC4/rhhh+0GMRIRzLN8DK0jV8JCzYdFHiRJOy2lNIOpmrrCmjRRxferc2G42+ePFIsslx hU46VSz1Z83NwIG3mpdYNV5WUTUdgzxExHTNTFCd7NKv0nlHKQa OpenPGP: url=https://posteo.de/keys/thievol@posteo.net.asc; preference=encrypt Received-SPF: pass client-ip=185.67.36.65; envelope-from=thievol@posteo.net; helo=mout01.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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_MED=-2.3, SPF_HELO_NONE=0.001, T_SPF_TEMPERROR=0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 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:296450 Archived-At: --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Hello Stefan, Stefan Kangas writes: > Eli Zaretskii writes: > >> And then I'd suggest something like >> >> If the substitution for a specification character is a function, the >> function will be called only if FORMAT uses that character. > > Thanks. Please find attached a complete patch with documentation. > > [2. text/x-diff; 0001-Make-format-spec-support-functions.patch]... After thinking at it, it would be great to allow using interactive calls in specs without wrapping them inside a function: Using this should ask for line number and file: (format-spec "Go to line %n in file %f %g" '((?n . (read-number "Number: ")) (?g . "now") (?f . (read-file-name "File: "= )))) Whereas using this should not ask for anything: (format-spec "Go to line %g" '((?n . (read-number "Number: ")) (?g . "now") (?f . (read-file-name "File: ")))) For this specs should be looked one by one and evaluated when needed, here a naive version of format-spec that allow this (doesn't handle 0, space, -_> etc..): (defun tv/format-spec-1 (format spec) (cl-loop with fma =3D format with result for (char . val) in spec for target =3D (if (string-match "%\\([[:alpha:]]\\)" fma) (string-to-char (match-string 1 fma)) fma) if (eq target char) return (eval val t) finally return target)) (defun tv/format-spec (format spec) (let (strs fmt-str) (with-temp-buffer (save-excursion (insert format)) (setq strs (cl-loop while (re-search-forward "%\\([[:alpha:]]\\)" nil= t) collect (match-string 0) do (replace-match "s" nil nil nil 1))) (setq fmt-str (buffer-string))) (apply #'format fmt-str (cl-loop for str in strs collect (tv/format-spec-1 str spec))))) Probably the idea handled by this code could be ported to format-spec? =2D-=20 Thierry --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQHHBAEBCgAxFiEEI9twfRN7r3nig/xwDsVtFB0W75MFAmM1RhsTHHRoaWV2b2xA cG9zdGVvLm5ldAAKCRAOxW0UHRbvk9d7DACC5svlwcXZjKTMenqRyjOB4gRCGBX6 uOe6DWU9cM7AftlC2LliWQDaZSpDrt6u4pjyIIC2RrSoaCH+dirKbQUcG+AHsVSH DPtqU4sWoY9ft6rNhHNhvyGuQzQd7m2bbcDea9VaQwMHYf6v7AiKAxPmQjaTAAYn QUkNwVwT+FrP/mGJdmTN/CWN/DUwcYdNijM7i4d40SV57RlWPwWBYgRJY/PVtlYD ls3rS+KylPX4hJpFGSwO58vrQ0tU7DsC0hmCGl1TGzGY/fgar3rEB6riJ/AU27as ldT95IvJs43E7ry9C28BW5WrUJqnrLybKY7ZdyOUsOjvQmWs6qOt7c6bN25vn6mZ UMX62eHP7/8B0Zf0MULlngU2xYGNFToA0TJqZwyhMR9e6XIVtg8GQN49wKBGOvc1 FSOQwZtS34wZbq2KUFQVAIimyl9BhrGGtwlt9AS2S5OFwXnsr6nUAqQjcZW+WDJf evNbO8ClPz+e0+qPBx1tlkp+UGdUtUy3ubw= =UgjR -----END PGP SIGNATURE----- --=-=-=--