* minibuffer-completion-help: make sorting of completions customizable?
@ 2011-01-25 19:46 T.V. Raman
2011-01-25 21:13 ` Stefan Monnier
0 siblings, 1 reply; 4+ messages in thread
From: T.V. Raman @ 2011-01-25 19:46 UTC (permalink / raw)
To: emacs-devel
Hi,
As implemented, minibuffer-completion-help *always* sorts the
completion list using string-lessp. This works most of the time,
except when the caller has already
set up the completions to reflect a desired order. Could the
implementation be updated to provide a setting that could be let
bound by the caller?
;;; suggested mod below:
(defvar minibuffer-completion-sort 'string-lessp
"Function used to sort minibuffer completions. Nil means dont
sort.")
(defun minibuffer-completion-help ()
"Display a list of possible completions of the current minibuffer contents."
(interactive)
(message "Making completion list...")
(lexical-let* ((start (field-beginning))
(end (field-end))
(string (field-string))
(completions (completion-all-completions
string
minibuffer-completion-table
minibuffer-completion-predicate
(- (point) (field-beginning)))))
(message nil)
(if (and completions
(or (consp (cdr completions))
(not (equal (car completions) string))))
(let* ((last (last completions))
(base-size (cdr last))
;; If the *Completions* buffer is shown in a new
;; window, mark it as softly-dedicated, so bury-buffer in
;; minibuffer-hide-completions will know whether to
;; delete the window or not.
(display-buffer-mark-dedicated 'soft))
(with-output-to-temp-buffer "*Completions*"
;; Remove the base-size tail because `sort' requires a properly
;; nil-terminated list.
(when last (setcdr last nil))
(when (and minibuffer-completion-sort (fboundp
'minibuffer-completion-sort))
(setq completions (sort completions minibuffer-completion-sort)))
(when completion-annotate-function
(setq completions
(mapcar (lambda (s)
(let ((ann
(funcall completion-annotate-function s)))
(if ann (list s ann) s)))
completions)))
(with-current-buffer standard-output
(set (make-local-variable 'completion-base-position)
(list (+ start base-size)
;; FIXME: We should pay attention to completion
;; boundaries here, but currently
;; completion-all-completions does not give us the
;; necessary information.
end)))
(display-completion-list completions)))
;; If there are no completions, or if the current input is already the
;; only possible completion, then hide (previous&stale) completions.
(minibuffer-hide-completions)
(ding)
(minibuffer-message
(if completions "Sole completion" "No completions")))
nil))
--
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: minibuffer-completion-help: make sorting of completions customizable?
2011-01-25 19:46 minibuffer-completion-help: make sorting of completions customizable? T.V. Raman
@ 2011-01-25 21:13 ` Stefan Monnier
2011-01-25 21:47 ` T.V. Raman
0 siblings, 1 reply; 4+ messages in thread
From: Stefan Monnier @ 2011-01-25 21:13 UTC (permalink / raw)
To: T.V. Raman; +Cc: emacs-devel
> As implemented, minibuffer-completion-help *always* sorts the
> completion list using string-lessp. This works most of the time,
> except when the caller has already
> set up the completions to reflect a desired order. Could the
> implementation be updated to provide a setting that could be let
> bound by the caller?
I've resisted it, because I think the right way is for the
completion-table itself to provide this function (the difference becomes
significant when completing things that are made of various parts, some
of which may be sorted one way and others some other way), but this is
a much more significant change.
It basically means extending the `boundaries' method into a generic
`meta-info' method that will include not just boundaries but also
sort-order, type (e.g. it can tell whether you're completing buffers,
files, or something else, which can then be associated to a config
variable to use different completion-styles for different types of
data), (un)quoting rules (needed for reliable completion of file names
in *shell* buffers), a different separator than \n to use in the
*Completions* buffer, ...
Stefan
^ permalink raw reply [flat|nested] 4+ messages in thread
* minibuffer-completion-help: make sorting of completions customizable?
2011-01-25 21:13 ` Stefan Monnier
@ 2011-01-25 21:47 ` T.V. Raman
2011-05-31 3:07 ` Stefan Monnier
0 siblings, 1 reply; 4+ messages in thread
From: T.V. Raman @ 2011-01-25 21:47 UTC (permalink / raw)
To: Stefan Monnier, emacs-devel
Stefane,
I hear you. I actually spent some time looking through the
completion table code to see where things were getting sorted,
and had to resort to debug-on-entry to figure out that the
sorting happened in minibuffer-completion-help --- so the design
you propose is actually the right one.
But this somewhat simplistic change I proposed lets
me implement google-suggest much better in package g-client which
is part of emacspeak
http://emacspeak.googlecode.com/svn/trunk/lisp/g-client/gweb.el
Basically, Google Suggest gives me the suggestions sorted by
number of hits; getting that list sorted using string-lessp loses basdly.
--
On 1/25/11, Stefan Monnier <monnier@iro.umontreal.ca> wrote:
>> As implemented, minibuffer-completion-help *always* sorts the
>> completion list using string-lessp. This works most of the time,
>> except when the caller has already
>> set up the completions to reflect a desired order. Could the
>> implementation be updated to provide a setting that could be let
>> bound by the caller?
>
> I've resisted it, because I think the right way is for the
> completion-table itself to provide this function (the difference becomes
> significant when completing things that are made of various parts, some
> of which may be sorted one way and others some other way), but this is
> a much more significant change.
>
> It basically means extending the `boundaries' method into a generic
> `meta-info' method that will include not just boundaries but also
> sort-order, type (e.g. it can tell whether you're completing buffers,
> files, or something else, which can then be associated to a config
> variable to use different completion-styles for different types of
> data), (un)quoting rules (needed for reliable completion of file names
> in *shell* buffers), a different separator than \n to use in the
> *Completions* buffer, ...
>
>
> Stefan
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: minibuffer-completion-help: make sorting of completions customizable?
2011-01-25 21:47 ` T.V. Raman
@ 2011-05-31 3:07 ` Stefan Monnier
0 siblings, 0 replies; 4+ messages in thread
From: Stefan Monnier @ 2011-05-31 3:07 UTC (permalink / raw)
To: T.V. Raman; +Cc: emacs-devel
>>> As implemented, minibuffer-completion-help *always* sorts the
>>> completion list using string-lessp. This works most of the time,
>>> except when the caller has already
>>> set up the completions to reflect a desired order. Could the
>>> implementation be updated to provide a setting that could be let
>>> bound by the caller?
The completion-table can now provide its own sorting function, via the
`display-sort-function' metadata.
Stefan
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2011-05-31 3:07 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-01-25 19:46 minibuffer-completion-help: make sorting of completions customizable? T.V. Raman
2011-01-25 21:13 ` Stefan Monnier
2011-01-25 21:47 ` T.V. Raman
2011-05-31 3:07 ` Stefan Monnier
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).