emacs-devel
[Top][All Lists]
Advanced

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

Re: [PATCH] `completing-read` - allow history=t, sorting improvements


From: Daniel Mendler
Subject: Re: [PATCH] `completing-read` - allow history=t, sorting improvements
Date: Tue, 20 Apr 2021 01:47:34 +0200

On 4/20/21 12:55 AM, Stefan Monnier wrote:
+(defun minibuffer--sort-preprocess-history (start string)
+  "Preprocess history, remove completion prefixes.
+STRING is the minibuffer content.
+START is the start position of the completion."
+  (let* ((def (car-safe minibuffer-default))
+         (hist (symbol-value minibuffer-history-variable))
+         (hist (if def (cons def hist) hist))
+         (bounds (completion-boundaries
+                  (substring string 0 (- (point) start))
+                  minibuffer-completion-table
+                  minibuffer-completion-predicate
+                  ""))

Actually, the caller has the info we need already in the (cdr last),
which it throws away in:

         (when last
           (setcdr last nil)
This info also has the advantage of working with partial-completion
because it comes from the completion-style output rather than from the
completion-table.

Yes, right. The base size, even better. I will use that instead!


[ If (cdr last) is nil it's equivalent to 0.  ]

I stumbled over this just today, when I had assumed that the cdr always has an integer. But the docs say it "may" have that.


+         (pre (substring string 0 (car bounds)))
+         (pre-len (length pre)))
+    ;; Preprocess history if completion boundaries are used
+    (cond
+     ;; Special handling of file name candidates.
+     ;; Drop prefix and everything after the first "/".
+     (minibuffer-completing-file-name

I hope that using (cdr last) will make it unnecessary to use such a hack.
If not, then please try and use the `category` from `md` rather than
`minibuffer-completing-file-name` which I consider as obsolete (tho it's
not marked as such yet).

I will check. I still believe a tiny hack is needed because of the final slash. And the advantage of dropping everything behind the slash is that accesses to files influence the position of their parent directory (if one considers that an advantage).

Thanks for letting me know about the `minibuffer-completing-file-name` variable. There is also `minibuffer-completing-symbol`. Shall we mark them as obsolete? I wondered why they exist but I took them thankfully as an easy way to access the category. I will revert this then in my packages.

Daniel



reply via email to

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