haml 3.0.25 → 3.1.0.alpha.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of haml might be problematic. Click here for more details.
- data/.yardopts +1 -1
- data/CONTRIBUTING +0 -1
- data/EDGE_GEM_VERSION +1 -0
- data/MIT-LICENSE +1 -1
- data/README.md +10 -175
- data/Rakefile +56 -84
- data/VERSION +1 -1
- data/VERSION_NAME +1 -1
- data/init.rb +1 -1
- data/lib/haml.rb +14 -12
- data/lib/haml/engine.rb +1 -1
- data/lib/haml/exec.rb +19 -316
- data/lib/haml/helpers/action_view_extensions.rb +1 -1
- data/lib/haml/html.rb +69 -76
- data/lib/haml/precompiler.rb +34 -41
- data/lib/haml/railtie.rb +4 -6
- data/lib/haml/template/plugin.rb +6 -16
- data/lib/haml/util.rb +91 -107
- data/lib/haml/version.rb +7 -0
- data/test/benchmark.rb +2 -9
- data/test/haml/engine_test.rb +195 -92
- data/test/haml/html2haml/erb_tests.rb +0 -14
- data/test/haml/util_test.rb +32 -0
- data/test/test_helper.rb +0 -39
- metadata +96 -324
- data/bin/css2sass +0 -13
- data/bin/sass +0 -8
- data/bin/sass-convert +0 -7
- data/extra/haml-mode.el +0 -753
- data/extra/sass-mode.el +0 -207
- data/lib/haml/util/subset_map.rb +0 -101
- data/lib/sass.rb +0 -29
- data/lib/sass/callbacks.rb +0 -52
- data/lib/sass/css.rb +0 -294
- data/lib/sass/engine.rb +0 -720
- data/lib/sass/environment.rb +0 -143
- data/lib/sass/error.rb +0 -198
- data/lib/sass/files.rb +0 -160
- data/lib/sass/less.rb +0 -382
- data/lib/sass/plugin.rb +0 -279
- data/lib/sass/plugin/configuration.rb +0 -221
- data/lib/sass/plugin/generic.rb +0 -15
- data/lib/sass/plugin/merb.rb +0 -37
- data/lib/sass/plugin/rack.rb +0 -47
- data/lib/sass/plugin/rails.rb +0 -32
- data/lib/sass/plugin/staleness_checker.rb +0 -123
- data/lib/sass/repl.rb +0 -58
- data/lib/sass/script.rb +0 -63
- data/lib/sass/script/bool.rb +0 -18
- data/lib/sass/script/color.rb +0 -491
- data/lib/sass/script/css_lexer.rb +0 -29
- data/lib/sass/script/css_parser.rb +0 -31
- data/lib/sass/script/funcall.rb +0 -77
- data/lib/sass/script/functions.rb +0 -861
- data/lib/sass/script/interpolation.rb +0 -70
- data/lib/sass/script/lexer.rb +0 -337
- data/lib/sass/script/literal.rb +0 -236
- data/lib/sass/script/node.rb +0 -112
- data/lib/sass/script/number.rb +0 -423
- data/lib/sass/script/operation.rb +0 -95
- data/lib/sass/script/parser.rb +0 -401
- data/lib/sass/script/string.rb +0 -67
- data/lib/sass/script/string_interpolation.rb +0 -93
- data/lib/sass/script/unary_operation.rb +0 -57
- data/lib/sass/script/variable.rb +0 -48
- data/lib/sass/scss.rb +0 -17
- data/lib/sass/scss/css_parser.rb +0 -46
- data/lib/sass/scss/parser.rb +0 -855
- data/lib/sass/scss/rx.rb +0 -126
- data/lib/sass/scss/sass_parser.rb +0 -11
- data/lib/sass/scss/script_lexer.rb +0 -15
- data/lib/sass/scss/script_parser.rb +0 -25
- data/lib/sass/scss/static_parser.rb +0 -40
- data/lib/sass/selector.rb +0 -361
- data/lib/sass/selector/abstract_sequence.rb +0 -62
- data/lib/sass/selector/comma_sequence.rb +0 -82
- data/lib/sass/selector/sequence.rb +0 -237
- data/lib/sass/selector/simple.rb +0 -113
- data/lib/sass/selector/simple_sequence.rb +0 -136
- data/lib/sass/tree/charset_node.rb +0 -37
- data/lib/sass/tree/comment_node.rb +0 -128
- data/lib/sass/tree/debug_node.rb +0 -36
- data/lib/sass/tree/directive_node.rb +0 -75
- data/lib/sass/tree/extend_node.rb +0 -65
- data/lib/sass/tree/for_node.rb +0 -55
- data/lib/sass/tree/if_node.rb +0 -69
- data/lib/sass/tree/import_node.rb +0 -102
- data/lib/sass/tree/mixin_def_node.rb +0 -48
- data/lib/sass/tree/mixin_node.rb +0 -111
- data/lib/sass/tree/node.rb +0 -464
- data/lib/sass/tree/prop_node.rb +0 -220
- data/lib/sass/tree/root_node.rb +0 -163
- data/lib/sass/tree/rule_node.rb +0 -261
- data/lib/sass/tree/variable_node.rb +0 -39
- data/lib/sass/tree/warn_node.rb +0 -42
- data/lib/sass/tree/while_node.rb +0 -36
- data/test/haml/util/subset_map_test.rb +0 -91
- data/test/sass/callbacks_test.rb +0 -61
- data/test/sass/conversion_test.rb +0 -1218
- data/test/sass/css2sass_test.rb +0 -364
- data/test/sass/data/hsl-rgb.txt +0 -319
- data/test/sass/engine_test.rb +0 -2267
- data/test/sass/extend_test.rb +0 -1348
- data/test/sass/functions_test.rb +0 -556
- data/test/sass/less_conversion_test.rb +0 -653
- data/test/sass/more_results/more1.css +0 -9
- data/test/sass/more_results/more1_with_line_comments.css +0 -26
- data/test/sass/more_results/more_import.css +0 -29
- data/test/sass/more_templates/_more_partial.sass +0 -2
- data/test/sass/more_templates/more1.sass +0 -23
- data/test/sass/more_templates/more_import.sass +0 -11
- data/test/sass/plugin_test.rb +0 -433
- data/test/sass/results/alt.css +0 -4
- data/test/sass/results/basic.css +0 -9
- data/test/sass/results/compact.css +0 -5
- data/test/sass/results/complex.css +0 -86
- data/test/sass/results/compressed.css +0 -1
- data/test/sass/results/expanded.css +0 -19
- data/test/sass/results/import.css +0 -31
- data/test/sass/results/import_charset.css +0 -4
- data/test/sass/results/import_charset_1_8.css +0 -4
- data/test/sass/results/import_charset_ibm866.css +0 -4
- data/test/sass/results/line_numbers.css +0 -49
- data/test/sass/results/mixins.css +0 -95
- data/test/sass/results/multiline.css +0 -24
- data/test/sass/results/nested.css +0 -22
- data/test/sass/results/options.css +0 -1
- data/test/sass/results/parent_ref.css +0 -13
- data/test/sass/results/script.css +0 -16
- data/test/sass/results/scss_import.css +0 -31
- data/test/sass/results/scss_importee.css +0 -2
- data/test/sass/results/subdir/nested_subdir/nested_subdir.css +0 -1
- data/test/sass/results/subdir/subdir.css +0 -3
- data/test/sass/results/units.css +0 -11
- data/test/sass/results/warn.css +0 -0
- data/test/sass/results/warn_imported.css +0 -0
- data/test/sass/script_conversion_test.rb +0 -314
- data/test/sass/script_test.rb +0 -470
- data/test/sass/scss/css_test.rb +0 -916
- data/test/sass/scss/rx_test.rb +0 -156
- data/test/sass/scss/scss_test.rb +0 -1122
- data/test/sass/scss/test_helper.rb +0 -37
- data/test/sass/templates/_imported_charset_ibm866.sass +0 -4
- data/test/sass/templates/_imported_charset_utf8.sass +0 -4
- data/test/sass/templates/_partial.sass +0 -2
- data/test/sass/templates/alt.sass +0 -16
- data/test/sass/templates/basic.sass +0 -23
- data/test/sass/templates/bork1.sass +0 -2
- data/test/sass/templates/bork2.sass +0 -2
- data/test/sass/templates/bork3.sass +0 -2
- data/test/sass/templates/bork4.sass +0 -2
- data/test/sass/templates/compact.sass +0 -17
- data/test/sass/templates/complex.sass +0 -305
- data/test/sass/templates/compressed.sass +0 -15
- data/test/sass/templates/expanded.sass +0 -17
- data/test/sass/templates/import.sass +0 -12
- data/test/sass/templates/import_charset.sass +0 -7
- data/test/sass/templates/import_charset_1_8.sass +0 -4
- data/test/sass/templates/import_charset_ibm866.sass +0 -9
- data/test/sass/templates/importee.less +0 -2
- data/test/sass/templates/importee.sass +0 -19
- data/test/sass/templates/line_numbers.sass +0 -13
- data/test/sass/templates/mixin_bork.sass +0 -5
- data/test/sass/templates/mixins.sass +0 -76
- data/test/sass/templates/multiline.sass +0 -20
- data/test/sass/templates/nested.sass +0 -25
- data/test/sass/templates/nested_bork1.sass +0 -2
- data/test/sass/templates/nested_bork2.sass +0 -2
- data/test/sass/templates/nested_bork3.sass +0 -2
- data/test/sass/templates/nested_bork4.sass +0 -2
- data/test/sass/templates/nested_mixin_bork.sass +0 -6
- data/test/sass/templates/options.sass +0 -2
- data/test/sass/templates/parent_ref.sass +0 -25
- data/test/sass/templates/script.sass +0 -101
- data/test/sass/templates/scss_import.scss +0 -11
- data/test/sass/templates/scss_importee.scss +0 -1
- data/test/sass/templates/subdir/nested_subdir/_nested_partial.sass +0 -2
- data/test/sass/templates/subdir/nested_subdir/nested_subdir.sass +0 -3
- data/test/sass/templates/subdir/subdir.sass +0 -6
- data/test/sass/templates/units.sass +0 -11
- data/test/sass/templates/warn.sass +0 -3
- data/test/sass/templates/warn_imported.sass +0 -4
- data/vendor/fssm/LICENSE +0 -20
- data/vendor/fssm/README.markdown +0 -55
- data/vendor/fssm/Rakefile +0 -59
- data/vendor/fssm/VERSION.yml +0 -5
- data/vendor/fssm/example.rb +0 -9
- data/vendor/fssm/fssm.gemspec +0 -77
- data/vendor/fssm/lib/fssm.rb +0 -33
- data/vendor/fssm/lib/fssm/backends/fsevents.rb +0 -36
- data/vendor/fssm/lib/fssm/backends/inotify.rb +0 -26
- data/vendor/fssm/lib/fssm/backends/polling.rb +0 -25
- data/vendor/fssm/lib/fssm/backends/rubycocoa/fsevents.rb +0 -131
- data/vendor/fssm/lib/fssm/monitor.rb +0 -26
- data/vendor/fssm/lib/fssm/path.rb +0 -91
- data/vendor/fssm/lib/fssm/pathname.rb +0 -502
- data/vendor/fssm/lib/fssm/state/directory.rb +0 -57
- data/vendor/fssm/lib/fssm/state/file.rb +0 -24
- data/vendor/fssm/lib/fssm/support.rb +0 -63
- data/vendor/fssm/lib/fssm/tree.rb +0 -176
- data/vendor/fssm/profile/prof-cache.rb +0 -40
- data/vendor/fssm/profile/prof-fssm-pathname.html +0 -1231
- data/vendor/fssm/profile/prof-pathname.rb +0 -68
- data/vendor/fssm/profile/prof-plain-pathname.html +0 -988
- data/vendor/fssm/profile/prof.html +0 -2379
- data/vendor/fssm/spec/path_spec.rb +0 -75
- data/vendor/fssm/spec/root/duck/quack.txt +0 -0
- data/vendor/fssm/spec/root/file.css +0 -0
- data/vendor/fssm/spec/root/file.rb +0 -0
- data/vendor/fssm/spec/root/file.yml +0 -0
- data/vendor/fssm/spec/root/moo/cow.txt +0 -0
- data/vendor/fssm/spec/spec_helper.rb +0 -14
data/bin/css2sass
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require File.dirname(__FILE__) + '/../lib/haml'
|
4
|
-
require 'haml/exec'
|
5
|
-
|
6
|
-
warn <<END
|
7
|
-
DEPRECATION WARNING:
|
8
|
-
The css2sass tool is deprecated and will be removed in Sass 3.2.
|
9
|
-
Use the sass-convert tool instead.
|
10
|
-
END
|
11
|
-
|
12
|
-
opts = Haml::Exec::SassConvert.new(%w[--from css --to sass] + ARGV)
|
13
|
-
opts.parse!
|
data/bin/sass
DELETED
data/bin/sass-convert
DELETED
data/extra/haml-mode.el
DELETED
@@ -1,753 +0,0 @@
|
|
1
|
-
;;; haml-mode.el --- Major mode for editing Haml files
|
2
|
-
|
3
|
-
;; Copyright (c) 2007, 2008 Nathan Weizenbaum
|
4
|
-
|
5
|
-
;; Author: Nathan Weizenbaum
|
6
|
-
;; URL: http://github.com/nex3/haml/tree/master
|
7
|
-
;; Version: 3.0.19
|
8
|
-
;; Created: 2007-03-08
|
9
|
-
;; By: Nathan Weizenbaum
|
10
|
-
;; Keywords: markup, language, html
|
11
|
-
|
12
|
-
;;; Commentary:
|
13
|
-
|
14
|
-
;; Because Haml's indentation schema is similar
|
15
|
-
;; to that of YAML and Python, many indentation-related
|
16
|
-
;; functions are similar to those in yaml-mode and python-mode.
|
17
|
-
|
18
|
-
;; To install, save this on your load path and add the following to
|
19
|
-
;; your .emacs file:
|
20
|
-
;;
|
21
|
-
;; (require 'haml-mode)
|
22
|
-
|
23
|
-
;;; Code:
|
24
|
-
|
25
|
-
(eval-when-compile (require 'cl))
|
26
|
-
(require 'ruby-mode)
|
27
|
-
|
28
|
-
;; Additional (optional) libraries for fontification
|
29
|
-
(require 'css-mode nil t)
|
30
|
-
(require 'textile-mode nil t)
|
31
|
-
(require 'markdown-mode nil t)
|
32
|
-
(require 'javascript-mode "javascript" t)
|
33
|
-
(require 'js nil t)
|
34
|
-
|
35
|
-
|
36
|
-
;; User definable variables
|
37
|
-
|
38
|
-
(defgroup haml nil
|
39
|
-
"Support for the Haml template language."
|
40
|
-
:group 'languages
|
41
|
-
:prefix "haml-")
|
42
|
-
|
43
|
-
(defcustom haml-mode-hook nil
|
44
|
-
"Hook run when entering Haml mode."
|
45
|
-
:type 'hook
|
46
|
-
:group 'haml)
|
47
|
-
|
48
|
-
(defcustom haml-indent-offset 2
|
49
|
-
"Amount of offset per level of indentation."
|
50
|
-
:type 'integer
|
51
|
-
:group 'haml)
|
52
|
-
|
53
|
-
(defcustom haml-backspace-backdents-nesting t
|
54
|
-
"Non-nil to have `haml-electric-backspace' re-indent blocks of code.
|
55
|
-
This means that all code nested beneath the backspaced line is
|
56
|
-
re-indented along with the line itself."
|
57
|
-
:type 'boolean
|
58
|
-
:group 'haml)
|
59
|
-
|
60
|
-
(defvar haml-indent-function 'haml-indent-p
|
61
|
-
"A function for checking if nesting is allowed.
|
62
|
-
This function should look at the current line and return t
|
63
|
-
if the next line could be nested within this line.
|
64
|
-
|
65
|
-
The function can also return a positive integer to indicate
|
66
|
-
a specific level to which the current line could be indented.")
|
67
|
-
|
68
|
-
(defconst haml-tag-beg-re
|
69
|
-
"^[ \t]*\\(?:[%\\.#][a-z0-9_:\\-]*\\)+\\(?:(.*)\\|{.*}\\|\\[.*\\]\\)*"
|
70
|
-
"A regexp matching the beginning of a Haml tag, through (), {}, and [].")
|
71
|
-
|
72
|
-
(defvar haml-block-openers
|
73
|
-
`(,(concat haml-tag-beg-re "[><]*[ \t]*$")
|
74
|
-
"^[ \t]*[&!]?[-=~].*do[ \t]*\\(|.*|[ \t]*\\)?$"
|
75
|
-
,(concat "^[ \t]*[&!]?[-=~][ \t]*\\("
|
76
|
-
(regexp-opt '("if" "unless" "while" "until" "else" "for"
|
77
|
-
"begin" "elsif" "rescue" "ensure" "when"))
|
78
|
-
"\\)")
|
79
|
-
"^[ \t]*/\\(\\[.*\\]\\)?[ \t]*$"
|
80
|
-
"^[ \t]*-#"
|
81
|
-
"^[ \t]*:")
|
82
|
-
"A list of regexps that match lines of Haml that open blocks.
|
83
|
-
That is, a Haml line that can have text nested beneath it should
|
84
|
-
be matched by a regexp in this list.")
|
85
|
-
|
86
|
-
;; Font lock
|
87
|
-
|
88
|
-
(defun haml-nested-regexp (re)
|
89
|
-
"Create a regexp to match a block starting with RE.
|
90
|
-
The line containing RE is matched, as well as all lines indented beneath it."
|
91
|
-
(concat "^\\([ \t]*\\)" re "\\(\n\\(?:\\(?:\\1 .*\\| *\\)\n\\)*\\(?:\\1 .*\\| *\\)?\\)?"))
|
92
|
-
|
93
|
-
(defconst haml-font-lock-keywords
|
94
|
-
`((,(haml-nested-regexp "\\(?:-#\\|/\\).*") 0 font-lock-comment-face)
|
95
|
-
(,(haml-nested-regexp ":\\w+") 0 font-lock-string-face)
|
96
|
-
(haml-highlight-ruby-filter-block 1 font-lock-preprocessor-face)
|
97
|
-
(haml-highlight-css-filter-block 1 font-lock-preprocessor-face)
|
98
|
-
(haml-highlight-textile-filter-block 1 font-lock-preprocessor-face)
|
99
|
-
(haml-highlight-markdown-filter-block 1 font-lock-preprocessor-face)
|
100
|
-
(haml-highlight-js-filter-block 1 font-lock-preprocessor-face)
|
101
|
-
(haml-highlight-interpolation 1 font-lock-variable-name-face prepend)
|
102
|
-
(haml-highlight-ruby-tag 1 font-lock-preprocessor-face)
|
103
|
-
(haml-highlight-ruby-script 1 font-lock-preprocessor-face)
|
104
|
-
("^!!!.*" 0 font-lock-constant-face)
|
105
|
-
("| *$" 0 font-lock-string-face)))
|
106
|
-
|
107
|
-
(defconst haml-filter-re "^[ \t]*:\\w+")
|
108
|
-
(defconst haml-comment-re "^[ \t]*\\(?:-\\#\\|/\\)")
|
109
|
-
|
110
|
-
(defun haml-fontify-region (beg end keywords syntax-table syntactic-keywords)
|
111
|
-
"Fontify a region between BEG and END using another mode's fontification.
|
112
|
-
|
113
|
-
KEYWORDS, SYNTAX-TABLE, and SYNTACTIC-KEYWORDS are the values of that mode's
|
114
|
-
`font-lock-keywords', `font-lock-syntax-table',
|
115
|
-
and `font-lock-syntactic-keywords', respectively."
|
116
|
-
(save-excursion
|
117
|
-
(save-match-data
|
118
|
-
(let ((font-lock-keywords keywords)
|
119
|
-
(font-lock-syntax-table syntax-table)
|
120
|
-
(font-lock-syntactic-keywords syntactic-keywords)
|
121
|
-
(font-lock-multiline 'undecided)
|
122
|
-
font-lock-keywords-only
|
123
|
-
font-lock-extend-region-functions
|
124
|
-
font-lock-keywords-case-fold-search)
|
125
|
-
;; font-lock-fontify-region apparently isn't inclusive,
|
126
|
-
;; so we have to move the beginning back one char
|
127
|
-
(font-lock-fontify-region (- beg 1) end)))))
|
128
|
-
|
129
|
-
(defun haml-fontify-region-as-ruby (beg end)
|
130
|
-
"Use Ruby's font-lock variables to fontify the region between BEG and END."
|
131
|
-
(haml-fontify-region beg end ruby-font-lock-keywords
|
132
|
-
ruby-font-lock-syntax-table
|
133
|
-
ruby-font-lock-syntactic-keywords))
|
134
|
-
|
135
|
-
(defun haml-handle-filter (filter-name limit fn)
|
136
|
-
"If a FILTER-NAME filter is found within LIMIT, run FN on that filter.
|
137
|
-
|
138
|
-
FN is passed a pair of points representing the beginning and end
|
139
|
-
of the filtered text."
|
140
|
-
(when (re-search-forward (haml-nested-regexp (concat ":" filter-name)) limit t)
|
141
|
-
(funcall fn (+ 2 (match-beginning 2)) (match-end 2))))
|
142
|
-
|
143
|
-
(defun haml-fontify-filter-region (filter-name limit &rest fontify-region-args)
|
144
|
-
"If a FILTER-NAME filter is found within LIMIT, fontify it.
|
145
|
-
|
146
|
-
The fontification is done by passing FONTIFY-REGION-ARGS to
|
147
|
-
`haml-fontify-region'."
|
148
|
-
(haml-handle-filter filter-name limit
|
149
|
-
(lambda (beg end)
|
150
|
-
(apply 'haml-fontify-region
|
151
|
-
(append (list beg end)
|
152
|
-
fontify-region-args)))))
|
153
|
-
|
154
|
-
(defun haml-highlight-ruby-filter-block (limit)
|
155
|
-
"If a :ruby filter is found within LIMIT, highlight it."
|
156
|
-
(haml-handle-filter "ruby" limit 'haml-fontify-region-as-ruby))
|
157
|
-
|
158
|
-
(defun haml-highlight-css-filter-block (limit)
|
159
|
-
"If a :css filter is found within LIMIT, highlight it.
|
160
|
-
|
161
|
-
This requires that `css-mode' is available.
|
162
|
-
`css-mode' is included with Emacs 23."
|
163
|
-
(if (boundp 'css-font-lock-keywords)
|
164
|
-
(haml-fontify-filter-region "css" limit css-font-lock-keywords nil nil)))
|
165
|
-
|
166
|
-
(defun haml-highlight-js-filter-block (limit)
|
167
|
-
"If a :javascript filter is found within LIMIT, highlight it.
|
168
|
-
|
169
|
-
This requires that Karl Landström's javascript mode be available, either as the
|
170
|
-
\"js.el\" bundled with Emacs 23, or as \"javascript.el\" found in ELPA and
|
171
|
-
elsewhere."
|
172
|
-
(let ((keywords (or (and (featurep 'js) js--font-lock-keywords-3)
|
173
|
-
(and (featurep 'javascript-mode) js-font-lock-keywords-3)))
|
174
|
-
(syntax-table (or (and (featurep 'js) js-mode-syntax-table)
|
175
|
-
(and (featurep 'javascript-mode) javascript-mode-syntax-table))))
|
176
|
-
(when keywords
|
177
|
-
(haml-fontify-filter-region "javascript" limit keywords syntax-table nil))))
|
178
|
-
|
179
|
-
(defun haml-highlight-textile-filter-block (limit)
|
180
|
-
"If a :textile filter is found within LIMIT, highlight it.
|
181
|
-
|
182
|
-
This requires that `textile-mode' be available.
|
183
|
-
|
184
|
-
Note that the results are not perfect, since `textile-mode' expects
|
185
|
-
certain constructs such as \"h1.\" to be at the beginning of a line,
|
186
|
-
and indented Haml filters always have leading whitespace."
|
187
|
-
(if (boundp 'textile-font-lock-keywords)
|
188
|
-
(haml-fontify-filter-region "textile" limit textile-font-lock-keywords nil nil)))
|
189
|
-
|
190
|
-
(defun haml-highlight-markdown-filter-block (limit)
|
191
|
-
"If a :markdown filter is found within LIMIT, highlight it.
|
192
|
-
|
193
|
-
This requires that `markdown-mode' be available."
|
194
|
-
(if (boundp 'markdown-mode-font-lock-keywords)
|
195
|
-
(haml-fontify-filter-region "markdown" limit
|
196
|
-
markdown-mode-font-lock-keywords
|
197
|
-
markdown-mode-syntax-table
|
198
|
-
nil)))
|
199
|
-
|
200
|
-
(defun haml-highlight-ruby-script (limit)
|
201
|
-
"Highlight a Ruby script expression (-, =, or ~).
|
202
|
-
LIMIT works as it does in `re-search-forward'."
|
203
|
-
(when (re-search-forward "^[ \t]*\\(-\\|[&!]?[=~]\\) \\(.*\\)$" limit t)
|
204
|
-
(haml-fontify-region-as-ruby (match-beginning 2) (match-end 2))))
|
205
|
-
|
206
|
-
(defun haml-highlight-ruby-tag (limit)
|
207
|
-
"Highlight Ruby code within a Haml tag.
|
208
|
-
LIMIT works as it does in `re-search-forward'.
|
209
|
-
|
210
|
-
This highlights the tag attributes and object refs of the tag,
|
211
|
-
as well as the script expression (-, =, or ~) following the tag.
|
212
|
-
|
213
|
-
For example, this will highlight all of the following:
|
214
|
-
%p{:foo => 'bar'}
|
215
|
-
%p[@bar]
|
216
|
-
%p= 'baz'
|
217
|
-
%p{:foo => 'bar'}[@bar]= 'baz'"
|
218
|
-
(when (re-search-forward "^[ \t]*[%.#]" limit t)
|
219
|
-
(forward-char -1)
|
220
|
-
|
221
|
-
;; Highlight tag, classes, and ids
|
222
|
-
(while (haml-move "\\([.#%]\\)[a-z0-9_:\\-]*")
|
223
|
-
(put-text-property (match-beginning 0) (match-end 0) 'face
|
224
|
-
(case (char-after (match-beginning 1))
|
225
|
-
(?% font-lock-function-name-face)
|
226
|
-
(?# font-lock-keyword-face)
|
227
|
-
(?. font-lock-type-face))))
|
228
|
-
|
229
|
-
(block loop
|
230
|
-
(while t
|
231
|
-
(let ((eol (save-excursion (end-of-line) (point))))
|
232
|
-
(case (char-after)
|
233
|
-
;; Highlight obj refs
|
234
|
-
(?\[
|
235
|
-
(let ((beg (point)))
|
236
|
-
(haml-limited-forward-sexp eol)
|
237
|
-
(haml-fontify-region-as-ruby beg (point))))
|
238
|
-
;; Highlight new attr hashes
|
239
|
-
(?\(
|
240
|
-
(forward-char 1)
|
241
|
-
(while
|
242
|
-
(and (haml-parse-new-attr-hash
|
243
|
-
(lambda (type beg end)
|
244
|
-
(case type
|
245
|
-
(name (put-text-property beg end 'face font-lock-constant-face))
|
246
|
-
(value (haml-fontify-region-as-ruby beg end)))))
|
247
|
-
(not (eobp)))
|
248
|
-
(forward-line 1)
|
249
|
-
(beginning-of-line)))
|
250
|
-
;; Highlight old attr hashes
|
251
|
-
(?\{
|
252
|
-
(let ((beg (point)))
|
253
|
-
(haml-limited-forward-sexp eol)
|
254
|
-
|
255
|
-
;; Check for multiline
|
256
|
-
(while (and (eolp) (eq (char-before) ?,) (not (eobp)))
|
257
|
-
(forward-line)
|
258
|
-
(let ((eol (save-excursion (end-of-line) (point))))
|
259
|
-
;; If no sexps are closed,
|
260
|
-
;; we're still continuing a multiline hash
|
261
|
-
(if (>= (car (parse-partial-sexp (point) eol)) 0)
|
262
|
-
(end-of-line)
|
263
|
-
;; If sexps have been closed,
|
264
|
-
;; set the point at the end of the total sexp
|
265
|
-
(goto-char beg)
|
266
|
-
(haml-limited-forward-sexp eol))))
|
267
|
-
|
268
|
-
(haml-fontify-region-as-ruby (+ 1 beg) (point))))
|
269
|
-
(t (return-from loop))))))
|
270
|
-
|
271
|
-
;; Move past end chars
|
272
|
-
(when (looking-at "[<>&!]+") (goto-char (match-end 0)))
|
273
|
-
;; Highlight script
|
274
|
-
(if (looking-at "\\([=~]\\) \\(.*\\)$")
|
275
|
-
(haml-fontify-region-as-ruby (match-beginning 2) (match-end 2))
|
276
|
-
;; Give font-lock something to highlight
|
277
|
-
(forward-char -1)
|
278
|
-
(looking-at "\\(\\)"))
|
279
|
-
t))
|
280
|
-
|
281
|
-
(defun haml-move (re)
|
282
|
-
"Try matching and moving to the end of regular expression RE.
|
283
|
-
Returns non-nil if the expression was sucessfully matched."
|
284
|
-
(when (looking-at re)
|
285
|
-
(goto-char (match-end 0))
|
286
|
-
t))
|
287
|
-
|
288
|
-
(defun haml-highlight-interpolation (limit)
|
289
|
-
"Highlight Ruby interpolation (#{foo}).
|
290
|
-
LIMIT works as it does in `re-search-forward'."
|
291
|
-
(when (re-search-forward "\\(#{\\)" limit t)
|
292
|
-
(save-match-data
|
293
|
-
(forward-char -1)
|
294
|
-
(let ((beg (point)))
|
295
|
-
(haml-limited-forward-sexp limit)
|
296
|
-
(haml-fontify-region-as-ruby (+ 1 beg) (point)))
|
297
|
-
|
298
|
-
(when (eq (char-before) ?})
|
299
|
-
(put-text-property (- (point) 1) (point)
|
300
|
-
'face font-lock-variable-name-face))
|
301
|
-
t)))
|
302
|
-
|
303
|
-
(defun haml-limited-forward-sexp (limit &optional arg)
|
304
|
-
"Move forward using `forward-sexp' or to LIMIT, whichever comes first.
|
305
|
-
With ARG, do it that many times."
|
306
|
-
(let (forward-sexp-function)
|
307
|
-
(condition-case err
|
308
|
-
(save-restriction
|
309
|
-
(narrow-to-region (point) limit)
|
310
|
-
(forward-sexp arg))
|
311
|
-
(scan-error
|
312
|
-
(unless (equal (nth 1 err) "Unbalanced parentheses")
|
313
|
-
(signal 'scan-error (cdr err)))
|
314
|
-
(goto-char limit)))))
|
315
|
-
|
316
|
-
(defun* haml-extend-region-filters-comments ()
|
317
|
-
"Extend the font-lock region to encompass filters and comments."
|
318
|
-
(let ((old-beg font-lock-beg)
|
319
|
-
(old-end font-lock-end))
|
320
|
-
(save-excursion
|
321
|
-
(goto-char font-lock-beg)
|
322
|
-
(beginning-of-line)
|
323
|
-
(unless (or (looking-at haml-filter-re)
|
324
|
-
(looking-at haml-comment-re))
|
325
|
-
(return-from haml-extend-region-filters-comments))
|
326
|
-
(setq font-lock-beg (point))
|
327
|
-
(haml-forward-sexp)
|
328
|
-
(beginning-of-line)
|
329
|
-
(setq font-lock-end (max font-lock-end (point))))
|
330
|
-
(or (/= old-beg font-lock-beg)
|
331
|
-
(/= old-end font-lock-end))))
|
332
|
-
|
333
|
-
(defun* haml-extend-region-multiline-hashes ()
|
334
|
-
"Extend the font-lock region to encompass multiline attribute hashes."
|
335
|
-
(let ((old-beg font-lock-beg)
|
336
|
-
(old-end font-lock-end))
|
337
|
-
(save-excursion
|
338
|
-
(goto-char font-lock-beg)
|
339
|
-
(let ((attr-props (haml-parse-multiline-attr-hash))
|
340
|
-
multiline-end)
|
341
|
-
(when attr-props
|
342
|
-
(setq font-lock-beg (cdr (assq 'point attr-props)))
|
343
|
-
|
344
|
-
(end-of-line)
|
345
|
-
;; Move through multiline attrs
|
346
|
-
(when (eq (char-before) ?,)
|
347
|
-
(save-excursion
|
348
|
-
(while (progn (end-of-line)
|
349
|
-
(and (eq (char-before) ?,) (not (eobp))))
|
350
|
-
(forward-line))
|
351
|
-
|
352
|
-
(forward-line -1)
|
353
|
-
(end-of-line)
|
354
|
-
(setq multiline-end (point))))
|
355
|
-
|
356
|
-
(goto-char (+ (cdr (assq 'point attr-props))
|
357
|
-
(cdr (assq 'hash-indent attr-props))
|
358
|
-
-1))
|
359
|
-
(haml-limited-forward-sexp
|
360
|
-
(or multiline-end
|
361
|
-
(save-excursion (end-of-line) (point))))
|
362
|
-
(setq font-lock-end (max font-lock-end (point))))))
|
363
|
-
(or (/= old-beg font-lock-beg)
|
364
|
-
(/= old-end font-lock-end))))
|
365
|
-
|
366
|
-
|
367
|
-
;; Mode setup
|
368
|
-
|
369
|
-
(defvar haml-mode-syntax-table
|
370
|
-
(let ((table (make-syntax-table)))
|
371
|
-
(modify-syntax-entry ?: "." table)
|
372
|
-
(modify-syntax-entry ?_ "w" table)
|
373
|
-
table)
|
374
|
-
"Syntax table in use in `haml-mode' buffers.")
|
375
|
-
|
376
|
-
(defvar haml-mode-map
|
377
|
-
(let ((map (make-sparse-keymap)))
|
378
|
-
(define-key map [backspace] 'haml-electric-backspace)
|
379
|
-
(define-key map "\C-?" 'haml-electric-backspace)
|
380
|
-
(define-key map "\C-c\C-f" 'haml-forward-sexp)
|
381
|
-
(define-key map "\C-c\C-b" 'haml-backward-sexp)
|
382
|
-
(define-key map "\C-c\C-u" 'haml-up-list)
|
383
|
-
(define-key map "\C-c\C-d" 'haml-down-list)
|
384
|
-
(define-key map "\C-c\C-k" 'haml-kill-line-and-indent)
|
385
|
-
(define-key map "\C-c\C-r" 'haml-output-region)
|
386
|
-
(define-key map "\C-c\C-l" 'haml-output-buffer)
|
387
|
-
map))
|
388
|
-
|
389
|
-
;;;###autoload
|
390
|
-
(define-derived-mode haml-mode fundamental-mode "Haml"
|
391
|
-
"Major mode for editing Haml files.
|
392
|
-
|
393
|
-
\\{haml-mode-map}"
|
394
|
-
(set-syntax-table haml-mode-syntax-table)
|
395
|
-
(add-to-list 'font-lock-extend-region-functions 'haml-extend-region-filters-comments)
|
396
|
-
(add-to-list 'font-lock-extend-region-functions 'haml-extend-region-multiline-hashes)
|
397
|
-
(set (make-local-variable 'font-lock-multiline) t)
|
398
|
-
(set (make-local-variable 'indent-line-function) 'haml-indent-line)
|
399
|
-
(set (make-local-variable 'indent-region-function) 'haml-indent-region)
|
400
|
-
(set (make-local-variable 'parse-sexp-lookup-properties) t)
|
401
|
-
(setq comment-start "-#")
|
402
|
-
(setq font-lock-defaults '((haml-font-lock-keywords) t t)))
|
403
|
-
|
404
|
-
;; Useful functions
|
405
|
-
|
406
|
-
(defun haml-comment-block ()
|
407
|
-
"Comment the current block of Haml code."
|
408
|
-
(interactive)
|
409
|
-
(save-excursion
|
410
|
-
(let ((indent (current-indentation)))
|
411
|
-
(back-to-indentation)
|
412
|
-
(insert "-#")
|
413
|
-
(newline)
|
414
|
-
(indent-to indent)
|
415
|
-
(beginning-of-line)
|
416
|
-
(haml-mark-sexp)
|
417
|
-
(haml-reindent-region-by haml-indent-offset))))
|
418
|
-
|
419
|
-
(defun haml-uncomment-block ()
|
420
|
-
"Uncomment the current block of Haml code."
|
421
|
-
(interactive)
|
422
|
-
(save-excursion
|
423
|
-
(beginning-of-line)
|
424
|
-
(while (not (looking-at haml-comment-re))
|
425
|
-
(haml-up-list)
|
426
|
-
(beginning-of-line))
|
427
|
-
(haml-mark-sexp)
|
428
|
-
(kill-line 1)
|
429
|
-
(haml-reindent-region-by (- haml-indent-offset))))
|
430
|
-
|
431
|
-
(defun haml-replace-region (start end)
|
432
|
-
"Replace the current block of Haml code with the HTML equivalent.
|
433
|
-
Called from a program, START and END specify the region to indent."
|
434
|
-
(interactive "r")
|
435
|
-
(save-excursion
|
436
|
-
(goto-char end)
|
437
|
-
(setq end (point-marker))
|
438
|
-
(goto-char start)
|
439
|
-
(let ((ci (current-indentation)))
|
440
|
-
(while (re-search-forward "^ +" end t)
|
441
|
-
(replace-match (make-string (- (current-indentation) ci) ? ))))
|
442
|
-
(shell-command-on-region start end "haml" "haml-output" t)))
|
443
|
-
|
444
|
-
(defun haml-output-region (start end)
|
445
|
-
"Displays the HTML output for the current block of Haml code.
|
446
|
-
Called from a program, START and END specify the region to indent."
|
447
|
-
(interactive "r")
|
448
|
-
(kill-new (buffer-substring start end))
|
449
|
-
(with-temp-buffer
|
450
|
-
(yank)
|
451
|
-
(haml-indent-region (point-min) (point-max))
|
452
|
-
(shell-command-on-region (point-min) (point-max) "haml" "haml-output")))
|
453
|
-
|
454
|
-
(defun haml-output-buffer ()
|
455
|
-
"Displays the HTML output for entire buffer."
|
456
|
-
(interactive)
|
457
|
-
(haml-output-region (point-min) (point-max)))
|
458
|
-
|
459
|
-
;; Navigation
|
460
|
-
|
461
|
-
(defun haml-forward-through-whitespace (&optional backward)
|
462
|
-
"Move the point forward through any whitespace.
|
463
|
-
The point will move forward at least one line, until it reaches
|
464
|
-
either the end of the buffer or a line with no whitespace.
|
465
|
-
|
466
|
-
If BACKWARD is non-nil, move the point backward instead."
|
467
|
-
(let ((arg (if backward -1 1))
|
468
|
-
(endp (if backward 'bobp 'eobp)))
|
469
|
-
(loop do (forward-line arg)
|
470
|
-
while (and (not (funcall endp))
|
471
|
-
(looking-at "^[ \t]*$")))))
|
472
|
-
|
473
|
-
(defun haml-at-indent-p ()
|
474
|
-
"Return non-nil if the point is before any text on the line."
|
475
|
-
(let ((opoint (point)))
|
476
|
-
(save-excursion
|
477
|
-
(back-to-indentation)
|
478
|
-
(>= (point) opoint))))
|
479
|
-
|
480
|
-
(defun haml-forward-sexp (&optional arg)
|
481
|
-
"Move forward across one nested expression.
|
482
|
-
With ARG, do it that many times. Negative arg -N means move
|
483
|
-
backward across N balanced expressions.
|
484
|
-
|
485
|
-
A sexp in Haml is defined as a line of Haml code as well as any
|
486
|
-
lines nested beneath it."
|
487
|
-
(interactive "p")
|
488
|
-
(or arg (setq arg 1))
|
489
|
-
(if (and (< arg 0) (not (haml-at-indent-p)))
|
490
|
-
(back-to-indentation)
|
491
|
-
(while (/= arg 0)
|
492
|
-
(let ((indent (current-indentation)))
|
493
|
-
(loop do (haml-forward-through-whitespace (< arg 0))
|
494
|
-
while (and (not (eobp))
|
495
|
-
(not (bobp))
|
496
|
-
(> (current-indentation) indent)))
|
497
|
-
(back-to-indentation)
|
498
|
-
(setq arg (+ arg (if (> arg 0) -1 1)))))))
|
499
|
-
|
500
|
-
(defun haml-backward-sexp (&optional arg)
|
501
|
-
"Move backward across one nested expression.
|
502
|
-
With ARG, do it that many times. Negative arg -N means move
|
503
|
-
forward across N balanced expressions.
|
504
|
-
|
505
|
-
A sexp in Haml is defined as a line of Haml code as well as any
|
506
|
-
lines nested beneath it."
|
507
|
-
(interactive "p")
|
508
|
-
(haml-forward-sexp (if arg (- arg) -1)))
|
509
|
-
|
510
|
-
(defun haml-up-list (&optional arg)
|
511
|
-
"Move out of one level of nesting.
|
512
|
-
With ARG, do this that many times."
|
513
|
-
(interactive "p")
|
514
|
-
(or arg (setq arg 1))
|
515
|
-
(while (> arg 0)
|
516
|
-
(let ((indent (current-indentation)))
|
517
|
-
(loop do (haml-forward-through-whitespace t)
|
518
|
-
while (and (not (bobp))
|
519
|
-
(>= (current-indentation) indent)))
|
520
|
-
(setq arg (- arg 1))))
|
521
|
-
(back-to-indentation))
|
522
|
-
|
523
|
-
(defun haml-down-list (&optional arg)
|
524
|
-
"Move down one level of nesting.
|
525
|
-
With ARG, do this that many times."
|
526
|
-
(interactive "p")
|
527
|
-
(or arg (setq arg 1))
|
528
|
-
(while (> arg 0)
|
529
|
-
(let ((indent (current-indentation)))
|
530
|
-
(haml-forward-through-whitespace)
|
531
|
-
(when (<= (current-indentation) indent)
|
532
|
-
(haml-forward-through-whitespace t)
|
533
|
-
(back-to-indentation)
|
534
|
-
(error "Nothing is nested beneath this line"))
|
535
|
-
(setq arg (- arg 1))))
|
536
|
-
(back-to-indentation))
|
537
|
-
|
538
|
-
(defun haml-mark-sexp ()
|
539
|
-
"Mark the next Haml block."
|
540
|
-
(let ((forward-sexp-function 'haml-forward-sexp))
|
541
|
-
(mark-sexp)))
|
542
|
-
|
543
|
-
(defun haml-mark-sexp-but-not-next-line ()
|
544
|
-
"Mark the next Haml block, but not the next line.
|
545
|
-
Put the mark at the end of the last line of the sexp rather than
|
546
|
-
the first non-whitespace character of the next line."
|
547
|
-
(haml-mark-sexp)
|
548
|
-
(set-mark
|
549
|
-
(save-excursion
|
550
|
-
(goto-char (mark))
|
551
|
-
(forward-line -1)
|
552
|
-
(end-of-line)
|
553
|
-
(point))))
|
554
|
-
|
555
|
-
;; Indentation and electric keys
|
556
|
-
|
557
|
-
(defun* haml-indent-p ()
|
558
|
-
"Returns t if the current line can have lines nested beneath it."
|
559
|
-
(let ((attr-props (haml-parse-multiline-attr-hash)))
|
560
|
-
(when attr-props
|
561
|
-
(return-from haml-indent-p
|
562
|
-
(if (haml-unclosed-attr-hash-p) (cdr (assq 'hash-indent attr-props))
|
563
|
-
(list (+ (cdr (assq 'indent attr-props)) haml-indent-offset) nil)))))
|
564
|
-
(loop for opener in haml-block-openers
|
565
|
-
if (looking-at opener) return t
|
566
|
-
finally return nil))
|
567
|
-
|
568
|
-
(defun* haml-parse-multiline-attr-hash ()
|
569
|
-
"Parses a multiline attribute hash, and returns
|
570
|
-
an alist with the following keys:
|
571
|
-
|
572
|
-
INDENT is the indentation of the line beginning the hash.
|
573
|
-
|
574
|
-
HASH-INDENT is the indentation of the first character
|
575
|
-
within the attribute hash.
|
576
|
-
|
577
|
-
POINT is the character position at the beginning of the line
|
578
|
-
beginning the hash."
|
579
|
-
(save-excursion
|
580
|
-
(while t
|
581
|
-
(beginning-of-line)
|
582
|
-
(if (looking-at (concat haml-tag-beg-re "\\([{(]\\)"))
|
583
|
-
(progn
|
584
|
-
(goto-char (- (match-end 0) 1))
|
585
|
-
(haml-limited-forward-sexp (save-excursion (end-of-line) (point)))
|
586
|
-
(return-from haml-parse-multiline-attr-hash
|
587
|
-
(when (or (string-equal (match-string 1) "(") (eq (char-before) ?,))
|
588
|
-
`((indent . ,(current-indentation))
|
589
|
-
(hash-indent . ,(- (match-end 0) (match-beginning 0)))
|
590
|
-
(point . ,(match-beginning 0))))))
|
591
|
-
(when (bobp) (return-from haml-parse-multiline-attr-hash))
|
592
|
-
(forward-line -1)
|
593
|
-
(unless (haml-unclosed-attr-hash-p)
|
594
|
-
(return-from haml-parse-multiline-attr-hash))))))
|
595
|
-
|
596
|
-
(defun* haml-unclosed-attr-hash-p ()
|
597
|
-
"Return t if this line has an unclosed attribute hash, new or old."
|
598
|
-
(save-excursion
|
599
|
-
(end-of-line)
|
600
|
-
(when (eq (char-before) ?,) (return-from haml-unclosed-attr-hash-p t))
|
601
|
-
(re-search-backward "(\\|^")
|
602
|
-
(haml-move "(")
|
603
|
-
(haml-parse-new-attr-hash)))
|
604
|
-
|
605
|
-
(defun* haml-parse-new-attr-hash (&optional (fn (lambda (type beg end) ())))
|
606
|
-
"Parse a new-style attribute hash on this line, and returns
|
607
|
-
t if it's not finished on the current line.
|
608
|
-
|
609
|
-
FN should take three parameters: TYPE, BEG, and END.
|
610
|
-
TYPE is the type of text parsed ('name or 'value)
|
611
|
-
and BEG and END delimit that text in the buffer."
|
612
|
-
(let ((eol (save-excursion (end-of-line) (point))))
|
613
|
-
(while (not (haml-move ")"))
|
614
|
-
(haml-move "[ \t]*")
|
615
|
-
(unless (haml-move "[a-z0-9_:\\-]+")
|
616
|
-
(return-from haml-parse-new-attr-hash (haml-move "[ \t]*$")))
|
617
|
-
(funcall fn 'name (match-beginning 0) (match-end 0))
|
618
|
-
(haml-move "[ \t]*")
|
619
|
-
(when (haml-move "=")
|
620
|
-
(haml-move "[ \t]*")
|
621
|
-
(unless (looking-at "[\"'@a-z]") (return-from haml-parse-new-attr-hash))
|
622
|
-
(let ((beg (point)))
|
623
|
-
(haml-limited-forward-sexp eol)
|
624
|
-
(funcall fn 'value beg (point)))
|
625
|
-
(haml-move "[ \t]*")))
|
626
|
-
nil))
|
627
|
-
|
628
|
-
(defun haml-compute-indentation ()
|
629
|
-
"Calculate the maximum sensible indentation for the current line."
|
630
|
-
(save-excursion
|
631
|
-
(beginning-of-line)
|
632
|
-
(if (bobp) (list 0 nil)
|
633
|
-
(haml-forward-through-whitespace t)
|
634
|
-
(let ((indent (funcall haml-indent-function)))
|
635
|
-
(cond
|
636
|
-
((consp indent) indent)
|
637
|
-
((integerp indent) (list indent t))
|
638
|
-
(indent (list (+ (current-indentation) haml-indent-offset) nil))
|
639
|
-
(t (list (current-indentation) nil)))))))
|
640
|
-
|
641
|
-
(defun haml-indent-region (start end)
|
642
|
-
"Indent each nonblank line in the region.
|
643
|
-
This is done by indenting the first line based on
|
644
|
-
`haml-compute-indentation' and preserving the relative
|
645
|
-
indentation of the rest of the region. START and END specify the
|
646
|
-
region to indent.
|
647
|
-
|
648
|
-
If this command is used multiple times in a row, it will cycle
|
649
|
-
between possible indentations."
|
650
|
-
(save-excursion
|
651
|
-
(goto-char end)
|
652
|
-
(setq end (point-marker))
|
653
|
-
(goto-char start)
|
654
|
-
(let (this-line-column current-column
|
655
|
-
(next-line-column
|
656
|
-
(if (and (equal last-command this-command) (/= (current-indentation) 0))
|
657
|
-
(* (/ (- (current-indentation) 1) haml-indent-offset) haml-indent-offset)
|
658
|
-
(car (haml-compute-indentation)))))
|
659
|
-
(while (< (point) end)
|
660
|
-
(setq this-line-column next-line-column
|
661
|
-
current-column (current-indentation))
|
662
|
-
;; Delete whitespace chars at beginning of line
|
663
|
-
(delete-horizontal-space)
|
664
|
-
(unless (eolp)
|
665
|
-
(setq next-line-column (save-excursion
|
666
|
-
(loop do (forward-line 1)
|
667
|
-
while (and (not (eobp)) (looking-at "^[ \t]*$")))
|
668
|
-
(+ this-line-column
|
669
|
-
(- (current-indentation) current-column))))
|
670
|
-
;; Don't indent an empty line
|
671
|
-
(unless (eolp) (indent-to this-line-column)))
|
672
|
-
(forward-line 1)))
|
673
|
-
(move-marker end nil)))
|
674
|
-
|
675
|
-
(defun haml-indent-line ()
|
676
|
-
"Indent the current line.
|
677
|
-
The first time this command is used, the line will be indented to the
|
678
|
-
maximum sensible indentation. Each immediately subsequent usage will
|
679
|
-
back-dent the line by `haml-indent-offset' spaces. On reaching column
|
680
|
-
0, it will cycle back to the maximum sensible indentation."
|
681
|
-
(interactive "*")
|
682
|
-
(let ((ci (current-indentation))
|
683
|
-
(cc (current-column)))
|
684
|
-
(destructuring-bind (need strict) (haml-compute-indentation)
|
685
|
-
(save-excursion
|
686
|
-
(beginning-of-line)
|
687
|
-
(delete-horizontal-space)
|
688
|
-
(if (and (not strict) (equal last-command this-command) (/= ci 0))
|
689
|
-
(indent-to (* (/ (- ci 1) haml-indent-offset) haml-indent-offset))
|
690
|
-
(indent-to need))))
|
691
|
-
(when (< (current-column) (current-indentation))
|
692
|
-
(forward-to-indentation 0))))
|
693
|
-
|
694
|
-
(defun haml-reindent-region-by (n)
|
695
|
-
"Add N spaces to the beginning of each line in the region.
|
696
|
-
If N is negative, will remove the spaces instead. Assumes all
|
697
|
-
lines in the region have indentation >= that of the first line."
|
698
|
-
(let* ((ci (current-indentation))
|
699
|
-
(indent-rx
|
700
|
-
(concat "^"
|
701
|
-
(if indent-tabs-mode
|
702
|
-
(concat (make-string (/ ci tab-width) ?\t)
|
703
|
-
(make-string (mod ci tab-width) ?\t))
|
704
|
-
(make-string ci ?\s)))))
|
705
|
-
(save-excursion
|
706
|
-
(while (re-search-forward indent-rx (mark) t)
|
707
|
-
(let ((ci (current-indentation)))
|
708
|
-
(delete-horizontal-space)
|
709
|
-
(beginning-of-line)
|
710
|
-
(indent-to (max 0 (+ ci n))))))))
|
711
|
-
|
712
|
-
(defun haml-electric-backspace (arg)
|
713
|
-
"Delete characters or back-dent the current line.
|
714
|
-
If invoked following only whitespace on a line, will back-dent
|
715
|
-
the line and all nested lines to the immediately previous
|
716
|
-
multiple of `haml-indent-offset' spaces. With ARG, do it that
|
717
|
-
many times.
|
718
|
-
|
719
|
-
Set `haml-backspace-backdents-nesting' to nil to just back-dent
|
720
|
-
the current line."
|
721
|
-
(interactive "*p")
|
722
|
-
(if (or (/= (current-indentation) (current-column))
|
723
|
-
(bolp)
|
724
|
-
(looking-at "^[ \t]+$"))
|
725
|
-
(backward-delete-char arg)
|
726
|
-
(save-excursion
|
727
|
-
(let ((ci (current-column)))
|
728
|
-
(beginning-of-line)
|
729
|
-
(if haml-backspace-backdents-nesting
|
730
|
-
(haml-mark-sexp-but-not-next-line)
|
731
|
-
(set-mark (save-excursion (end-of-line) (point))))
|
732
|
-
(haml-reindent-region-by (* (- arg) haml-indent-offset))
|
733
|
-
(pop-mark)))
|
734
|
-
(back-to-indentation)))
|
735
|
-
|
736
|
-
(defun haml-kill-line-and-indent ()
|
737
|
-
"Kill the current line, and re-indent all lines nested beneath it."
|
738
|
-
(interactive)
|
739
|
-
(beginning-of-line)
|
740
|
-
(haml-mark-sexp-but-not-next-line)
|
741
|
-
(kill-line 1)
|
742
|
-
(haml-reindent-region-by (* -1 haml-indent-offset)))
|
743
|
-
|
744
|
-
(defun haml-indent-string ()
|
745
|
-
"Return the indentation string for `haml-indent-offset'."
|
746
|
-
(mapconcat 'identity (make-list haml-indent-offset " ") ""))
|
747
|
-
|
748
|
-
;;;###autoload
|
749
|
-
(add-to-list 'auto-mode-alist '("\\.haml$" . haml-mode))
|
750
|
-
|
751
|
-
;; Setup/Activation
|
752
|
-
(provide 'haml-mode)
|
753
|
-
;;; haml-mode.el ends here
|