Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #3 from mmichelli/master

Stylus-mode
  • Loading branch information...
commit 523ac5b79f66eeccce11f4876556e6e9939fa29a 2 parents e9cc84a + c6623ac
@brianc brianc authored
Showing with 90 additions and 0 deletions.
  1. +90 −0 stylus-mode.el
View
90 stylus-mode.el
@@ -0,0 +1,90 @@
+;; copied from http://xahlee.org/emacs/elisp_syntax_coloring.html
+(require 'font-lock)
+
+(defun stylus-debug (string &rest args)
+ "Prints a debug message"
+ (apply 'message (append (list string) args)))
+
+(defmacro stylus-line-as-string ()
+ "Returns the current line as a string."
+ `(buffer-substring (point-at-bol) (point-at-eol)))
+
+
+(defun stylus-empty-line-p ()
+ "If line is empty or not."
+ (= (point-at-eol) (point-at-bol)))
+
+(defun stylus-blank-line-p ()
+ "If line contains only spaces."
+ (string-match-p "^[ ]*$" (stylus-line-as-string)))
+
+(defconst stylus-colours
+ (eval-when-compile
+ (regexp-opt
+ '("black" "silver" "gray" "white" "maroon" "red"
+ "purple" "fuchsia" "green" "lime" "olive" "yellow" "navy"
+ "blue" "teal" "aqua")))
+ "Stylus keywords.")
+
+(defconst stylus-keywords
+ (eval-when-compile
+ (regexp-opt
+ '("return" "if" "else" "unless" "for" "in" "true" "false")))
+ "Stylus keywords.")
+
+(setq stylus-font-lock-keywords
+ `(
+ (,"^[ {2,}]+[a-z0-9_:\\-]+[ ]" 0 font-lock-variable-name-face)
+ (,"^//.*" 0 font-lock-comment-face)
+ (,"\\(::?\\(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
+ (,(concat "[^_$]?\\<\\(" stylus-colours "\\)\\>[^_]?")
+ 0 font-lock-constant-face)
+ (,(concat "[^_$]?\\<\\(" stylus-keywords "\\)\\>[^_]?")
+ 0 font-lock-keyword-face)
+ (,"\\([0-9]+:?\\(em\\|ex\\|px\\|mm\\|cm\\|in\\|pt\\|pc\\|deg\\|rad\\|grad\\|ms\\|s\\|Hz\\|kHz\\|rem\\|%\\)\\)" 0 font-lock-constant-face)
+ (,"#\\w+" 0 font-lock-keyword-face)
+ (,"$\\w+" 0 font-lock-variable-name-face)
+ ))
+
+(defun stylus-region-for-sexp ()
+ "Selects the current sexp as the region"
+ (interactive)
+ (beginning-of-line)
+ (let ((ci (current-indentation)))
+ (push-mark nil nil t)
+ (while (> (stylus-next-line-indent) ci)
+ (next-line)
+ (end-of-line))))
+
+(defvar stylus-mode-map (make-sparse-keymap))
+;;defer to sws-mode
+;;(define-key stylus-mode-map [S-tab] 'stylus-unindent-line)
+
+;; mode declaration
+(define-derived-mode stylus-mode sws-mode
+ "Stylus"
+ "Major mode for editing stylus node.js templates"
+ (kill-all-local-variables)
+ (setq tab-width 2)
+
+ (setq mode-name "Stylus")
+ (setq major-mode 'stylus-mode)
+
+ ;; default tab width
+ (setq sws-tab-width 2)
+ (make-local-variable 'indent-line-function)
+ (setq indent-line-function 'sws-indent-line)
+ (make-local-variable 'indent-region-function)
+
+ (setq indent-region-function 'sws-indent-region)
+
+
+ ;; keymap
+ (use-local-map stylus-mode-map)
+
+ ;; highlight syntax
+ (setq font-lock-defaults '(stylus-font-lock-keywords)))
+
+(provide 'stylus-mode)
+
+(add-to-list 'auto-mode-alist '("\\.styl$" . stylus-mode))
Please sign in to comment.
Something went wrong with that request. Please try again.