branch: elpa/sass-mode commit 28dd06ba642620c76e38f8b60b06718fcdfd9f29 Merge: bf846d6 3930ddc Author: Steve Purcell <st...@sanityinc.com> Commit: Steve Purcell <st...@sanityinc.com>
Merge remote-tracking branch 'refs/remotes/nex3/pr/1' --- sass-mode.el | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/sass-mode.el b/sass-mode.el index 3c94cea..662b2ff 100644 --- a/sass-mode.el +++ b/sass-mode.el @@ -182,9 +182,17 @@ LIMIT is the limit of the search." ;; Mode setup +(defvar sass-mode-map + (let ((map (make-sparse-keymap))) + (define-key map "\C-c\C-r" 'sass-output-region) + (define-key map "\C-c\C-l" 'sass-output-buffer) + map)) + ;;;###autoload (define-derived-mode sass-mode haml-mode "Sass" - "Major mode for editing Sass files." + "Major mode for editing Sass files. + +\\{sass-mode-map}" (set-syntax-table sass-syntax-table) (setq font-lock-extend-region-functions '(font-lock-extend-region-wholelines font-lock-extend-region-multiline)) @@ -202,6 +210,24 @@ LIMIT is the limit of the search." if (looking-at opener) return nil finally return t)) +;; Command + +(defun sass-output-region (start end) + "Displays the CSS output for the current block of Sass code. +Called from a program, START and END specify the region to indent." + (interactive "r") + (let* ((text (buffer-substring-no-properties start end)) + (command (format "ruby -rubygems -e \"require 'sass'; puts Sass::Engine.new('%s').render\"" text))) + (kill-new text) + (with-temp-buffer + (yank) + (shell-command-on-region (point-min) (point-max) command "sass-output")))) + +(defun sass-output-buffer () + "Displays the CSS output for entire buffer." + (interactive) + (sass-output-region (point-min) (point-max))) + ;;;###autoload (add-to-list 'auto-mode-alist '("\\.sass\\'" . sass-mode))