diff options
| -rw-r--r-- | corfu.el | 19 |
1 files changed, 12 insertions, 7 deletions
@@ -717,22 +717,27 @@ there hasn't been any input, then quit." (let* ((cw (cl-loop for x in cands maximize (string-width (car x)))) (pw (cl-loop for x in cands maximize (string-width (cadr x)))) (sw (cl-loop for x in cands maximize (string-width (caddr x)))) - (width (+ pw cw sw))) + (width (+ pw cw sw)) + ;; -4 because of margins and some additional safety + (max-width (min corfu-max-width (- (frame-width) 4)))) + (when (> width max-width) + (setq sw (max 0 (- max-width pw cw)) + width (+ pw cw sw))) (when (< width corfu-min-width) (setq cw (+ cw (- corfu-min-width width)) width corfu-min-width)) - ;; -4 because of margins and some additional safety - (setq width (min width corfu-max-width (- (frame-width) 4))) + (setq width (min width max-width)) (list pw width (cl-loop for (cand prefix suffix) in cands collect (truncate-string-to-width (concat prefix - (make-string (- pw (string-width prefix)) ?\s) + (make-string (max 0 (- pw (string-width prefix))) ?\s) cand (when (/= sw 0) - (make-string (+ (- cw (string-width cand)) - (- sw (string-width suffix))) - ?\s)) + (make-string + (+ (max 0 (- cw (string-width cand))) + (max 0 (- sw (string-width suffix)))) + ?\s)) suffix) width))))) |
