Permalink
Browse files

Merge branch 'json'

  • Loading branch information...
2 parents b85949c + 99202c8 commit 74d67e11c6bb67f66cadcb4062cc69dba1b28aae @fred-o fred-o committed Jul 10, 2012
Showing with 181 additions and 197 deletions.
  1. +2 −2 ac-emacs-eclim-source.el
  2. +48 −48 company-emacs-eclim.el
  3. +34 −43 eclim-java.el
  4. +35 −35 eclim-problems.el
  5. +30 −35 eclim-project.el
  6. +32 −34 eclim.el
View
4 ac-emacs-eclim-source.el
@@ -43,8 +43,8 @@
(defun ac-emacs-eclim-candidates ()
(with-no-warnings
- (loop for c in (eclim/java-complete)
- collect (nth 2 c))))
+ (mapcar (lambda (c) (assoc-default 'info c))
+ (eclim/java-complete))))
(defun ac-emacs-eclim-available ()
(eclim--accepted-p (buffer-file-name)))
View
96 company-emacs-eclim.el
@@ -23,7 +23,7 @@
;; "eclim--<descriptive-name>", and name eclim command invocations
;; "eclim/command-name", like eclim/project-list.
;;; Description
-;;
+;;
;; company-emacs-eclim.el -- a company-mode backend that replaces company-eclim
;;
;; To activate this backend, replace company-eclim with
@@ -58,21 +58,21 @@
"If we are lookup at a list of method call completions, check
if we have already typed part of this call."
(cond ((every (lambda (c) (string= "f" (eclim--completion-candidate-type c))) candidates)
- ;; When completing a method call that have alread been completed
- ;; up to the 'method(' point, eclim still reports the
- ;; completions as 'method(arg1, arg2, ...)', which is not what
- ;; company-mode expects.
- (let ((common (try-completion "" (mapcar 'eclim--completion-candidate-doc candidates))))
- (save-excursion
- (if (search-backward common (- (point) (length common)) t)
- (mapcar (lambda (c)
- (list
- (eclim--completion-candidate-type c)
- (eclim--completion-candidate-class c)
- (substring (eclim--completion-candidate-doc c) (length common))))
- candidates)
- candidates))))
- (t candidates)))
+ ;; When completing a method call that have alread been completed
+ ;; up to the 'method(' point, eclim still reports the
+ ;; completions as 'method(arg1, arg2, ...)', which is not what
+ ;; company-mode expects.
+ (let ((common (try-completion "" (mapcar 'eclim--completion-candidate-doc candidates))))
+ (save-excursion
+ (if (search-backward common (- (point) (length common)) t)
+ (mapcar (lambda (c)
+ (list
+ (eclim--completion-candidate-type c)
+ (eclim--completion-candidate-class c)
+ (substring (eclim--completion-candidate-doc c) (length common))))
+ candidates)
+ candidates))))
+ (t candidates)))
(defun cee--candidates (prefix)
"Calls eclim to get a list of matching completion candidates."
@@ -132,7 +132,7 @@ COMPANY-POINT - 1."
(let ((doc (eclim--completion-candidate-doc candidate)))
(if (or (string-match "\\(.*\\)(\\(.*\\))" doc)
(string-match "\\(\\)\\(.*\\))" doc))
- (mapcar (lambda (e) (split-string e " "))
+ (mapcar (lambda (e) (split-string e " "))
(split-string (match-string 2 doc) ", " t)))))
(defun cee--join-list (lst glue)
@@ -148,13 +148,13 @@ inserted between each element."
"Displays/inserts an argument list at point, using yasnippet if
available."
(flet ((args-to-string (arg-list)
- (apply 'concat
- (append
+ (apply 'concat
+ (append
(when start-delim (list start-delim))
(cee--join-list arg-list glue)
(when end-delim (list end-delim))))))
(if (and eclim-use-yasnippet (featurep 'yasnippet))
- (yas/expand-snippet (args-to-string
+ (yas/expand-snippet (args-to-string
(loop for arg in args
for i from 1
collect (concat "${" (int-to-string i) ":" arg "}"))))
@@ -165,36 +165,36 @@ available."
(defun cee--completion-finished (arg)
"Post-completion hook after running company-mode completions."
(let* ((candidate (cee--lookup-candidate arg))
- (type (eclim--completion-candidate-type candidate)))
+ (type (eclim--completion-candidate-type candidate)))
(when candidate
(if (string= "c" type)
- ;; If this is a class, first check if this is a completion of generic argumends
- (let ((gen-args (cee--generic-args candidate)))
- (if gen-args
- (progn
- (delete-region company-point (point))
- (cee--show-arg-list nil gen-args ", " ">"))
- (progn
- ;; otherwise, remove the doc string and insert an import statement
- (cee--delete-backward " - ")
- (eclim--java-organize-imports
- (eclim/execute-command "java_import_order" "-p")
- (list
- (concat (eclim--completion-candidate-package candidate) "."
- (eclim--completion-candidate-class candidate)))))))
- ;; Otherwise, check if this is a method call
- (if (string= "f" type)
- (let ((call-args (cee--method-call candidate)))
- (push-mark (point) t)
- (goto-char (search-backward "("))
- (cee--show-arg-list "("
- (mapcar (lambda (c) (concat (first c) " " (second c))) call-args)
- ", " ")")
- (save-excursion
- (delete-region (1- (search-forward "(")) (mark t)))
- (pop-mark))
- ;; Otherwise, just delete the doc string
- (cee--delete-backward " : "))))))
+ ;; If this is a class, first check if this is a completion of generic argumends
+ (let ((gen-args (cee--generic-args candidate)))
+ (if gen-args
+ (progn
+ (delete-region company-point (point))
+ (cee--show-arg-list nil gen-args ", " ">"))
+ (progn
+ ;; otherwise, remove the doc string and insert an import statement
+ (cee--delete-backward " - ")
+ (eclim--java-organize-imports
+ (eclim/execute-command "java_import_order" "-p")
+ (list
+ (concat (eclim--completion-candidate-package candidate) "."
+ (eclim--completion-candidate-class candidate)))))))
+ ;; Otherwise, check if this is a method call
+ (if (string= "f" type)
+ (let ((call-args (cee--method-call candidate)))
+ (push-mark (point) t)
+ (goto-char (search-backward "("))
+ (cee--show-arg-list "("
+ (mapcar (lambda (c) (concat (first c) " " (second c))) call-args)
+ ", " ")")
+ (save-excursion
+ (delete-region (1- (search-forward "(")) (mark t)))
+ (pop-mark))
+ ;; Otherwise, just delete the doc string
+ (cee--delete-backward " : "))))))
(add-hook 'company-completion-finished-hook
'cee--completion-finished)
View
77 eclim-java.el
@@ -76,9 +76,7 @@ the current buffer is contained within this list"
"references"))
(defun eclim/java-complete ()
- (mapcar (lambda (line)
- (split-string line "|" nil))
- (eclim/execute-command "java_complete" "-p" "-f" "-e" ("-l" "standard") "-o")))
+ (eclim/execute-command "java_complete" "-p" "-f" "-e" ("-l" "standard") "-o"))
(defun eclim/java-src-update (&optional save-others)
"If `eclim-auto-save' is non-nil, save the current java
@@ -121,15 +119,15 @@ has been found."
(defun eclim--completion-candidate-type (candidate)
"Returns the type of a candidate."
- (first candidate))
+ (assoc-default 'type candidate))
(defun eclim--completion-candidate-class (candidate)
"Returns the class name of a candidate."
- (second candidate))
+ (assoc-default 'info candidate))
(defun eclim--completion-candidate-doc (candidate)
"Returns the documentation for a candidate."
- (third candidate))
+ (assoc-default 'menu candidate))
(defun eclim--completion-candidate-package (candidate)
"Returns the package name of a candidate."
@@ -178,15 +176,14 @@ has been found."
(interactive)
(let* ((i (eclim--java-identifier-at-point t))
(n (read-string (concat "Rename " (cdr i) " to: ") (cdr i))))
- (eclim/with-results files ("java_refactor_rename" "-p" "-e" "-f" ("-n" n)
- ("-o" (car i)) ("-l" (length (cdr i))))
- (when (not (string= "files:" (first files)))
- (error (first files)))
+ (eclim/with-results res ("java_refactor_rename" "-p" "-e" "-f" ("-n" n)
+ ("-o" (car i)) ("-l" (length (cdr i))))
+ (when (stringp res) (error res))
(when (not (file-exists-p (buffer-file-name)))
(kill-buffer)
(eclim-java-find-type n))
(let ((current (current-buffer)))
- (loop for file in files
+ (loop for file in (mapcar (lambda (x) (assoc-default 'file x)) res)
for buf = (get-file-buffer (file-name-nondirectory file))
when buf do (progn (switch-to-buffer buf)
(revert-buffer t t t)))
@@ -199,9 +196,7 @@ has been found."
(eclim--byte-offset)
(eclim--current-encoding)))
(let ((top-node (eclim--java-insert-file-path-for-hierarchy-nodes
- (json-read-from-string
- (replace-regexp-in-string
- "'" "\"" (car (eclim/java-hierarchy project file offset encoding)))))))
+ (eclim/java-hierarchy project file offset encoding))))
(pop-to-buffer "*eclim: hierarchy*" t)
(special-mode)
(let ((buffer-read-only nil))
@@ -216,7 +211,7 @@ has been found."
;that isn't part of the project which then breaks future
;*-find-type calls and isn't what we want here anyway.
(eclim/with-results hits ("java_search" ("-p" (cdr (assoc 'qualified node))) ("-t" "type") ("-x" "declarations") ("-s" "workspace"))
- (add-to-list 'node `(file-path . ,(first (split-string (first hits) "|"))))
+ (add-to-list 'node `(file-path . ,(assoc-default 'message (elt hits 0))))
(let ((children (cdr (assoc 'children node))))
(loop for child across children do
(eclim--java-insert-file-path-for-hierarchy-nodes child)))
@@ -239,25 +234,19 @@ has been found."
(loop for child across children do
(eclim--java-insert-hierarchy-node project child (+ level 1)))))
-(defun eclim--java-split-search-results (res)
- (mapcar (lambda (l) (split-string l "|" nil)) res))
-
(defun eclim-java-find-declaration ()
"Find and display the declaration of the java identifier at point."
(interactive)
(let ((i (eclim--java-identifier-at-point t)))
(eclim/with-results hits ("java_search" "-n" "-f" ("-o" (car i)) ("-l" (length (cdr i))) ("-x" "declaration"))
- (let ((r (eclim--java-split-search-results hits)))
- (if (= (length r) 1)
- (eclim--visit-declaration (car r))
- (eclim--find-display-results (cdr i) r))))))
+ (eclim--find-display-results (cdr i) hits t))))
(defun eclim-java-find-references ()
"Find and display references for the java identifier at point."
(interactive)
(let ((i (eclim--java-identifier-at-point t)))
(eclim/with-results hits ("java_search" "-n" "-f" ("-o" (car i)) ("-l" (length (cdr i))) ("-x" "references"))
- (eclim--find-display-results (cdr i) (eclim--java-split-search-results hits)))))
+ (eclim--find-display-results (cdr i) hits))))
(defun eclim-java-find-type (type-name)
"Searches the project for a given class. The TYPE-NAME is the pattern, which will be used for the search."
@@ -274,7 +263,7 @@ has been found."
(eclim--completing-read "Type: " eclim--java-search-types)
(read-string "Pattern: ")))
(eclim/with-results hits ("java_search" ("-p" pattern) ("-t" type) ("-x" context) ("-s" scope))
- (eclim--find-display-results pattern (eclim--java-split-search-results hits) open-single-file)))
+ (eclim--find-display-results pattern hits open-single-file)))
(defun eclim--java-identifier-at-point (&optional full position)
"Returns a cons cell (BEG . IDENTIFIER) where BEG is the start
@@ -385,38 +374,40 @@ a java type that can be imported."
user if necessary."
(interactive)
(eclim/with-results imports-order ("java_import_order" "-p")
- (loop for unused across
- (json-read-from-string
- (replace-regexp-in-string "'" "\"" (first (eclim/execute-command "java_import_missing" "-p" "-f"))))
+ (loop for unused across (eclim/execute-command "java_import_missing" "-p" "-f")
do (let* ((candidates (append (cdr (assoc 'imports unused)) nil))
- (type (cdr (assoc 'type unused)))
- (import (if (= 1 (length candidates))
- (car candidates)
- (eclim--completing-read (concat "Missing type '" type "'")
- candidates))))
- (when import
- (eclim--java-organize-imports imports-order
- (list (if (string-endswith-p import type)
- import
- (concat import "." type)))))))))
+ (type (cdr (assoc 'type unused)))
+ (import (if (= 1 (length candidates))
+ (car candidates)
+ (eclim--completing-read (concat "Missing type '" type "'")
+ candidates))))
+ (when import
+ (eclim--java-organize-imports imports-order
+ (list (if (string-endswith-p import type)
+ import
+ (concat import "." type)))))))))
(defun eclim-java-remove-unused-imports ()
"Remove usused import from the current java source file."
(interactive)
(eclim/with-results unused ("java_imports_unused" "-p" "-f")
- (let ((imports-order (eclim/execute-command "java_import_order" "-p")))
- (eclim--java-organize-imports imports-order nil unused))))
+ (print unused)
+ (let ((imports-order (eclim/execute-command "java_import_order" "-p")))
+ (eclim--java-organize-imports imports-order nil (append unused '())))))
(defun eclim-java-implement ()
"Lets the user select from a list of methods to
implemnt/override, then inserts a skeleton for the chosen
method."
(interactive)
(eclim/with-results response ("java_impl" "-p" "-f" "-o")
- (let* ((methods
- (remove-if (lambda (element) (string-match "//" element))
- (remove-if-not (lambda (element) (string-match "(.*)" element))
- response)))
+ (let* ((methods
+ (mapcar (lambda (x) (replace-regexp-in-string " *\n *" " " x))
+ (mapcar (lambda (x) (assoc-default 'signature x))
+ (remove-if-not (lambda (x) (eq :json-false (assoc-default 'implemented x)))
+ (apply 'append
+ (mapcar (lambda (x) (append (assoc-default 'methods x) nil))
+ (assoc-default 'superTypes response)))))))
(start (point)))
(insert
"@Override\n"
View
70 eclim-problems.el
@@ -113,17 +113,16 @@
(eclim--call-process "problems"
"-p" eclim--problems-project))))
-(defun eclim--problem-file (p) (first p))
-(defun eclim--problem-pos (p) (second p))
-(defun eclim--problem-description (p) (third p))
-(defun eclim--problem-type (p) (fourth p))
+;; (defun eclim--problem-file (p) (assoc-default 'filename p))
+;; (defun eclim--problem-pos (p) (second p))
+;; (defun eclim--problem-description (p) (assoc-default 'message p))
+;; (defun eclim--problem-type (p) (fourth p))
(defun eclim--problem-goto-pos (p)
- (let ((pos (split-string (eclim--problem-pos p) " col ")))
- (goto-char (point-min))
- (forward-line (1- (string-to-int (first pos))))
- (dotimes (i (1- (string-to-int (second pos))))
- (forward-char))))
+ (goto-char (point-min))
+ (forward-line (1- (assoc-default 'line p)))
+ (dotimes (i (1- (assoc-default 'column p)))
+ (forward-char)))
(defun eclim--problems-apply-filter (f)
(setq eclim--problems-filter f)
@@ -154,11 +153,11 @@
(end (+ (car id) (length (cdr id)))))
(let ((highlight (make-overlay start end (current-buffer) t t)))
(overlay-put highlight 'face
- (if (string= (eclim--problem-type problem) "e")
- 'eclim-problems-highlight-error-face
- 'eclim-problems-highlight-warning-face))
+ (if (eq t (assoc-default 'warning problem))
+ 'eclim-problems-highlight-warning-face
+ 'eclim-problems-highlight-error-face))
(overlay-put highlight 'category 'eclim-problem)
- (overlay-put highlight 'kbd-help (eclim--problem-description problem))))))
+ (overlay-put highlight 'kbd-help (assoc-default 'message problem))))))
(defun eclim--problems-clear-highlights ()
(remove-overlays nil nil 'category 'eclim-problem))
@@ -176,39 +175,37 @@
(interactive)
(when (eclim--file-managed-p)
(eclim--problems-clear-highlights)
- (loop for problem in (remove-if-not (lambda (p) (string= (eclim--problem-file p) (buffer-file-name))) eclim--problems-list)
+ (loop for problem across (remove-if-not (lambda (p) (string= (assoc-default 'filename p) (buffer-file-name))) eclim--problems-list)
do (eclim--problems-insert-highlight problem))))
(defun eclim-problems-open-current ()
(interactive)
- (let* ((p (nth (1- (line-number-at-pos)) (eclim--problems-filtered))))
- (find-file-other-window (eclim--problem-file p))
+ (let* ((p (aref (eclim--problems-filtered) (1- (line-number-at-pos)))))
+ (find-file-other-window (assoc-default 'filename p))
(eclim--problem-goto-pos p)))
(defun eclim-problems-buffer-refresh ()
"Refresh the problem list and draw it on screen."
(interactive)
(message "refreshing... %s " (current-buffer))
(eclim/with-results-async res ("problems" ("-p" eclim--problems-project))
- (setq eclim--problems-list
- (remove-if-not (lambda (l) (= (length l) 4)) ;; for now, ignore multiline errors
- (mapcar (lambda (line) (split-string line "|" nil)) res)))
+ (setq eclim--problems-list res)
(eclim--problems-buffer-redisplay)
(if (not (minibuffer-window-active-p (minibuffer-window)))
(message "Eclim reports %d errors, %d warnings."
- (length (remove-if-not (lambda (p) (string-equal "e" (eclim--problem-type p))) eclim--problems-list))
- (length (remove-if-not (lambda (p) (string-equal "w" (eclim--problem-type p))) eclim--problems-list))))))
+ (length (remove-if-not (lambda (p) (not (eq t (assoc-default 'warning p)))) eclim--problems-list))
+ (length (remove-if-not (lambda (p) (eq t (assoc-default 'warning p))) eclim--problems-list))))))
(defun eclim--problems-cleanup-filename (filename)
- (let ((x (file-name-nondirectory (eclim--problem-file problem))))
+ (let ((x (file-name-nondirectory (assoc-default 'filename problem))))
(if eclim-problems-show-file-extension x (file-name-sans-extension x))))
(defun eclim--problems-filecol-size ()
(if eclim-problems-resize-file-column
(min 40
(apply #'max 0
(mapcar (lambda (problem)
- (length (eclim--problems-cleanup-filename (eclim--problem-file problem))))
+ (length (eclim--problems-cleanup-filename (assoc-default 'filename problem))))
(eclim--problems-filtered))))
40))
@@ -236,8 +233,8 @@
(line-number (line-number-at-pos))
(filecol-size (eclim--problems-filecol-size)))
(erase-buffer)
- (dolist (problem (eclim--problems-filtered))
- (eclim--insert-problem problem filecol-size))
+ (loop for problem across (eclim--problems-filtered)
+ do (eclim--insert-problem problem filecol-size))
(goto-char (point-min))
(forward-line (1- line-number)))))))
@@ -253,29 +250,32 @@ COMPILATION-SKIP-THRESHOLD, implement this feature."
(remove-if-not
(lambda (x) (and
(or (not eclim--problems-filefilter)
- (string= (eclim--problem-file x) eclim--problems-file))
+ (string= (assoc-default 'filename x) eclim--problems-file))
(or ignore-type-filter
(not eclim--problems-filter)
- (string= (eclim--problem-type x) eclim--problems-filter))))
+ (and (string= "e" eclim--problems-filter)
+ (not (eq t (assoc-default 'warning x))))
+ (and (string= "w" eclim--problems-filter)
+ (eq t (assoc-default 'warning x))))))
eclim--problems-list))
(defun eclim--insert-problem (problem filecol-size)
(let* ((filecol-format-string (concat "%-" (number-to-string filecol-size) "s"))
- (filename (truncate-string-to-width (eclim--problems-cleanup-filename (eclim--problem-file problem))
+ (filename (truncate-string-to-width (eclim--problems-cleanup-filename (assoc-default 'filename problem))
40 0 nil t))
(text (if eclim-problems-show-pos
(format (concat filecol-format-string
- " | %-12s"
+ " | line %-12s"
" | %s")
filename
- (eclim--problem-pos problem)
- (eclim--problem-description problem))
+ (assoc-default 'line problem)
+ (assoc-default 'message problem))
;; else
(format (concat filecol-format-string
" | %s")
filename
- (eclim--problem-description problem)))))
- (when (and eclim-problems-hl-errors (string= (eclim--problem-type problem) "e"))
+ (assoc-default 'message problem)))))
+ (when (and eclim-problems-hl-errors (eq :json-false (assoc-default 'warning problem)))
(put-text-property 0 (length text) 'face 'bold text))
(insert text)
(insert "\n")))
@@ -392,9 +392,9 @@ is convenient as it lets the user navigate between errors using
(display-buffer compil-buffer 'other-window)))
(defun eclim--insert-problem-compilation (problem filecol-size project-directory)
- (let ((filename (first (split-string (eclim--problem-file problem) project-directory t)))
+ (let ((filename (first (split-string (assoc-default 'filename problem) project-directory t)))
(position (split-string (eclim--problem-pos problem) " col " t))
- (description (eclim--problem-description problem))
+ (description (assoc-default 'message problem))
(type (eclim--problem-type problem)))
(let ((line (first position))
(col (second position)))
View
65 eclim-project.el
@@ -70,19 +70,18 @@
(defun eclim--check-project (project)
(let ((projects (or eclim--projects-cache
- (setq eclim--projects-cache (mapcar 'third (eclim/project-list))))))
+ (setq eclim--projects-cache (mapcar (lambda (p) (assoc-default 'name p)) (eclim/project-list))))))
(when (not (assoc-string project projects))
- (error (concat "invalid project: " project)))))
+ (error (concat "invalid project: " project))))) ;
(defun eclim--project-read (&optional single)
(interactive)
- (if (eq major-mode
- 'eclim-project-mode)
+ (if (eq major-mode 'eclim-project-mode)
(progn
(or (if single nil (eclim--project-get-marked))
(eclim--project-current-line)))
(eclim--completing-read "Project: "
- (mapcar (lambda (row) (nth 2 row)) (eclim/project-list)))))
+ (mapcar (lambda (p) (assoc-default 'name p)) (eclim/project-list)))))
(defun eclim--project-mode-init ()
(switch-to-buffer (get-buffer-create "*eclim: projects*"))
@@ -112,17 +111,15 @@
(let ((inhibit-read-only t)
(line-number (line-number-at-pos)))
(erase-buffer)
- (dolist (project (eclim/project-list))
- (eclim--insert-project project))
+ (loop for project across (eclim/project-list)
+ do (eclim--insert-project project))
(goto-line line-number))))
(defun eclim--insert-project (project)
- ;; TODO: remove fixed whitespace size and insert dynamic columns
- (let ((name (truncate-string-to-width (third project) 30 0 nil t))
- (status (second project))
- (path (first project)))
- (insert (format " | %-6s | %-30s | %s" status name path))
- (insert "\n")))
+ (insert (format " | %-6s | %-30s | %s\n"
+ (if (eq :json-false (assoc-default 'open project)) "closed" "open")
+ (truncate-string-to-width (assoc-default 'name project) 30 0 nil t)
+ (assoc-default 'path project))))
(defun eclim--project-insert-mark-current (face)
(let ((inhibit-read-only t))
@@ -164,17 +161,14 @@
(eclim--project-column-end 3)))))
(defun eclim/project-list ()
- (eclim/with-results res ("project_list")
- (mapcar (lambda (line) (nreverse (split-string line " +- +" nil))) res)))
-
+ (eclim/execute-command "project_list"))
(defun eclim/project-import (folder)
(eclim--project-clear-cache)
(eclim--call-process "project_import" "-f" (expand-file-name folder)))
(defun eclim/project-create (folder natures name &optional depends)
;; TODO: allow multiple natures
- ;; (eclim--check-nature natures)
(eclim--project-clear-cache)
(eclim--call-process "project_create" "-f" folder "-n" natures "-p" name))
@@ -188,7 +182,6 @@
(eclim--call-process "project_open" "-p" project))
(defun eclim/project-close (project)
- (message (concat "CLOSING: " project))
(eclim--check-project project)
(eclim--call-process "project_close" "-p" project))
@@ -246,31 +239,31 @@
(defun eclim-project-rename (project name)
(interactive (let ((project-name (eclim--project-read t)))
(list project-name (read-string (concat "Rename <" project-name "> To: ")))))
- (message (first (eclim/project-rename project name)))
+ (message (eclim/project-rename project name))
(eclim--project-buffer-refresh))
(defun eclim-project-delete (projects)
(interactive (list (eclim--project-read)))
(when (not (listp projects)) (set 'projects (list projects)))
(dolist (project projects)
(when (yes-or-no-p (concat "Delete Project: <" project"> "))
- (message (first (eclim/project-delete project)))))
+ (message (eclim/project-delete project))))
(eclim--project-buffer-refresh))
(defun eclim-project-create (name path nature)
(interactive (list (read-string "Name: ")
(expand-file-name (read-directory-name "Project Directory: "))
(eclim--project-nature-read)))
- (message (first (eclim/project-create path nature name)))
+ (message (eclim/project-create path nature name))
(eclim--project-buffer-refresh))
(defun eclim-project-import (folder)
(interactive "DProject Directory: ")
- (message (first (eclim/project-import folder)))
+ (message (eclim/project-import folder))
(eclim--project-buffer-refresh))
(defun eclim--project-nature-read ()
- (completing-read "Type: " (eclim/project-nature-aliases)))
+ (completing-read "Type: " (append (eclim/project-nature-aliases) '())))
(defun eclim-project-mode-refresh ()
(interactive)
@@ -282,11 +275,11 @@
(pop-to-buffer "*eclim: find*" t)
(when header (insert header))
(insert "searching for: " pattern "..." "\n\n")
- (dolist (match matches)
- (when match
- (insert (third (split-string match "|")) ":0:\t"
- (first (split-string match "|"))
- "\n")))
+ (loop for match across matches
+ do (insert (format "%s:0:\t%s\n"
+ (assoc-default 'path match)
+ (assoc-default 'name match))))
+ (goto-char 0)
(grep-mode))
(defun eclim-project-file-locate (pattern)
@@ -353,24 +346,26 @@
(defun eclim-project-goto (project)
(interactive (list (eclim--project-read t)))
- (let ((path (cdr (assoc project (mapcar (lambda (row) (cons (nth 2 row) (nth 0 row))) (eclim/project-list))))))
- (ido-find-file-in-dir path)))
+ (ido-find-file-in-dir
+ (assoc-default 'path
+ (find project (eclim/project-list)
+ :key (lambda (e) (assoc-default 'name e))
+ :test #'string=))))
(defun eclim-project-info (project)
(interactive (list (eclim--project-read t)))
(let ((old-buffer (current-buffer))
(project-info "")
(project-settings ""))
(switch-to-buffer (get-buffer-create "*eclim: info*"))
- (insert (dolist (line (eclim/project-info project) project-info)
- (set 'project-info (concat project-info line "\n"))))
+ (loop for attr in (eclim/project-info project)
+ do (insert (format "%s: %s\n" (car attr) (cdr attr))))
(insert "\n\nSETTINGS:\n")
- (insert (dolist (line (eclim/project-settings project) project-settings)
- (set 'project-settings (concat project-settings line "\n"))))
+ (loop for attr across (eclim/project-settings project)
+ do (insert (format "%s: %s\n" (assoc-default 'name attr) (assoc-default 'value attr))))
(local-set-key (kbd "q") (lambda ()
(interactive)
(kill-buffer)))
-
(beginning-of-buffer)
(setq major-mode 'special-mode
mode-name "eclim/project-info"
View
66 eclim.el
@@ -141,15 +141,12 @@ eclimd."
cmd))
(defun eclim--parse-result (result)
- "Handles the text result of an eclim operation by splitting it
-into a list lines (removing empty elements). Also performs some
-elementary error checking."
- (let ((res (remove-if (lambda (s) (= 0 (length s)))
- (split-string result "\n"))))
- (when (and res (or (string-match "connect:\s+\\(.*\\)" (first res))
- (string-match "Missing argument for required option:\s*\\(.*\\)" (first res))))
- (error (match-string 1 (first res))))
- res))
+ "Parses the result of an eclim operation, raising an error if
+the result is not valid JSON."
+ (condition-case nil
+ (json-read-from-string result)
+ ('json-readtable-error
+ (error result))))
(defun eclim--call-process (&rest args)
"Calls eclim with the supplied arguments. Consider using
@@ -327,12 +324,14 @@ FILENAME is given, return that file's project name instead."
(let ((project-list (eclim/project-list))
(project-dir (eclim--project-dir (or filename buffer-file-name))))
(when (and project-list project-dir)
- (car (or (cddr (assoc project-dir project-list)) ;; sensitive match
- (cddr (assoc (downcase project-dir) ;; insensitive match
- (mapcar (lambda (project)
- (cons (downcase (first project))
- (rest project)))
- project-list))))))))))
+ (assoc-default 'name
+ (or
+ (find project-dir project-list ;; case sensitive
+ :key (lambda (e) (assoc-default 'path e))
+ :test #'string=)
+ (find project-dir project-list ;; case insensitive
+ :key (lambda (e) (assoc-default 'path e))
+ :test (lambda (s1 s2) (string= s1 (downcase s2)))))))))))
(defun eclim--find-file (path-to-file)
(if (not (string-match-p "!" path-to-file))
@@ -354,36 +353,35 @@ FILENAME is given, return that file's project name instead."
(kill-buffer old-buffer)))))
(defun eclim--find-display-results (pattern results &optional open-single-file)
- (let ((res (remove-if-not (lambda (r) (or (not eclim-limit-search-results) (eclim--accepted-p (car r))))
- (remove-if (lambda (r) (zerop (length (remove-if (lambda (r) (zerop (length r))) r)))) results))))
- (if (and (= 1 (length res)) open-single-file) (eclim--visit-declaration (car res))
+ (if (and (= 1 (length results)) open-single-file) (eclim--visit-declaration (elt results 0))
(pop-to-buffer (get-buffer-create "*eclim: find"))
(let ((buffer-read-only nil))
(erase-buffer)
(insert (concat "-*- mode: eclim-find; default-directory: " default-directory " -*-"))
(newline 2)
(insert (concat "eclim java_search -p " pattern))
(newline)
- (dolist (result res)
- (insert (eclim--convert-find-result-to-string result default-directory))
- (newline))
- (grep-mode)))))
+ (loop for result across results
+ do (progn
+ (insert (eclim--convert-find-result-to-string result default-directory))
+ (newline)))
+ (goto-char 0)
+ (grep-mode))))
(defun eclim--convert-find-result-to-string (line &optional directory)
- (let ((converted-directory (replace-regexp-in-string "\\\\" "/" (car line))))
- (concat (if converted-directory
+ (let ((converted-directory (replace-regexp-in-string "\\\\" "/" (assoc-default 'filename line))))
+ (format "%s:%d:%d:%s"
+ (if converted-directory
(replace-regexp-in-string (concat (regexp-quote directory) "/?") "" converted-directory)
converted-directory)
- ":" (replace-regexp-in-string " col " ":" (second line)) " "
- (third line))))
+ (assoc-default 'line line)
+ (assoc-default 'column line)
+ (assoc-default 'message line))))
-(defun eclim--visit-declaration (eclim-response)
- (let* ((file-name (car eclim-response))
- (line-and-column (cadr eclim-response))
- (position (split-string line-and-column " col ")))
- (eclim--find-file file-name)
- (goto-line (string-to-number (car position)))
- (move-to-column (- (string-to-number (cadr position)) 1))))
+(defun eclim--visit-declaration (line)
+ (eclim--find-file (assoc-default 'filename line))
+ (goto-line (assoc-default 'line line))
+ (move-to-column (- (assoc-default 'column line) 1)))
(defun eclim--string-strip (content)
(replace-regexp-in-string "\s*$" "" content))
@@ -407,7 +405,7 @@ FILENAME is given, return that file's project name instead."
(if mapped-coding-system mapped-coding-system coding-system)))
(defun eclim/workspace-dir ()
- (car (eclim--call-process "workspace_dir")))
+ (eclim--call-process "workspace_dir"))
(defun eclim/jobs (&optional family)
(eclim/execute-command "jobs" ("-f" family)))

0 comments on commit 74d67e1

Please sign in to comment.