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 17:36:00 +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="22107"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mutt/+ () (2022-05-21) Cc: help-gnu-emacs@gnu.org To: Michael Heerdegen Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Fri Jun 24 01:18:37 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 1o4W5s-0005XF-T0 for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 24 Jun 2022 01:18:36 +0200 Original-Received: from localhost ([::1]:33714 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o4W5r-0005Mq-P9 for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 23 Jun 2022 19:18:35 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:46116) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4W5H-0005MR-FC for help-gnu-emacs@gnu.org; Thu, 23 Jun 2022 19:17:59 -0400 Original-Received: from stw1.rcdrun.com ([217.170.207.13]:41775) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4W5F-0004ro-IE for help-gnu-emacs@gnu.org; Thu, 23 Jun 2022 19:17:59 -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 0000000000087C52.0000000062B4F482.00001EF3; Thu, 23 Jun 2022 16:17:21 -0700 Mail-Followup-To: Michael Heerdegen , help-gnu-emacs@gnu.org 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:138052 Archived-At: I like my function `rcd-ask' as it saves me generation of history variables automatically. (defun rcd-symbol-if-not-exist (variable &optional value description) "Return symbol for VARIABLE string. It will generate new VARIABLE if it does not exist. VALUE and DESCRIPTION are optional." (let* ((variable (replace-regexp-in-string "[^[:alnum:]]" "-" (downcase variable))) (rcd-symbol (intern variable)) (description (or description (format "Generated variable `%s'" variable)))) (if (boundp rcd-symbol) rcd-symbol (eval (list 'defvar rcd-symbol value description))))) (defun rcd-ask-history-variable (prompt) "Generate history variable based on PROMPT." (let* ((description (format "History for `%s' prompt." prompt))) (rcd-symbol-if-not-exist (concat "rcd-" prompt "-history") nil description))) (defun rcd-ask (&optional prompt initial-contents keymap read default-value) "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)) (input (read-from-minibuffer prompt initial-contents keymap read history default-value t)) (input (string-trim input))) input)) ;; (rcd-ask "First name: ") ⇒ "Emmanuel" ;; In the next step "Emmanuel" is automatically history, and one can get him by M-n M-p ;; (rcd-ask "First name: ") ;; (rcd-ask) ⇒ "Here is some string" And I also like this function that asks few TIMES for something: (defun rcd-ask-times (times &optional prompt initial-contents keymap read default-value) "Return list of queries by multiples TIMES" (let ((list ()) (count 0)) (while (< count times) (push (rcd-ask (concat (format "[#%s] " (1+ count)) prompt) initial-contents keymap read default-value) list) (setq count (1+ count))) (reverse list))) ;; (rcd-ask-times 3 "Query: ") ⇒ ("Emmanuel" "Berg" "Sweden") -- Jean Take action in Free Software Foundation campaigns: https://www.fsf.org/campaigns In support of Richard M. Stallman https://stallmansupport.org/