[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/company b798634 2/4: Don't create extra-wide margins wh
From: |
ELPA Syncer |
Subject: |
[elpa] externals/company b798634 2/4: Don't create extra-wide margins when backend shows no kinds |
Date: |
Sun, 28 Mar 2021 22:57:06 -0400 (EDT) |
branch: externals/company
commit b798634b468248524cb51df5cf9287918da69fac
Author: Dmitry Gutov <dgutov@yandex.ru>
Commit: Dmitry Gutov <dgutov@yandex.ru>
Don't create extra-wide margins when backend shows no kinds
---
company.el | 59 ++++++++++++++++++++++++++++++++++++++---------------------
1 file changed, 38 insertions(+), 21 deletions(-)
diff --git a/company.el b/company.el
index 151029b..cb64777 100644
--- a/company.el
+++ b/company.el
@@ -1432,7 +1432,7 @@ end of the match."
(concat
(propertize " " 'display spec)
(propertize " " 'display `(space . (:width ,(- 2 (car (image-size
spec))))))))
- " "))
+ nil))
(defun company-vscode-dark-icons-margin (candidate selected)
"Margin function which returns icons from vscode's dark theme."
@@ -2832,11 +2832,8 @@ If SHOW-VERSION is non-nil, show the version in the echo
area."
(mapcar (lambda (f) (company--face-attribute f attr))
face)))))
-(defun company--replacement-string (lines old column nl &optional align-top)
- (cl-decf column (or (when company-format-margin-function
- (when-let (margin (funcall
company-format-margin-function nil nil))
- (length margin)))
- company-tooltip-margin))
+(defun company--replacement-string (lines column-offset old column nl
&optional align-top)
+ (cl-decf column column-offset)
(when (and align-top company-tooltip-flip-when-above)
(setq lines (reverse lines)))
@@ -2892,6 +2889,8 @@ If SHOW-VERSION is non-nil, show the version in the echo
area."
(defun company--create-lines (selection limit)
(let ((len company-candidates-length)
(window-width (company--window-width))
+ left-margins
+ left-margin-size
lines
width
lines-copy
@@ -2932,22 +2931,34 @@ If SHOW-VERSION is non-nil, show the version in the
echo area."
(cl-decf window-width (* 2 company-tooltip-margin))
(when scrollbar-bounds (cl-decf window-width))
- (dotimes (i len)
+ (when company-format-margin-function
+ (let ((lines-copy lines-copy)
+ res)
+ (dotimes (i len)
+ (push (funcall company-format-margin-function
+ (pop lines-copy)
+ (equal selection i))
+ res))
+ (setq left-margins (nreverse res))))
+
+ ;; XXX: format-function outputting shorter strings than the
+ ;; default margin is not supported (yet?).
+ (setq left-margin-size (apply #'max company-tooltip-margin
+ (mapcar #'length left-margins)))
+
+ (dotimes (_ len)
(let* ((value (pop lines-copy))
(annotation (company-call-backend 'annotation value))
- (candidate-prefix (when company-format-margin-function
- (funcall company-format-margin-function
- value
- (equal selection i)))))
+ (left-margin (or (pop left-margins)
+ (company-space-string left-margin-size))))
(setq value (company--clean-string value))
(when annotation
(setq annotation (company--clean-string annotation))
(when company-tooltip-align-annotations
;; `lisp-completion-at-point' adds a space.
(setq annotation (string-trim-left annotation))))
- (push (list value annotation candidate-prefix) items)
+ (push (list value annotation left-margin) items)
(setq width (max (+ (length value)
- (length candidate-prefix)
(if (and annotation
company-tooltip-align-annotations)
(1+ (length annotation))
(length annotation)))
@@ -2974,10 +2985,9 @@ If SHOW-VERSION is non-nil, show the version in the echo
area."
(let* ((item (pop items))
(str (car item))
(annotation (cadr item))
- (candidate-prefix (nth 2 item))
+ (left (nth 2 item))
(margin (company-space-string company-tooltip-margin))
- (left (or candidate-prefix margin))
- (right margin)
+ (right (company-space-string company-tooltip-margin))
(width width))
(when (< numbered 10)
(cl-decf width 2)
@@ -2997,7 +3007,9 @@ If SHOW-VERSION is non-nil, show the version in the echo
area."
(when remainder
(push (company--scrollpos-line remainder width) new))
- (nreverse new))))
+ (cons
+ left-margin-size
+ (nreverse new)))))
(defun company--scrollbar-bounds (offset limit length)
(when (> length limit)
@@ -3055,9 +3067,12 @@ Returns a negative number if the tooltip should be
displayed above point."
(setq company-pseudo-tooltip-overlay ov)
(overlay-put ov 'company-replacement-args args)
- (let ((lines (company--create-lines selection (abs height))))
+ (let* ((lines-and-offset (company--create-lines selection (abs
height)))
+ (lines (cdr lines-and-offset))
+ (column-offset (car lines-and-offset)))
(overlay-put ov 'company-display
- (apply 'company--replacement-string lines args))
+ (apply 'company--replacement-string
+ lines column-offset args))
(overlay-put ov 'company-width (string-width (car lines))))
(overlay-put ov 'company-column column)
@@ -3071,12 +3086,14 @@ Returns a negative number if the tooltip should be
displayed above point."
(defun company-pseudo-tooltip-edit (selection)
(let* ((height (overlay-get company-pseudo-tooltip-overlay 'company-height))
- (lines (company--create-lines selection (abs height))))
+ (lines-and-offset (company--create-lines selection (abs height)))
+ (lines (cdr lines-and-offset))
+ (column-offset (car lines-and-offset)))
(overlay-put company-pseudo-tooltip-overlay 'company-width
(string-width (car lines)))
(overlay-put company-pseudo-tooltip-overlay 'company-display
(apply 'company--replacement-string
- lines
+ lines column-offset
(overlay-get company-pseudo-tooltip-overlay
'company-replacement-args)))))