From 4d973434010020dff752e349b667660b87076ee9 Mon Sep 17 00:00:00 2001 From: Nathan Weizenbaum Date: Tue, 22 Apr 2008 16:36:51 -0700 Subject: [PATCH] Clean up haml- and sass-mode.el. --- extra/haml-mode.el | 96 +++++++++++++++++++--------------------------- extra/sass-mode.el | 78 ++++++++++++++----------------------- 2 files changed, 68 insertions(+), 106 deletions(-) diff --git a/extra/haml-mode.el b/extra/haml-mode.el index 3ff1912d..ebd2c9d5 100644 --- a/extra/haml-mode.el +++ b/extra/haml-mode.el @@ -24,17 +24,17 @@ :prefix "haml-") (defcustom haml-mode-hook nil - "*Hook run by `haml-mode'." + "Hook run when entering Haml mode." :type 'hook :group 'haml) (defcustom haml-indent-offset 2 - "*Amount of offset per level of indentation." + "Amount of offset per level of indentation." :type 'integer :group 'haml) (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 :group 'haml) @@ -66,45 +66,31 @@ returns a non-nil value, or nil if no such element is found." ;; Font lock -(defconst haml-font-lock-keywords-1 - (list - ;; instruct - '("^!!!.*" 0 font-lock-constant-face) - ;; strings - '("\\('[^']*'\\)" 1 font-lock-string-face append) - '("\\(\"[^\"]*\"\\)" 1 font-lock-string-face append) - ;; symbol - '("&?:\\w+" 0 font-lock-constant-face append) - ;; ruby varible - '("@[a-z0-9_]+" 0 font-lock-variable-name-face append) - ;; pipe - '("| *$" 0 font-lock-string-face) - ;; comment - '("^[ \t]*\\(/.*\\)$" 1 font-lock-comment-face append) - ;; id - '("^ *\\(#[a-z0-9_]+\/?\\)" 1 font-lock-keyword-face) - ;; class - '("^ *\\(\\.[a-z0-9_]+\/?\\)" 1 font-lock-type-face) - ;; tag - '("^ *\\(%[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))) - ;; class after class - '("^ *\\(\\.[a-z0-9_]+\/?\\)" (1 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_]+" 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))) +(defconst haml-font-lock-keywords + '(("^!!!.*" 0 font-lock-constant-face) + ("\\('[^']*'\\)" 1 font-lock-string-face append) + ("\\(\"[^\"]*\"\\)" 1 font-lock-string-face append) + ("&?:\\w+" 0 font-lock-constant-face append) + ("@[a-z0-9_]+" 0 font-lock-variable-name-face append) + ("| *$" 0 font-lock-string-face) + ("^[ \t]*\\(/.*\\)$" 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) + ("^ *\\(#[a-z0-9_]+\/?\\)" (1 font-lock-keyword-face) + ("\\.[a-z0-9_]+" nil nil (0 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_]+\/?\\)" (1 font-lock-type-face) + ("\\#[a-z0-9_]+" nil nil (0 font-lock-keyword-face))) + ("^ *\\(%[a-z0-9_]+\/?\\)" (1 font-lock-function-name-face) + ("\\.[a-z0-9_]+" nil nil (0 font-lock-type-face))) + ("^ *\\(%[a-z0-9_]+\/?\\)" (1 font-lock-function-name-face) + ("\\#[a-z0-9_]+" nil nil (0 font-lock-keyword-face))) + ("^ *\\([~=-] .*\\)" 1 font-lock-preprocessor-face prepend) + ("^ *[\\.#%a-z0-9_]+\\([~=-] .*\\)" 1 font-lock-preprocessor-face prepend) + ("^ *[\\.#%a-z0-9_]+\\({[^}]+}\\)" 1 font-lock-preprocessor-face prepend) + ("^ *[\\.#%a-z0-9_]+\\(\\[[^]]+\\]\\)" 1 font-lock-preprocessor-face prepend))) ;; Constants @@ -113,8 +99,9 @@ returns a non-nil value, or nil if no such element is found." (defconst haml-blank-line-re "^[ \t]*$" "Regexp matching a line containing only whitespace.") -; Base for Regexen matching a Haml tag. -(setq haml-tag-re-base (hre "\\([%\\.#][^ \t]*\\)\\({.*}\\)?\\(\\[.*\\]\\)?")) +(defconst haml-tag-re-base + (hre "\\([%\\.#][^ \t]*\\)\\({.*}\\)?\\(\\[.*\\]\\)?") + "Base for regexps matching Haml tags.") (defconst haml-tag-nest-re (concat haml-tag-re-base "[ \t]*$") "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) "Syntax table in use in haml-mode buffers.") -(defvar haml-mode-map () - "Keymap used in `haml-mode' buffers.") -(if haml-mode-map - nil - (setq haml-mode-map (make-sparse-keymap)) - (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)) +(defvar haml-mode-map + (let ((map (make-sparse-keymap))) + (define-key map [backspace] 'haml-electric-backspace) + (define-key map "\C-?" 'haml-electric-backspace) + map)) (define-derived-mode haml-mode fundamental-mode "Haml" - "Simple mode to edit Haml. + "Major mode for editing Haml files. \\{haml-mode-map}" (set-syntax-table haml-mode-syntax-table) (set (make-local-variable 'indent-line-function) 'haml-indent-line) (set (make-local-variable 'indent-region-function) 'haml-indent-region) - (set (make-local-variable 'font-lock-defaults) - '((haml-font-lock-keywords-1) - nil - t))) + (setq font-lock-defaults + '((haml-font-lock-keywords) nil t))) ;; Indentation and electric keys diff --git a/extra/sass-mode.el b/extra/sass-mode.el index b38fb7c7..0ccacb6e 100644 --- a/extra/sass-mode.el +++ b/extra/sass-mode.el @@ -22,17 +22,17 @@ :prefix "sass-") (defcustom sass-mode-hook nil - "*Hook run by `sass-mode'." + "Hook run when entering Sass mode." :type 'hook :group 'sass) (defcustom sass-indent-offset 2 - "*Amount of offset per level of indentation." + "Amount of offset per level of indentation." :type 'integer :group 'sass) (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 :group 'sass) @@ -63,43 +63,28 @@ ;; Font lock -(defconst sass-font-lock-keywords-1 - (list - ;; directives - '("^@.*" 0 font-lock-constant-face) - ;; strings and hex constants - '("\\(\'[^']*'\\)" 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) - ;; attributes - '("\\(:[A-Za-z-]+\\|[A-Za-z-]+:\\)" 0 font-lock-constant-face append) - ;; constants - '("![a-z0-9_-]+" 0 font-lock-variable-name-face append) - ;; comments - '("^ *\\(/[/*].*\\)$" 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) +(defconst sass-font-lock-keywords + '(("^@.*" 0 font-lock-constant-face) + ("\\(\'[^']*'\\)" 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) ("\\.[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))) - ;; 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))) - ;; 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))) - ;; id after tag - '("\\(?:^\\|,\\) *\\(&\\|[a-z0-9_]+\/?\\)" (1 font-lock-function-name-face) - ("\\#[a-z0-9_-]+" nil nil (0 font-lock-keyword-face))) - ;; expressions - '("\\([=]\\)" 0 font-lock-preprocessor-face prepend))) + ("\\(?:^\\|,\\) *\\(&\\|[a-z0-9_]+\/?\\)" (1 font-lock-function-name-face) + ("\\#[a-z0-9_-]+" nil nil (0 font-lock-keyword-face))))) ;; Constants @@ -113,24 +98,19 @@ ;; Mode setup -(defvar sass-mode-map () - "Keymap used in `sass-mode' buffers.") -(if sass-mode-map - nil - (setq sass-mode-map (make-sparse-keymap)) - (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)) +(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" - "Simple mode to edit Sass. + "Major mode for editing Sass files. \\{sass-mode-map}" (set (make-local-variable 'indent-line-function) 'sass-indent-line) - (set (make-local-variable 'font-lock-defaults) - '((sass-font-lock-keywords-1) - nil - t))) + (setq font-lock-defaults + '(sass-font-lock-keywords nil t))) ;; Indentation and electric keys