-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathFUTURE
124 lines (92 loc) · 3.36 KB
/
FUTURE
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
-*- Outline -*-
* Here is a list of future improvements to the scala mode
** Automatic indentation should work in all cases
Automatic indentation is incredibly basic and doesn't work correctly
in many situations, including:
- multi-line "case" statements, e.g.
case Pair(x,y) =>
Console.println(x);
Console.println(y); // not indented correctly
- multi-line "case" patterns, e.g.
case 'a' | 'b' | 'c'
| 'd' | 'e' | 'f' // not indented correctly
- multi-line comments, e.g.
/*
* // not indented correctly
*/ // not indented correctly
- other cases of single-line constructs as soon as they span
multiple lines.
** Implement customize variable to toggle smart indent on/off
** Create templates for normal and scaladoc comments (with menu and shurtcut)
** Scaladoc font-lock mode
** Support for XEmacs
** Add support for Flymode
(require 'scala-mode)
(require 'compile)
(require 'flymake)
(require 'font-lock)
(defvar scala-build-commad nil)
(make-variable-buffer-local 'scala-build-command)
(add-hook 'scala-mode-hook
(lambda ()
(flymake-mode-on)
))
(defun flymake-scala-init ()
(let* ((text-of-first-line (buffer-substring-no-properties (point-min) (min 20 (point-max)))))
(progn
(remove-hook 'after-save-hook 'flymake-after-save-hook t)
(save-buffer)
(add-hook 'after-save-hook 'flymake-after-save-hook nil t)
(if (string-match "^//script" text-of-first-line)
(list "fsc" (list "-Xscript" "MainScript" "-d" "c:/tmp" buffer-file-name))
(or scala-build-command (list "fsc" (list "-d" "c:/tmp" buffer-file-name))))
)))
(push '(".+\\.scala$" flymake-scala-init) flymake-allowed-file-name-masks)
(push '("^\\(.*\\):\\([0-9]+\\): error: \\(.*\\)$" 1 2 nil 3) flymake-err-line-patterns)
(set (make-local-variable 'indent-line-function) 'scala-indent-line)
(defun scala-indent-line ()
"Indent current line of Scala code."
(interactive)
(indent-line-to (max 0 (scala-calculate-indentation))))
(defun scala-calculate-indentation ()
"Return the column to which the current line should be indented."
(save-excursion
(scala-maybe-skip-leading-close-delim)
(let ((pos (point)))
(beginning-of-line)
(if (not (search-backward-regexp "[^\n\t\r ]" 1 0))
0
(progn
(scala-maybe-skip-leading-close-delim)
(+ (current-indentation) (* 2 (scala-count-scope-depth (point) pos))))))))
(defun scala-maybe-skip-leading-close-delim ()
(beginning-of-line)
(forward-to-indentation 0)
(if (looking-at "\\s)")
(forward-char)
(beginning-of-line)))
(defun scala-face-at-point (pos)
"Return face descriptor for char at point."
(plist-get (text-properties-at pos) 'face))
(defun scala-count-scope-depth (rstart rend)
"Return difference between open and close scope delimeters."
(save-excursion
(goto-char rstart)
(let ((open-count 0)
(close-count 0)
opoint)
(while (and (< (point) rend)
(progn (setq opoint (point))
(re-search-forward "\\s)\\|\\s(" rend t)))
(if (= opoint (point))
(forward-char 1)
(cond
;; Use font-lock-mode to ignore strings and comments
((scala-face-at-point (- (point) 1)))
((looking-back "\\s)")
(incf close-count))
((looking-back "\\s(")
(incf open-count))
)))
(- open-count close-count))))
(provide 'scala-extensions)