emacs-devel
[Top][All Lists]
Advanced

[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

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

--



reply via email to

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