unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* 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

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).