]> code.delx.au - gnu-emacs-elpa/commitdiff
Extracted company-set-selection macro.
authorNikolaj Schumacher <git@nschum.de>
Mon, 16 Mar 2009 11:48:28 +0000 (12:48 +0100)
committerNikolaj Schumacher <git@nschum.de>
Fri, 20 Mar 2009 11:50:10 +0000 (12:50 +0100)
company.el

index f9cae142b0e4ff4f6395c48116a71af2d58db19d..92e357a8f17432b1fce185303bbab6017226574f 100644 (file)
   (dolist (frontend company-frontends)
     (funcall frontend command)))
 
+(defsubst company-set-selection (selection)
+  (setq selection (max 0 (min (1- (length company-candidates)) selection)))
+  (unless (equal selection company-selection)
+    (setq company-selection selection
+          company-selection-changed t)
+    (company-call-frontends 'update)))
+
 (defsubst company-calculate-candidates (prefix)
   (or (setq company-candidates (cdr (assoc prefix company-candidates-cache)))
       (let ((len (length prefix))
 (defun company-select-next ()
   (interactive)
   (when (company-manual-begin)
-    (setq company-selection (min (1- (length company-candidates))
-                                 (1+ company-selection))
-          company-selection-changed t))
-  (company-call-frontends 'update))
+    (company-set-selection (1+ company-selection))))
 
 (defun company-select-previous ()
   (interactive)
   (when (company-manual-begin)
-    (setq company-selection (max 0 (1- company-selection))
-          company-selection-changed t))
-  (company-call-frontends 'update))
+    (company-set-selection (1- company-selection))))
 
 (defun company-complete-selection ()
   (interactive)