help-gnu-emacs
[Top][All Lists]
Advanced

[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:24:21 +0300
User-agent: Mutt/+ () (2022-05-21)

* Michael Heerdegen <michael_heerdegen@web.de> [2022-06-23 14:22]:
> Arash Esbati <arash@gnu.org> 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/



reply via email to

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