From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: pietru@caramail.com Newsgroups: gmane.emacs.help Subject: Re: Optional Arguments Date: Mon, 7 Dec 2020 13:37:34 +0100 Message-ID: References: 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="28624"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Help Gnu Emacs To: Alexis Roda Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Mon Dec 07 13:48:14 2020 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 1kmFw6-0007Kv-BR for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 07 Dec 2020 13:48:14 +0100 Original-Received: from localhost ([::1]:45224 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kmFw5-0003uI-7W for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 07 Dec 2020 07:48:13 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:54856) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kmFm1-0003th-TL for help-gnu-emacs@gnu.org; Mon, 07 Dec 2020 07:37:49 -0500 Original-Received: from mout.gmx.net ([212.227.17.20]:49115) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kmFlp-00076J-Si for help-gnu-emacs@gnu.org; Mon, 07 Dec 2020 07:37:45 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1607344654; bh=OjgaP0zzrk9ULVD0rt1lm4EhAog4ulraNxrhwWt6ZQc=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=RpJZyyOI6BMiAn+888s3m22oXNwtzlhhugyVOsmYuFa0fUeSz/d5wisDA2LMPvz+R q4AOXFmFy7qT/joaIKuHXBwW4c59G6JKvzfyMTnbjkWqq3nl8mVvdSCaHIFLSSi6eA gWdiFb5Dj8HMGKx82nwtOi99zMM+Zr4Gc64UJC0A= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Original-Received: from [213.165.168.94] ([213.165.168.94]) by web-mail.gmx.net (3c-app-mailcom-bs11.server.lan [172.19.170.179]) (via HTTP); Mon, 7 Dec 2020 13:37:34 +0100 Importance: normal Sensitivity: Normal In-Reply-To: X-UI-Message-Type: mail X-Priority: 3 X-Provags-ID: V03:K1:r4X9YBK7cpZabe0nnuCndriBpOWEjyTj3GsN9YR5xwkX5vLMggO2ymXlwHmofRxPZRcBS cSmDKo/fsPfRa8Pb6cINpYINW+PksGxCkjmAJkYnFrinWY5Y8Myo7S9whYT7x/mpTnhveGr1vxds bfeIqow7kIShAqaYe7p8lcoT8vK+nk1M6l+m21NZABuaMN1/D9jcodFXVDCso6F7faxBdMsk+QWO QbpAxxkLHqMz6qgYMrAUX2XvNQL7dEpnTDoPMN8XphYJvOQAKkKU/w+JnzhP1FG42tzscYKsZXWZ IQ= X-UI-Out-Filterresults: notjunk:1;V03:K0:nudrX/BJFrk=:xafkhAiRuA3gI5xyueDf4+ Q45jdsCWYaAOuoJwTBRdrTdcmBmol1xEldtZnRkgdPMVlcpxxXA76VJuCWrN3ZNar995L26hm U2ZBWzuwGmggrZD4OWinNVTBxdAtKzf2r8jkNN8J1OK3qpEBYwYYIP5FQOA4WKRErq5BIJuPn P3WlZRBbmbLdgj94o5pfoTFKMd/wioVixZKYAzcawVG6NIULqVSc/fdsasTtVorgxiKJsJ5Bp djo+Ztu/5ua7n3bcG2ygcGsRW/JkiZInH7tutpgGfVUKyPemKI5RLxg1W/xjaSypfvqrx8q6Y OovqKzdKaVe6kSGRHaDhoPhPNqEosEhOqSuJKYgwWHLePN79gMvW7ErN3/BVr4LD5Au8Q6IVs 5PWu/ie+A0nJpd99uRK9D+2JS7Z9tr18+/Qz+SIG5aOwrh6rDmuEIHkPk2pT4PslPjS6D2uC0 dudR8zkCsu5rwb+cK9lGo+ZbfjaOjJgSRiZNNfJMim/H0dlifvYolMElxEslwsX07vlcm5HIc XUfOTZmUkXDhTj+b92k/mK7AymXZGS4TVjEPwGTne2n0zebeaiRIH2nh1Ae6wZmC+Y63MBw15 Mg1oeAMMU9804= Received-SPF: pass client-ip=212.227.17.20; envelope-from=pietru@caramail.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 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 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:126148 Archived-At: > Sent: Monday, December 07, 2020 at 9:16 AM > From: "Alexis Roda" > To: pietru@caramail=2Ecom > Cc: "Help Gnu Emacs" > Subject: Re: Optional Arguments > > Hi, >=20 > Not sure what your question is=2E It is bit confusing=2E I want to use typh-word-markers to compute ma and mb so I can use the two values in another function=2E Had put (interactive) in my effort to test it, but created problems as you say=2E The function would be called when cursor is on a word, so that I get the word "beg" and "end"=2E (defun typh-word-markers (ma mb) (skip-chars-backward "[:alpha:]") (setq ma (point)) (skip-chars-forward "[:alpha:]") (setq mb (point)) (message "[ma,mb]: %s,%s" ma mb) ) =20 > Regarding the error, I'm assuming that you execute the function with 'M-= x > typh-word-markers'=2E That won't work interactively because the function > expects two arguments and 'interactive' don't tell emacs how to get them= =2E > It works if you execute it with 'M-: (typh-word-markers nil nil)', from > IELM or from the scratch buffer=2E >=20 > That said, in your code the arguments are not required, they are used on= ly > as local variables, not to provide information to the function, so the > function can be written with a 'let' [1][2] form defining local variable= s: >=20 > (defun typh-word-markers () > (interactive) > (let ((ma) > (mb)) > (skip-chars-backward "[:alpha:]") > (setq ma (point)) > (skip-chars-forward "[:alpha:]") > (setq mb (point)) > (message "[ma,mb]: %s,%s" ma mb)) ) >=20 > In the first function '&optional' is not strictly required=2E Since you > specify in 'interactive' the 'n' option [3] (A number, read with the > minibuffer=2E If the input is not a number, the user has to try again=2E= =E2=80=98n=E2=80=99 > never uses the prefix argument=2E Prompt=2E) the user will be prompted f= or a > numeric value and the function will always get an argument=2E That's the > opposite case to typh-word-markers=2E >=20 > Probably you want the 'p' code [3]: The numeric prefix argument=2E (Note= that > this =E2=80=98p=E2=80=99 is lower case=2E) No I/O=2E >=20 > (defun typh-skip-chars (n) > (interactive "p") > (if (=3D n 1) > (skip-chars-forward "[:alpha:]") > (skip-chars-backward "[:alpha:]")) ) >=20 > That way executing 'M-x typh-skip-chars' will skip chars forward while '= C-u > M-x typh-skip-chars' will skip chars backward=2E No interactive input wi= ll be > requested to the user, the input to the function is provided with the > prefix argument [4]=2E That's more idiomatic=2E >=20 >=20 > Hope this helps >=20 > [1] > https://www=2Egnu=2Eorg/software/emacs/manual/html_node/eintr/Parts-of-l= et-Expression=2Ehtml > [2] > https://www=2Egnu=2Eorg/software/emacs/manual/html_node/eintr/Sample-let= -Expression=2Ehtml#Sample-let-Expression > [3] > https://www=2Egnu=2Eorg/software/emacs/manual/html_node/elisp/Interactiv= e-Codes=2Ehtml > [4] https://www=2Egnu=2Eorg/software/emacs/manual/html_node/emacs/Argume= nts=2Ehtml >=20 >=20 > Missatge de l'adre=C3=A7a del dia dl=2E, 7 de de= s=2E 2020 a > les 4:17: >=20 > > Would like to have two functions > > > > 1=2E skip-chars - skip to beg of word (if no argument) or end of word = (if > > argument is 1) > > > > 2=2E word-markers - get beg and end of a word position of word > > > > Have written the following=2E For the first one, I have not used optio= nal > > arguments before=2E > > And have read documentation about functions=2E > > > > About the second, there errors when I try to execute=2E > > > > (defun typh-skip-chars (&optional n) > > (interactive "n Skip direction: ") > > (if (=3D n 1) > > (skip-chars-forward "[:alpha:]") > > (skip-chars-backward "[:alpha:]")) ) > > > > (defun typh-word-markers (ma mb) > > (interactive) > > (skip-chars-backward "[:alpha:]") > > (setq ma (point)) > > (skip-chars-forward "[:alpha:]") > > (setq mb (point)) > > (message "[ma,mb]: %s,%s" ma mb) ) > > > > > > > > >