From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "T.V. Raman" Newsgroups: gmane.emacs.devel Subject: minibuffer-completion-help: make sorting of completions customizable? Date: Tue, 25 Jan 2011 11:46:13 -0800 Message-ID: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: dough.gmane.org 1295984910 558 80.91.229.12 (25 Jan 2011 19:48:30 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 25 Jan 2011 19:48:30 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Jan 25 20:48:26 2011 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PhosI-000264-MM for ged-emacs-devel@m.gmane.org; Tue, 25 Jan 2011 20:48:23 +0100 Original-Received: from localhost ([127.0.0.1]:47006 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Phos7-0004fb-Im for ged-emacs-devel@m.gmane.org; Tue, 25 Jan 2011 14:48:11 -0500 Original-Received: from [140.186.70.92] (port=55109 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PhoqJ-0003TZ-IF for emacs-devel@gnu.org; Tue, 25 Jan 2011 14:46:21 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PhoqE-0003vQ-WD for emacs-devel@gnu.org; Tue, 25 Jan 2011 14:46:16 -0500 Original-Received: from mail-ew0-f41.google.com ([209.85.215.41]:63894) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PhoqE-0003uo-RM for emacs-devel@gnu.org; Tue, 25 Jan 2011 14:46:14 -0500 Original-Received: by ewy27 with SMTP id 27so2755578ewy.0 for ; Tue, 25 Jan 2011 11:46:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:date:message-id:subject:from:to :content-type; bh=yGKcd3LKhnR2xjGAexS9XKnR4hHQydnyQILSb7uOyzc=; b=Se1E0wgyKxGRR5DmuwETJhlUxULvUdcQk1pAprTy0uisFw0ZB17vqa6Ll/eyIty0Z1 D51fW6tGlEHtE7zH83DaHNtGZ7BWdbJtMENIKJiykHLHaMaaCqulFlHYGTw9+5OuLEFL WAu5D0W9ufz93t5ZYuo2JqZd7SKOz490ygEHQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=RSuG04BrGYEKTM2G/nxuScLPsYzd6/sJQDnsS+YU1iw0IW2QGta/lCAcRjmSRRf9KG EyHKMeor7iKmDdKn7U48uylOLcrY10YgTbPaD+dPSyG5naRypYM3is0jbX+EqqhzdTMK zHzbQ0niAM7Qx/AHyIUuig8l0sYETQ4uWR3/U= Original-Received: by 10.213.15.135 with SMTP id k7mr54023eba.26.1295984773121; Tue, 25 Jan 2011 11:46:13 -0800 (PST) Original-Received: by 10.213.14.20 with HTTP; Tue, 25 Jan 2011 11:46:13 -0800 (PST) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:134953 Archived-At: 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)) --