all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Christopher Dimech <dimech@gmx.com>
To: Yuri Khan <yuri.v.khan@gmail.com>
Cc: help-gnu-emacs <help-gnu-emacs@gnu.org>
Subject: Re: Making a function than can only be used interactively
Date: Fri, 8 Jul 2022 14:11:51 +0200	[thread overview]
Message-ID: <trinity-99182828-1b3c-4d87-b82e-670603bfe7ce-1657282311129@3c-app-mailcom-bs14> (raw)
In-Reply-To: <CAP_d_8V3N8S0U5Zdfu6H+qF2kNk_DF7aO-RU2JZ5wpmqzOT9Rg@mail.gmail.com>




> Sent: Friday, July 08, 2022 at 6:55 PM
> From: "Yuri Khan" <yuri.v.khan@gmail.com>
> To: "help-gnu-emacs" <help-gnu-emacs@gnu.org>
> Subject: Re: Making a function than can only be used interactively
>
> On Fri, 8 Jul 2022 at 13:31, Emanuel Berg <incal@dataswamp.org> wrote:
> 
> > > It does not matter for interactive use. [...] ‘&optional’
> > > comes into play if you use this function non-interactively,
> > > from Lisp
> >
> > No, it matters. One example how it matters is that optional
> > arguments defaults to nil.
> 
> You’re right, with an interactive specification that evaluates to a
> list it matters, because the list you return may or may not have as
> many arguments as the function takes.
> 
> 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.
> 
> 
> > 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)) ))
> 
> Here you have two cases. If the region is active, you produce a
> two-element list, otherwise, a 0-element list. The function signature
> allows 0..2 arguments, so it works in either case.
> 
> > ;; 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)) )))
> 
> Mostly same, except you build a list of 3 or 1 elements, and the
> function accepts 1..3 arguments.
> 
> > ;; example 4, let's do that with the `interactive' spec
> > ;; string. 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.
> >
> > (defun test-dwim-4 (re &optional beg end)
> >   (interactive "sre: \nr")
> 
> Here you use a string interactive spec which always produces 3
> elements. 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).
> 
> As to your “clearing” the region, Emacs always maintains the point and
> mark positions, and the ‘r’ interactive spec code ignores the region
> activation flag and always passes the point and mark. (This could be
> considered a bug, but I see no good alternative behavior, except maybe
> passing two nils if the region is not active.)
> 

When using the prefix argument, what makes sense?  A mandatory or an optional 
declaration for the prefix argument?



  parent reply	other threads:[~2022-07-08 12:11 UTC|newest]

Thread overview: 70+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-03 19:16 Making a function than can only be used interactively carlmarcos--- via Users list for the GNU Emacs text editor
2022-07-03 19:28 ` Bruno Barbier
     [not found] ` <N64WnlX--3-2@missing-mail-id>
2022-07-03 19:36   ` carlmarcos--- via Users list for the GNU Emacs text editor
2022-07-03 19:53     ` Tassilo Horn
2022-07-03 20:17       ` carlmarcos--- via Users list for the GNU Emacs text editor
2022-07-04  4:51         ` Tassilo Horn
2022-07-05 23:13       ` Emanuel Berg
2022-07-03 20:14     ` Stefan Monnier via Users list for the GNU Emacs text editor
2022-07-03 20:27       ` carlmarcos--- via Users list for the GNU Emacs text editor
2022-07-03 20:51       ` carlmarcos--- via Users list for the GNU Emacs text editor
2022-07-03 21:18         ` Stefan Monnier
2022-07-03 21:29       ` carlmarcos--- via Users list for the GNU Emacs text editor
2022-07-03 22:01         ` Stefan Monnier via Users list for the GNU Emacs text editor
2022-07-03 22:45           ` carlmarcos--- via Users list for the GNU Emacs text editor
2022-07-04  1:13             ` Stefan Monnier
     [not found]             ` <jwvczelllyq.fsf-monnier+emacs@gnu.org-N65lQ2m----2>
2022-07-04 10:36               ` carlmarcos--- via Users list for the GNU Emacs text editor
2022-07-04 10:55                 ` Tassilo Horn
2022-07-04 11:43                   ` Christopher Dimech
2022-07-04 13:21                     ` Stefan Monnier
2022-07-04 14:08                       ` Robert Pluim
2022-07-04 21:40                       ` Christopher Dimech
2022-07-05 17:35                         ` Jean Louis
2022-07-04 19:17                   ` carlmarcos--- via Users list for the GNU Emacs text editor
2022-07-04 19:40                     ` Stefan Monnier
2022-07-04 19:50                       ` carlmarcos--- via Users list for the GNU Emacs text editor
2022-07-04 20:45                         ` Stefan Monnier
2022-07-06  0:07                         ` Jean Louis
2022-07-06 20:00                           ` Christopher Dimech
2022-07-06 20:29                             ` Jean Louis
2022-07-07 11:03                               ` Christopher Dimech
2022-07-07 21:06                               ` carlmarcos--- via Users list for the GNU Emacs text editor
2022-07-07 21:28                                 ` Emanuel Berg
2022-07-07 22:14                                   ` carlmarcos--- via Users list for the GNU Emacs text editor
2022-07-08  3:40                                     ` Emanuel Berg
2022-07-08  6:08                                     ` Yuri Khan
2022-07-08  6:30                                       ` Emanuel Berg
2022-07-08  6:55                                         ` Yuri Khan
2022-07-08 11:44                                           ` carlmarcos--- via Users list for the GNU Emacs text editor
2022-07-09  2:05                                             ` Emanuel Berg
2022-07-10  4:33                                             ` Emanuel Berg
2022-07-08 12:06                                           ` carlmarcos--- via Users list for the GNU Emacs text editor
2022-07-08 12:11                                           ` Christopher Dimech [this message]
     [not found]                                           ` <N6Sh4jm--3-2@tutanota.com-N6ShCt5----2>
2022-07-08 12:18                                             ` carlmarcos--- via Users list for the GNU Emacs text editor
2022-07-08 16:14                                           ` Christopher Dimech
2022-07-08 20:29                                             ` [External] : " Drew Adams
2022-07-08 21:09                                               ` carlmarcos--- via Users list for the GNU Emacs text editor
2022-07-08 22:17                                                 ` Drew Adams
2022-07-08 22:34                                                   ` carlmarcos--- via Users list for the GNU Emacs text editor
2022-07-09 14:53                                                     ` Drew Adams
2022-08-09  2:24                                                   ` Emanuel Berg
2022-07-09  2:06                                                 ` Emanuel Berg
2022-07-08 23:19                                               ` Emanuel Berg
2022-07-04 20:53                       ` Drew Adams
2022-07-05 23:30           ` no difference between interactive and "from Lisp" (was: Re: Making a function than can only be used interactively) Emanuel Berg
2022-07-06  2:28             ` no difference between interactive and "from Lisp" Stefan Monnier via Users list for the GNU Emacs text editor
2022-07-06  3:42               ` Emanuel Berg
2022-07-04  1:06     ` Making a function than can only be used interactively Po Lu
  -- strict thread matches above, loose matches on Subject: below --
2022-07-04 19:32 Christopher Dimech
2022-07-04 20:10 Christopher Dimech
2022-07-04 20:35 ` Stefan Monnier
2022-07-04 20:46   ` Christopher Dimech
2022-07-04 21:18     ` Stefan Monnier
2022-07-04 21:59       ` Christopher Dimech
2022-07-05 22:34       ` carlmarcos--- via Users list for the GNU Emacs text editor
2022-07-04 21:07 Christopher Dimech
2022-07-04 21:45 ` Stefan Monnier
2022-07-04 22:05   ` Christopher Dimech
2022-07-04 22:35     ` Stefan Monnier via Users list for the GNU Emacs text editor
2022-07-04 23:33     ` Christopher Dimech
2022-07-04 23:42 Christopher Dimech

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=trinity-99182828-1b3c-4d87-b82e-670603bfe7ce-1657282311129@3c-app-mailcom-bs14 \
    --to=dimech@gmx.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=yuri.v.khan@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.