emacs-devel
[Top][All Lists]
Advanced

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

Re: Vertical completions


From: Juri Linkov
Subject: Re: Vertical completions
Date: Tue, 17 Nov 2009 19:45:54 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (x86_64-pc-linux-gnu)

>>>> And speaking about *Completions*, would it be possible to fill the
>>>> completions column-first, not row-first as it is now?  I find it quite
>>>> unreasonable, as the display is column-wise, but not so filling, making
>>>> it harder to quickly skim through the list.
>>
>> It's easier to skim through a list when completions are sorted
>> vertically in columns down the screen.
>>
>> That's what `ls' does by default for the list of files unless
>> `-x' (`--format=horizontal') is specified.  As well as readline
>> completions in bash unless `print-completions-horizontally' is `On'.
>
> If it's not too problematic to implement, I'm all for the change (or
> rather an option to have it).

Not problematic at all.  Below is a small patch that implements
a new option for vertical completions with the default to
traditional horizontal completions, of course.

Index: lisp/minibuffer.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/minibuffer.el,v
retrieving revision 1.96
diff -c -w -b -r1.96 minibuffer.el
*** lisp/minibuffer.el  12 Nov 2009 23:10:06 -0000      1.96
--- lisp/minibuffer.el  17 Nov 2009 17:44:46 -0000
***************
*** 778,783 ****
--- 778,793 ----
  (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,805 ****
--- 810,817 ----
                     (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,815 ****
--- 822,840 ----
                              (+ (string-width (car str))
                                 (string-width (cadr str)))
                            (string-width str))))
+             (cond
+            ((eq completions-format 'vertical)
+             ;; Vertical format
+             (when (> row rows)
+               (forward-line (- -1 rows))
+               (setq row 0 column (setq column (+ column colwidth))))
+             (when (> column 0)
+               (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.
***************
*** 823,829 ****
                                       ;; 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)
--- 848,854 ----
                                       ;; 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)
***************
*** 832,841 ****
                (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))))))))))
  
  (defvar completion-common-substring nil)
  (make-obsolete-variable 'completion-common-substring nil "23.1")
--- 857,875 ----
                (add-text-properties (point) (progn (insert (cadr str)) (point))
                                     '(mouse-face nil
                                                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")

-- 
Juri Linkov
http://www.jurta.org/emacs/




reply via email to

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