Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 114 lines (98 sloc) 4.168 kb
2e56b7a @antonj Scss cleanup
authored
1 ;;; scss-mode.el --- Major mode for editing SCSS files
59f48d7 @antonj Fixed SCSS comments to adhere http://www.emacswiki.org/cgi-bin/wiki/E…
authored
2 ;;
3 ;; Author: Anton Johansson <anton.johansson@gmail.com> - http://antonj.se
e28d048 @antonj Changed URL to git repository
authored
4 ;; URL: https://github.com/antonj/scss-mode
2e56b7a @antonj Scss cleanup
authored
5 ;; Created: Sep 1 23:11:26 2010
0a8247b @antonj Version number added, and customizable scss-sass-options added. Thank…
authored
6 ;; Version: 0.5.0
59f48d7 @antonj Fixed SCSS comments to adhere http://www.emacswiki.org/cgi-bin/wiki/E…
authored
7 ;; Keywords: scss css mode
8 ;;
4e1dd53 @antonj Added trivial scss-mode
authored
9 ;; This program is free software; you can redistribute it and/or
10 ;; modify it under the terms of the GNU General Public License as
11 ;; published by the Free Software Foundation; either version 2 of
12 ;; the License, or (at your option) any later version.
59f48d7 @antonj Fixed SCSS comments to adhere http://www.emacswiki.org/cgi-bin/wiki/E…
authored
13 ;;
4e1dd53 @antonj Added trivial scss-mode
authored
14 ;; This program is distributed in the hope that it will be
15 ;; useful, but WITHOUT ANY WARRANTY; without even the implied
16 ;; warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
17 ;; PURPOSE. See the GNU General Public License for more details.
59f48d7 @antonj Fixed SCSS comments to adhere http://www.emacswiki.org/cgi-bin/wiki/E…
authored
18 ;;
19 ;;; Commentary:
3f3e32e @antonj Scss-mode
authored
20 ;;
2e56b7a @antonj Scss cleanup
authored
21 ;; Command line utility sass is required, see http://sass-lang.com/
22 ;; To install sass (haml):
23 ;; gem install haml
3f3e32e @antonj Scss-mode
authored
24 ;;
2e56b7a @antonj Scss cleanup
authored
25 ;; Also make sure sass location is in emacs PATH, example:
0a47464 @antonj Documentation string fix
authored
26 ;; (setq exec-path (cons (expand-file-name "~/.gem/ruby/1.8/bin") exec-path))
2e56b7a @antonj Scss cleanup
authored
27 ;; or customize `scss-sass-command' to point to your sass executable.
59f48d7 @antonj Fixed SCSS comments to adhere http://www.emacswiki.org/cgi-bin/wiki/E…
authored
28 ;;
29 ;;; Code:
4e1dd53 @antonj Added trivial scss-mode
authored
30
31 (require 'derived)
4376d1d @antonj Regex to find errors from sass compilation
authored
32 (require 'compile)
8312651 @jschaf Add (require 'flymake) because we use the flymake-allowed-file-name-m…
jschaf authored
33 (require 'flymake)
4e1dd53 @antonj Added trivial scss-mode
authored
34
2e56b7a @antonj Scss cleanup
authored
35 (defgroup scss nil
36 "Scss mode"
37 :prefix "scss-"
38 :group 'css)
39
40 (defcustom scss-sass-command "sass"
41 "Command used to compile SCSS files, should be sass or the
42 complete path to your sass runnable example:
43 \"~/.gem/ruby/1.8/bin/sass\""
44 :group 'scss)
45
46 (defcustom scss-compile-at-save t
47 "If not nil the SCSS buffers will be compiled after each save"
48 :type 'boolean
49 :group 'scss)
50
0a8247b @antonj Version number added, and customizable scss-sass-options added. Thank…
authored
51 (defcustom scss-sass-options '()
52 "Command line Options for sass executable, for example:
53 '(\"--cache-location\" \"'/tmp/.sass-cache'\")"
54 :group 'scss)
55
5289863 @antonj New regex that matches errors 'on line x of file in section \n from l…
authored
56 (defcustom scss-compile-error-regex '("\\(Syntax error:\s*.*\\)\n\s*on line\s*\\([0-9]+\\) of \\([^, \n]+\\)" 3 2 nil nil 1)
2e56b7a @antonj Scss cleanup
authored
57 "Regex for finding line number file and error message in
58 compilation buffers, syntax from
59 `compilation-error-regexp-alist' (REGEXP FILE LINE COLUMN TYPE
60 HYPERLINK HIGHLIGHT)"
61 :group 'scss)
62
4e1dd53 @antonj Added trivial scss-mode
authored
63 (defconst scss-font-lock-keywords
3f3e32e @antonj Scss-mode
authored
64 ;; Variables
3641e4e @samh Fixed quotes in single-line (//) comments.
samh authored
65 '(("$[a-z_-][a-z-_0-9]*" . font-lock-constant-face)))
4e1dd53 @antonj Added trivial scss-mode
authored
66
2e56b7a @antonj Scss cleanup
authored
67 (defun scss-compile-maybe()
68 "Runs `scss-compile' on if `scss-compile-at-save' is t"
69 (if scss-compile-at-save
70 (scss-compile)))
4376d1d @antonj Regex to find errors from sass compilation
authored
71
2e56b7a @antonj Scss cleanup
authored
72 (defun scss-compile()
ce3c0c2 @antonj Changed use of (buffer-name) to var buffer-file-name which makes more…
authored
73 "Compiles the current buffer, sass filename.scss filename.css"
2e56b7a @antonj Scss cleanup
authored
74 (interactive)
0a8247b @antonj Version number added, and customizable scss-sass-options added. Thank…
authored
75 (compile (concat scss-sass-command " " (mapconcat 'identity scss-sass-options " ") " "
480bed7 @antonj Fix for compilation of SCSS-files that are placed in folders with nam…
authored
76 "'" buffer-file-name "' '"
77 (first (split-string buffer-file-name "[.]scss$")) ".css'")))
3f3e32e @antonj Scss-mode
authored
78
4e1dd53 @antonj Added trivial scss-mode
authored
79 ;;;###autoload
73352b8 @antonj Added flymake support
authored
80 (define-derived-mode scss-mode css-mode "SCSS"
81 "Major mode for editing SCSS files, http://sass-lang.com/
2e56b7a @antonj Scss cleanup
authored
82 Special commands:
83 \\{scss-mode-map}"
4e1dd53 @antonj Added trivial scss-mode
authored
84 (font-lock-add-keywords nil scss-font-lock-keywords)
3641e4e @samh Fixed quotes in single-line (//) comments.
samh authored
85 ;; Add the single-line comment syntax ('//', ends with newline)
86 ;; as comment style 'b' (see "Syntax Flags" in elisp manual)
9afd3de @jschaf Fix syntax table bug that didn't match //$blah.
jschaf authored
87 (modify-syntax-entry ?/ ". 124" css-mode-syntax-table)
88 (modify-syntax-entry ?* ". 23b" css-mode-syntax-table)
89 (modify-syntax-entry ?\n ">" css-mode-syntax-table)
4376d1d @antonj Regex to find errors from sass compilation
authored
90 (add-to-list 'compilation-error-regexp-alist scss-compile-error-regex)
2e56b7a @antonj Scss cleanup
authored
91 (add-hook 'after-save-hook 'scss-compile-maybe nil t))
4e1dd53 @antonj Added trivial scss-mode
authored
92
2e56b7a @antonj Scss cleanup
authored
93 (define-key scss-mode-map "\C-c\C-c" 'scss-compile)
94
73352b8 @antonj Added flymake support
authored
95 (defun flymake-scss-init ()
96 "Flymake support for SCSS files"
97 (let* ((temp-file (flymake-init-create-temp-buffer-copy
98 'flymake-create-temp-inplace))
99 (local-file (file-relative-name
100 temp-file
101 (file-name-directory buffer-file-name))))
0a8247b @antonj Version number added, and customizable scss-sass-options added. Thank…
authored
102 (list scss-sass-command (append scss-sass-options (list "--scss" "--check" local-file)))))
73352b8 @antonj Added flymake support
authored
103
104 (push '(".+\\.scss$" flymake-scss-init) flymake-allowed-file-name-masks)
105
106 ;;;; TODO: Not possible to use multiline regexs flymake? flymake-err-[line]-patterns
107 ;; '("Syntax error:\s*\\(.*\\)\n\s*on line\s*\\([0-9]+\\) of \\([^ ]+\\)$" 3 2 nil 1)
108 (push '("on line \\([0-9]+\\) of \\([^ ]+\\)$" 2 1 nil 2) flymake-err-line-patterns)
109
2e56b7a @antonj Scss cleanup
authored
110 ;;;###autoload
111 (add-to-list 'auto-mode-alist '("\\.scss\\'" . scss-mode))
4e1dd53 @antonj Added trivial scss-mode
authored
112
65ef71b @mltucker Added inline comment support to sccs-mode.el.
mltucker authored
113 (provide 'scss-mode)
59f48d7 @antonj Fixed SCSS comments to adhere http://www.emacswiki.org/cgi-bin/wiki/E…
authored
114 ;;; scss-mode.el ends here
Something went wrong with that request. Please try again.