]> code.delx.au - gnu-emacs-elpa/commitdiff
Limit tooltip height to remaining window height.
authorNikolaj Schumacher <git@nschum.de>
Mon, 16 Mar 2009 15:54:10 +0000 (16:54 +0100)
committerNikolaj Schumacher <git@nschum.de>
Fri, 20 Mar 2009 11:50:11 +0000 (12:50 +0100)
company.el

index 56a57206cd5bf27331773dc4544ec3e258077444..54feaf8e2427aee7d527ae10e7c47b319523dfa2 100644 (file)
             (mapconcat 'identity (nreverse new) "\n")
             "\n")))
 
-(defun company-create-lines (column lines selection)
+(defun company-create-lines (column lines selection limit)
 
-  (let ((limit (max company-tooltip-limit 3))
-        (len (length lines))
+  (let ((len (length lines))
         width
         lines-copy
         previous
 
 ;; show
 
+(defsubst company-pseudo-tooltip-height ()
+  "Calculate the appropriate tooltip height."
+  (max 3 (min company-tooltip-limit
+              (- (window-height) (cdr (posn-col-row (posn-at-point))) 2))))
+
 (defun company-pseudo-tooltip-show (row column lines selection)
   (company-pseudo-tooltip-hide)
   (unless lines (error "No text provided"))
 
     (move-to-column 0)
 
-    (let* ((lines (company-create-lines column lines selection))
+    (let* ((height (company-pseudo-tooltip-height))
+           (lines (company-create-lines column lines selection height))
            (nl (< (move-to-window-line row) row))
            (beg (point))
            (end (save-excursion
-                  (move-to-window-line (min (window-height)
-                                            (+ row company-tooltip-limit)))
+                  (move-to-window-line (+ row height))
                   (point)))
            (old-string (company-buffer-lines beg end))
            str)
       (overlay-put company-pseudo-tooltip-overlay 'company-nl nl)
       (overlay-put company-pseudo-tooltip-overlay 'company-before
                    (company-replacement-string old-string lines column nl))
+      (overlay-put company-pseudo-tooltip-overlay 'company-height height)
 
       (overlay-put company-pseudo-tooltip-overlay 'window (selected-window)))))
 
   (let* ((old-string (overlay-get company-pseudo-tooltip-overlay 'company-old))
          (column (overlay-get company-pseudo-tooltip-overlay 'company-column))
          (nl (overlay-get company-pseudo-tooltip-overlay 'company-nl))
-         (lines (company-create-lines column lines selection)))
+         (height (overlay-get company-pseudo-tooltip-overlay 'company-height))
+         (lines (company-create-lines column lines selection height)))
     (overlay-put company-pseudo-tooltip-overlay 'company-before
                  (company-replacement-string old-string lines column nl))))
 
   (case command
     ('pre-command (company-pseudo-tooltip-hide-temporarily))
     ('post-command
-     (unless (overlayp company-pseudo-tooltip-overlay)
+     (unless (and (overlayp company-pseudo-tooltip-overlay)
+                  (equal (overlay-get company-pseudo-tooltip-overlay
+                                      'company-height)
+                         (company-pseudo-tooltip-height)))
+       ;; Redraw needed.
        (company-pseudo-tooltip-show-at-point (- (point)
                                                 (length company-prefix))))
      (company-pseudo-tooltip-unhide))