]> code.delx.au - gnu-emacs-elpa/blobdiff - packages/company/company-eclim.el
Sync with yasnippet/master
[gnu-emacs-elpa] / packages / company / company-eclim.el
index b9ac24207f173d8bf731aa7ce332d721accd1528..70db7c31b10c52c014323b2224fb7be014e51a27 100644 (file)
@@ -1,4 +1,4 @@
-;;; company-eclim.el --- A company-mode completion back-end for eclim.
+;;; company-eclim.el --- company-mode completion back-end for Eclim
 
 ;; Copyright (C) 2009, 2011, 2013  Free Software Foundation, Inc.
 
 
 ;; Copyright (C) 2009, 2011, 2013  Free Software Foundation, Inc.
 
 (require 'company-template)
 (eval-when-compile (require 'cl))
 
 (require 'company-template)
 (eval-when-compile (require 'cl))
 
+(defgroup company-eclim nil
+  "Completion back-end for Eclim."
+  :group 'company)
+
 (defun company-eclim-executable-find ()
   (let (file)
     (dolist (eclipse-root '("/Applications/eclipse" "/usr/lib/eclipse"
 (defun company-eclim-executable-find ()
   (let (file)
     (dolist (eclipse-root '("/Applications/eclipse" "/usr/lib/eclipse"
 (defcustom company-eclim-executable
   (or (executable-find "eclim") (company-eclim-executable-find))
   "Location of eclim executable."
 (defcustom company-eclim-executable
   (or (executable-find "eclim") (company-eclim-executable-find))
   "Location of eclim executable."
-  :group 'company
   :type 'file)
 
 (defcustom company-eclim-auto-save t
   "Determines whether to save the buffer when retrieving completions.
 eclim can only complete correctly when the buffer has been saved."
   :type 'file)
 
 (defcustom company-eclim-auto-save t
   "Determines whether to save the buffer when retrieving completions.
 eclim can only complete correctly when the buffer has been saved."
-  :group 'company
   :type '(choice (const :tag "Off" nil)
                  (const :tag "On" t)))
 
   :type '(choice (const :tag "Off" nil)
                  (const :tag "On" t)))
 
@@ -67,6 +69,9 @@ eclim can only complete correctly when the buffer has been saved."
 (defvar company-eclim--doc nil)
 (make-variable-buffer-local 'company-eclim--doc)
 
 (defvar company-eclim--doc nil)
 (make-variable-buffer-local 'company-eclim--doc)
 
+(declare-function json-read "json")
+(defvar json-array-type)
+
 (defun company-eclim--call-process (&rest args)
   (let ((coding-system-for-read 'utf-8)
         res)
 (defun company-eclim--call-process (&rest args)
   (let ((coding-system-for-read 'utf-8)
         res)
@@ -105,8 +110,7 @@ eclim can only complete correctly when the buffer has been saved."
 (defun company-eclim--candidates (prefix)
   (interactive "d")
   (let ((project-file (file-relative-name buffer-file-name
 (defun company-eclim--candidates (prefix)
   (interactive "d")
   (let ((project-file (file-relative-name buffer-file-name
-                                          (company-eclim--project-dir)))
-        (project-name (company-eclim--project-name)))
+                                          (company-eclim--project-dir))))
     (when company-eclim-auto-save
       (when (buffer-modified-p)
         (basic-save-buffer))
     (when company-eclim-auto-save
       (when (buffer-modified-p)
         (basic-save-buffer))
@@ -140,21 +144,16 @@ eclim can only complete correctly when the buffer has been saved."
 (defun company-eclim--meta (candidate)
   (gethash candidate company-eclim--doc))
 
 (defun company-eclim--meta (candidate)
   (gethash candidate company-eclim--doc))
 
-(defun company-eclim--templatify (call)
-  (let* ((end (point))
-         (beg (- (point) (length call)))
-         (templ (company-template-declare-template beg end)))
-    (save-excursion
-      (goto-char beg)
-      (while (re-search-forward "\\([(,] ?\\)\\([^ ]+ \\)\\([^ ,)]*\\)" end t)
-        (let ((name (match-string 3)))
-          (replace-match "\\1" t)
-          (decf end (length (match-string 2)))
-          (company-template-add-field templ (point) name))))
-    (company-template-move-to-first templ)))
+(defun company-eclim--prefix ()
+  (let ((prefix (company-grab-symbol)))
+    (when prefix
+      ;; Completion candidates for annotations don't include '@'.
+      (when (eq ?@ (string-to-char prefix))
+        (setq prefix (substring prefix 1)))
+      prefix)))
 
 (defun company-eclim (command &optional arg &rest ignored)
 
 (defun company-eclim (command &optional arg &rest ignored)
-  "`company-mode' completion back-end for Eclim.
+  "`company-mode' completion back-end for Eclim.
 Eclim provides access to Eclipse Java IDE features for other editors.
 
 Eclim version 1.7.13 or newer (?) is required.
 Eclim provides access to Eclipse Java IDE features for other editors.
 
 Eclim version 1.7.13 or newer (?) is required.
@@ -169,7 +168,7 @@ Completions only work correctly when the buffer has been saved.
                  company-eclim-executable
                  (company-eclim--project-name)
                  (not (company-in-string-or-comment))
                  company-eclim-executable
                  (company-eclim--project-name)
                  (not (company-in-string-or-comment))
-                 (or (company-grab-symbol) 'stop)))
+                 (or (company-eclim--prefix) 'stop)))
     (candidates (company-eclim--candidates arg))
     (meta (company-eclim--meta arg))
     ;; because "" doesn't return everything
     (candidates (company-eclim--candidates arg))
     (meta (company-eclim--meta arg))
     ;; because "" doesn't return everything
@@ -177,7 +176,7 @@ Completions only work correctly when the buffer has been saved.
     (crop (when (string-match "(" arg)
             (substring arg 0 (match-beginning 0))))
     (post-completion (when (string-match "([^)]" arg)
     (crop (when (string-match "(" arg)
             (substring arg 0 (match-beginning 0))))
     (post-completion (when (string-match "([^)]" arg)
-                       (company-eclim--templatify arg)))))
+                       (company-template-c-like-templatify arg)))))
 
 (provide 'company-eclim)
 ;;; company-eclim.el ends here
 
 (provide 'company-eclim)
 ;;; company-eclim.el ends here