From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Heime Newsgroups: gmane.emacs.help Subject: Re: Handling defaults values for both interactive and non-interactive use Date: Wed, 11 Sep 2024 00:23:10 +0000 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="20329"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Heime via Users list for the GNU Emacs text editor To: Heime Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Wed Sep 11 02:23:58 2024 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 1soB9J-0005BQ-W4 for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 11 Sep 2024 02:23:58 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1soB8k-0004KW-Tu; Tue, 10 Sep 2024 20:23:22 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1soB8h-0004K3-3J for help-gnu-emacs@gnu.org; Tue, 10 Sep 2024 20:23:19 -0400 Original-Received: from mail-43166.protonmail.ch ([185.70.43.166]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1soB8f-00045X-4M for help-gnu-emacs@gnu.org; Tue, 10 Sep 2024 20:23:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1726014194; x=1726273394; bh=CGd02ySXpKEmFNHyoybvuppxsbE9nkeTeZ7PVxahZjo=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=mniBZsTAJa4XLA2u0gD8EPEXu/Z0xZMYlmZM01/o/kHHaOqfY+Kcfjy/kz18Lnrou eDFgAotrexvBGFN5yPrudd9jEhQ2hAK/y5xihqfZqNJtXKHvo/A43+djc/1ihbxh+I oUjysMfp7+e0tNt9/auJ7By6zXgIgUkZ7wCg3nHbfCUaVx+Y0uS2UchHbizV/aX9PQ N+DEN4xD+C2Xg7GBpe9bEKMWKcfhXOtILNe380tlzPq2Htz1Yhyp3oO8HxuhGa/Sxt J+uoYPf2cK36Cwkj8YGtbX0CnbYrlRmQivJrEUz5Cst7bdU3dpj6tHBT2pdHUO+v7U Ol4iQ/mn1iYlw== In-Reply-To: Feedback-ID: 57735886:user:proton X-Pm-Message-ID: b7a3b44e7a426709d3cb63c7f559fe8327ae71f4 Received-SPF: pass client-ip=185.70.43.166; envelope-from=heimeborgia@protonmail.com; helo=mail-43166.protonmail.ch X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, TO_EQ_FM_DIRECT_MX=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 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-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.help:147950 Archived-At: On Wednesday, September 11th, 2024 at 5:29 AM, Heime wrote: =20 > Sent with Proton Mail secure email. >=20 > On Tuesday, September 10th, 2024 at 3:37 PM, Heime heimeborgia@protonmail= .com wrote: >=20 > > How is one to handle setting defaults for both interactive > > and non-interactive use, properly ? > >=20 > > (defun xiakos-context (search-text &optional n bfrn) > >=20 > > (setq n (or n 8)) > > (setq bfrn (or bfrn "Context")) > >=20 > > (interactive > > (list > > (read-string " Search Text: ") > > (read-number " Number of Context Lines: ") > > (read-string " Buffer Name: "))) > >=20 > > (if (string-match-p "^\\s-*$" bfrn) "Context") >=20 >=20 > Would one handle the default non-interactive and default > interactive separately ? Or does one handle the defaults > after having parsed the non-interactive or the interactive > part ? In summary, would the default values be handled > after the interactive clause ? Or does one set the default > for the interactive part inside the interactive clause ? I decided that the best strategy would be to set the default=20 for the interactive case within the interactive clause. For the non-interactive case, I check if the optional arguments=20 are nil and set default values accordingly after the interactive=20 clause. Here is how I structured it (defun xiakos-context (search-text &optional n bfrn) "Search for SEARCH-TEXT and show context of N lines in buffer BFRN." (interactive (list (read-string "Search Text: ") ;; If the user does not provide a number of context lines, default to 8 (let ((context-lines (read-number "Number of Context Lines (default 8):= "))) (if (zerop context-lines) 8 context-lines)) ;; If the user does not provide a buffer name, default to 'Context' (let ((buffer-name (read-string "Buffer Name (default Context): "))) (if (string=3D buffer-name "") "Context" buffer-name)))) ;; ----------------------------------------------------------------------= - =20 ;; Handle defaults for non-interactive use ;; Default to 8 context lines if n is nil (setq n (or n 8)) ;; Default to "Context" if bfrn is nil or empty (setq bfrn (if (or (not bfrn) (string=3D bfrn "")) "Context" bfrn)) ;; The rest of the function logic (message "Search Text: %s, Context Lines: %d, Buffer: %s" search-text n b= frn)) Should one check strings like this for the interactive case ? (if (string-match-p "^\\s-*$" bfrn) "Context")