Make sass-mode inherit from haml-mode.

This commit is contained in:
Nathan Weizenbaum 2008-04-22 18:43:31 -07:00
parent d08fc6eda0
commit 13c868e00e
2 changed files with 16 additions and 55 deletions

View File

@ -40,6 +40,12 @@
:group 'faces
:group 'haml)
(defvar haml-compute-indentation-function 'haml-compute-indentation
"The function used to compute the indentation of a Haml line.
This function should return a number indicating the column at
which the current line should be indented. This column should be
the maximum column that makes sense to indent the line.")
;; Font lock
(defconst haml-font-lock-keywords
@ -149,7 +155,7 @@
(defun haml-indent-region (start end)
"Indent each nonblank line in the region.
This is done by indenting the first line based on
`haml-compute-indentation' and preserving the relative
`haml-compute-indentation-function' and preserving the relative
indentation of the rest of the region.
If this command is used multiple times in a row, it will cycle
@ -164,7 +170,7 @@ between possible indentations."
(next-line-column
(if (and (equal last-command this-command) (/= (current-indentation) 0))
(* (/ (- (current-indentation) 1) haml-indent-offset) haml-indent-offset)
(haml-compute-indentation))))
(funcall haml-compute-indentation-function))))
(while (< (point) end)
(setq this-line-column next-line-column
current-column (current-indentation))
@ -190,7 +196,7 @@ back-dent the line by `haml-indent-offset' spaces. On reaching column
(interactive "*")
(let ((ci (current-indentation))
(cc (current-column))
(need (haml-compute-indentation)))
(need (funcall haml-compute-indentation-function)))
(save-excursion
(beginning-of-line)
(delete-horizontal-space)

View File

@ -14,6 +14,8 @@
;;; Code:
(require 'haml-mode)
;; User definable variables
(defgroup sass nil
@ -31,17 +33,10 @@
:type 'integer
:group 'sass)
(defface sass-tab-face
'((((class color)) (:background "hotpink"))
(t (:reverse-video t)))
"Face to use for highlighting tabs in Sass files."
:group 'faces
:group 'sass)
;; Font lock
(defconst sass-font-lock-keywords
'(("^ *\\(\t\\)" 1 'sass-tab-face)
'(("^ *\\(\t\\)" 1 'haml-tab-face)
("^@.*" 0 font-lock-constant-face)
("\\(\'[^']*'\\)" 1 font-lock-string-face append)
("\\(\"[^\"]*\"\\)" 1 font-lock-string-face append)
@ -74,17 +69,10 @@
;; Mode setup
(defvar sass-mode-map
(let ((map (make-sparse-keymap)))
(define-key sass-mode-map [backspace] 'sass-electric-backspace)
(define-key sass-mode-map "\C-?" 'sass-electric-backspace)
map))
(define-derived-mode sass-mode fundamental-mode "Sass"
"Major mode for editing Sass files.
\\{sass-mode-map}"
(set (make-local-variable 'indent-line-function) 'sass-indent-line)
(define-derived-mode sass-mode haml-mode "Sass"
"Major mode for editing Sass files."
(set (make-local-variable 'haml-compute-indentation-function) 'sass-compute-indentation)
(set (make-local-variable 'haml-indent-offset) sass-indent-offset)
(setq font-lock-defaults
'(sass-font-lock-keywords nil t)))
@ -103,39 +91,6 @@
(if (not (looking-at sass-full-attr-re))
sass-indent-offset 0)))))
(defun sass-indent-line ()
"Indent the current line.
The first time this command is used, the line will be indented to the
maximum sensible indentation. Each immediately subsequent usage will
back-dent the line by `sass-indent-offset' spaces. On reaching column
0, it will cycle back to the maximum sensible indentation."
(interactive "*")
(let ((ci (current-indentation))
(cc (current-column))
(need (sass-compute-indentation)))
(save-excursion
(beginning-of-line)
(delete-horizontal-space)
(if (and (equal last-command this-command) (/= ci 0))
(indent-to (* (/ (- ci 1) sass-indent-offset) sass-indent-offset))
(indent-to need)))
(if (< (current-column) (current-indentation))
(forward-to-indentation 0))))
(defun sass-electric-backspace (arg)
"Delete characters or back-dent the current line.
If invoked following only whitespace on a line, will back-dent to the
immediately previous multiple of `sass-indent-offset' spaces."
(interactive "*p")
(if (or (/= (current-indentation) (current-column)) (bolp))
(backward-delete-char arg)
(let ((ci (current-column)))
(beginning-of-line)
(delete-horizontal-space)
(indent-to (* (/ (- ci (* arg sass-indent-offset))
sass-indent-offset)
sass-indent-offset)))))
;; Setup/Activation
(provide 'sass-mode)