[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: default value with interactive
From: |
Michael Heerdegen |
Subject: |
Re: default value with interactive |
Date: |
Sun, 19 Nov 2017 22:49:34 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) |
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.
- default value with interactive, Emanuel Berg, 2017/11/19
- Re: default value with interactive,
Michael Heerdegen <=
- Re: default value with interactive, Emanuel Berg, 2017/11/19
- Re: default value with interactive, Michael Heerdegen, 2017/11/19
- Re: default value with interactive, Emanuel Berg, 2017/11/19
- Re: default value with interactive, Michael Heerdegen, 2017/11/19
- Re: default value with interactive, Emanuel Berg, 2017/11/19
- Re: default value with interactive, Robert Thorpe, 2017/11/20
- Re: default value with interactive, Emanuel Berg, 2017/11/20