1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00
haml--haml/extra/sass-mode.el

104 lines
3.6 KiB
EmacsLisp
Raw Normal View History

;;; sass-mode.el --- Major mode for editing Sass files
;; Copyright (c) 2007, 2008 Nathan Weizenbaum
;; Author: Nathan Weizenbaum
;; URL: http://github.com/nex3/haml/tree/master
;; Version: 1.0
;; Keywords: markup, language
;;; Commentary:
;; Because Sass's indentation schema is similar
;; to that of YAML and Python, many indentation-related
;; functions are similar to those in yaml-mode and python-mode.
;; To install, save this on your load path and add the following to
;; your .emacs file:
;;
;; (require 'sass-mode)
;;; Code:
2008-04-22 18:43:31 -07:00
(require 'haml-mode)
;; User definable variables
(defgroup sass nil
"Support for the Sass template language."
:group 'languages
:prefix "sass-")
(defcustom sass-mode-hook nil
2008-04-22 16:36:51 -07:00
"Hook run when entering Sass mode."
:type 'hook
:group 'sass)
(defcustom sass-indent-offset 2
2008-04-22 16:36:51 -07:00
"Amount of offset per level of indentation."
:type 'integer
:group 'sass)
2008-04-24 09:09:42 -07:00
(defvar sass-non-block-openers
'("^ *:[^ \t]+[ \t]+[^ \t]"
"^ *[^ \t:]+[ \t]*[=:][ \t]*[^ \t]")
"A list of regexps that match lines of Sass that couldn't have
text nested beneath them.")
2008-02-16 17:31:10 +07:00
;; Font lock
2008-04-22 16:36:51 -07:00
(defconst sass-font-lock-keywords
2008-04-22 18:43:31 -07:00
'(("^ *\\(\t\\)" 1 'haml-tab-face)
("^@.*" 0 font-lock-constant-face)
2008-04-22 16:36:51 -07:00
("\\(\'[^']*'\\)" 1 font-lock-string-face append)
("\\(\"[^\"]*\"\\)" 1 font-lock-string-face append)
("\\(#[0-9a-fA-F]\\{3\\}\\{1,2\\}\\>\\)" 1 font-lock-string-face append)
("\\(:[A-Za-z-]+\\|[A-Za-z-]+:\\)" 0 font-lock-constant-face append)
("![a-z0-9_-]+" 0 font-lock-variable-name-face append)
("^ *\\(/[/*].*\\)$" 1 font-lock-comment-face append)
("\\(?:^\\|,\\) *\\(#[a-z0-9_-]+\/?\\)" 1 font-lock-keyword-face)
("\\(?:^\\|,\\) *\\(\\.[a-z0-9_-]+\/?\\)" 1 font-lock-type-face)
("\\(?:^\\|,\\) *\\(&\\|[a-z0-9_]+\/?\\)" 1 font-lock-function-name-face)
("\\([=]\\)" 0 font-lock-preprocessor-face prepend)
("\\(?:^\\|,\\) *\\(#[a-z0-9_]+\/?\\)" (1 font-lock-keyword-face)
2008-02-16 17:31:10 +07:00
("\\.[a-z0-9_-]+" nil nil (0 font-lock-type-face)))
2008-04-22 16:36:51 -07:00
("\\(?:^\\|,\\) *\\(\\.[a-z0-9_]+\/?\\)" (1 font-lock-type-face)
2008-02-16 17:31:10 +07:00
("\\.[a-z0-9_-]+" nil nil (0 font-lock-type-face)))
2008-04-22 16:36:51 -07:00
("\\(?:^\\|,\\) *\\(\\.[a-z0-9_]+\/?\\)" (1 font-lock-type-face)
2008-02-16 17:31:10 +07:00
("\\#[a-z0-9_-]+" nil nil (0 font-lock-keyword-face)))
2008-04-22 16:36:51 -07:00
("\\(?:^\\|,\\) *\\(&\\|[a-z0-9_]+\/?\\)" (1 font-lock-function-name-face)
2008-02-16 17:31:10 +07:00
("\\.[a-z0-9_-]+" nil nil (0 font-lock-type-face)))
2008-04-22 16:36:51 -07:00
("\\(?:^\\|,\\) *\\(&\\|[a-z0-9_]+\/?\\)" (1 font-lock-function-name-face)
("\\#[a-z0-9_-]+" nil nil (0 font-lock-keyword-face)))))
2008-02-16 17:31:10 +07:00
;; Constants
;; Mode setup
2008-11-27 22:57:30 -08:00
;;;###autoload
2008-04-22 18:43:31 -07:00
(define-derived-mode sass-mode haml-mode "Sass"
"Major mode for editing Sass files."
(set-syntax-table (make-syntax-table))
(setq font-lock-extend-region-functions
'(font-lock-extend-region-wholelines font-lock-extend-region-multiline))
(setq font-lock-multiline nil)
(setq comment-start "/*")
2008-04-24 09:09:42 -07:00
(set (make-local-variable 'haml-indent-function) 'sass-indent-p)
2008-04-22 18:43:31 -07:00
(set (make-local-variable 'haml-indent-offset) sass-indent-offset)
(setq font-lock-defaults '(sass-font-lock-keywords nil t)))
2008-04-24 09:09:42 -07:00
;; Indentation
(defun sass-indent-p ()
"Returns t if the current line can have lines nested beneath it."
2008-04-24 09:09:42 -07:00
(loop for opener in sass-non-block-openers
unless (looking-at opener) return t
return nil))
;;;###autoload
(add-to-list 'auto-mode-alist '("\\.sass$" . sass-mode))
;; Setup/Activation
(provide 'sass-mode)
;;; sass-mode.el ends here