[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/frog-menu 68c8688 2/3: Allow for vertical or horizontal
From: |
Clemens Radermacher |
Subject: |
[elpa] externals/frog-menu 68c8688 2/3: Allow for vertical or horizontal string order via frog-menu-format |
Date: |
Tue, 30 Apr 2019 09:46:20 -0400 (EDT) |
branch: externals/frog-menu
commit 68c8688b43f3001feb2faac3028acc060afa1971
Author: Clemens Radermacher <address@hidden>
Commit: Clemens Radermacher <address@hidden>
Allow for vertical or horizontal string order via frog-menu-format
---
frog-menu.el | 77 +++++++++++++++++++++++++++++++++++++++++++-----------------
1 file changed, 56 insertions(+), 21 deletions(-)
diff --git a/frog-menu.el b/frog-menu.el
index 4f39ad7..f1dc407 100644
--- a/frog-menu.el
+++ b/frog-menu.el
@@ -358,6 +358,7 @@ ACTIONS."
(replace-match " "))))
(buffer-string))))
+;; Taken partly from `completion--insert-strings'
(defun frog-menu--grid-format (strings cols &optional width)
"Return grid string built with STRINGS.
@@ -365,7 +366,7 @@ The grid will be segmented into columns. COLS is the maximum
number of columns to use. The columns have WIDTH space in
horizontal direction which default to frame width.
-Returns the buffer containing the formatted grid."
+Returns the formatted grid string."
(with-temp-buffer
(let* ((length (apply #'max
(mapcar #'string-width strings)))
@@ -374,27 +375,53 @@ Returns the buffer containing the formatted grid."
(colwidth (/ wwidth columns))
(column 0)
(first t)
- laststring)
+ (rows (/ (length strings) columns))
+ (row 0))
(dolist (str strings)
- (unless (equal laststring str)
- (setq laststring str)
- (let ((length (string-width str)))
- (unless first
- (if (or (< wwidth (+ (max colwidth length) column))
- (zerop length))
- (progn
- (insert "\n" (if (zerop length) "\n" ""))
- (setq column 0))
- (insert " \t")
- (set-text-properties (1- (point)) (point)
- `(display (space :align-to ,column)))))
- (setq first (zerop length))
- (add-text-properties (point)
- (progn (insert str)
- (point))
- '(face frog-menu-candidates-face))
- (setq column (+ column
- (* colwidth (ceiling length colwidth)))))))
+ (let ((length (string-width str)))
+ (cond ((eq frog-menu-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 (1- (point)) (point)
+ `(display (space :align-to ,column))))
+
+ (add-text-properties (point)
+ (progn (insert str)
+ (point))
+ '(face frog-menu-candidates-face))
+
+ (if (> column 0)
+ (forward-line)
+ (insert "\n"))
+ (setq row (1+ row)))
+ (t
+ ;; horizontal
+ (unless first
+ (if (or (< wwidth (+ (max colwidth length) column))
+ (zerop length))
+ (progn
+ (insert "\n" (if (zerop length) "\n" ""))
+ (setq column 0))
+ (insert " \t")
+ (set-text-properties (1- (point)) (point)
+ `(display (space :align-to
,column)))))
+ (setq first (zerop length))
+ (add-text-properties (point)
+ (progn (insert str)
+ (point))
+ '(face frog-menu-candidates-face))
+ (setq column (+ column
+ (* colwidth (ceiling length colwidth))))))))
(buffer-string))))
@@ -601,6 +628,14 @@ pass the strings to be displayed and the function to
`sort':
(let ((frog-menu-sort-function #'string<))
(frog-menu-read \"Example\" '(\"z\" \"a\")))")
+(defvar frog-menu-format completions-format
+ "Defines in which order strings for `frog-menu-read' are displayed.
+
+If the value is `vertical', strings are ordered vertically. If
+the value is `horizontal', strings are ordered horizontally. This
+variable does not define sorting, see `frog-menu-sort-function'
+for this.")
+
;;;###autoload
(defun frog-menu-read (prompt collection &optional actions)