[Top][All Lists]

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

minibuffer-completion-help: make sorting of completions customizable?

From: T.V. Raman
Subject: minibuffer-completion-help: make sorting of completions customizable?
Date: Tue, 25 Jan 2011 11:46:13 -0800


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

(defun minibuffer-completion-help ()
  "Display a list of possible completions of the current minibuffer contents."
  (message "Making completion list...")
  (lexical-let* ((start (field-beginning))
                 (end (field-end))
                 (string (field-string))
                 (completions (completion-all-completions
                               (- (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
            (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)))
            (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.
            (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.
       (if completions "Sole completion" "No completions")))


reply via email to

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