]> code.delx.au - gnu-emacs-elpa/commitdiff
Allow including window-start in the doc-buffer return value
authorDmitry Gutov <dgutov@yandex.ru>
Thu, 4 Jun 2015 23:05:47 +0000 (02:05 +0300)
committerDmitry Gutov <dgutov@yandex.ru>
Fri, 5 Jun 2015 09:53:11 +0000 (12:53 +0300)
Closes #357

NEWS.md
company.el

diff --git a/NEWS.md b/NEWS.md
index 012d0bc63d8d7698754922ad3e13e776ae7ade96..319e959affdca7e64b7973a1ba6a1616fa825742 100644 (file)
--- a/NEWS.md
+++ b/NEWS.md
@@ -2,6 +2,8 @@
 
 ## Next
 
+* Backend command `doc-buffer` now can also return a cons of buffer and window
+  start position.
 * Backend command `ignore-case` has been documented.
 * `company-template-c-like-templatify` does not replace the default argument
   values with `argN` anymore
index af5c04069b424648863bb1f6f9f569161a94ccb6..1481914bc4bd14d397c737f8da4d76541c8184e5 100644 (file)
@@ -375,9 +375,11 @@ them from cache.
 documentation string for it.
 
 `doc-buffer': The second argument is a completion candidate.  Return a
-buffer with documentation for it.  Preferably use `company-doc-buffer',
+buffer with documentation for it.  Preferably use `company-doc-buffer'.  If
+not all buffer contents pertain to this candidate, return a cons of buffer
+and window start position.
 
-`location': The second argument is a completion candidate.  Return the cons
+`location': The second argument is a completion candidate.  Return a cons
 of buffer and buffer location, or of file and line number where the
 completion candidate was defined.
 
@@ -2066,11 +2068,14 @@ character, stripping the modifiers.  That character must be a digit."
     (company--electric-do
       (let* ((selected (nth company-selection company-candidates))
              (doc-buffer (or (company-call-backend 'doc-buffer selected)
-                             (error "No documentation available"))))
+                             (error "No documentation available")))
+             start)
+        (when (consp doc-buffer)
+          (setq start (cdr doc-buffer)
+                doc-buffer (car doc-buffer)))
         (setq other-window-scroll-buffer (get-buffer doc-buffer))
-        (with-current-buffer doc-buffer
-          (goto-char (point-min)))
-        (display-buffer doc-buffer t)))))
+        (let ((win (display-buffer doc-buffer t)))
+          (set-window-start win (if start start (point-min))))))))
 (put 'company-show-doc-buffer 'company-keep t)
 
 (defun company-show-location ()