Subject: Re: bug#18504: 24.3.93; posn-at-point intermittently returns wrong value for a valid buffer position

From: Dmitry Gutov <[email-masked]>
Date: Fri, 19 Sep 2014 17:46:57 +0400

On 09/19/2014 05:35 PM, Eli Zaretskii wrote:

> Btw, why is it important what happens when the user types C-g, i.e. if
> she abandons the completion?  Or does the problem happen without C-g
> as well?

I'm not quite sure how we get to that point, to be honest. The code gets 
called from `company-post-command' (which is in post-command-hook), but 
this-command is nil when that happens.

>> If `posn-at-point' is itself stateless (and doesn't modify any relevant
>> caches), why not call it again at that point?
>
> Because it will most probably produce the correct result.
>
> But you can try that yourself: insert a second call under the
> conditions that you know are evidence of the problem.  If that is
> repeatable, i.e. if that second call always produces the wrong result,
> then I have what I need.

It is. Try this:

diff --git a/company.el b/company.el
index fdf09f7..01a3cb5 100644
--- a/company.el
+++ b/company.el
@@ -782,7 +782,13 @@ means that `company-mode' is always turned on 
except in `message-mode' buffers."
      (cons (+ col (window-hscroll)) row)))

  (defun company--col-row (&optional pos)
-  (company--posn-col-row (posn-at-point pos)))
+  (let ((posn (posn-at-point pos)))
+    ;; Completion should be invoked at column > 1.
+    (when (zerop (car (posn-x-y posn)))
+      (message "company--col-row zero!")
+      (message "then:")
+      (message "%s" (posn-x-y (posn-at-point pos))))
+    (company--posn-col-row posn)))

  (defun company--row (&optional pos)
    (cdr (company--col-row pos)))

I get:

company--col-row zero!
then:
(0 . 198)