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:19:42 +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="24704"; 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:11 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 1o4W6R-0006Hn-5I for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 24 Jun 2022 01:19:11 +0200 Original-Received: from localhost ([::1]:34584 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o4W6P-0005zr-PF for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 23 Jun 2022 19:19:09 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:46132) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4W5J-0005Na-T1 for help-gnu-emacs@gnu.org; Thu, 23 Jun 2022 19:18:01 -0400 Original-Received: from stw1.rcdrun.com ([217.170.207.13]:58753) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4W5I-0004s2-6Q; Thu, 23 Jun 2022 19:18:01 -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 0000000000087C5D.0000000062B4F485.00001F02; Thu, 23 Jun 2022 16:17:25 -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_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:138053 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?). I am used to automatically generate history variables based on prompt. And I use often read-from-minibuffer wrapped in my function, this below is using automatically inserted initial contents based on history variable. I find that useful. (defun rcd-ask (&optional prompt initial-contents keymap read default-value auto-initial-contents) "Modified function `read-from-minibuffer'. This is shorter, simpler function that generates the prompt automatically, generates history variable automatically and inherits the input method. The input will be returned trimmed." (let* ((prompt (or prompt "Input data: ")) (history (rcd-ask-history-variable prompt)) (initial-contents (or initial-contents (when auto-initial-contents (car (symbol-value history))))) (input (read-from-minibuffer prompt initial-contents keymap read history default-value t)) (input (string-trim input))) input)) ;; (rcd-ask "First name: " "Emmanuel") ⇒ "Emmanuel" ;; (rcd-ask "First name: ") ⇒ "Berg" ;; rcd-first-name---history ⇒ ("Berg" "Emmanuel" "Jean" "Louis") Then we get automatic initial contents based on the prompt: (rcd-ask "First name: " nil nil nil nil t) as then minibuffer says "First name: Berg" and waits for input. Having initial contents based on last value of the history is useful on my side. But then again I have another wrapper that uses `completing-read' which I also want to adapt to use auto-initial-input based on last value of history variable. For example I am often entering country names, and often people from same country, having last history variable as auto-initial-input is useful (defun rcd-completing-read-sql-hash (prompt sql pg &optional history initial-input not-require-match) "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))) (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)))) -- Jean Take action in Free Software Foundation campaigns: https://www.fsf.org/campaigns In support of Richard M. Stallman https://stallmansupport.org/