help-gnu-emacs
[Top][All Lists]
Advanced

[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*)))
    ...))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]