mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
Clean up haml- and sass-mode.el.
This commit is contained in:
parent
5f09785d91
commit
4d97343401
2 changed files with 68 additions and 106 deletions
|
@ -24,17 +24,17 @@
|
||||||
:prefix "haml-")
|
:prefix "haml-")
|
||||||
|
|
||||||
(defcustom haml-mode-hook nil
|
(defcustom haml-mode-hook nil
|
||||||
"*Hook run by `haml-mode'."
|
"Hook run when entering Haml mode."
|
||||||
:type 'hook
|
:type 'hook
|
||||||
:group 'haml)
|
:group 'haml)
|
||||||
|
|
||||||
(defcustom haml-indent-offset 2
|
(defcustom haml-indent-offset 2
|
||||||
"*Amount of offset per level of indentation."
|
"Amount of offset per level of indentation."
|
||||||
:type 'integer
|
:type 'integer
|
||||||
:group 'haml)
|
:group 'haml)
|
||||||
|
|
||||||
(defcustom haml-backspace-function 'backward-delete-char-untabify
|
(defcustom haml-backspace-function 'backward-delete-char-untabify
|
||||||
"*Function called by `haml-electric-backspace' when deleting backwards."
|
"Function called by `haml-electric-backspace' when deleting backwards."
|
||||||
:type 'function
|
:type 'function
|
||||||
:group 'haml)
|
:group 'haml)
|
||||||
|
|
||||||
|
@ -66,45 +66,31 @@ returns a non-nil value, or nil if no such element is found."
|
||||||
|
|
||||||
;; Font lock
|
;; Font lock
|
||||||
|
|
||||||
(defconst haml-font-lock-keywords-1
|
(defconst haml-font-lock-keywords
|
||||||
(list
|
'(("^!!!.*" 0 font-lock-constant-face)
|
||||||
;; instruct
|
("\\('[^']*'\\)" 1 font-lock-string-face append)
|
||||||
'("^!!!.*" 0 font-lock-constant-face)
|
("\\(\"[^\"]*\"\\)" 1 font-lock-string-face append)
|
||||||
;; strings
|
("&?:\\w+" 0 font-lock-constant-face append)
|
||||||
'("\\('[^']*'\\)" 1 font-lock-string-face append)
|
("@[a-z0-9_]+" 0 font-lock-variable-name-face append)
|
||||||
'("\\(\"[^\"]*\"\\)" 1 font-lock-string-face append)
|
("| *$" 0 font-lock-string-face)
|
||||||
;; symbol
|
("^[ \t]*\\(/.*\\)$" 1 font-lock-comment-face append)
|
||||||
'("&?:\\w+" 0 font-lock-constant-face append)
|
("^ *\\(#[a-z0-9_]+\/?\\)" 1 font-lock-keyword-face)
|
||||||
;; ruby varible
|
("^ *\\(\\.[a-z0-9_]+\/?\\)" 1 font-lock-type-face)
|
||||||
'("@[a-z0-9_]+" 0 font-lock-variable-name-face append)
|
("^ *\\(%[a-z0-9_]+\/?\\)" 1 font-lock-function-name-face)
|
||||||
;; pipe
|
("^ *\\(#[a-z0-9_]+\/?\\)" (1 font-lock-keyword-face)
|
||||||
'("| *$" 0 font-lock-string-face)
|
("\\.[a-z0-9_]+" nil nil (0 font-lock-type-face)))
|
||||||
;; comment
|
("^ *\\(\\.[a-z0-9_]+\/?\\)" (1 font-lock-type-face)
|
||||||
'("^[ \t]*\\(/.*\\)$" 1 font-lock-comment-face append)
|
("\\.[a-z0-9_]+" nil nil (0 font-lock-type-face)))
|
||||||
;; id
|
("^ *\\(\\.[a-z0-9_]+\/?\\)" (1 font-lock-type-face)
|
||||||
'("^ *\\(#[a-z0-9_]+\/?\\)" 1 font-lock-keyword-face)
|
("\\#[a-z0-9_]+" nil nil (0 font-lock-keyword-face)))
|
||||||
;; class
|
("^ *\\(%[a-z0-9_]+\/?\\)" (1 font-lock-function-name-face)
|
||||||
'("^ *\\(\\.[a-z0-9_]+\/?\\)" 1 font-lock-type-face)
|
("\\.[a-z0-9_]+" nil nil (0 font-lock-type-face)))
|
||||||
;; tag
|
("^ *\\(%[a-z0-9_]+\/?\\)" (1 font-lock-function-name-face)
|
||||||
'("^ *\\(%[a-z0-9_]+\/?\\)" 1 font-lock-function-name-face )
|
("\\#[a-z0-9_]+" nil nil (0 font-lock-keyword-face)))
|
||||||
;; class after id
|
("^ *\\([~=-] .*\\)" 1 font-lock-preprocessor-face prepend)
|
||||||
'("^ *\\(#[a-z0-9_]+\/?\\)" (1 font-lock-keyword-face) ("\\.[a-z0-9_]+" nil nil (0 font-lock-type-face)))
|
("^ *[\\.#%a-z0-9_]+\\([~=-] .*\\)" 1 font-lock-preprocessor-face prepend)
|
||||||
;; class after class
|
("^ *[\\.#%a-z0-9_]+\\({[^}]+}\\)" 1 font-lock-preprocessor-face prepend)
|
||||||
'("^ *\\(\\.[a-z0-9_]+\/?\\)" (1 font-lock-type-face) ("\\.[a-z0-9_]+" nil nil (0 font-lock-type-face)))
|
("^ *[\\.#%a-z0-9_]+\\(\\[[^]]+\\]\\)" 1 font-lock-preprocessor-face prepend)))
|
||||||
;; id after class
|
|
||||||
'("^ *\\(\\.[a-z0-9_]+\/?\\)" (1 font-lock-type-face) ("\\#[a-z0-9_]+" nil nil (0 font-lock-keyword-face)))
|
|
||||||
;; class after tag
|
|
||||||
'("^ *\\(%[a-z0-9_]+\/?\\)" (1 font-lock-function-name-face) ("\\.[a-z0-9_]+" nil nil (0 font-lock-type-face)))
|
|
||||||
;; id after tag
|
|
||||||
'("^ *\\(%[a-z0-9_]+\/?\\)" (1 font-lock-function-name-face) ("\\#[a-z0-9_]+" nil nil (0 font-lock-keyword-face)))
|
|
||||||
;; embeded ruby: beggin of line
|
|
||||||
'("^ *\\([~=-] .*\\)" 1 font-lock-preprocessor-face prepend)
|
|
||||||
;; embeded ruby: after tag,class,id
|
|
||||||
'("^ *[\\.#%a-z0-9_]+\\([~=-] .*\\)" 1 font-lock-preprocessor-face prepend)
|
|
||||||
;; embeded ruby: attributes
|
|
||||||
'("^ *[\\.#%a-z0-9_]+\\({[^}]+}\\)" 1 font-lock-preprocessor-face prepend)
|
|
||||||
;; embeded ruby: square
|
|
||||||
'("^ *[\\.#%a-z0-9_]+\\(\\[[^]]+\\]\\)" 1 font-lock-preprocessor-face prepend)))
|
|
||||||
|
|
||||||
;; Constants
|
;; Constants
|
||||||
|
|
||||||
|
@ -113,8 +99,9 @@ returns a non-nil value, or nil if no such element is found."
|
||||||
(defconst haml-blank-line-re "^[ \t]*$"
|
(defconst haml-blank-line-re "^[ \t]*$"
|
||||||
"Regexp matching a line containing only whitespace.")
|
"Regexp matching a line containing only whitespace.")
|
||||||
|
|
||||||
; Base for Regexen matching a Haml tag.
|
(defconst haml-tag-re-base
|
||||||
(setq haml-tag-re-base (hre "\\([%\\.#][^ \t]*\\)\\({.*}\\)?\\(\\[.*\\]\\)?"))
|
(hre "\\([%\\.#][^ \t]*\\)\\({.*}\\)?\\(\\[.*\\]\\)?")
|
||||||
|
"Base for regexps matching Haml tags.")
|
||||||
|
|
||||||
(defconst haml-tag-nest-re (concat haml-tag-re-base "[ \t]*$")
|
(defconst haml-tag-nest-re (concat haml-tag-re-base "[ \t]*$")
|
||||||
"Regexp matching a Haml tag that can have nested elements.")
|
"Regexp matching a Haml tag that can have nested elements.")
|
||||||
|
@ -149,26 +136,21 @@ returns a non-nil value, or nil if no such element is found."
|
||||||
table)
|
table)
|
||||||
"Syntax table in use in haml-mode buffers.")
|
"Syntax table in use in haml-mode buffers.")
|
||||||
|
|
||||||
(defvar haml-mode-map ()
|
(defvar haml-mode-map
|
||||||
"Keymap used in `haml-mode' buffers.")
|
(let ((map (make-sparse-keymap)))
|
||||||
(if haml-mode-map
|
(define-key map [backspace] 'haml-electric-backspace)
|
||||||
nil
|
(define-key map "\C-?" 'haml-electric-backspace)
|
||||||
(setq haml-mode-map (make-sparse-keymap))
|
map))
|
||||||
(define-key haml-mode-map [backspace] 'haml-electric-backspace)
|
|
||||||
(define-key haml-mode-map "\C-?" 'haml-electric-backspace)
|
|
||||||
(define-key haml-mode-map "\C-j" 'newline-and-indent))
|
|
||||||
|
|
||||||
(define-derived-mode haml-mode fundamental-mode "Haml"
|
(define-derived-mode haml-mode fundamental-mode "Haml"
|
||||||
"Simple mode to edit Haml.
|
"Major mode for editing Haml files.
|
||||||
|
|
||||||
\\{haml-mode-map}"
|
\\{haml-mode-map}"
|
||||||
(set-syntax-table haml-mode-syntax-table)
|
(set-syntax-table haml-mode-syntax-table)
|
||||||
(set (make-local-variable 'indent-line-function) 'haml-indent-line)
|
(set (make-local-variable 'indent-line-function) 'haml-indent-line)
|
||||||
(set (make-local-variable 'indent-region-function) 'haml-indent-region)
|
(set (make-local-variable 'indent-region-function) 'haml-indent-region)
|
||||||
(set (make-local-variable 'font-lock-defaults)
|
(setq font-lock-defaults
|
||||||
'((haml-font-lock-keywords-1)
|
'((haml-font-lock-keywords) nil t)))
|
||||||
nil
|
|
||||||
t)))
|
|
||||||
|
|
||||||
;; Indentation and electric keys
|
;; Indentation and electric keys
|
||||||
|
|
||||||
|
|
|
@ -22,17 +22,17 @@
|
||||||
:prefix "sass-")
|
:prefix "sass-")
|
||||||
|
|
||||||
(defcustom sass-mode-hook nil
|
(defcustom sass-mode-hook nil
|
||||||
"*Hook run by `sass-mode'."
|
"Hook run when entering Sass mode."
|
||||||
:type 'hook
|
:type 'hook
|
||||||
:group 'sass)
|
:group 'sass)
|
||||||
|
|
||||||
(defcustom sass-indent-offset 2
|
(defcustom sass-indent-offset 2
|
||||||
"*Amount of offset per level of indentation."
|
"Amount of offset per level of indentation."
|
||||||
:type 'integer
|
:type 'integer
|
||||||
:group 'sass)
|
:group 'sass)
|
||||||
|
|
||||||
(defcustom sass-backspace-function 'backward-delete-char-untabify
|
(defcustom sass-backspace-function 'backward-delete-char-untabify
|
||||||
"*Function called by `sass-electric-backspace' when deleting backwards."
|
"Function called by `sass-electric-backspace' when deleting backwards."
|
||||||
:type 'function
|
:type 'function
|
||||||
:group 'sass)
|
:group 'sass)
|
||||||
|
|
||||||
|
@ -63,43 +63,28 @@
|
||||||
|
|
||||||
;; Font lock
|
;; Font lock
|
||||||
|
|
||||||
(defconst sass-font-lock-keywords-1
|
(defconst sass-font-lock-keywords
|
||||||
(list
|
'(("^@.*" 0 font-lock-constant-face)
|
||||||
;; directives
|
("\\(\'[^']*'\\)" 1 font-lock-string-face append)
|
||||||
'("^@.*" 0 font-lock-constant-face)
|
("\\(\"[^\"]*\"\\)" 1 font-lock-string-face append)
|
||||||
;; strings and hex constants
|
("\\(#[0-9a-fA-F]\\{3\\}\\{1,2\\}\\>\\)" 1 font-lock-string-face append)
|
||||||
'("\\(\'[^']*'\\)" 1 font-lock-string-face append)
|
("\\(:[A-Za-z-]+\\|[A-Za-z-]+:\\)" 0 font-lock-constant-face append)
|
||||||
'("\\(\"[^\"]*\"\\)" 1 font-lock-string-face append)
|
("![a-z0-9_-]+" 0 font-lock-variable-name-face append)
|
||||||
'("\\(#[0-9a-fA-F]\\{3\\}\\{1,2\\}\\>\\)" 1 font-lock-string-face append)
|
("^ *\\(/[/*].*\\)$" 1 font-lock-comment-face append)
|
||||||
;; attributes
|
("\\(?:^\\|,\\) *\\(#[a-z0-9_-]+\/?\\)" 1 font-lock-keyword-face)
|
||||||
'("\\(:[A-Za-z-]+\\|[A-Za-z-]+:\\)" 0 font-lock-constant-face append)
|
("\\(?:^\\|,\\) *\\(\\.[a-z0-9_-]+\/?\\)" 1 font-lock-type-face)
|
||||||
;; constants
|
("\\(?:^\\|,\\) *\\(&\\|[a-z0-9_]+\/?\\)" 1 font-lock-function-name-face)
|
||||||
'("![a-z0-9_-]+" 0 font-lock-variable-name-face append)
|
("\\([=]\\)" 0 font-lock-preprocessor-face prepend)
|
||||||
;; comments
|
("\\(?:^\\|,\\) *\\(#[a-z0-9_]+\/?\\)" (1 font-lock-keyword-face)
|
||||||
'("^ *\\(/[/*].*\\)$" 1 font-lock-comment-face append)
|
|
||||||
;; ids
|
|
||||||
'("\\(?:^\\|,\\) *\\(#[a-z0-9_-]+\/?\\)" 1 font-lock-keyword-face)
|
|
||||||
;; classes
|
|
||||||
'("\\(?:^\\|,\\) *\\(\\.[a-z0-9_-]+\/?\\)" 1 font-lock-type-face)
|
|
||||||
;; tags
|
|
||||||
'("\\(?:^\\|,\\) *\\(&\\|[a-z0-9_]+\/?\\)" 1 font-lock-function-name-face )
|
|
||||||
;; class after id
|
|
||||||
'("\\(?:^\\|,\\) *\\(#[a-z0-9_]+\/?\\)" (1 font-lock-keyword-face)
|
|
||||||
("\\.[a-z0-9_-]+" nil nil (0 font-lock-type-face)))
|
("\\.[a-z0-9_-]+" nil nil (0 font-lock-type-face)))
|
||||||
;; class after class
|
("\\(?:^\\|,\\) *\\(\\.[a-z0-9_]+\/?\\)" (1 font-lock-type-face)
|
||||||
'("\\(?:^\\|,\\) *\\(\\.[a-z0-9_]+\/?\\)" (1 font-lock-type-face)
|
|
||||||
("\\.[a-z0-9_-]+" nil nil (0 font-lock-type-face)))
|
("\\.[a-z0-9_-]+" nil nil (0 font-lock-type-face)))
|
||||||
;; id after class
|
("\\(?:^\\|,\\) *\\(\\.[a-z0-9_]+\/?\\)" (1 font-lock-type-face)
|
||||||
'("\\(?:^\\|,\\) *\\(\\.[a-z0-9_]+\/?\\)" (1 font-lock-type-face)
|
|
||||||
("\\#[a-z0-9_-]+" nil nil (0 font-lock-keyword-face)))
|
("\\#[a-z0-9_-]+" nil nil (0 font-lock-keyword-face)))
|
||||||
;; class after tag
|
("\\(?:^\\|,\\) *\\(&\\|[a-z0-9_]+\/?\\)" (1 font-lock-function-name-face)
|
||||||
'("\\(?:^\\|,\\) *\\(&\\|[a-z0-9_]+\/?\\)" (1 font-lock-function-name-face)
|
|
||||||
("\\.[a-z0-9_-]+" nil nil (0 font-lock-type-face)))
|
("\\.[a-z0-9_-]+" nil nil (0 font-lock-type-face)))
|
||||||
;; id after tag
|
("\\(?:^\\|,\\) *\\(&\\|[a-z0-9_]+\/?\\)" (1 font-lock-function-name-face)
|
||||||
'("\\(?:^\\|,\\) *\\(&\\|[a-z0-9_]+\/?\\)" (1 font-lock-function-name-face)
|
("\\#[a-z0-9_-]+" nil nil (0 font-lock-keyword-face)))))
|
||||||
("\\#[a-z0-9_-]+" nil nil (0 font-lock-keyword-face)))
|
|
||||||
;; expressions
|
|
||||||
'("\\([=]\\)" 0 font-lock-preprocessor-face prepend)))
|
|
||||||
|
|
||||||
;; Constants
|
;; Constants
|
||||||
|
|
||||||
|
@ -113,24 +98,19 @@
|
||||||
|
|
||||||
;; Mode setup
|
;; Mode setup
|
||||||
|
|
||||||
(defvar sass-mode-map ()
|
(defvar sass-mode-map
|
||||||
"Keymap used in `sass-mode' buffers.")
|
(let ((map (make-sparse-keymap)))
|
||||||
(if sass-mode-map
|
(define-key sass-mode-map [backspace] 'sass-electric-backspace)
|
||||||
nil
|
(define-key sass-mode-map "\C-?" 'sass-electric-backspace)
|
||||||
(setq sass-mode-map (make-sparse-keymap))
|
map))
|
||||||
(define-key sass-mode-map [backspace] 'sass-electric-backspace)
|
|
||||||
(define-key sass-mode-map "\C-?" 'sass-electric-backspace)
|
|
||||||
(define-key sass-mode-map "\C-j" 'newline-and-indent))
|
|
||||||
|
|
||||||
(define-derived-mode sass-mode fundamental-mode "Sass"
|
(define-derived-mode sass-mode fundamental-mode "Sass"
|
||||||
"Simple mode to edit Sass.
|
"Major mode for editing Sass files.
|
||||||
|
|
||||||
\\{sass-mode-map}"
|
\\{sass-mode-map}"
|
||||||
(set (make-local-variable 'indent-line-function) 'sass-indent-line)
|
(set (make-local-variable 'indent-line-function) 'sass-indent-line)
|
||||||
(set (make-local-variable 'font-lock-defaults)
|
(setq font-lock-defaults
|
||||||
'((sass-font-lock-keywords-1)
|
'(sass-font-lock-keywords nil t)))
|
||||||
nil
|
|
||||||
t)))
|
|
||||||
|
|
||||||
;; Indentation and electric keys
|
;; Indentation and electric keys
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue