-
Notifications
You must be signed in to change notification settings - Fork 1
/
sbt.el
106 lines (87 loc) · 3.69 KB
/
sbt.el
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
;; Support for running sbt in inferior mode.
(eval-when-compile (require 'cl))
(require 'tool-bar)
(require 'compile)
(defgroup sbt nil
"Run SBT REPL as inferior of Emacs, parse error messages."
:group 'tools
:group 'processes)
(defconst sbt-copyright "Copyright (C) 2008 Raymond Paul Racine")
(defconst sbt-copyright-2 "Portions Copyright (C) Free Software Foundation")
(defconst sbt-version "0.02")
(defconst sbt-author-name "Raymond Racine")
(defconst sbt-author-email "[email protected]")
(defconst sbt-legal-notice
"This is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation; either version 2, or (at your option) any later version. This is
distributed in the hope that it will be useful, but without any warranty;
without even the implied warranty of merchantability or fitness for a
particular purpose. See the GNU General Public License for more details. You
should have received a copy of the GNU General Public License along with Emacs;
see the file `COPYING'. If not, write to the Free Software Foundation, Inc.,
59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.")
(defgroup sbt nil
"Support for sbt build REPL."
:group 'sbt
:prefix "sbt-")
(defcustom sbt-program-name "sbt"
"Program invoked by the `run-sbt' command."
:type 'string
:group 'sbt)
(defun sbt-build-buffer-name (mode)
"*Scala Build Tool*")
(defun sbt-shell ()
"Launch the sbt shell."
(interactive)
(compile (concat "cd " (sbt-find-path-to-project) "; sbt") t)
(pop-to-buffer (sbt-build-buffer-name nil))
(end-of-buffer))
(defun sbt-clear ()
"Clear (erase) the SBT buffer."
(interactive)
(with-current-buffer (sbt-build-buffer-name nil)
(let ((inhibit-read-only t))
(erase-buffer))))
(customize-set-variable 'scala-compile-error-regex
'("^\\[error\\] \\([.a-zA-Z0-9/-]+[.]scala\\):\\([0-9]+\\):" 1 2 nil 2 nil))
(customize-set-variable 'compilation-buffer-name-function 'sbt-build-buffer-name)
(customize-set-variable 'compilation-error-regexp-alist (list scala-compile-error-regex))
(customize-set-variable 'compilation-mode-font-lock-keywords
'(("^\\[error\\] Error running compile:"
(0 compilation-error-face))
("^\\[warn\\][^\n]*"
(0 compilation-warning-face))
("^\\(\\[info\\]\\)\\([^\n]*\\)"
(0 compilation-info-face)
(1 compilation-line-face))
("^\\[success\\][^\n]*"
(0 compilation-info-face))))
(customize-set-variable 'comint-prompt-read-only t)
(customize-set-variable 'compilation-buffer-name-function
'sbt-build-buffer-name)
(customize-set-variable 'compilation-error-regexp-alist
(list scala-compile-error-regex))
(set 'compilation-auto-jump-to-first-error t)
(ansi-color-for-comint-mode-on)
;; Locate the project root directory from the source buffer location.
(defun sbt-project-dir-p (path)
"Does a project/build.properties exists in the given path."
(file-exists-p (concat path "/project/build.properties")))
(defun sbt-at-root (path)
"Determine if the given path is root."
(equal path (sbt-parent-path path)))
(defun sbt-parent-path (path)
"The parent path for the given path."
(file-truename (concat path "/..")))
;; Search up the directory tree until directory with a "project" subdir
;; is found with build.properties
(defun sbt-find-path-to-project ()
"Move up the directory tree for the current buffer until root or a directory with a project/build.properities is found."
(interactive)
(let ((fn (buffer-file-name)))
(let ((path (file-name-directory fn)))
(while (and (not (sbt-project-dir-p path))
(not (sbt-at-root path)))
(setf path (file-truename (sbt-parent-path path))))
path)))