dgutov pushed a commit to branch master in repository elpa. commit e69b3e64d0b2575146a47aa47d573b48fa3c5254 Author: Dmitry Gutov <dgu...@yandex.ru> Date: Thu Jan 23 03:54:28 2014 +0200
Fix #49 Adjust for window-width aberrations when Emacs runs in a terminal. --- company.el | 16 ++++++++++++++-- 1 files changed, 14 insertions(+), 2 deletions(-) diff --git a/company.el b/company.el index ec8a4a1..165ac64 100644 --- a/company.el +++ b/company.el @@ -1752,7 +1752,7 @@ Example: \(company-begin-with '\(\"foo\" \"foobar\" \"foobarbaz\"\)\)" (defun company--replacement-string (lines old column nl &optional align-top) (let ((width (length (car lines))) - (remaining-cols (- (+ (window-width) (window-hscroll)) + (remaining-cols (- (+ (company--window-width) (window-hscroll)) column))) (when (> width remaining-cols) (decf column (- width remaining-cols)))) @@ -1804,7 +1804,7 @@ Example: \(company-begin-with '\(\"foo\" \"foobar\" \"foobarbaz\"\)\)" (dotimes (_ len) (setq width (max (length (pop lines-copy)) width))) - (setq width (min (window-width) + (setq width (min (company--window-width) (if company-show-numbers (+ 2 width) width))) @@ -1844,6 +1844,18 @@ Example: \(company-begin-with '\(\"foo\" \"foobar\" \"foobarbaz\"\)\)" (let ((edges (window-inside-edges))) (- (nth 3 edges) (nth 1 edges)))) +(defsubst company--window-width () + (- (window-width) + (cond + ((display-graphic-p) 0) + ;; Account for the line continuation column. + ((version< "24.3.1" emacs-version) 1) + ;; Emacs 24.3 and earlier included margins + ;; in window-width when in TTY. + (t (1+ (let ((margins (window-margins))) + (+ (or (car margins) 0) + (or (cdr margins) 0)))))))) + (defun company--pseudo-tooltip-height () "Calculate the appropriate tooltip height. Returns a negative number if the tooltip should be displayed above point."