Added some infrastructure
[eclim-emacs.git] / eclim.el
bloba44b54f94abbce67bd9f83acd3e21b5a5037e70e
2 ;;* Eclim
4 (eval-when-compile (require 'cl))
6 ;;** Basics
8 (defgroup eclim nil
9 "Interface to the Eclipse IDE."
10 :group 'tools)
12 (defun eclim-executable-find ()
13 (let (file)
14 (dolist (eclipse-root '("/Applications/eclipse" "/usr/lib/eclipse"
15 "/usr/local/lib/eclipse"))
16 (and (file-exists-p (setq file (expand-file-name "plugins" eclipse-root)))
17 (setq file (car (last (directory-files file t "^org.eclim_"))))
18 (file-exists-p (setq file (expand-file-name "bin/eclim" file)))
19 (return file)))))
21 (defcustom eclim-executable
22 (or (executable-find "eclim") (eclim-executable-find))
23 "Location of eclim executable."
24 :group 'eclim
25 :type 'file)
27 (defcustom eclim-auto-save nil
28 "Determines whether to save the buffer when retrieving completions.
29 eclim can only complete correctly when the buffer has been
30 saved."
31 :group 'eclim
32 :type '(choice (const :tag "Off" nil)
33 (const :tag "On" t)))
35 (defvar eclim--project-dir nil)
36 (make-variable-buffer-local 'eclim--project-dir)
38 (defvar eclim--project-name nil)
39 (make-variable-buffer-local 'eclim--project-name)
41 (defvar eclim--doc nil)
42 (make-variable-buffer-local 'eclim--doc)
44 (defun eclim--buffer-lines ()
45 (goto-char (point-max))
46 (let (lines)
47 (while (= 0 (forward-line -1))
48 (push (buffer-substring-no-properties (line-beginning-position)
49 (line-end-position))
50 lines))
51 lines))
53 (defun eclim--call-process (&rest args)
54 (let ((coding-system-for-read 'utf-8))
55 (with-temp-buffer
56 (if (= 0 (apply 'call-process eclim-executable nil t nil
57 "-command" args))
58 (eclim--buffer-lines)
59 ;; TODO: A more meaningful error message
60 (message "Eclim command failed")
61 nil))))
63 (defun eclim--project-dir ()
64 "Return this file's project root directory."
65 (or eclim--project-dir
66 (setq eclim--project-dir
67 (directory-file-name
68 (expand-file-name
69 (locate-dominating-file buffer-file-name ".project"))))))
71 (defun eclim--project-name ()
72 (or eclim--project-name
73 (setq eclim--project-name
74 (car (cddr (assoc (eclim--project-dir)
75 (eclim/project-list)))))))
77 (defun eclim/project-list ()
78 (mapcar (lambda (line) (nreverse (split-string line " *- *" nil)))
79 (eclim--call-process "project_list")))
81 (define-minor-mode eclim-mode
82 "An interface to the Eclipse IDE."
83 nil
84 "Eclim"
85 (eclim--project-name)