all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Michael Heerdegen <michael_heerdegen@web.de>
To: help-gnu-emacs@gnu.org
Subject: Re: default value with interactive
Date: Sun, 19 Nov 2017 22:49:34 +0100	[thread overview]
Message-ID: <87d14e6is1.fsf@web.de> (raw)
In-Reply-To: <86a7zi13ze.fsf@zoho.com> (Emanuel Berg's message of "Sun, 19 Nov 2017 20:08:05 +0100")

Emanuel Berg <moasen@zoho.com> writes:

> I'm preparing one of my packs for MELPA so I go
> thru the list of formal style
> suggestions [1] ...
>
> One I don't know how to do is when there is
> a default value. The info node that is
> referenced in the suggestion list, namely
>
>     (info "(elisp) Programming Tips")
>
> says the prompt string should look like this
>
>     Enter the answer (default 42):
>
> However then it says it should be implemented
> like this
>
>     (defun foo (pos)
>       (interactive
>         (list (if SPECIFIED SPECIFIED-POS)))
>       (unless pos (setq pos DEFAULT-POS))
>       ...)
>
> Note that DEFAULT-POS in this example does not
> appear in the `interactive' form! So how does
> it appear in the prompt string at all?
>
> And even if it did, how do you then get around
> it without having to compute/fetch DEFAULT-POS
> two times? One time for the prompt string, and
> then again to set pos (in the abstract example
> above)?
>
> Is there a real-code example somewhere when
> this is done the right way?

It depends on you case.  How does it look like?  I think there is no
general answer.

In most situations, the prompt will rather look like

 "Position (default: point)"

instead of

 "Position (default 15327)".

In other situations, it is not really a problem to let `interactive'
return the default value, because when you repeat the command, you want
to specify the argument anyway, and a reasonable "default" is not
well-defined when repeating.

In some cases, maybe your case is such a case, it is better to read the
arguments in the body of the function and test with
`called-interactively-p' whether that is necessary.


Michael.



  reply	other threads:[~2017-11-19 21:49 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-19 19:08 default value with interactive Emanuel Berg
2017-11-19 21:49 ` Michael Heerdegen [this message]
2017-11-19 22:54   ` Emanuel Berg
2017-11-20  0:05     ` Michael Heerdegen
2017-11-20  1:10       ` Emanuel Berg
2017-11-20  2:18         ` Michael Heerdegen
2017-11-20  3:10           ` Emanuel Berg
2017-11-21  0:31             ` Robert Thorpe
2017-11-21  2:00               ` Emanuel Berg

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=87d14e6is1.fsf@web.de \
    --to=michael_heerdegen@web.de \
    --cc=help-gnu-emacs@gnu.org \
    /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.