From 6468e89e00758abebc42477cc0df30a960546d78 Mon Sep 17 00:00:00 2001 From: Dmitry Gutov Date: Mon, 18 Aug 2014 04:49:19 +0400 Subject: [PATCH] Use `posn-actual-col-row' to determine the current col and row Issue #136 WIP. Reverting d21bb454dcfacda8808b596e4bca85a53a99eabf, for the most part, http://lists.gnu.org/archive/html/emacs-devel/2014-08/msg00361.html. --- company.el | 40 +++++++++++++++------------------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/company.el b/company.el index 4b5965587..f5598cc20 100644 --- a/company.el +++ b/company.el @@ -778,22 +778,19 @@ means that `company-mode' is always turned on except in `message-mode' buffers." (defun company-input-noop () (push 31415926 unread-command-events)) -(defun company--column (&optional pos) - (save-excursion - (when pos (goto-char pos)) - (save-restriction - (+ (save-excursion - (vertical-motion 0) - (narrow-to-region (point) (point-max)) - (let ((prefix (get-text-property (point) 'line-prefix))) - (if prefix (length prefix) 0))) - (current-column))))) +(defun company--posn-col-row (pos) + (let* ((col-row (posn-actual-col-row pos)) + (col (car col-row)) + (row (cdr col-row))) + (when header-line-format + (cl-decf row)) + (cons (+ col (window-hscroll)) row))) + +(defun company--col-row (&optional pos) + (company--posn-col-row (posn-at-point pos))) (defun company--row (&optional pos) - (save-excursion - (when pos (goto-char pos)) - (count-screen-lines (window-start) - (progn (vertical-motion 0) (point))))) + (cdr (company--col-row pos))) ;;; backends ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -1813,14 +1810,7 @@ and invoke the normal binding." (>= evt-row (+ row height))))))) (defun company--event-col-row (event) - (let* ((col-row (posn-actual-col-row (event-start event))) - (col (car col-row)) - (row (cdr col-row))) - (cl-incf col (window-hscroll)) - (and header-line-format - (version< "24" emacs-version) - (cl-decf row)) - (cons col row))) + (company--posn-col-row (event-start event))) (defun company-select-mouse (event) "Select the candidate picked by the mouse." @@ -2426,10 +2416,10 @@ Returns a negative number if the tooltip should be displayed above point." (overlay-put ov 'company-height height))))) (defun company-pseudo-tooltip-show-at-point (pos column-offset) - (let ((row (company--row pos)) - (col (- (company--column pos) column-offset))) + (let* ((col-row (company--col-row pos)) + (col (- (car col-row) column-offset))) (when (< col 0) (setq col 0)) - (company-pseudo-tooltip-show (1+ row) col company-selection))) + (company-pseudo-tooltip-show (1+ (cdr col-row)) col company-selection))) (defun company-pseudo-tooltip-edit (selection) (let* ((height (overlay-get company-pseudo-tooltip-overlay 'company-height)) -- 2.39.2