all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Documentation of ‘define-alternatives’
@ 2023-08-14 12:34 Shynur Xie
  2023-08-14 18:00 ` Eli Zaretskii
  0 siblings, 1 reply; 4+ messages in thread
From: Shynur Xie @ 2023-08-14 12:34 UTC (permalink / raw)
  To: help-gnu-emacs@gnu.org

Hi friends, I’m reading (elisp) 22.2.5 Select among Command
Alternatives.  It’s a little difficult for me understand it:

> contain an alist with alternative implementations

What does it mean by ‘implementation’?  An expression?

> If customizations is non-nil, it should consist of ...  and values
> to add to the declaration of command-alternatives.

How to include the ‘values’?

I tried:

  - evaluate:

        (define-alternatives your/generic-cmd-1)
        (setq your/generic-cmd-1-alternatives '((1 . (ignore))))
        ;; Or the reverse order.

    then type ‘M-x your/generic-cmd-1 <return> <tab>’.
    Got ‘no match’

  - evaluate:

        (define-alternatives your/generic-cmd-2
          '(1 . (ignore))
          '(2 . (ignore)))

    Got error.

IMHO, section 22.2.5 needs an example or more readable or clear
description for ‘define-alternatives’.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Documentation of ‘define-alternatives’
  2023-08-14 12:34 Shynur Xie
@ 2023-08-14 18:00 ` Eli Zaretskii
  0 siblings, 0 replies; 4+ messages in thread
From: Eli Zaretskii @ 2023-08-14 18:00 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Shynur Xie <one.last.kiss@outlook.com>
> Date: Mon, 14 Aug 2023 12:34:42 +0000
> 
> Hi friends, I’m reading (elisp) 22.2.5 Select among Command
> Alternatives.  It’s a little difficult for me understand it:

Not the best example of our documentation, obviously...

> > If customizations is non-nil, it should consist of ...  and values
> > to add to the declaration of command-alternatives.
> 
> How to include the ‘values’?
> 
> I tried:
> 
>   - evaluate:
> 
>         (define-alternatives your/generic-cmd-1)
>         (setq your/generic-cmd-1-alternatives '((1 . (ignore))))
>         ;; Or the reverse order.
> 
>     then type ‘M-x your/generic-cmd-1 <return> <tab>’.
>     Got ‘no match’
> 
>   - evaluate:
> 
>         (define-alternatives your/generic-cmd-2
>           '(1 . (ignore))
>           '(2 . (ignore)))
> 
>     Got error.

The value of COMMAND-alternatives is an alist whose elements are of
the form (ALTERNATIVE-NAME . ALTERNATIVE-FUNCTION), where car is a
string, the name of the alternative command to be shown to the user;
and ALTERNATIVE-FUNCTION is the function to be called when that
alternative is selected.  Your "values" are not of that form.

> IMHO, section 22.2.5 needs an example or more readable or clear
> description for ‘define-alternatives’.

The latter, of course.



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Documentation of ‘define-alternatives’
@ 2023-08-15 10:16 Shynur Xie
  2023-08-15 12:53 ` Eli Zaretskii
  0 siblings, 1 reply; 4+ messages in thread
From: Shynur Xie @ 2023-08-15 10:16 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: help-gnu-emacs@gnu.org

> The value of COMMAND-alternatives is an alist whose elements are of
> the form (ALTERNATIVE-NAME . ALTERNATIVE-FUNCTION), where car is a
> string, the name of the alternative command to be shown to the user;
> and ALTERNATIVE-FUNCTION is the function to be called when that
> alternative is selected.

Thx, quite clear now!

One more question (info "(elisp) Generic Commands"):

> Macro: define-alternatives command &rest customizations
>
>  ... ...
>
>  If CUSTOMIZATIONS is non-‘nil’, it should consist of ... and values
>  to add to the declaration of ‘COMMAND-alternatives’.

Does it mean that user can initialize ‘COMMAND-alternatives’ by
putting the expected values in the ‘(define-alternative COMMAND ...)’
form?  If so, what is the standard way?  I tried:

    (define-alternatives your/generic-cmd-1
      '("1" . ignore)
      '("2" . ignore))
    (define-alternatives your/generic-cmd-2
      '(("1" . ignore)
        ("2" . ignore)))

Both don’t work (perhaps because the macro expects a keyword here).


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Documentation of ‘define-alternatives’
  2023-08-15 10:16 Documentation of ‘define-alternatives’ Shynur Xie
@ 2023-08-15 12:53 ` Eli Zaretskii
  0 siblings, 0 replies; 4+ messages in thread
From: Eli Zaretskii @ 2023-08-15 12:53 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Shynur Xie <one.last.kiss@outlook.com>
> CC: "help-gnu-emacs@gnu.org" <help-gnu-emacs@gnu.org>
> Date: Tue, 15 Aug 2023 10:16:36 +0000
> msip_labels:
> 
> > Macro: define-alternatives command &rest customizations
> >
> >  ... ...
> >
> >  If CUSTOMIZATIONS is non-‘nil’, it should consist of ... and values
> >  to add to the declaration of ‘COMMAND-alternatives’.
> 
> Does it mean that user can initialize ‘COMMAND-alternatives’ by
> putting the expected values in the ‘(define-alternative COMMAND ...)’
> form?

No.  The text says:

     If CUSTOMIZATIONS is non-‘nil’, it should consist of alternating
     ‘defcustom’ keywords (typically ‘:group’ and ‘:version’) and values
     to add to the declaration of ‘COMMAND-alternatives’.

So CUSTOMIZATIONS is for adding keyword/value pairs we usually use in
a defcustom (since this macro creates a defcustom).



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-08-15 12:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-15 10:16 Documentation of ‘define-alternatives’ Shynur Xie
2023-08-15 12:53 ` Eli Zaretskii
  -- strict thread matches above, loose matches on Subject: below --
2023-08-14 12:34 Shynur Xie
2023-08-14 18:00 ` Eli Zaretskii

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.