diff options
| -rw-r--r-- | lisp/minibuffer.el | 77 |
1 files changed, 58 insertions, 19 deletions
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index 223817ddc75..472fd95ece2 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el | |||
| @@ -778,6 +778,16 @@ Return nil if there is no valid completion, else t." | |||
| 778 | (defface completions-annotations '((t :inherit italic)) | 778 | (defface completions-annotations '((t :inherit italic)) |
| 779 | "Face to use for annotations in the *Completions* buffer.") | 779 | "Face to use for annotations in the *Completions* buffer.") |
| 780 | 780 | ||
| 781 | (defcustom completions-format nil | ||
| 782 | "Define the appearance and sorting of completions. | ||
| 783 | If the value is `vertical', display completions sorted vertically | ||
| 784 | in columns in the *Completions* buffer. | ||
| 785 | If the value is `horizontal' or nil, display completions sorted | ||
| 786 | horizontally in alphabetical order, rather than down the screen." | ||
| 787 | :type '(choice (const nil) (const horizontal) (const vertical)) | ||
| 788 | :group 'minibuffer | ||
| 789 | :version "23.2") | ||
| 790 | |||
| 781 | (defun completion--insert-strings (strings) | 791 | (defun completion--insert-strings (strings) |
| 782 | "Insert a list of STRINGS into the current buffer. | 792 | "Insert a list of STRINGS into the current buffer. |
| 783 | Uses columns to keep the listing readable but compact. | 793 | Uses columns to keep the listing readable but compact. |
| @@ -800,6 +810,8 @@ It also eliminates runs of equal strings." | |||
| 800 | (max 1 (/ (length strings) 2)))) | 810 | (max 1 (/ (length strings) 2)))) |
| 801 | (colwidth (/ wwidth columns)) | 811 | (colwidth (/ wwidth columns)) |
| 802 | (column 0) | 812 | (column 0) |
| 813 | (rows (/ (length strings) columns)) | ||
| 814 | (row 0) | ||
| 803 | (laststring nil)) | 815 | (laststring nil)) |
| 804 | ;; The insertion should be "sensible" no matter what choices were made | 816 | ;; The insertion should be "sensible" no matter what choices were made |
| 805 | ;; for the parameters above. | 817 | ;; for the parameters above. |
| @@ -810,20 +822,38 @@ It also eliminates runs of equal strings." | |||
| 810 | (+ (string-width (car str)) | 822 | (+ (string-width (car str)) |
| 811 | (string-width (cadr str))) | 823 | (string-width (cadr str))) |
| 812 | (string-width str)))) | 824 | (string-width str)))) |
| 813 | (unless (bolp) | 825 | (cond |
| 814 | (if (< wwidth (+ (max colwidth length) column)) | 826 | ((eq completions-format 'vertical) |
| 815 | ;; No space for `str' at point, move to next line. | 827 | ;; Vertical format |
| 816 | (progn (insert "\n") (setq column 0)) | 828 | (when (> row rows) |
| 817 | (insert " \t") | 829 | (forward-line (- -1 rows)) |
| 818 | ;; Leave the space unpropertized so that in the case we're | 830 | (setq row 0 column (+ column colwidth))) |
| 819 | ;; already past the goal column, there is still | 831 | (when (> column 0) |
| 820 | ;; a space displayed. | 832 | (end-of-line) |
| 821 | (set-text-properties (- (point) 1) (point) | 833 | (while (> (current-column) column) |
| 822 | ;; We can't just set tab-width, because | 834 | (if (eobp) |
| 823 | ;; completion-setup-function will kill all | 835 | (insert "\n") |
| 824 | ;; local variables :-( | 836 | (forward-line 1) |
| 825 | `(display (space :align-to ,column))) | 837 | (end-of-line))) |
| 826 | nil)) | 838 | (insert " \t") |
| 839 | (set-text-properties (- (point) 1) (point) | ||
| 840 | `(display (space :align-to ,column))))) | ||
| 841 | (t | ||
| 842 | ;; Horizontal format | ||
| 843 | (unless (bolp) | ||
| 844 | (if (< wwidth (+ (max colwidth length) column)) | ||
| 845 | ;; No space for `str' at point, move to next line. | ||
| 846 | (progn (insert "\n") (setq column 0)) | ||
| 847 | (insert " \t") | ||
| 848 | ;; Leave the space unpropertized so that in the case we're | ||
| 849 | ;; already past the goal column, there is still | ||
| 850 | ;; a space displayed. | ||
| 851 | (set-text-properties (- (point) 1) (point) | ||
| 852 | ;; We can't just set tab-width, because | ||
| 853 | ;; completion-setup-function will kill all | ||
| 854 | ;; local variables :-( | ||
| 855 | `(display (space :align-to ,column))) | ||
| 856 | nil)))) | ||
| 827 | (if (not (consp str)) | 857 | (if (not (consp str)) |
| 828 | (put-text-property (point) (progn (insert str) (point)) | 858 | (put-text-property (point) (progn (insert str) (point)) |
| 829 | 'mouse-face 'highlight) | 859 | 'mouse-face 'highlight) |
| @@ -831,11 +861,20 @@ It also eliminates runs of equal strings." | |||
| 831 | 'mouse-face 'highlight) | 861 | 'mouse-face 'highlight) |
| 832 | (add-text-properties (point) (progn (insert (cadr str)) (point)) | 862 | (add-text-properties (point) (progn (insert (cadr str)) (point)) |
| 833 | '(mouse-face nil | 863 | '(mouse-face nil |
| 834 | face completions-annotations))) | 864 | face completions-annotations))) |
| 835 | ;; Next column to align to. | 865 | (cond |
| 836 | (setq column (+ column | 866 | ((eq completions-format 'vertical) |
| 837 | ;; Round up to a whole number of columns. | 867 | ;; Vertical format |
| 838 | (* colwidth (ceiling length colwidth)))))))))) | 868 | (if (> column 0) |
| 869 | (forward-line) | ||
| 870 | (insert "\n")) | ||
| 871 | (setq row (1+ row))) | ||
| 872 | (t | ||
| 873 | ;; Horizontal format | ||
| 874 | ;; Next column to align to. | ||
| 875 | (setq column (+ column | ||
| 876 | ;; Round up to a whole number of columns. | ||
| 877 | (* colwidth (ceiling length colwidth)))))))))))) | ||
| 839 | 878 | ||
| 840 | (defvar completion-common-substring nil) | 879 | (defvar completion-common-substring nil) |
| 841 | (make-obsolete-variable 'completion-common-substring nil "23.1") | 880 | (make-obsolete-variable 'completion-common-substring nil "23.1") |