From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: 2QdxY4RzWzUUiLuE@potatochowder.com Newsgroups: gmane.emacs.help Subject: Re: same data appears twice, interactive then function body Date: Tue, 15 Dec 2020 22:16:13 -0600 Message-ID: References: <87y2hya6i1.fsf@zoho.eu> <87tusm9z4z.fsf@zoho.eu> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="22726"; mail-complaints-to="usenet@ciao.gmane.io" To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Wed Dec 16 05:17:28 2020 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kpOFj-0005nV-Pe for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 16 Dec 2020 05:17:27 +0100 Original-Received: from localhost ([::1]:41952 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kpOFi-0003tn-Rq for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 15 Dec 2020 23:17:26 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:51842) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <2QdxY4RzWzUUiLuE@potatochowder.com>) id 1kpOEp-0003tZ-Kp for help-gnu-emacs@gnu.org; Tue, 15 Dec 2020 23:16:31 -0500 Original-Received: from www458.your-server.de ([136.243.165.62]:48230) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <2QdxY4RzWzUUiLuE@potatochowder.com>) id 1kpOEi-0006Lc-0k for help-gnu-emacs@gnu.org; Tue, 15 Dec 2020 23:16:29 -0500 Original-Received: from sslproxy05.your-server.de ([78.46.172.2]) by www458.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92.3) (envelope-from <2QdxY4RzWzUUiLuE@potatochowder.com>) id 1kpOEa-0000uC-9z for help-gnu-emacs@gnu.org; Wed, 16 Dec 2020 05:16:16 +0100 Original-Received: from [172.58.62.142] (helo=localhost) by sslproxy05.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from <2QdxY4RzWzUUiLuE@potatochowder.com>) id 1kpOEZ-000VYN-ME for help-gnu-emacs@gnu.org; Wed, 16 Dec 2020 05:16:16 +0100 Mail-Followup-To: help-gnu-emacs@gnu.org Content-Disposition: inline In-Reply-To: <87tusm9z4z.fsf@zoho.eu> X-Authenticated-Sender: 2QdxY4RzWzUUiLuE@potatochowder.com X-Virus-Scanned: Clear (ClamAV 0.102.4/26018/Tue Dec 15 15:37:09 2020) Received-SPF: pass client-ip=136.243.165.62; envelope-from=2QdxY4RzWzUUiLuE@potatochowder.com; helo=www458.your-server.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:126394 Archived-At: On 2020-12-16 at 05:02:36 +0100, Emanuel Berg via Users list for the GNU Emacs text editor 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*))) ...))