[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Stepping Back: A Wealth Of Completion systems Re: [ELPA] New package
From: |
Jean Louis |
Subject: |
Re: Stepping Back: A Wealth Of Completion systems Re: [ELPA] New package: vertico |
Date: |
Sun, 11 Apr 2021 16:31:20 +0300 |
User-agent: |
Mutt/2.0.6 (2021-03-06) |
* Philip Kaludercic <philipk@posteo.net> [2021-04-11 14:19]:
>
> Dmitry Gutov <dgutov@yandex.ru> writes:
>
> > - It uses data structures quite different from what completing-read
> > uses. That's pretty inconvenient, and requires a mental switch. I'd
> > rather the two functions (or some future versions of them) were more
> > similar in shape, yet (obviously) different in behavior.
>
> I think it would be possible to also support alists, hash tables,
> vectors but I'm not sure if it is necessary. Functions might be
> interesting to consider.
Helm has good support for such data structures. Completing-read can
also support hashes. I would like that such functions support variety
of data structures. Because they don't I have to cope with
it. Currently I am removing the built-in helm from all my functions as
I want them to work with any completion system.
One way I use for complex data structures is to have some kind of ID
and visual description, then by using the ID I fetch the data
structure later.
(defun rcd-completing-read-sql-hash (prompt sql pg &optional history
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"
(let* ((hash (rcd-sql-hash-with-key sql pg))
(values (hash-table-values hash))
(length (length values)))
(if (= length 1)
(car values)
(let* ((completion-ignore-case t)
(choice (completing-read prompt hash nil t initial-input history))
(choice (string-trim choice))
(id (gethash choice hash)))
id))))
(defun rcd-sql-hash-with-key (sql pg)
"Returns hash with key TEXT [ID] and value ID from SQL result
in the form ID, TEXT"
(let ((hash (make-hash-table :test 'equal))
(res (rcd-sql sql pg)))
(dolist (i res hash)
(cond ((eq (type-of i) 'vector) (puthash (format "%s [%s]" (elt i 1) (elt
i 0)) (elt i 0) hash))))))
Then I can complete by using database entries which are converted to
hash. And I place unique IDs appended to the string such as:
Selection entry [123]
Some entries may have duplicate names. Showing the ID is necessary to
make the name unique as selection time.
--
Jean
Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns
Sign an open letter in support of Richard M. Stallman
https://rms-support-letter.github.io/
- Re: Stepping Back: A Wealth Of Completion systems Re: [ELPA] New package: vertico, (continued)
- Re: Stepping Back: A Wealth Of Completion systems Re: [ELPA] New package: vertico, Philip Kaludercic, 2021/04/10
- Re: Stepping Back: A Wealth Of Completion systems Re: [ELPA] New package: vertico, Dmitry Gutov, 2021/04/10
- Re: Stepping Back: A Wealth Of Completion systems Re: [ELPA] New package: vertico, Philip Kaludercic, 2021/04/11
- Re: Stepping Back: A Wealth Of Completion systems Re: [ELPA] New package: vertico, Eli Zaretskii, 2021/04/11
- Re: Stepping Back: A Wealth Of Completion systems Re: [ELPA] New package: vertico, Philip Kaludercic, 2021/04/11
- Re: Stepping Back: A Wealth Of Completion systems Re: [ELPA] New package: vertico, Eli Zaretskii, 2021/04/11
- Re: Stepping Back: A Wealth Of Completion systems Re: [ELPA] New package: vertico, Philip Kaludercic, 2021/04/11
- Re: Stepping Back: A Wealth Of Completion systems Re: [ELPA] New package: vertico, Eli Zaretskii, 2021/04/11
- Re: Stepping Back: A Wealth Of Completion systems Re: [ELPA] New package: vertico,
Jean Louis <=
- Re: Stepping Back: A Wealth Of Completion systems Re: [ELPA] New package: vertico, Philip Kaludercic, 2021/04/11
- Re: Stepping Back: A Wealth Of Completion systems Re: [ELPA] New package: vertico, Jean Louis, 2021/04/12
- Re: Stepping Back: A Wealth Of Completion systems Re: [ELPA] New package: vertico, Philip Kaludercic, 2021/04/12
- Re: Stepping Back: A Wealth Of Completion systems Re: [ELPA] New package: vertico, Jean Louis, 2021/04/12
- Re: Stepping Back: A Wealth Of Completion systems Re: [ELPA] New package: vertico, Philip Kaludercic, 2021/04/12
- Re: Stepping Back: A Wealth Of Completion systems Re: [ELPA] New package: vertico, Eric Abrahamsen, 2021/04/12
- RE: [External] : Re: Stepping Back: A Wealth Of Completion systems Re: [ELPA] New package: vertico, Drew Adams, 2021/04/12
- Re: [External] : Re: Stepping Back: A Wealth Of Completion systems Re: [ELPA] New package: vertico, Eric Abrahamsen, 2021/04/12
- RE: [External] : Re: Stepping Back: A Wealth Of Completion systems Re: [ELPA] New package: vertico, Drew Adams, 2021/04/12
- Re: [External] : Re: Stepping Back: A Wealth Of Completion systems Re: [ELPA] New package: vertico, Eric Abrahamsen, 2021/04/12