Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 114 lines (92 sloc) 3.591 kb
41351ec @purcell Add autoload declarations, explicit requires and ELPA package dependenci...
purcell authored
1 ;;; stylus-mode.el --- Major mode for editing .jade files
2 ;;;
a1cbadd @brianc add .el file headers to enable automatic packaging - closes gh#6
authored
3 ;;; URL: https://github.com/brianc/jade-mode
4 ;;; Author: Brian M. Carlson and other contributors
41351ec @purcell Add autoload declarations, explicit requires and ELPA package dependenci...
purcell authored
5 ;;; Package-Requires: ((sws-mode "0"))
6 ;;;
a1cbadd @brianc add .el file headers to enable automatic packaging - closes gh#6
authored
7 ;;; copied from http://xahlee.org/emacs/elisp_syntax_coloring.html
c6623ac added a basic stylus-mode
mmichelli authored
8 (require 'font-lock)
41351ec @purcell Add autoload declarations, explicit requires and ELPA package dependenci...
purcell authored
9 (require 'sws-mode)
c6623ac added a basic stylus-mode
mmichelli authored
10
11 (defun stylus-debug (string &rest args)
12 "Prints a debug message"
13 (apply 'message (append (list string) args)))
14
15 (defmacro stylus-line-as-string ()
16 "Returns the current line as a string."
17 `(buffer-substring (point-at-bol) (point-at-eol)))
18
19
20 (defun stylus-empty-line-p ()
21 "If line is empty or not."
22 (= (point-at-eol) (point-at-bol)))
23
24 (defun stylus-blank-line-p ()
25 "If line contains only spaces."
26 (string-match-p "^[ ]*$" (stylus-line-as-string)))
27
28 (defconst stylus-colours
29 (eval-when-compile
30 (regexp-opt
31 '("black" "silver" "gray" "white" "maroon" "red"
32 "purple" "fuchsia" "green" "lime" "olive" "yellow" "navy"
33 "blue" "teal" "aqua")))
34 "Stylus keywords.")
35
36 (defconst stylus-keywords
37 (eval-when-compile
38 (regexp-opt
39 '("return" "if" "else" "unless" "for" "in" "true" "false")))
40 "Stylus keywords.")
41
62c012c @jkpl Improved Stylus comments syntax highlighting.
jkpl authored
42 (defvar stylus-font-lock-keywords
43 `(
44 (,"^[ {2,}]+[a-z0-9_:\\-]+[ ]" 0 font-lock-variable-name-face)
45 (,"\\(::?\\(root\\|nth-child\\|nth-last-child\\|nth-of-type\\|nth-last-of-type\\|first-child\\|last-child\\|first-of-type\\|last-of-type\\|only-child\\|only-of-type\\|empty\\|link\\|visited\\|active\\|hover\\|focus\\|target\\|lang\\|enabled\\|disabled\\|checked\\|not\\)\\)*" . font-lock-type-face) ;; pseudoSelectors
46 (,(concat "[^_$]?\\<\\(" stylus-colours "\\)\\>[^_]?")
47 0 font-lock-constant-face)
48 (,(concat "[^_$]?\\<\\(" stylus-keywords "\\)\\>[^_]?")
49 0 font-lock-keyword-face)
8f61e0d @jkpl Decimal point can be part of a constant.
jkpl authored
50 (,"\\([.0-9]+:?\\(em\\|ex\\|px\\|mm\\|cm\\|in\\|pt\\|pc\\|deg\\|rad\\|grad\\|ms\\|s\\|Hz\\|kHz\\|rem\\|%\\)\\)" 0 font-lock-constant-face)
62c012c @jkpl Improved Stylus comments syntax highlighting.
jkpl authored
51 (,"#\\w+" 0 font-lock-keyword-face)
52 (,"$\\w+" 0 font-lock-variable-name-face)
53 ))
c6623ac added a basic stylus-mode
mmichelli authored
54
109b985 @jkpl Created a syntax table for Stylus mode.
jkpl authored
55 (defvar stylus-syntax-table
56 (let ((syntable (make-syntax-table)))
57 (modify-syntax-entry ?\/ ". 124b" syntable)
58 (modify-syntax-entry ?* ". 23" syntable)
59 (modify-syntax-entry ?\n "> b" syntable)
a7c85da @jkpl Added single quoted strings support to stylus mode.
jkpl authored
60 (modify-syntax-entry ?' "\"" syntable)
109b985 @jkpl Created a syntax table for Stylus mode.
jkpl authored
61 syntable)
62 "Syntax table for `stylus-mode'.")
63
c6623ac added a basic stylus-mode
mmichelli authored
64 (defun stylus-region-for-sexp ()
65 "Selects the current sexp as the region"
66 (interactive)
67 (beginning-of-line)
68 (let ((ci (current-indentation)))
69 (push-mark nil nil t)
70 (while (> (stylus-next-line-indent) ci)
71 (next-line)
72 (end-of-line))))
73
74 (defvar stylus-mode-map (make-sparse-keymap))
75 ;;defer to sws-mode
76 ;;(define-key stylus-mode-map [S-tab] 'stylus-unindent-line)
77
78 ;; mode declaration
41351ec @purcell Add autoload declarations, explicit requires and ELPA package dependenci...
purcell authored
79 ;;;###autoload
c6623ac added a basic stylus-mode
mmichelli authored
80 (define-derived-mode stylus-mode sws-mode
81 "Stylus"
82 "Major mode for editing stylus node.js templates"
83 (setq tab-width 2)
84
85 (setq mode-name "Stylus")
86 (setq major-mode 'stylus-mode)
87
109b985 @jkpl Created a syntax table for Stylus mode.
jkpl authored
88 ;; syntax table
89 (set-syntax-table stylus-syntax-table)
90
62c012c @jkpl Improved Stylus comments syntax highlighting.
jkpl authored
91 ;; highlight syntax
92 (setq font-lock-defaults '(stylus-font-lock-keywords))
93
94 ;; comments
95 (set (make-local-variable 'comment-start) "//")
96 (set (make-local-variable 'comment-end) "")
97
c6623ac added a basic stylus-mode
mmichelli authored
98 ;; default tab width
99 (setq sws-tab-width 2)
100 (make-local-variable 'indent-line-function)
101 (setq indent-line-function 'sws-indent-line)
102 (make-local-variable 'indent-region-function)
103
104 (setq indent-region-function 'sws-indent-region)
105
106 ;; keymap
62c012c @jkpl Improved Stylus comments syntax highlighting.
jkpl authored
107 (use-local-map stylus-mode-map))
c6623ac added a basic stylus-mode
mmichelli authored
108
41351ec @purcell Add autoload declarations, explicit requires and ELPA package dependenci...
purcell authored
109 ;;;###autoload
c6623ac added a basic stylus-mode
mmichelli authored
110 (add-to-list 'auto-mode-alist '("\\.styl$" . stylus-mode))
41351ec @purcell Add autoload declarations, explicit requires and ELPA package dependenci...
purcell authored
111
112 (provide 'stylus-mode)
113 ;;; stylus-mode.el ends here
Something went wrong with that request. Please try again.