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.devel Subject: Re: Stepping Back: A Wealth Of Completion systems Re: [ELPA] New package: vertico Date: Sun, 11 Apr 2021 16:31:20 +0300 Message-ID: References: <9c9af088-580f-9fb1-4d79-237a74ce605c@inventati.org> <874kgkxxs0.fsf@posteo.net> <87blamp5hy.fsf@posteo.net> <2ce73f33-8675-211a-9eb7-ea63de1a161e@yandex.ru> <871rbh6pd4.fsf@posteo.net> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="40025"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mutt/2.0.6 (2021-03-06) Cc: emacs-devel@gnu.org, Dmitry Gutov To: Philip Kaludercic Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Apr 11 15:36:47 2021 Return-path: Envelope-to: ged-emacs-devel@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 1lVaGd-000AJn-KE for ged-emacs-devel@m.gmane-mx.org; Sun, 11 Apr 2021 15:36:47 +0200 Original-Received: from localhost ([::1]:51530 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lVaGc-0008Ui-Lp for ged-emacs-devel@m.gmane-mx.org; Sun, 11 Apr 2021 09:36:46 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:36328) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lVaFU-0007Wy-DV for emacs-devel@gnu.org; Sun, 11 Apr 2021 09:35:36 -0400 Original-Received: from stw1.rcdrun.com ([217.170.207.13]:46599) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lVaFS-0000gW-98 for emacs-devel@gnu.org; Sun, 11 Apr 2021 09:35:36 -0400 Original-Received: from localhost ([::ffff:41.202.241.27]) (AUTH: PLAIN securesender, TLS: TLS1.3,256bits,ECDHE_RSA_AES_256_GCM_SHA384) by stw1.rcdrun.com with ESMTPSA id 00000000000280C9.000000006072FB23.000069DB; Sun, 11 Apr 2021 06:35:30 -0700 Mail-Followup-To: Philip Kaludercic , Dmitry Gutov , emacs-devel@gnu.org Content-Disposition: inline In-Reply-To: <871rbh6pd4.fsf@posteo.net> Received-SPF: pass client-ip=217.170.207.13; envelope-from=bugs@gnu.support; helo=stw1.rcdrun.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:267874 Archived-At: * Philip Kaludercic [2021-04-11 14:19]: > > Dmitry Gutov 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/