[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: same data appears twice, interactive then function body
From: |
2QdxY4RzWzUUiLuE |
Subject: |
Re: same data appears twice, interactive then function body |
Date: |
Tue, 15 Dec 2020 22:16:13 -0600 |
On 2020-12-16 at 05:02:36 +0100,
Emanuel Berg via Users list for the GNU Emacs text editor
<help-gnu-emacs@gnu.org> wrote:
> Stefan Monnier wrote:
>
> > Here's my take on it:
> >
> > (defun insert-string-centered (string &optional width)
> > (interactive
> > (list (read-from-minibuffer "string: ")
> > (string-to-number (read-from-minibuffer "width [80]: "))) )
> > (let*((max (if (< 0 width) width (+ 42 42 -4)))
> > [...]
> >
> > Now the question is how to avoid having 42 appear twice,
> > I guess
>
> Ha :)
>
> No but do tell!
>
> Maybe it can't be done, even?
That depends on the unspecified requirements and constraints).
What about a defvar outside the function (completely untested)?
(defvar *default-width* 80
"default width")
(defun insert-string-centered (string &optional width)
(interactive
(list (read-from-minibuffer "string: ")
(string-to-number
(read-from-minibuffer
(format "width [%d]: " *max-width*)))))
(let* ((max (if (< 0 width) width *default-width*)))
...))
- same data appears twice, interactive then function body, Emanuel Berg, 2020/12/15
- Re: same data appears twice, interactive then function body, Stefan Monnier, 2020/12/15
- Re: same data appears twice, interactive then function body, Jean Louis, 2020/12/15
- Re: same data appears twice, interactive then function body, Emanuel Berg, 2020/12/15
- Re: same data appears twice, interactive then function body, Yuri Khan, 2020/12/15
- Re: same data appears twice, interactive then function body, Emanuel Berg, 2020/12/16
- Re: same data appears twice, interactive then function body, Emanuel Berg, 2020/12/18
- RE: same data appears twice, interactive then function body, Drew Adams, 2020/12/18
- Re: same data appears twice, interactive then function body, Jean Louis, 2020/12/18
- Re: same data appears twice, interactive then function body, Jean Louis, 2020/12/18