changeset 106122:4ff55285a1c0

(completions-format): New defcustom. (completion--insert-strings): Implement vertical format.
author Juri Linkov <juri@jurta.org>
date Thu, 19 Nov 2009 17:38:37 +0000
parents f58be5f9ad87
children fdcf81336623
files lisp/minibuffer.el
diffstat 1 files changed, 58 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/minibuffer.el	Thu Nov 19 17:37:22 2009 +0000
+++ b/lisp/minibuffer.el	Thu Nov 19 17:38:37 2009 +0000
@@ -778,6 +778,16 @@
 (defface completions-annotations '((t :inherit italic))
   "Face to use for annotations in the *Completions* buffer.")
 
+(defcustom completions-format nil
+  "Define the appearance and sorting of completions.
+If the value is `vertical', display completions sorted vertically
+in columns in the *Completions* buffer.
+If the value is `horizontal' or nil, display completions sorted
+horizontally in alphabetical order, rather than down the screen."
+  :type '(choice (const nil) (const horizontal) (const vertical))
+  :group 'minibuffer
+  :version "23.2")
+
 (defun completion--insert-strings (strings)
   "Insert a list of STRINGS into the current buffer.
 Uses columns to keep the listing readable but compact.
@@ -800,6 +810,8 @@
 		     (max 1 (/ (length strings) 2))))
 	   (colwidth (/ wwidth columns))
            (column 0)
+	   (rows (/ (length strings) columns))
+	   (row 0)
 	   (laststring nil))
       ;; The insertion should be "sensible" no matter what choices were made
       ;; for the parameters above.
@@ -810,20 +822,38 @@
                             (+ (string-width (car str))
                                (string-width (cadr str)))
                           (string-width str))))
-            (unless (bolp)
-              (if (< wwidth (+ (max colwidth length) column))
-                  ;; No space for `str' at point, move to next line.
-                  (progn (insert "\n") (setq column 0))
-                (insert " \t")
-                ;; Leave the space unpropertized so that in the case we're
-                ;; already past the goal column, there is still
-                ;; a space displayed.
-                (set-text-properties (- (point) 1) (point)
-                                     ;; We can't just set tab-width, because
-                                     ;; completion-setup-function will kill all
-                                     ;; local variables :-(
-                                     `(display (space :align-to ,column)))
-                nil))
+            (cond
+	     ((eq completions-format 'vertical)
+	      ;; Vertical format
+	      (when (> row rows)
+		(forward-line (- -1 rows))
+		(setq row 0 column (+ column colwidth)))
+	      (when (> column 0)
+		(end-of-line)
+		(while (> (current-column) column)
+		  (if (eobp)
+		      (insert "\n")
+		    (forward-line 1)
+		    (end-of-line)))
+		(insert " \t")
+		(set-text-properties (- (point) 1) (point)
+				     `(display (space :align-to ,column)))))
+	     (t
+	      ;; Horizontal format
+	      (unless (bolp)
+		(if (< wwidth (+ (max colwidth length) column))
+		    ;; No space for `str' at point, move to next line.
+		    (progn (insert "\n") (setq column 0))
+		  (insert " \t")
+		  ;; Leave the space unpropertized so that in the case we're
+		  ;; already past the goal column, there is still
+		  ;; a space displayed.
+		  (set-text-properties (- (point) 1) (point)
+				       ;; We can't just set tab-width, because
+				       ;; completion-setup-function will kill all
+				       ;; local variables :-(
+				       `(display (space :align-to ,column)))
+		  nil))))
             (if (not (consp str))
                 (put-text-property (point) (progn (insert str) (point))
                                    'mouse-face 'highlight)
@@ -831,11 +861,20 @@
                                  'mouse-face 'highlight)
               (add-text-properties (point) (progn (insert (cadr str)) (point))
                                    '(mouse-face nil
-                                     face completions-annotations)))
-            ;; Next column to align to.
-            (setq column (+ column
-                            ;; Round up to a whole number of columns.
-                            (* colwidth (ceiling length colwidth))))))))))
+						face completions-annotations)))
+	    (cond
+	     ((eq completions-format 'vertical)
+	      ;; Vertical format
+	      (if (> column 0)
+		  (forward-line)
+		(insert "\n"))
+	      (setq row (1+ row)))
+	     (t
+	      ;; Horizontal format
+	      ;; Next column to align to.
+	      (setq column (+ column
+			      ;; Round up to a whole number of columns.
+			      (* colwidth (ceiling length colwidth))))))))))))
 
 (defvar completion-common-substring nil)
 (make-obsolete-variable 'completion-common-substring nil "23.1")