vendor/plugins/haml/extra/haml-mode.el in radiant-0.9.1 vs vendor/plugins/haml/extra/haml-mode.el in radiant-1.0.0.rc1

- old
+ new

@@ -2,11 +2,11 @@ ;; Copyright (c) 2007, 2008 Nathan Weizenbaum ;; Author: Nathan Weizenbaum ;; URL: http://github.com/nex3/haml/tree/master -;; Version: 2.2.21 +;; Version: 3.0.19 ;; Created: 2007-03-08 ;; By: Nathan Weizenbaum ;; Keywords: markup, language, html ;;; Commentary: @@ -55,49 +55,42 @@ This means that all code nested beneath the backspaced line is re-indented along with the line itself." :type 'boolean :group 'haml) -(defface haml-tab-face - '((((class color)) (:background "hotpink")) - (t (:reverse-video t))) - "Face to use for highlighting tabs in Haml files." - :group 'faces - :group 'haml) - (defvar haml-indent-function 'haml-indent-p "A function for checking if nesting is allowed. This function should look at the current line and return t if the next line could be nested within this line. The function can also return a positive integer to indicate a specific level to which the current line could be indented.") (defconst haml-tag-beg-re - "^ *\\(?:[%\\.#][a-z0-9_:\\-]*\\)+\\(?:(.*)\\|{.*}\\|\\[.*\\]\\)*" + "^[ \t]*\\(?:[%\\.#][a-z0-9_:\\-]*\\)+\\(?:(.*)\\|{.*}\\|\\[.*\\]\\)*" "A regexp matching the beginning of a Haml tag, through (), {}, and [].") (defvar haml-block-openers `(,(concat haml-tag-beg-re "[><]*[ \t]*$") - "^ *[&!]?[-=~].*do[ \t]*\\(|.*|[ \t]*\\)?$" - ,(concat "^ *[&!]?[-=~][ \t]*\\(" - (regexp-opt '("if" "unless" "while" "until" "else" + "^[ \t]*[&!]?[-=~].*do[ \t]*\\(|.*|[ \t]*\\)?$" + ,(concat "^[ \t]*[&!]?[-=~][ \t]*\\(" + (regexp-opt '("if" "unless" "while" "until" "else" "for" "begin" "elsif" "rescue" "ensure" "when")) "\\)") - "^ */\\(\\[.*\\]\\)?[ \t]*$" - "^ *-#" - "^ *:") + "^[ \t]*/\\(\\[.*\\]\\)?[ \t]*$" + "^[ \t]*-#" + "^[ \t]*:") "A list of regexps that match lines of Haml that open blocks. That is, a Haml line that can have text nested beneath it should be matched by a regexp in this list.") ;; Font lock (defun haml-nested-regexp (re) "Create a regexp to match a block starting with RE. The line containing RE is matched, as well as all lines indented beneath it." - (concat "^\\( *\\)" re "\\(\n\\(?:\\(?:\\1 .*\\| *\\)\n\\)*\\(?:\\1 .*\\| *\\)?\\)?")) + (concat "^\\([ \t]*\\)" re "\\(\n\\(?:\\(?:\\1 .*\\| *\\)\n\\)*\\(?:\\1 .*\\| *\\)?\\)?")) (defconst haml-font-lock-keywords `((,(haml-nested-regexp "\\(?:-#\\|/\\).*") 0 font-lock-comment-face) (,(haml-nested-regexp ":\\w+") 0 font-lock-string-face) (haml-highlight-ruby-filter-block 1 font-lock-preprocessor-face) @@ -106,16 +99,15 @@ (haml-highlight-markdown-filter-block 1 font-lock-preprocessor-face) (haml-highlight-js-filter-block 1 font-lock-preprocessor-face) (haml-highlight-interpolation 1 font-lock-variable-name-face prepend) (haml-highlight-ruby-tag 1 font-lock-preprocessor-face) (haml-highlight-ruby-script 1 font-lock-preprocessor-face) - ("^ *\\(\t\\)" 1 'haml-tab-face) ("^!!!.*" 0 font-lock-constant-face) ("| *$" 0 font-lock-string-face))) -(defconst haml-filter-re "^ *:\\w+") -(defconst haml-comment-re "^ *\\(?:-\\#\\|/\\)") +(defconst haml-filter-re "^[ \t]*:\\w+") +(defconst haml-comment-re "^[ \t]*\\(?:-\\#\\|/\\)") (defun haml-fontify-region (beg end keywords syntax-table syntactic-keywords) "Fontify a region between BEG and END using another mode's fontification. KEYWORDS, SYNTAX-TABLE, and SYNTACTIC-KEYWORDS are the values of that mode's @@ -134,11 +126,12 @@ ;; so we have to move the beginning back one char (font-lock-fontify-region (- beg 1) end))))) (defun haml-fontify-region-as-ruby (beg end) "Use Ruby's font-lock variables to fontify the region between BEG and END." - (haml-fontify-region beg end ruby-font-lock-keywords nil + (haml-fontify-region beg end ruby-font-lock-keywords + ruby-font-lock-syntax-table ruby-font-lock-syntactic-keywords)) (defun haml-handle-filter (filter-name limit fn) "If a FILTER-NAME filter is found within LIMIT, run FN on that filter. @@ -205,11 +198,11 @@ nil))) (defun haml-highlight-ruby-script (limit) "Highlight a Ruby script expression (-, =, or ~). LIMIT works as it does in `re-search-forward'." - (when (re-search-forward "^ *\\(-\\|[&!]?[=~]\\) \\(.*\\)$" limit t) + (when (re-search-forward "^[ \t]*\\(-\\|[&!]?[=~]\\) \\(.*\\)$" limit t) (haml-fontify-region-as-ruby (match-beginning 2) (match-end 2)))) (defun haml-highlight-ruby-tag (limit) "Highlight Ruby code within a Haml tag. LIMIT works as it does in `re-search-forward'. @@ -220,11 +213,11 @@ For example, this will highlight all of the following: %p{:foo => 'bar'} %p[@bar] %p= 'baz' %p{:foo => 'bar'}[@bar]= 'baz'" - (when (re-search-forward "^ *[%.#]" limit t) + (when (re-search-forward "^[ \t]*[%.#]" limit t) (forward-char -1) ;; Highlight tag, classes, and ids (while (haml-move "\\([.#%]\\)[a-z0-9_:\\-]*") (put-text-property (match-beginning 0) (match-end 0) 'face @@ -350,11 +343,12 @@ (end-of-line) ;; Move through multiline attrs (when (eq (char-before) ?,) (save-excursion - (while (progn (end-of-line) (and (eq (char-before) ?,) (not (eobp)))) + (while (progn (end-of-line) + (and (eq (char-before) ?,) (not (eobp)))) (forward-line)) (forward-line -1) (end-of-line) (setq multiline-end (point)))) @@ -403,11 +397,10 @@ (set (make-local-variable 'font-lock-multiline) t) (set (make-local-variable 'indent-line-function) 'haml-indent-line) (set (make-local-variable 'indent-region-function) 'haml-indent-region) (set (make-local-variable 'parse-sexp-lookup-properties) t) (setq comment-start "-#") - (setq indent-tabs-mode nil) (setq font-lock-defaults '((haml-font-lock-keywords) t t))) ;; Useful functions (defun haml-comment-block () @@ -616,22 +609,22 @@ FN should take three parameters: TYPE, BEG, and END. TYPE is the type of text parsed ('name or 'value) and BEG and END delimit that text in the buffer." (let ((eol (save-excursion (end-of-line) (point)))) (while (not (haml-move ")")) - (haml-move " *") + (haml-move "[ \t]*") (unless (haml-move "[a-z0-9_:\\-]+") - (return-from haml-parse-new-attr-hash (haml-move " *$"))) + (return-from haml-parse-new-attr-hash (haml-move "[ \t]*$"))) (funcall fn 'name (match-beginning 0) (match-end 0)) - (haml-move " *") + (haml-move "[ \t]*") (when (haml-move "=") - (haml-move " *") + (haml-move "[ \t]*") (unless (looking-at "[\"'@a-z]") (return-from haml-parse-new-attr-hash)) (let ((beg (point))) (haml-limited-forward-sexp eol) (funcall fn 'value beg (point))) - (haml-move " *"))) + (haml-move "[ \t]*"))) nil)) (defun haml-compute-indentation () "Calculate the maximum sensible indentation for the current line." (save-excursion @@ -700,14 +693,23 @@ (defun haml-reindent-region-by (n) "Add N spaces to the beginning of each line in the region. If N is negative, will remove the spaces instead. Assumes all lines in the region have indentation >= that of the first line." - (let ((ci (current-indentation))) + (let* ((ci (current-indentation)) + (indent-rx + (concat "^" + (if indent-tabs-mode + (concat (make-string (/ ci tab-width) ?\t) + (make-string (mod ci tab-width) ?\t)) + (make-string ci ?\s))))) (save-excursion - (while (re-search-forward (concat "^" (make-string ci ?\s)) (mark) t) - (replace-match (make-string (max 0 (+ ci n)) ?\s)))))) + (while (re-search-forward indent-rx (mark) t) + (let ((ci (current-indentation))) + (delete-horizontal-space) + (beginning-of-line) + (indent-to (max 0 (+ ci n)))))))) (defun haml-electric-backspace (arg) "Delete characters or back-dent the current line. If invoked following only whitespace on a line, will back-dent the line and all nested lines to the immediately previous @@ -726,11 +728,11 @@ (beginning-of-line) (if haml-backspace-backdents-nesting (haml-mark-sexp-but-not-next-line) (set-mark (save-excursion (end-of-line) (point)))) (haml-reindent-region-by (* (- arg) haml-indent-offset)) - (back-to-indentation) - (pop-mark))))) + (pop-mark))) + (back-to-indentation))) (defun haml-kill-line-and-indent () "Kill the current line, and re-indent all lines nested beneath it." (interactive) (beginning-of-line)