Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

update to version 2.3 #1

Open
wants to merge 5 commits into from

1 participant

@will-v-king

improved:
from
var a = [[[{
a: 'a'
}, {
A: 'A'
}], {
b: 'b'
,B: 'B'
}], [{
c: 'c'
}, {
C: 'C'
}], {
d: 'd'
}, {
D: 'D'
}]

to
var a = [[[{
a: 'a'
}, {
A: 'A'
}], {
b: 'b'
,B: 'B'
}], [{
c: 'c'
}, {
C: 'C'
}], {
d: 'd'
}, {
D: 'D'
}]

will-v-king added some commits
@will-v-king will-v-king Update _jsbeautify from version 2.2 to 2.3
improved the format of the result:
Example:
in version 2.2
<code>	var a = [[[{
		a: 'a'
	}, {
		A: 'A'
	}], {
		b: 'b'
		,B: 'B'
	}], [{
		c: 'c'
	}, {
		C: 'C'
	}], {
		d: 'd'
	}, {
		D: 'D'
	}]
</code>
in this version 2.3:
<code>
		var a = [[[{
						a: 'a'
					}, {
						A: 'A'
				}], {
					b: 'b'
					,B: 'B'
			}], [{
					c: 'c'
				}, {
					C: 'C'
			}], {
				d: 'd'
			}, {
				D: 'D'
		}]

</code>
it's good for fold method in VIM when fold method's value is "indent"
dc42fd3
@will-v-king will-v-king Update README
version 2.3
af3cbcd
@will-v-king will-v-king reopened this
will-v-king added some commits
@will-v-king will-v-king Update _jsbeautify.vim
 (function(){})(). may cause a little bug. fixed in this version.
b0fa141
@will-v-king will-v-king Update README
update README, specify the version of the change.
4d55ecb
@will-v-king will-v-king Update README
add commit, in 2.3+ code format is more kind for 
:set foldmethod = indent
33b54c8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 13, 2013
  1. @will-v-king

    Update _jsbeautify from version 2.2 to 2.3

    will-v-king authored
    improved the format of the result:
    Example:
    in version 2.2
    <code>	var a = [[[{
    		a: 'a'
    	}, {
    		A: 'A'
    	}], {
    		b: 'b'
    		,B: 'B'
    	}], [{
    		c: 'c'
    	}, {
    		C: 'C'
    	}], {
    		d: 'd'
    	}, {
    		D: 'D'
    	}]
    </code>
    in this version 2.3:
    <code>
    		var a = [[[{
    						a: 'a'
    					}, {
    						A: 'A'
    				}], {
    					b: 'b'
    					,B: 'B'
    			}], [{
    					c: 'c'
    				}, {
    					C: 'C'
    			}], {
    				d: 'd'
    			}, {
    				D: 'D'
    		}]
    
    </code>
    it's good for fold method in VIM when fold method's value is "indent"
  2. @will-v-king

    Update README

    will-v-king authored
    version 2.3
Commits on Mar 14, 2013
  1. @will-v-king

    Update _jsbeautify.vim

    will-v-king authored
     (function(){})(). may cause a little bug. fixed in this version.
Commits on Mar 19, 2013
  1. @will-v-king

    Update README

    will-v-king authored
    update README, specify the version of the change.
  2. @will-v-king

    Update README

    will-v-king authored
    add commit, in 2.3+ code format is more kind for 
    :set foldmethod = indent
This page is out of date. Refresh to see the latest.
Showing with 125 additions and 6 deletions.
  1. +48 −3 README
  2. +77 −3 plugin/_jsbeautify.vim
View
51 README
@@ -2,8 +2,8 @@ This is a mirror of http://www.vim.org/scripts/script.php?script_id=4063
Another plugin to format your JavaScript source code
-I modified the jsbeautify.vim as I need. (Original jsbeautify.vim is here: http://www.vim.org/scripts/script.php?script_id=2727 ) (changes happened on lines 1, 4, 532, 534, 538, 540 and 503)
-
+I modified the jsbeautify.vim as I need. (Original jsbeautify.vim is here: http://www.vim.org/scripts/script.php?script_id=2727 ) (changes happened on lines 1, 4, 532, 534, 538, 540 and 503(version 2.1))
+in version 2.1+
{
a: 'a',
@@ -57,7 +57,52 @@ var initRoleMutexGroupGrid = function() {
}, RMGGridRowClick); // There won be a newline after } , when it's in an Expression.
}
⇱ END
-
+------------------------------
+in versino 2.3+
+⇲
+ var a = [[[{
+ a: 'a'
+ }, {
+ A: 'A'
+ }], {
+ b: 'b'
+ ,B: 'B'
+ }], [{
+ c: 'c'
+ }, {
+ C: 'C'
+ }], {
+ d: 'd'
+ }, {
+ D: 'D'
+ }]
+⇱
+also good for indent fold method:
+before 2.3
+⇲
+var a = {
+ columns:[{
+ field:'A'
+ ,label:'A'
+ }, {
+ field:'B'
+ ,label:'B'
+ }]
+}
+⇱
+in version 2.3+
+⇲
+var a = {
+ columns:[{
+ field:'A'
+ ,label:'A'
+ }, {
+ field:'B'
+ ,label:'B'
+ }]
+}
+⇱
+END
This vim-script also works at a low performance:)
View
80 plugin/_jsbeautify.vim
@@ -1,7 +1,7 @@
if &cp || exists("loaded__jsbeautify")
finish
endif
-let loaded__jsbeautify = 2.2
+let loaded__jsbeautify = 2.3.1
@@ -61,10 +61,23 @@ endfunction
function! s:remove_indent() " if the last item of output (stringArray) is indent string, remove it.
if len(s:output)>0 && s:output[len(s:output) -1] == s:indent_string
+ "unlet s:output[-1]
call remove(s:output, -1)
endif
endfunction
+function! s:remove_last_indent()
+ let i = len(s:output)
+ while i >= 0
+ let i -= 1
+ if s:output[i] == s:indent_string
+ "call remove(s:output, i)
+ unlet s:output[i]
+ break
+ endif
+ endwhile
+endfunction
+
function! s:set_mode(mode) " push last mode into modes and update current mode.
call add(s:modes, s:current_mode)
let s:current_mode = a:mode
@@ -146,14 +159,69 @@ function! s:get_next_token() " return next array of string and type. the string
return [c, "TK_WORD"]
endif
if c == "(" || c == "["
+ if c == "["
+ call s:indent()
+ endif
return [c, "TK_START_EXPR"]
endif
-
+ if c == "(" " prepare for next version
+ return [c,"TK_START_PARENTHESIS"]
+ endif
+ if c == "[" " prepare for next change
+ all s:indent()
+ return [c,"TK_START_BRACKET"]
+ endif
if c == ")" || c == "]"
+ if c == "]" "for deindent the line ] is in
+ call s:unindent()
+ let i = len(s:output)
+ let ignore = 0 " if there's a [ match ], ignore the deindent
+ while i >= 0
+ let i -= 1
+ if s:output[i] == "["
+ let ignore += 1
+ elseif s:output[i] == "]"
+ let ignore -= 1
+ elseif s:output[i] == s:indent_string
+ "call remove(s:output, i)
+ unlet s:output[i]
+ break
+ endif
+ if ignore == 1
+ break
+ endif
+ endwhile
+ "call s:remove_last_indent()
+ endif
return [c, "TK_END_EXPR"]
endif
+ if c == ")" " prepare for next version
+ return [c, "TK_END_PARENTHESIS"]
+ endif
+ if c == "]" " prepare for nextversion
+ "for deindent the line ] is in
+ call s:unindent()
+ let i = len(s:output)
+ let ignore = 0 " if there's a [ match ], ignore the deindent
+ while i >= 0
+ let i -= 1
+ if s:output[i] == "["
+ let ignore += 1
+ elseif s:output[i] == "]"
+ let ignore -= 1
+ elseif s:output[i] == s:indent_string
+ "call remove(s:output, i)
+ unlet s:output[i]
+ break
+ endif
+ if ignore == 1
+ break
+ endif
+ endwhile
+ return [c,"TK_END_BRACKET"]
+ endif
- if c == "{"
+ if c == "{" "BRACE
return [c, "TK_START_BLOCK"]
endif
@@ -291,6 +359,10 @@ function! s:is_js()
return expand("%:e") == "js"
endfunction
+function! s:currentMode()
+ return mode()
+endfunction
+
"function! g:_Jsbeautify(js_source_text, options)
function! g:_Jsbeautify()
if !s:is_js()
@@ -367,6 +439,7 @@ function! g:_Jsbeautify()
call s:print_token()
elseif s:token_type == "TK_END_EXPR"
+ "call s:remove_last_indent()
call s:print_token()
call s:restore_mode()
elseif s:token_type == "TK_START_BLOCK"
@@ -647,3 +720,4 @@ function! g:_Jsbeautify()
endfunction
nnoremap <silent> <leader>_ff :call g:_Jsbeautify()<cr>
+vmap <F4> :call g:_Jsbeautify()<cr>
Something went wrong with that request. Please try again.