Permalink
Browse files

Better behaviour for curly braces

  • Loading branch information...
1 parent eebcf99 commit 12e29b9778c037893fa93fe26a5f53caa6e0151e @AndrewRadev committed Jun 12, 2013
Showing with 42 additions and 2 deletions.
  1. +4 −2 plugin/whitespaste.vim
  2. +38 −0 spec/plugin/global.rb
View
@@ -29,12 +29,14 @@ endif
if !exists('g:whitespaste_linewise_definitions')
let g:whitespaste_linewise_definitions = {
\ 'top': [
- \ { 'target_line': 0, 'blank_lines': 0 },
- \ { 'target_text': '{\s*$', 'blank_lines': 0 },
+ \ { 'target_line': 0, 'blank_lines': 0 },
+ \ { 'target_text': '^\s*}\s*$', 'pasted_text': '{\s*$', 'blank_lines': 1 },
+ \ { 'target_text': '{\s*$', 'blank_lines': 0 },
\ { 'compress_blank_lines': 1 },
\ ],
\ 'bottom': [
\ { 'target_line': -1, 'blank_lines': 0 },
+ \ { 'target_text': '{\s*$', 'pasted_text': '^\s*}\s*$', 'blank_lines': 1 },
\ { 'target_text': '^\s*}\s*$', 'blank_lines': 0 },
\ { 'compress_blank_lines': 1 },
\ ]
View
@@ -0,0 +1,38 @@
+require 'spec_helper'
+
+describe "global" do
+ let(:filename) { 'test.js' }
+ let(:vim) { @vim }
+
+ specify "curly brackets" do
+ set_file_contents <<-EOF
+ if (one) {
+ if (two) {
+ three();
+ }
+
+ if (four) {
+ five();
+ }
+ }
+ EOF
+
+ vim.search 'two'
+ vim.normal 'Vjjjd'
+ vim.search 'four'
+ vim.normal '$%'
+ vim.whitespaste_after
+
+ assert_file_contents <<-EOF
+ if (one) {
+ if (four) {
+ five();
+ }
+
+ if (two) {
+ three();
+ }
+ }
+ EOF
+ end
+end

0 comments on commit 12e29b9

Please sign in to comment.