Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 5add7f6c21
Fetching contributors…

Cannot retrieve contributors at this time

file 257 lines (217 sloc) 8.763 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
(defcustom eclim-problems-resize-file-column t
  "Resizes file column in emacs-eclim problems mode"
  :group 'eclim
  :type '(choice (const :tag "Off" nil)
(const :tag "On" t)))

(defcustom eclim-problems-show-pos nil
  "Shows problem line/column in emacs-eclim problems mode"
  :group 'eclim
  :type '(choice (const :tag "Off" nil)
(const :tag "On" t)))

(defcustom eclim-problems-show-file-extension nil
  "Shows file extensions in emacs-eclim problems mode"
  :group 'eclim
  :type '(choice (const :tag "Off" nil)
(const :tag "On" t)))

(defcustom eclim-problems-hl-errors t
  "Highlights errors"
  :group 'eclim
  :type '(choice (const :tag "Off" nil)
(const :tag "On" t)))

(defvar eclim-autoupdate-problems t)

(defvar eclim-problems-mode-hook nil)

(defvar eclim--problems-filter-description "")
(defvar eclim--problems-project nil) ;; problems are relative to this project
(defvar eclim--problems-file nil) ;; problems are relative to this file (when eclim--problems-filefilter is non-nil)

(setq eclim-problems-mode-map
      (let ((map (make-keymap)))
(suppress-keymap map t)
(define-key map (kbd "a") 'eclim-problems-show-all)
(define-key map (kbd "e") 'eclim-problems-show-errors)
(define-key map (kbd "g") 'eclim-problems-buffer-refresh)
(define-key map (kbd "q") 'quit-window)
(define-key map (kbd "w") 'eclim-problems-show-warnings)
(define-key map (kbd "f") 'eclim-problems-toggle-filefilter)
(define-key map (kbd "RET") 'eclim-problems-open-current)
map))

(define-key eclim-mode-map (kbd "C-c C-e b") 'eclim-problems)
(define-key eclim-mode-map (kbd "C-c C-e o") 'eclim-problems-open)

(defvar eclim--problems-list nil)

(defvar eclim--problems-filter nil) ;; nil -> all problems, w -> warnings, e -> errors
(defvar eclim--problems-filefilter nil) ;; should filter by file name

(defvar eclim--problems-faces
  '(("e" foreground-color . "red")
    ("w" foreground-color . "yellow")))

(defconst eclim--problems-buffer-name "*eclim: problems*")

(defun eclim--problems-mode ()
  (kill-all-local-variables)
  (buffer-disable-undo)
  (setq majod-mode 'eclim-problems-mode
mode-name "eclim/problems"
mode-line-process ""
truncate-lines t
line-move-visual nil
buffer-read-only t
default-directory (eclim/workspace-dir))
  (setq mode-line-format
(list "-"
'mode-line-mule-info
'mode-line-modified
'mode-line-frame-identification
'mode-line-buffer-identification

" "
'mode-line-position

" "
'eclim--problems-filter-description

" "
'mode-line-modes
'(which-func-mode ("" which-func-format "--"))

'global-mode-string
"-%-"))
  (hl-line-mode t)
  (use-local-map eclim-problems-mode-map)
  (run-mode-hooks 'eclim-problems-mode-hook))

(defun eclim--problems ()
  "Calls eclipse to obtain all current problems. Returns a list of lists."
  (remove-if-not (lambda (l) (= (length l) 4)) ;; for now, ignore multiline errors
(mapcar (lambda (line) (split-string line "|" nil))
(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--problems-apply-filter (f)
  (setq eclim--problems-filter f)
  (eclim--problems-buffer-redisplay))

(defun eclim-problems-show-errors ()
  (interactive)
  (eclim--problems-apply-filter "e"))

(defun eclim-problems-toggle-filefilter ()
  (interactive)
  (setq eclim--problems-filefilter (not eclim--problems-filefilter))
  (eclim--problems-buffer-redisplay))

(defun eclim-problems-show-warnings ()
  (interactive)
  (eclim--problems-apply-filter "w"))

(defun eclim-problems-show-all ()
  (interactive)
  (eclim--problems-apply-filter nil))

(defun eclim-problems-open-current ()
  (interactive)
  (let* ((p (nth (1- (line-number-at-pos)) (eclim--problems-filtered)))
(pos (split-string (eclim--problem-pos p) " col ")))
    (find-file-other-window (eclim--problem-file p))
    (goto-line (string-to-int (first pos)))
    (beginning-of-line)
    (dotimes (i (1- (string-to-int (second pos))))
      (forward-char))))

(defun eclim-problems-buffer-refresh ()
  "Refresh the problem list and draw it on screen."
  (interactive)
  (setq eclim--problems-list (eclim--problems))
  (eclim--problems-buffer-redisplay)
  (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))))

(defun eclim--problems-cleanup-filename (filename)
  (let ((x (file-name-nondirectory (eclim--problem-file 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))))
(eclim--problems-filtered))))
    40))

(defun eclim--problems-update-filter-description ()
  (if eclim--problems-filefilter
      (if eclim--problems-filter
(setq eclim--problems-filter-description (concat "(file-" eclim--problems-filter ")"))
(setq eclim--problems-filter-description "(file)"))
    (if eclim--problems-filter
(setq eclim--problems-filter-description (concat eclim--problems-project "(" eclim--problems-filter ")"))
      (setq eclim--problems-filter-description eclim--problems-project))))

(defun eclim--problems-buffer-redisplay ()
  "Draw the problem list on screen."
  (eclim--problems-update-filter-description)
  (let ((inhibit-read-only t)
(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))
    (goto-line line-number)))

(defun eclim--problems-filtered ()
  (remove-if-not
   (lambda (x) (and
(or (not eclim--problems-filefilter)
(string= (eclim--problem-file x) eclim--problems-file))
(or (not eclim--problems-filter)
(string= (eclim--problem-type x) eclim--problems-filter))))
   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))
40 0 nil t))
(text (if eclim-problems-show-pos
(format (concat filecol-format-string
" | %-12s"
" | %s")
filename
(eclim--problem-pos problem)
(eclim--problem-description 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"))
      (put-text-property 0 (length text) 'face 'bold text))
    (insert text)
    (insert "\n")))

(defun eclim--problems-mode-init ()
  (setq eclim--problems-project (eclim--project-name))
  (setq eclim--problems-file buffer-file-name)
  (switch-to-buffer (get-buffer-create "*eclim: problems*"))
  (eclim--problems-mode)
  (eclim-problems-buffer-refresh)
  (beginning-of-buffer))

(defun eclim-problems ()
  "Show current compilation problems in a separate window."
  (interactive)
  (eclim--problems-mode-init))

(defun eclim-problems-open ()
  "Opens a new (emacs) window inside the current frame showing the current project compilation problems"
  (interactive)
  (let ((w (selected-window)))
    (select-window (split-window nil (round (* (window-height w) 0.75)) nil))
    (eclim-problems)
    (select-window w)))

(defun eclim-problems-refocus ()
  (interactive)

  (when eclim--project-dir
    (setq eclim--problems-project (eclim--project-name))
    (setq eclim--problems-file buffer-file-name)
    (with-current-buffer eclim--problems-buffer-name
      (eclim-problems-buffer-refresh))))

(defun eclim--problems-update-maybe ()
  "If autoupdate is enabled, this function triggers a delayed
refresh of the problems buffer."
  (when (and eclim--project-dir
eclim-autoupdate-problems)
    (setq eclim--problems-project (eclim--project-name))
    (setq eclim--problems-file buffer-file-name)
    (run-with-idle-timer 1 nil
(lambda()
(let ((b (current-buffer))
(p (get-buffer eclim--problems-buffer-name)))
(if p
(progn
(switch-to-buffer p)
(eclim-problems-buffer-refresh))
(eclim--problems-mode-init))
(switch-to-buffer b))))))
 
(add-hook 'after-save-hook #'eclim--problems-update-maybe)

(provide 'eclim-problems)
Something went wrong with that request. Please try again.