emacs-elpa-diffs
[Top][All Lists]
Advanced

[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)))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]