]> rtime.felk.cvut.cz Git - sojka/company-mode.git/commitdiff
Extracted company--begin-new.
authorNikolaj Schumacher <git@nschum.de>
Fri, 17 Apr 2009 12:38:18 +0000 (14:38 +0200)
committerNikolaj Schumacher <git@nschum.de>
Sat, 18 Apr 2009 11:06:47 +0000 (13:06 +0200)
company.el

index 5c2b840a1aef53d4c6ad5977811a17f7c4156dbc..b190111cf34c3df501c6a7a0756fda87725d0096 100644 (file)
@@ -872,36 +872,37 @@ keymap during active completions (`company-active-map'):
       c)
      (t (company--continue-failed new-prefix)))))
 
+(defun company--begin-new ()
+  (let (prefix c)
+    (dolist (backend (if company-backend
+                         ;; prefer manual override
+                         (list company-backend)
+                       company-backends))
+      (setq prefix
+            (if (or (symbolp backend)
+                    (functionp backend))
+                (when (or (not (symbolp backend))
+                          (get backend 'company-init))
+                  (funcall backend 'prefix))
+              (company--multi-backend-adapter backend 'prefix)))
+      (when prefix
+        (when (and (stringp prefix)
+                   (>= (length prefix) company-minimum-prefix-length))
+          (setq company-backend backend
+                company-prefix prefix
+                c (company-calculate-candidates prefix))
+          ;; t means complete/unique.  We don't start, so no hooks.
+          (when (consp c)
+            (company-update-candidates c)
+            (run-hook-with-args 'company-completion-started-hook
+                                (company-explicit-action-p))
+            (company-call-frontends 'show)))
+        (return c)))))
+
 (defun company-begin ()
-  (when company-candidates
-    (setq company-candidates (company--continue)))
-  (when (and (not company-candidates)
-             (company--should-complete))
-    (let (prefix)
-      (dolist (backend (if company-backend
-                           ;; prefer manual override
-                           (list company-backend)
-                         company-backends))
-        (setq prefix
-              (if (or (symbolp backend)
-                      (functionp backend))
-                  (when (or (not (symbolp backend))
-                            (get backend 'company-init))
-                    (funcall backend 'prefix))
-                (company--multi-backend-adapter backend 'prefix)))
-        (when prefix
-          (when (and (stringp prefix)
-                     (>= (length prefix) company-minimum-prefix-length))
-            (setq company-backend backend
-                  company-prefix prefix)
-            (let ((c (company-calculate-candidates prefix)))
-              ;; t means complete/unique.  We don't start, so no hooks.
-              (when (consp c)
-                (company-update-candidates c)
-                (run-hook-with-args 'company-completion-started-hook
-                                    (company-explicit-action-p))
-                (company-call-frontends 'show))))
-          (return prefix)))))
+  (setq company-candidates
+        (or (and company-candidates (company--continue))
+            (and (company--should-complete) (company--begin-new))))
   (if company-candidates
       (progn
         (when (and company-end-of-buffer-workaround (eobp))