]> rtime.felk.cvut.cz Git - sojka/company-mode.git/commitdiff
Added count of hidden items to tooltip.
authorNikolaj Schumacher <git@nschum.de>
Sat, 14 Mar 2009 17:36:23 +0000 (18:36 +0100)
committerNikolaj Schumacher <git@nschum.de>
Fri, 20 Mar 2009 08:46:05 +0000 (09:46 +0100)
company.el

index dbdfba247d9e780bf326f8a4eb7e13e5db50291c..5f5733719de234418630f254945808ad67c9206c 100644 (file)
 (defvar company-tooltip-offset 0)
 (make-variable-buffer-local 'company-tooltip-offset)
 
+(defun company-pseudo-tooltip-update-offset (selection num-lines limit)
+
+  (decf limit 2)
+  (setq company-tooltip-offset
+        (max (min selection company-tooltip-offset)
+             (- selection -1 limit)))
+
+  (when (<= company-tooltip-offset 1)
+    (incf limit)
+    (setq company-tooltip-offset 0))
+
+  (when (>= company-tooltip-offset (- num-lines limit 1))
+    (incf limit)
+    (when (= selection (1- num-lines))
+      (setq company-tooltip-offset (max (1- company-tooltip-offset) 0))))
+
+  limit)
+
 ;;; propertize
 
 (defun company-fill-propertize (line width selected)
   (unless lines (error "No text provided"))
   (save-excursion
 
-    ;; Scroll to offset.
-    (setq company-tooltip-offset
-          (max (min selection company-tooltip-offset)
-               (- selection -1 company-tooltip-limit)))
+    (let ((limit (max company-tooltip-limit 3))
+          (len (length lines))
+          width
+          lines-copy
+          previous
+          remainder
+          new)
+
+      ;; Scroll to offset.
+      (setq limit (company-pseudo-tooltip-update-offset selection len limit))
 
-    (setq lines (nthcdr company-tooltip-offset lines))
-    (decf selection company-tooltip-offset)
+      (when (> company-tooltip-offset 0)
+        (setq previous (format "...(%d)" company-tooltip-offset)))
+
+      (setq remainder (- len limit company-tooltip-offset)
+            remainder (when (> remainder 0)
+                        (setq remainder (format "...(%d)" remainder))))
+
+      (decf selection company-tooltip-offset)
+      (setq width (min (length previous) (length remainder))
+            lines (nthcdr company-tooltip-offset lines)
+            len (min limit (length lines))
+            lines-copy lines)
 
-    (let ((width 0)
-          (lines-copy lines)
-          (len (min company-tooltip-limit (length lines)))
-          new)
       (dotimes (i len)
         (setq width (max (length (pop lines-copy)) width)))
       (setq width (min width (- (window-width) column)))
+
+      (when previous
+        (push (propertize (company-safe-substring previous 0 width)
+                          'face 'company-tooltip)
+              new))
+
       (dotimes (i len)
         (push (company-fill-propertize (company-reformat (pop lines))
                                        width (equal i selection))
               new))
 
+      (when remainder
+        (push (propertize (company-safe-substring remainder 0 width)
+                          'face 'company-tooltip)
+              new))
+
       (setq lines (nreverse new)))
 
     (move-to-column 0)