[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/company 2ddbe40f80: Allow customizing minimum padding b
From: |
ELPA Syncer |
Subject: |
[elpa] externals/company 2ddbe40f80: Allow customizing minimum padding before annotation (right-aligned) |
Date: |
Sun, 2 Apr 2023 22:57:33 -0400 (EDT) |
branch: externals/company
commit 2ddbe40f807a15b8f3e5f0f785a25cd959ba8c65
Author: Dmitry Gutov <dgutov@yandex.ru>
Commit: Dmitry Gutov <dgutov@yandex.ru>
Allow customizing minimum padding before annotation (right-aligned)
https://github.com/company-mode/company-mode/discussions/1376
---
NEWS.md | 3 +++
company.el | 22 ++++++++++++++++------
test/frontends-tests.el | 21 +++++++++++++++++++++
3 files changed, 40 insertions(+), 6 deletions(-)
diff --git a/NEWS.md b/NEWS.md
index 25e86e364c..b08b412f51 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -2,6 +2,9 @@
## Next
+* `company-tooltip-align-annotations` can be set to a number, and be taken to
+ mean the minimum padding between the text and annotation
+ ([#1376](https://github.com/company-mode/company-mode/discussions/1376)).
* When a snippet name is typed in full, completion does not abort now (only
affects completions which have `snippet` kind),
([#205](https://github.com/company-mode/company-mode/issues/205)).
diff --git a/company.el b/company.el
index b95c4d8bc0..7c4d654989 100644
--- a/company.el
+++ b/company.el
@@ -300,8 +300,12 @@ This doesn't include the margins and the scroll bar."
(const :tag "Two lines" lines)))
(defcustom company-tooltip-align-annotations nil
- "When non-nil, align annotations to the right tooltip border."
- :type 'boolean
+ "When non-nil, align annotations to the right tooltip border.
+
+When the value is a number, maintain at least this many spaces between the
+completion text and its annotation."
+ :type '(choice (const :tag "Align to the right" t)
+ (number :tag "Align to the right with minimum spacing"))
:package-version '(company . "0.7.1"))
(defcustom company-tooltip-flip-when-above nil
@@ -3087,11 +3091,11 @@ If SHOW-VERSION is non-nil, show the version in the
echo area."
(ann-ralign company-tooltip-align-annotations)
(ann-truncate (< width
(+ (length value) (length annotation)
- (if ann-ralign 1 0))))
+ (or ann-ralign 0))))
(ann-start (+ margin
(if ann-ralign
(if ann-truncate
- (1+ (length value))
+ (+ (length value) ann-ralign)
(- width (length annotation)))
(length value))))
(ann-end (min (+ ann-start (length annotation)) (+ margin width)))
@@ -3099,7 +3103,8 @@ If SHOW-VERSION is non-nil, show the version in the echo
area."
(if (or ann-truncate (not ann-ralign))
(company-safe-substring
(concat value
- (when (and annotation ann-ralign) " ")
+ (when (and annotation ann-ralign)
+ (company-space-string ann-ralign))
annotation)
0 width)
(concat
@@ -3327,6 +3332,10 @@ but adjust the expected values appropriately."
(defun company--create-lines (selection limit)
(let ((len company-candidates-length)
(window-width (company--window-width))
+ (company-tooltip-align-annotations
+ (if (eq company-tooltip-align-annotations t)
+ 1
+ company-tooltip-align-annotations))
left-margins
left-margin-size
lines
@@ -3400,7 +3409,8 @@ but adjust the expected values appropriately."
(push (list value annotation left) items)
(setq width (max (+ (length value)
(if (and annotation
company-tooltip-align-annotations)
- (1+ (length annotation))
+ (+ (length annotation)
+ company-tooltip-align-annotations)
(length annotation)))
width))))
diff --git a/test/frontends-tests.el b/test/frontends-tests.el
index 5e5d9bb96a..6e9c70a7d9 100644
--- a/test/frontends-tests.el
+++ b/test/frontends-tests.el
@@ -132,6 +132,27 @@
(should (string= (overlay-get ov 'company-display)
" 123 (4) \n 45 \n 67 (891011)
\n")))))))
+(ert-deftest company-pseudo-tooltip-show-with-annotations-padding-2 ()
+ :tags '(interactive)
+ (with-temp-buffer
+ (save-window-excursion
+ (set-window-buffer nil (current-buffer))
+ (insert " ")
+ (save-excursion (insert "\n"))
+ (let ((company-candidates-length 3)
+ (company-backend (lambda (action &optional arg &rest _ignore)
+ (when (eq action 'annotation)
+ (cdr (assoc arg '(("123" . "(4)")
+ ("67" . "(891011)")))))))
+ (company-candidates '("123" "45" "67"))
+ (company-tooltip-align-annotations 2))
+ (company-pseudo-tooltip-show-at-point (point) 0)
+ (let ((ov company-pseudo-tooltip-overlay))
+ ;; With margins.
+ (should (eq (overlay-get ov 'company-width) 14))
+ (should (string= (overlay-get ov 'company-display)
+ " 123 (4) \n 45 \n 67 (891011)
\n")))))))
+
(ert-deftest company-create-lines-shows-quick-access ()
(let ((company-show-quick-access t)
(company-candidates '("x" "y" "z"))
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [elpa] externals/company 2ddbe40f80: Allow customizing minimum padding before annotation (right-aligned),
ELPA Syncer <=