]> code.delx.au - gnu-emacs-elpa/commitdiff
Moved back-ends to separate files.
authorNikolaj Schumacher <git@nschum.de>
Wed, 11 Mar 2009 16:07:40 +0000 (17:07 +0100)
committerNikolaj Schumacher <git@nschum.de>
Fri, 20 Mar 2009 08:46:03 +0000 (09:46 +0100)
company-elisp.el [new file with mode: 0644]
company.el

diff --git a/company-elisp.el b/company-elisp.el
new file mode 100644 (file)
index 0000000..b915423
--- /dev/null
@@ -0,0 +1,23 @@
+(require 'company)
+(eval-when-compile (require 'cl))
+
+(defvar company-lisp-symbol-regexp
+  "\\_<\\(\\sw\\|\\s_\\)+\\_>\\=")
+
+(defun company-grab-lisp-symbol ()
+  (let ((prefix (or (company-grab company-lisp-symbol-regexp) "")))
+    (unless (and (company-in-string-or-comment (- (point) (length prefix)))
+                 (/= (char-before (- (point) (length prefix))) ?`))
+      prefix)))
+
+(defun company-elisp (command &optional arg &rest ignored)
+  (case command
+    ('prefix (and (eq major-mode 'emacs-lisp-mode)
+                  (company-grab-lisp-symbol)))
+    ('candidates (let ((completion-ignore-case nil))
+                   (all-completions arg obarray
+                                    (lambda (symbol) (or (boundp symbol)
+                                                         (fboundp symbol))))))))
+
+(provide 'company-elisp)
+;;; company-elisp.el ends here
index 6ec1d4970371b8214dba66e9b5c115ae05f91e56..af0f63a878d0ce6a86d71b93929968a1551e02ec 100644 (file)
@@ -93,7 +93,7 @@
                                 company-preview-if-just-one-frontend)
                          (function :tag "custom function" nil))))
 
                                 company-preview-if-just-one-frontend)
                          (function :tag "custom function" nil))))
 
-(defcustom company-backends '(company-elisp-completion)
+(defcustom company-backends '(company-elisp)
   "*"
   :group 'company
   :type '(repeat (function :tag "function" nil)))
   "*"
   :group 'company
   :type '(repeat (function :tag "function" nil)))
   (let ((pos (syntax-ppss)))
     (or (nth 3 pos) (nth 4 pos) (nth 7 pos))))
 
   (let ((pos (syntax-ppss)))
     (or (nth 3 pos) (nth 4 pos) (nth 7 pos))))
 
-;;; elisp
-
-(defvar company-lisp-symbol-regexp
-  "\\_<\\(\\sw\\|\\s_\\)+\\_>\\=")
-
-(defun company-grab-lisp-symbol ()
-  (let ((prefix (or (company-grab company-lisp-symbol-regexp) "")))
-    (unless (and (company-in-string-or-comment (- (point) (length prefix)))
-                 (/= (char-before (- (point) (length prefix))) ?`))
-      prefix)))
-
-(defun company-elisp-completion (command &optional arg &rest ignored)
-  (case command
-    ('prefix (and (eq major-mode 'emacs-lisp-mode)
-                  (company-grab-lisp-symbol)))
-    ('candidates (let ((completion-ignore-case nil))
-                   (all-completions arg obarray
-                                    (lambda (symbol) (or (boundp symbol)
-                                                         (fboundp symbol))))))))
-
 ;;; completion mechanism ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 (defvar company-backend nil)
 ;;; completion mechanism ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 (defvar company-backend nil)
 (defvar company-point nil)
 (make-variable-buffer-local 'company-point)
 
 (defvar company-point nil)
 (make-variable-buffer-local 'company-point)
 
+(defvar company-disabled-backends nil)
+
 (defsubst company-strip-prefix (str)
   (substring str (length company-prefix)))
 
 (defsubst company-strip-prefix (str)
   (substring str (length company-prefix)))
 
       (let ((completion-ignore-case nil) ;; TODO: make this optional
             prefix)
         (dolist (backend company-backends)
       (let ((completion-ignore-case nil) ;; TODO: make this optional
             prefix)
         (dolist (backend company-backends)
-          (when (setq prefix (funcall backend 'prefix))
-            (when (company-should-complete prefix)
-              (setq company-backend backend
-                    company-prefix prefix
-                    company-candidates
-                    (funcall company-backend 'candidates prefix)
-                    company-common (try-completion prefix company-candidates)
-                    company-selection 0
-                    company-point (point))
-              (unless (funcall company-backend 'sorted)
-                (setq company-candidates (sort company-candidates 'string<)))
-              (company-call-frontends 'update))
-            (return prefix)))
+          (unless (fboundp backend)
+            (ignore-errors (require backend nil t)))
+          (if (fboundp backend)
+              (when (setq prefix (funcall backend 'prefix))
+                (when (company-should-complete prefix)
+                  (setq company-backend backend
+                        company-prefix prefix
+                        company-candidates
+                        (funcall company-backend 'candidates prefix)
+                        company-common
+                        (try-completion prefix company-candidates)
+                        company-selection 0
+                        company-point (point))
+                  (unless (funcall company-backend 'sorted)
+                    (setq company-candidates
+                          (sort company-candidates 'string<)))
+                  (company-call-frontends 'update))
+                (return prefix))
+            (unless (memq backend company-disabled-backends)
+              (push backend company-disabled-backends)
+              (message "Company back-end '%s' could not be initialized"
+                       backend))))
         (unless (and company-candidates
                      (not (eq t company-common)))
           (company-cancel)))))
         (unless (and company-candidates
                      (not (eq t company-common)))
           (company-cancel)))))