From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Christopher Dimech Newsgroups: gmane.emacs.help Subject: Re: Making a function than can only be used interactively Date: Fri, 8 Jul 2022 14:11:51 +0200 Message-ID: References: <87pmiljgah.fsf@gnu.org> <875yk8ehp8.fsf@dataswamp.org> <87bku0ce1f.fsf@dataswamp.org> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="21596"; mail-complaints-to="usenet@ciao.gmane.io" Cc: help-gnu-emacs To: Yuri Khan Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Fri Jul 08 14:12:46 2022 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 1o9mqj-0005SL-V2 for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 08 Jul 2022 14:12:46 +0200 Original-Received: from localhost ([::1]:43326 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o9mqi-00027V-8K for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 08 Jul 2022 08:12:44 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:45266) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o9mq2-000277-Ik for help-gnu-emacs@gnu.org; Fri, 08 Jul 2022 08:12:02 -0400 Original-Received: from mout.gmx.net ([212.227.15.15]:49281) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o9mpx-0004Fs-3j for help-gnu-emacs@gnu.org; Fri, 08 Jul 2022 08:12:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1657282311; bh=nfBzU/2DpSDfQ8DIOHkP/NC3I6hHbadZiOoV87/sVfY=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=H7JOG44eXN30xTZclqTyQ4pmir9rKb5h0QVFwtOLvpZveO8EH6mCPZngz9tERLz8m 1PhF4CSQnJToDzb0+3qczH/AJh98KiNBjhIbhCK9FKb1SuuI50Ppt4B1HxEHgYf+U0 L+CDznVLHCFnFrPYVRLAalSoGSZX2wiopLOrVwcc= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Original-Received: from [92.251.127.164] ([92.251.127.164]) by web-mail.gmx.net (3c-app-mailcom-bs14.server.lan [172.19.170.182]) (via HTTP); Fri, 8 Jul 2022 14:11:51 +0200 Importance: normal Sensitivity: Normal In-Reply-To: X-UI-Message-Type: mail X-Priority: 3 X-Provags-ID: V03:K1:8axdhwjNIakRGimpR9yoJ96TKP5sFfbaKeshb/LXKinW7hu2EFyTEVayhLPwO9KFj3b+o WRq4loT0LuLPCIXV3wY5+smFLSrCP4rblOas6zhA0R43wVZwQBqpyIcV21QrZSbvY7TBVVrKhCUQ yzUZsGrGhnvdXb5cEpfuYjw2lleikj7Mfwj431xWP2T+LTAt49L/J+NpPX0GH0+5m6YZXLcrYQTK j7Sa2264dJtwp4Pkrsdi26+cwt1YiPywR+sBxWtk3jMYPrBs4KFBiDjMljRRYnRq0YfBqTDBJ3bC P8= X-UI-Out-Filterresults: notjunk:1;V03:K0:ldPLczRsZKI=:2J6DvDuYZZTnrDDp28JzOb 8iFGgG1l9OoYHAV3e7UrNkUwdITpnqZ2PgRWM7LzFPqQl8n6X2fNQxol7KxIoa21ujPn4vH54 zHTBbrapzTxYOS430diDmrUTQ0D1uBQuzcyK+C5cgOandOoKeSWEQyAZ3ad3MoZyGVs4C6IBn CRSfrw3+jb3vIi+i6DdCCOHRpYbabja0Nsx3II5/Gr1b1QNMxxhAT1p/jCTtdidDoOVX4s7fa 4sYxP7pXfQSZR48becp8CBufXmhHeOpBjaCSuNMVamVZOhtHXk83BKCCO+YE5882zEv0EOZ8u 5k3XoszvQ6UVNdDohtAcLmN0e2ADqm+0bilwVoEOdYgRS6MfNIKrkFmSxi+2u3baCCWxzjdAL 41Htf+ZMAmCz8o3PWqp2CdHMRXCiiMsLQJBRhbfkqDtBJUcCnCeD85V8Zca/PlIy77urDX1nF BayZMh1BLmDlhqNcUuQftimZ6vcfAHGPIwLCM/FPck1jN+IPtCc89c0srokC/OYeaZ9mhU5zw ZrqOxGOTGedf32/Tk+0u7+bpey8Yz09mJd8+pHQfOkRkoJWk7tn3alzcTCPH6wmAGsqXrvKiI G5NLSDDamy8oXugcFe64jTbt2TdvrFTrbmfMpJhiqo0CIVXE22TO6l+0bi8oXxt9VNsxDhC/8 wV06kKLZMeBnVLBFdLs5ROEn3T0cxcXoo2bnFQsQGyOfbYIpln9KkkDVkPq+3cE3uvmjGJYY3 h0YSw0km79kFuYr8z1n6PcBbGDJg7DpcL/fuet45pgb6/f1FoMMb0yOY/TMWezceef5o12wT Received-SPF: pass client-ip=212.227.15.15; envelope-from=dimech@gmx.com; helo=mout.gmx.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, 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" Xref: news.gmane.io gmane.emacs.help:138377 Archived-At: > Sent: Friday, July 08, 2022 at 6:55 PM > From: "Yuri Khan" > To: "help-gnu-emacs" > Subject: Re: Making a function than can only be used interactively > > On Fri, 8 Jul 2022 at 13:31, Emanuel Berg wrote: >=20 > > > It does not matter for interactive use=2E [=2E=2E=2E] =E2=80=98&opti= onal=E2=80=99 > > > comes into play if you use this function non-interactively, > > > from Lisp > > > > No, it matters=2E One example how it matters is that optional > > arguments defaults to nil=2E >=20 > You=E2=80=99re right, with an interactive specification that evaluates t= o a > list it matters, because the list you return may or may not have as > many arguments as the function takes=2E >=20 > My point was that in the specific case of a three-argument function > and a three-item string-valued interactive specification, &optional > does not matter for interactive use=2E >=20 >=20 > > Check out this file and in particular example 4 which doesn't > > make sense to me? > > > > ;; DWIM example 1, from Lisp ignore region if set > > ;; example 2, use the region if available from Lisp as well > > > > (defun test-dwim (&optional beg end) > > (interactive (when (use-region-p) > > (list (region-beginning) (region-end)) )) >=20 > Here you have two cases=2E If the region is active, you produce a > two-element list, otherwise, a 0-element list=2E The function signature > allows 0=2E=2E2 arguments, so it works in either case=2E >=20 > > ;; example 3, one call to `use-region-p' is enough > > > > (defun test-dwim-3 (re &optional beg end) > > (interactive `(,(read-regexp "re: ") > > ,@(when (use-region-p) > > (list (region-beginning) (region-end)) ))) >=20 > Mostly same, except you build a list of 3 or 1 elements, and the > function accepts 1=2E=2E3 arguments=2E >=20 > > ;; example 4, let's do that with the `interactive' spec > > ;; string=2E but without `use-region-p' it doesn't reset after > > ;; I clear the region, or that's what I thought happened > > ;; anyway :) so this doesn't work as intended, which > > ;; `test-dwim-3' does, supposedly the worse one=2E > > > > (defun test-dwim-4 (re &optional beg end) > > (interactive "sre: \nr") >=20 > Here you use a string interactive spec which always produces 3 > elements=2E In non-interactive use, it will work if called as > (test-dwim-4 "^foo$"), (test-dwim-4 "^foo$" 42), or (test-dwim-4 > "^foo$" 42 69)=2E >=20 > As to your =E2=80=9Cclearing=E2=80=9D the region, Emacs always maintains= the point and > mark positions, and the =E2=80=98r=E2=80=99 interactive spec code ignore= s the region > activation flag and always passes the point and mark=2E (This could be > considered a bug, but I see no good alternative behavior, except maybe > passing two nils if the region is not active=2E) >=20 When using the prefix argument, what makes sense? A mandatory or an optio= nal=20 declaration for the prefix argument?