From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jean Louis Newsgroups: gmane.emacs.help Subject: Re: completing-read depricated initial-input Date: Thu, 23 Jun 2022 18:24:21 +0300 Message-ID: References: <86r13hubaw.fsf_-_@gnu.org> <86letphfke.fsf_-_@gnu.org> <86mte3lsj2.fsf_-_@gnu.org> <871qvfoce1.fsf@web.de> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="27601"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mutt/+ () (2022-05-21) Cc: Arash Esbati , Drew Adams , Christopher Dimech , "eliz@gnu.org" , "monnier@iro.umontreal.ca" , Help Gnu Emacs , "carlmarcos@tutanota.com" To: Michael Heerdegen Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Fri Jun 24 01:19:47 2022 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 1o4W71-000701-9f for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 24 Jun 2022 01:19:47 +0200 Original-Received: from localhost ([::1]:35448 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o4W6z-0006bF-WA for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 23 Jun 2022 19:19:46 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:46186) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4W5O-0005TD-4F for help-gnu-emacs@gnu.org; Thu, 23 Jun 2022 19:18:06 -0400 Original-Received: from stw1.rcdrun.com ([217.170.207.13]:53975) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4W5L-0004sF-7R; Thu, 23 Jun 2022 19:18:05 -0400 Original-Received: from localhost ([::ffff:154.225.108.87]) (AUTH: PLAIN admin, TLS: TLS1.3,256bits,ECDHE_RSA_AES_256_GCM_SHA384) by stw1.rcdrun.com with ESMTPSA id 0000000000087C62.0000000062B4F489.00001F19; Thu, 23 Jun 2022 16:17:29 -0700 Mail-Followup-To: Michael Heerdegen , Arash Esbati , Drew Adams , Christopher Dimech , "eliz@gnu.org" , "monnier@iro.umontreal.ca" , Help Gnu Emacs , "carlmarcos@tutanota.com" Content-Disposition: inline In-Reply-To: <871qvfoce1.fsf@web.de> Received-SPF: pass client-ip=217.170.207.13; envelope-from=bugs@gnu.support; helo=stw1.rcdrun.com X-Spam_score_int: -3 X-Spam_score: -0.4 X-Spam_bar: / X-Spam_report: (-0.4 / 5.0 requ) BAYES_00=-1.9, DATE_IN_PAST_06_12=1.543, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_FILL_THIS_FORM_SHORT=0.01, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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" Xref: news.gmane.io gmane.emacs.help:138054 Archived-At: * Michael Heerdegen [2022-06-23 14:22]: > Arash Esbati writes: > > > Note the terms "mostly-deprecated", "discourage", "recommend", > > "superseded". So maybe the docstring of `completing-read' should be > > adjusted to the statements above in order to avoid confusion? > > The purpose of `completing-read' is a bit different from `read-string' > and `read-from-minibuffer'. Providing INITIAL-INPUT is useful for the > latter, but much less for `completing-read' in my opinion. If at all > (anybody who has a believable real-life example?). Thanks, it gave me idea so I have improved my function to automatically insert auto-initial-input based on last value of automatically generated history variable. It spares my time in some entries, and I do many of them per day.. (defun rcd-completing-read-sql-hash (prompt sql pg &optional history initial-input not-require-match auto-initial-input) "Complete selection by using SQL. First column shall be unique id, followed by text representation. Example SQL query: SELECT people_id, people_firstname || ' ' || people_lastname FROM people PG is database handle. HISTORY is supported with INITIAL-INPUT Argument PROMPT will be displayed to user." (let* ((hash (rcd-sql-hash-with-key sql pg)) (completion-ignore-case t) (require-match (if not-require-match nil t)) (history (or history (rcd-ask-history-variable prompt))) (initial-input (or initial-input (when auto-initial-input (car (symbol-value history))))) (choice (completing-read prompt hash nil require-match initial-input history)) (choice (string-trim choice)) (id (gethash choice hash))) (if id id (if not-require-match choice)))) Example: That would show user's name and email address and ID number, and I would get ID number as result. (rcd-completing-read-sql-hash "People: " "SELECT people_id, people_firstname || ' ' || people_lastname FROM people LIMIT 10" cf-db nil nil nil t) ⇒ 32367 -- Jean Take action in Free Software Foundation campaigns: https://www.fsf.org/campaigns In support of Richard M. Stallman https://stallmansupport.org/