forked from antonj/scss-mode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scss-mode.el
121 lines (103 loc) · 4.08 KB
/
scss-mode.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
;;; scss-mode.el --- Major mode for editing SCSS files
;;
;; Author: Anton Johansson <anton.johansson@gmail.com> - http://antonj.se
;; URL: https://github.com/antonj/scss-mode
;; Created: Sep 1 23:11:26 2010
;; Keywords: scss css mode
;;
;; This program 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 of
;; the License, or (at your option) any later version.
;;
;; This program 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.
;;
;;; Commentary:
;;
;; Command line utility sass is required, see http://sass-lang.com/
;; To install sass (haml):
;; gem install haml
;;
;; Also make sure sass location is in emacs PATH, example:
;; (setq exec-path (cons (expand-file-name "~/.gem/ruby/1.8/bin") exec-path))
;; or customize `scss-sass-command' to point to your sass executable.
;;
;;; Code:
(require 'derived)
(require 'compile)
(require 'flymake)
(defgroup scss nil
"Scss mode"
:prefix "scss-"
:group 'css)
(defcustom scss-sass-command "sass"
"Command used to compile SCSS files, should be sass or the
complete path to your sass runnable example:
\"~/.gem/ruby/1.8/bin/sass\""
:group 'scss)
(defcustom scss-compile-at-save nil
"If not nil the SCSS buffers will be compiled after each save"
:type 'boolean
:group 'scss)
(defcustom scss-check-at-save t
"If not nil the SCSS buffers will be checked after each save"
:type 'boolean
:group 'scss)
(defcustom scss-compile-error-regex '("\\(Syntax error:\s*.*\\)\n\s*on line\s*\\([0-9]+\\) of \\([^, \n]+\\)" 3 2 nil nil 1)
"Regex for finding line number file and error message in
compilation buffers, syntax from
`compilation-error-regexp-alist' (REGEXP FILE LINE COLUMN TYPE
HYPERLINK HIGHLIGHT)"
:group 'scss)
(defconst scss-font-lock-keywords
;; Variables
'(("$[a-z_-][a-z-_0-9]*" . font-lock-constant-face)
("//.*$" . font-lock-comment-face)))
(defun scss-compile-maybe()
"Runs `scss-compile' on if `scss-compile-at-save' is t"
(if scss-compile-at-save
(scss-compile)))
(defun scss-check-maybe()
"Runs `scss-check' on if `scss-check-at-save' is t"
(if scss-check-at-save
(scss-check)))
(defun scss-compile()
"Compiles the current buffer, sass filename.scss filename.css"
(interactive)
(compile (concat scss-sass-command " " ;; " --no-cache " " --cache-location"
"'" buffer-file-name "' '"
(first (split-string buffer-file-name "[.]scss$")) ".css'")))
(defun scss-check()
"Checks the current buffer"
(interactive)
(compile (concat scss-sass-command " --check "
"'" buffer-file-name "'")))
;;;###autoload
(define-derived-mode scss-mode css-mode "SCSS"
"Major mode for editing SCSS files, http://sass-lang.com/
Special commands:
\\{scss-mode-map}"
(font-lock-add-keywords nil scss-font-lock-keywords)
(add-to-list 'compilation-error-regexp-alist scss-compile-error-regex)
(add-hook 'after-save-hook 'scss-compile-maybe nil t)
(add-hook 'after-save-hook 'scss-check-maybe nil t))
(define-key scss-mode-map "\C-c\C-c" 'scss-compile)
(defun flymake-scss-init ()
"Flymake support for SCSS files"
(let* ((temp-file (flymake-init-create-temp-buffer-copy
'flymake-create-temp-inplace))
(local-file (file-relative-name
temp-file
(file-name-directory buffer-file-name))))
(list scss-sass-command (list "--scss" "--check" local-file))))
(push '(".+\\.scss$" flymake-scss-init) flymake-allowed-file-name-masks)
;;;; TODO: Not possible to use multiline regexs flymake? flymake-err-[line]-patterns
;; '("Syntax error:\s*\\(.*\\)\n\s*on line\s*\\([0-9]+\\) of \\([^ ]+\\)$" 3 2 nil 1)
(push '("on line \\([0-9]+\\) of \\([^ ]+\\)$" 2 1 nil 2) flymake-err-line-patterns)
;;;###autoload
(add-to-list 'auto-mode-alist '("\\.scss\\'" . scss-mode))
(provide 'scss-mode)
;;; scss-mode.el ends here