-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
41303f8
commit 7cc3114
Showing
4 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
" TODO (2013-05-09) Only works for very simple things, needs work | ||
function! sj#haml#SplitInterpolation() | ||
let lineno = line('.') | ||
let line = getline('.') | ||
let indent = indent('.') | ||
let pattern = '^\s*%.\{-}\zs=' | ||
|
||
if line !~ pattern | ||
return 0 | ||
endif | ||
|
||
exe 's/'.pattern.'/\r=/' | ||
call s:SetIndent(lineno + 1, lineno + 1, indent + &sw) | ||
|
||
return 1 | ||
endfunction | ||
|
||
function! sj#haml#JoinInterpolation() | ||
if line('.') == line('$') | ||
return 0 | ||
endif | ||
|
||
let line = getline('.') | ||
let next_line = getline(line('.') + 1) | ||
|
||
if !(line =~ '^\s*%\k\+\s*$' && next_line =~ '^\s*=') | ||
return 0 | ||
end | ||
|
||
s/\n\s*// | ||
return 1 | ||
endfunction | ||
|
||
" Sets the absolute indent of the given range of lines to the given indent | ||
function! s:SetIndent(from, to, indent) | ||
let new_whitespace = repeat(' ', a:indent) | ||
exe a:from.','.a:to.'s/^\s*/'.new_whitespace | ||
endfunction |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
%div | ||
%span | ||
= 1 + 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
let b:splitjoin_split_callbacks = [ | ||
\ 'sj#haml#SplitInterpolation' | ||
\ ] | ||
|
||
let b:splitjoin_join_callbacks = [ | ||
\ 'sj#haml#JoinInterpolation' | ||
\ ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
require 'spec_helper' | ||
|
||
describe "haml" do | ||
let(:filename) { 'test.haml' } | ||
|
||
# Haml is not built-in, so let's set it up manually | ||
def setup_haml_filetype | ||
vim.set(:filetype, 'haml') | ||
vim.set(:expandtab) | ||
vim.set(:shiftwidth, 2) | ||
end | ||
|
||
specify "interpolation" do | ||
set_file_contents '%div= 1 + 2' | ||
setup_haml_filetype | ||
|
||
split | ||
|
||
assert_file_contents <<-EOF | ||
%div | ||
= 1 + 2 | ||
EOF | ||
|
||
join | ||
|
||
assert_file_contents '%div= 1 + 2' | ||
end | ||
end |