[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 99fa5a0 30/78: Refine col-row calculation in the presence
From: |
Dmitry Gutov |
Subject: |
[elpa] master 99fa5a0 30/78: Refine col-row calculation in the presence of line numbering |
Date: |
Sun, 18 Feb 2018 07:40:18 -0500 (EST) |
branch: master
commit 99fa5a0a0a6197486657d9e1c71b2dbb2e15f7de
Author: Dmitry Gutov <address@hidden>
Commit: Dmitry Gutov <address@hidden>
Refine col-row calculation in the presence of line numbering
Fixes #727
---
NEWS.md | 1 +
company.el | 9 ++++++---
test/core-tests.el | 17 +++++++++++++++++
3 files changed, 24 insertions(+), 3 deletions(-)
diff --git a/NEWS.md b/NEWS.md
index 7dbf3c0..c6b8139 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -2,6 +2,7 @@
## Next
+* Native line numbers compatibility fixes.
* New feature `company-tng`. It contains a frontend and some helper code.
The frontend triggers insertion of the candidate as soon as it's selected, so
you only need to press TAB. Add `(company-tng-configure-default)` to your
diff --git a/company.el b/company.el
index 4fafcc2..68fcaaa 100644
--- a/company.el
+++ b/company.el
@@ -833,6 +833,9 @@ means that `company-mode' is always turned on except in
`message-mode' buffers."
(defun company-input-noop ()
(push 'company-dummy-event unread-command-events))
+;; To avoid warnings in Emacs < 26.
+(declare-function line-number-display-width "indent.c")
+
(defun company--posn-col-row (posn)
(let ((col (car (posn-col-row posn)))
;; `posn-col-row' doesn't work well with lines of different height.
@@ -843,12 +846,12 @@ means that `company-mode' is always turned on except in
`message-mode' buffers."
(when (and header-line-format (version< emacs-version "24.3.93.3"))
;; http://debbugs.gnu.org/18384
(cl-decf row))
+ (when (bound-and-true-p display-line-numbers)
+ (cl-decf col (+ 2 (line-number-display-width))))
(cons (+ col (window-hscroll)) row)))
(defun company--col-row (&optional pos)
- (defvar display-line-numbers) ; For Emacs < 26.
- (let (display-line-numbers)
- (company--posn-col-row (posn-at-point pos))))
+ (company--posn-col-row (posn-at-point pos)))
(defun company--row (&optional pos)
(cdr (company--col-row pos)))
diff --git a/test/core-tests.el b/test/core-tests.el
index 6c846d2..7903649 100644
--- a/test/core-tests.el
+++ b/test/core-tests.el
@@ -544,3 +544,20 @@
(should (= (company--row) 0))
(setq header-line-format "aaaaaaa")
(should (= (company--row) 0)))))
+
+(ert-deftest company-column-with-line-numbers-display ()
+ (with-temp-buffer
+ (display-line-numbers-mode)
+ (save-window-excursion
+ (set-window-buffer nil (current-buffer))
+ (should (= (company--column) 0)))))
+
+(ert-deftest company-row-and-column-with-line-numbers-display ()
+ (with-temp-buffer
+ (display-line-numbers-mode)
+ (insert (make-string (+ (company--window-width)
(line-number-display-width)) ?a))
+ (insert ?\n)
+ (save-window-excursion
+ (set-window-buffer nil (current-buffer))
+ (should (= (company--column) 0))
+ (should (= (company--row) 2)))))
- [elpa] master 4240367 08/78: company-tng: Implement visualisation and completion, (continued)
- [elpa] master 4240367 08/78: company-tng: Implement visualisation and completion, Dmitry Gutov, 2018/02/18
- [elpa] master 1a9f0b8 14/78: company-tng: Kill local overlay variable after completion is done, Dmitry Gutov, 2018/02/18
- [elpa] master a528433 21/78: Fix the link text, Dmitry Gutov, 2018/02/18
- [elpa] master 66a9e65 15/78: company-tng: Use 'after-string when the prefix is empty, Dmitry Gutov, 2018/02/18
- [elpa] master 44b19b6 19/78: Tweak some more, Dmitry Gutov, 2018/02/18
- [elpa] master afa592d 18/78: Rewrite the tng documentation a bit, Dmitry Gutov, 2018/02/18
- [elpa] master eaddef4 22/78: company-tng: Remove redundant call to overlay-put, Dmitry Gutov, 2018/02/18
- [elpa] master 4c1fd0e 16/78: Merge pull request #706 from nikital/company-tng, Dmitry Gutov, 2018/02/18
- [elpa] master 096991d 26/78: Merge pull request #716 from jeffersoncarpenter/master, Dmitry Gutov, 2018/02/18
- [elpa] master 3d9272d 23/78: company-tng: Fully replace default frontend list, Dmitry Gutov, 2018/02/18
- [elpa] master 99fa5a0 30/78: Refine col-row calculation in the presence of line numbering,
Dmitry Gutov <=
- [elpa] master 8dea612 39/78: Merge pull request #740 from Havner/master, Dmitry Gutov, 2018/02/18
- [elpa] master a4e14ed 40/78: Add some Commentary, Dmitry Gutov, 2018/02/18
- [elpa] master a574418 46/78: Fix last change, Dmitry Gutov, 2018/02/18
- [elpa] master 4a34571 25/78: Place cursor at correct location for completions, Dmitry Gutov, 2018/02/18
- [elpa] master 78cbc69 32/78: Test in Emacs 25, too, Dmitry Gutov, 2018/02/18
- [elpa] master cf89f7c 27/78: Abort dabbrev search on input pending, Dmitry Gutov, 2018/02/18
- [elpa] master 1de463a 29/78: company--window-width: Account for display-line-numbers, Dmitry Gutov, 2018/02/18
- [elpa] master 47f3b9b 34/78: Which version?, Dmitry Gutov, 2018/02/18
- [elpa] master 098a907 35/78: Nah, Dmitry Gutov, 2018/02/18
- [elpa] master 27316ec 33/78: Try 'emacs', Dmitry Gutov, 2018/02/18