[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/company 246837b12c: Split off the new behavior into a n
From: |
ELPA Syncer |
Subject: |
[elpa] externals/company 246837b12c: Split off the new behavior into a new user option |
Date: |
Mon, 3 Apr 2023 21:57:37 -0400 (EDT) |
branch: externals/company
commit 246837b12cbedaac0c9e2b654d97426639e0c778
Author: Dmitry Gutov <dgutov@yandex.ru>
Commit: Dmitry Gutov <dgutov@yandex.ru>
Split off the new behavior into a new user option
And make it affect non-right-aligned annotations too.
https://github.com/company-mode/company-mode/discussions/1376#discussioncomment-5510800
---
NEWS.md | 3 +--
company.el | 40 +++++++++++++++++++++++-----------------
test/frontends-tests.el | 26 ++++++++++++++++++++++++--
3 files changed, 48 insertions(+), 21 deletions(-)
diff --git a/NEWS.md b/NEWS.md
index b08b412f51..a459a356e5 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -2,8 +2,7 @@
## Next
-* `company-tooltip-align-annotations` can be set to a number, and be taken to
- mean the minimum padding between the text and annotation
+* New user option `company-tooltip-annotation-padding`
([#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),
diff --git a/company.el b/company.el
index 7c4d654989..01e89a6d14 100644
--- a/company.el
+++ b/company.el
@@ -300,12 +300,8 @@ 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.
-
-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"))
+ "When non-nil, align annotations to the right tooltip border."
+ :type 'boolean
:package-version '(company . "0.7.1"))
(defcustom company-tooltip-flip-when-above nil
@@ -313,6 +309,16 @@ completion text and its annotation."
:type 'boolean
:package-version '(company . "0.8.1"))
+(defcustom company-tooltip-annotation-padding nil
+ "Non-nil to specify the padding before annotation.
+
+Depending on the value of `company-tooltip-align-annotations', the default
+padding is either 0 or 1 space. This variable allows to override that
+value to increase the padding. When annotations are right-aligned, it sets
+the minimum padding, and otherwise just the constant one."
+ :type 'number
+ :package-version '(company "0.9.14"))
+
(defvar company-safe-backends
'((company-abbrev . "Abbrev")
(company-bbdb . "BBDB")
@@ -3089,22 +3095,23 @@ If SHOW-VERSION is non-nil, show the version in the
echo area."
(_ (setq value (company-reformat (company--pre-render value))
annotation (and annotation (company--pre-render annotation
t))))
(ann-ralign company-tooltip-align-annotations)
+ (ann-padding (or company-tooltip-annotation-padding 0))
(ann-truncate (< width
(+ (length value) (length annotation)
- (or ann-ralign 0))))
+ ann-padding)))
(ann-start (+ margin
(if ann-ralign
(if ann-truncate
- (+ (length value) ann-ralign)
+ (+ (length value) ann-padding)
(- width (length annotation)))
- (length value))))
+ (+ (length value) ann-padding))))
(ann-end (min (+ ann-start (length annotation)) (+ margin width)))
(line (concat left
(if (or ann-truncate (not ann-ralign))
(company-safe-substring
(concat value
- (when (and annotation ann-ralign)
- (company-space-string ann-ralign))
+ (when annotation
+ (company-space-string ann-padding))
annotation)
0 width)
(concat
@@ -3332,10 +3339,9 @@ 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))
+ (company-tooltip-annotation-padding
+ (or company-tooltip-annotation-padding
+ (if company-tooltip-align-annotations 1 0)))
left-margins
left-margin-size
lines
@@ -3408,9 +3414,9 @@ but adjust the expected values appropriately."
(setq annotation (string-trim-left annotation))))
(push (list value annotation left) items)
(setq width (max (+ (length value)
- (if (and annotation
company-tooltip-align-annotations)
+ (if annotation
(+ (length annotation)
- company-tooltip-align-annotations)
+ company-tooltip-annotation-padding)
(length annotation)))
width))))
diff --git a/test/frontends-tests.el b/test/frontends-tests.el
index 6e9c70a7d9..9a0a355f9c 100644
--- a/test/frontends-tests.el
+++ b/test/frontends-tests.el
@@ -111,6 +111,27 @@
(should (string= (overlay-get ov 'company-display)
" 123(4) \n 45 \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-annotation-padding 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-pseudo-tooltip-show-with-annotations-right-aligned ()
:tags '(interactive)
(with-temp-buffer
@@ -132,7 +153,7 @@
(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 ()
+(ert-deftest company-pseudo-tooltip-show-with-annotations-right-padding-2 ()
:tags '(interactive)
(with-temp-buffer
(save-window-excursion
@@ -145,7 +166,8 @@
(cdr (assoc arg '(("123" . "(4)")
("67" . "(891011)")))))))
(company-candidates '("123" "45" "67"))
- (company-tooltip-align-annotations 2))
+ (company-tooltip-align-annotations t)
+ (company-tooltip-annotation-padding 2))
(company-pseudo-tooltip-show-at-point (point) 0)
(let ((ov company-pseudo-tooltip-overlay))
;; With margins.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [elpa] externals/company 246837b12c: Split off the new behavior into a new user option,
ELPA Syncer <=