Subject: Re: bug#44550: 28.0.50; proposal for tabulated-list-mode to provide narrowing incremental search

From: Jean Louis <[email-masked]>
Date: Wed, 11 Nov 2020 20:22:04 +0300

* Eli Zaretskii <[email-masked]> [2020-11-11 18:35]:
> > Date: Tue, 10 Nov 2020 22:57:35 +0300
> > From: Jean Louis <[email-masked]>
> > Cc: [email-masked]
> > 
> > - imagine list of items in tabulated-list-mode
> > 
> > - user press / to open up the feature (real time incremental narrowing)
> > 
> > - when user starts typing the list of items in tabulated-list-mode are
> >   narrowing themselves visually and in real time. It is very similar
> >   to completion networks.
> 
> What does "narrowing" mean in this context?  What should happen in
> real time?  Do you mean "filtering", i.e. that some items should
> disappear from view?

Yes, thank you. I mean filtering. By pressing specific key for
filtering let us say "/" or other key, user starts typing and anything
above X length of characters (normally 3, should be customizable)
starts removing other lines that do not contain the written
query. User could enter few words and words could go match filter also
in reverse order (could be customizable). When user finishes filtering
process one could press enter to get the display in order to browse
down or up in the list. Even filtered list as result can be very long.

> If so, what criteria should be used to filter out items, and how is
> that derived from what the user types?

Criteria is that query should match the line. I prefer that several
words or parts of words can be inserted and that they can be matched
in reverse order.

When choosing a chocolate, designation in the database can be:

"Chocolate (white)" or "White Chocolate" and program does not know how
user will want to search for white chocolate. That is why reverse
order helps. Multiple words should be possible

As I am using tabulated list mode I see that lines can be concatenated
so that it is a list of strings. Query that user types would make
temporary tabulated-list-entries-filtered that replaces the original
tabulated-list-entries. User could go back to unfiltered view.

> I'm still confused regarding the feature you are looking for, and
> how it relates to completion.

I am using already tabulated mode to choose an entry. I guess it was
made for that as there is function (tabulated-list-get-id) and by that
id the choice is completed.

tabulated-list-mode can be used as additional completing-read function
and is very suitable for that. I know it is no adapted to that. I just
see it is very simple as it works with the list tabulated-list-entries
and when redisplayed it shows candidates, one can obtain ID and
candidate entry.

This below should serve to concept understanding that such function
"tabulated-completing-read" is possible.

(define-derived-mode choice-mode tabulated-list-mode "Choice" "Choice Mode"
  (setq tabulated-list-format [("Prompt here" 80 t)])
  (setq tabulated-list-padding 1)
  (tabulated-list-init-header))

(define-key choice-mode-map (kbd "<RET>") 'choice-get-id)

(defun tabulated-completing-read (prompt collection)
  (erase-buffer)
  (choice-mode)
  (setq tabulated-list-entries collection)
  (read-only-mode 1)
  (tabulated-list-print t))

(setq collection '((1 ["~/tmp"]) (2 ["~/Maildir"])))

(defun choice-get-id ()
  "Returns the choice"
  (interactive)
  (let ((id (tabulated-list-get-id)))
    (when id
      (set-register 100 (aref (car (alist-get id collection)) 0)) ;; character d
      (kill-this-buffer)
      (get-register 100))))

;; I do not know how to return, so in my program I am using register,
;; but I do not know how to return register from similar function as
;; above

;; When you evaluate this below buffer will change.

;; (tabulated-completing-read "Files" collection)

> > In general I would like to have direct real time incremental narrowing
> > of collection instead of blowing up minibuffer, making modeline jump
> > up and down with ivy-mode and splitting windows.
> > 
> > Interface would be clean just as tabulated-list-mode is and minibuffer
> > could be used for narrowing.
> 
> And now I'm completely confused: I thought you were talking about
> tabulated-list-mode, but now you've made some gigantic leap to much
> more general issues.

For my personal use case I almost finished such function but I do not
know how to return the ID. When that is solved then it becomes
possible for tabulated list mode to be used as replacement for usual
completing-read.