[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: completing-read depricated initial-input

From: Jean Louis
Subject: Re: completing-read depricated initial-input
Date: Thu, 23 Jun 2022 18:19:42 +0300
User-agent: Mutt/+ () (2022-05-21)

* 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 
  "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)))

;; (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 
         (choice (string-trim choice))
         (id (gethash choice hash)))
    (if id id
      (if not-require-match 


Take action in Free Software Foundation campaigns:

In support of Richard M. Stallman

reply via email to

[Prev in Thread] Current Thread [Next in Thread]