]> code.delx.au - gnu-emacs-elpa/commitdiff
Added semantic backend.
authorNikolaj Schumacher <git@nschum.de>
Sun, 15 Mar 2009 15:51:23 +0000 (16:51 +0100)
committerNikolaj Schumacher <git@nschum.de>
Fri, 20 Mar 2009 08:46:06 +0000 (09:46 +0100)
company-semantic.el [new file with mode: 0644]
company.el

diff --git a/company-semantic.el b/company-semantic.el
new file mode 100644 (file)
index 0000000..0b4906c
--- /dev/null
@@ -0,0 +1,24 @@
+(require 'company)
+(require 'semantic-ia)
+(eval-when-compile (require 'cl))
+
+(defvar company-semantic-context-regexp
+  "\\(->\\|\\.\\|\\_<\\)\\(\\(\\s_\\|\\sw\\)+\\_>\\=\\)")
+
+(defsubst company-semantic-completions (prefix)
+  (ignore-errors
+    (let ((completion-ignore-case nil)
+          (context (semantic-analyze-current-context)))
+      (all-completions prefix (semantic-ia-get-completions context (point))))))
+
+(defun company-semantic (command &optional arg &rest ignored)
+  (case command
+    ('prefix (and (memq major-mode '(c-mode c++-mode jde-mode java-mode))
+                  (not (company-in-string-or-comment))
+                  (or (company-grab company-semantic-context-regexp 2) "")))
+    ('candidates (or (company-semantic-completions arg)
+                     (mapcar 'semantic-tag-name
+                             (semantic-analyze-find-tags-by-prefix arg))))))
+
+(provide 'company-semantic)
+;;; company-semantic.el ends here
index 4a67cb53f313483a7add0897dd9bdbcd76caee52..b2a4582adbfd8bb30ae63ee34eba079ca1a8bac2 100644 (file)
@@ -94,7 +94,7 @@
                          (function :tag "custom function" nil))))
 
 (defcustom company-backends '(company-elisp company-nxml company-css
-                              company-ispell)
+                              company-semantic company-ispell)
   "*"
   :group 'company
   :type '(repeat (function :tag "function" nil)))