1 ;; eclim.el --- an interface to the Eclipse IDE.
3 ;; Copyright (C) 2009 Tassilo Horn <tassilo@member.fsf.org>
5 ;; This program is free software: you can redistribute it and/or modify
6 ;; it under the terms of the GNU General Public License as published by
7 ;; the Free Software Foundation, either version 3 of the License, or
8 ;; (at your option) any later version.
10 ;; This program is distributed in the hope that it will be useful,
11 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ;; GNU General Public License for more details.
15 ;; You should have received a copy of the GNU General Public License
16 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ;; - Nikolaj Schumacher <bugs * nschum de>
24 ;; Conventions used in this file: Name internal variables and functions
25 ;; "eclim--<descriptive-name>", and name eclim command invocations
26 ;; "eclim/command-name", like eclim/project-list.
30 (eval-when-compile (require 'cl
))
35 "Interface to the Eclipse IDE."
38 (defun eclim-executable-find ()
40 (dolist (eclipse-root '("/Applications/eclipse" "/usr/lib/eclipse"
41 "/usr/local/lib/eclipse"))
43 (setq file
(expand-file-name "plugins" eclipse-root
)))
44 (setq file
(car (last (directory-files file t
"^org.eclim_"))))
45 (file-exists-p (setq file
(expand-file-name "bin/eclim" file
)))
48 (defcustom eclim-executable
49 (or (executable-find "eclim") (eclim-executable-find))
50 "Location of eclim executable."
54 (defcustom eclim-auto-save nil
55 "Determines whether to save the buffer when retrieving completions.
56 eclim can only complete correctly when the buffer has been
59 :type
'(choice (const :tag
"Off" nil
)
62 (defvar eclim--project-dir nil
)
63 (make-variable-buffer-local 'eclim--project-dir
)
65 (defvar eclim--project-name nil
)
66 (make-variable-buffer-local 'eclim--project-name
)
68 (defun eclim--buffer-lines ()
69 (goto-char (point-max))
71 (while (= 0 (forward-line -
1))
72 (push (buffer-substring-no-properties (line-beginning-position)
77 (defun eclim--error-buffer (text)
78 (let ((errbuf (get-buffer-create "*Eclim errors*")))
81 (setq buffer-read-only t
)
82 (display-buffer errbuf t
)))
84 (defun eclim--call-process (&rest args
)
85 (let ((coding-system-for-read 'utf-8
))
87 (if (= 0 (apply 'call-process eclim-executable nil t nil
91 (buffer-substring-no-properties
92 (point-min) (point-max)))
95 (defun eclim--project-dir ()
96 "Return this file's project root directory."
97 (or eclim--project-dir
98 (setq eclim--project-dir
101 (locate-dominating-file buffer-file-name
".project"))))))
103 (defun eclim--project-name ()
104 (or eclim--project-name
105 (setq eclim--project-name
106 (car (cddr (assoc (eclim--project-dir)
107 (eclim/project-list
)))))))
109 (defun eclim/project-list
()
110 (mapcar (lambda (line) (nreverse (split-string line
" *- *" nil
)))
111 (eclim--call-process "project_list")))
113 ;;** The minor mode and its keymap
115 (defvar eclim-mode-map
116 (let ((map (make-sparse-keymap)))
118 "The keymap used in `eclim-mode'.")
120 (define-minor-mode eclim-mode
121 "An interface to the Eclipse IDE."
127 ;; Set project dir and name.
129 (eclim--project-name))
130 (kill-local-variable 'eclim--project-dir
)
131 (kill-local-variable 'eclim--project-name
)))