至於這一個 OOP javascript indentation : This indentation script for OOP
javascript (especially for EXTJS) http://www.vim.org/scripts/script.php?script_id=1936
這一個的話,似乎更多問題。 我想應該只有對EXTJS比較有用..
On Dec 21, 1:13 am, Kent Chen <chenk...@gmail.com> wrote:
> Great, support github :)
> 突然想到個問題,以Vimana為例,從cpan安裝的,應該會比github上的版本來得舊些,是吧 ?!
對。不過通常都是 stable 才會 release 到 cpan 上。(大部分)
> 試用了一下這個js
> beautify,似乎無法滿足我的要求,像是底下這類的code,beautify完,append後面那些會被接成"一行"....囧..看來還不夠彈性, 沒有這類參數供彈整
> for (i = 0; i < MD_WINDOW_SIZE; i++)
> {
>
> $("#StreamContainer").append(
> '<div id="MDWindow'+i+'" class="MDW_style">'+
> '<div class="MDW_drag">'+
> '<span title="param"
> class="MDW_title">motion_c0_win_i'+i+'_name</span>'+
> '<a class="ui-dialog-titlebar-close"
> href="#"><span>X</span></a>'+
> '</div>'+
> '</div>')
> }
這個時候我只好說,如果沒辦法找到期他好用的 formater ,那只好自己 patch 了 XD
其實你不一定要把整個檔案重新 tidy 呀
equalprg 的好處是他可以只對一個區塊 re-tidy
如果你想要自己寫 vim script 來 re-indent 的話 (只做 indent)
可以參考 *indent-expression* 章節
其實預設的 javascript 是使用 c 的 indent 來方式,好像還堪用
indent method 的實做方式可以參考: $vimruntime/indent/perl.vim
裡面有範例。 你寫好的 indent script 放在 ~/.vim/indent/javascript.vim 就可以用了。
:-)
== current line
=i{ current block
或是 V 進去選了 region , 按 =
都可。
gg=G 是很... rough 的 :p
> --
> Let's Blogging...http://chenkaie.blogspot.com
> Sent from San-Ch'ung, Tpe, Taiwan
>
> 2009/12/20 Cornelius <cornelius.h...@gmail.com>
>
>
>
> > 我本來是想寫一個 c 版本的 js tidy
> > 不過因為有 perl 的版本,所以就直接用 perl 了,用起來還不賴!
> > 應該是不會再 finetune... XD
>
> > 附帶一提 , Vimana 現在可以直接從一個 git repository 裝了
>
> > vimana i git:git://path/to/repository.git
>
> > 也可以直接從 local directory 裝
>
> > vimana i .
>
> > 以上。其他詳細資訊在:http://github.com/c9s/vimana/
>
> > /Thanks/
>
> > 2009/12/20 Kent Chen <chenk...@gmail.com>
>
> >> 看來,容易手癢的c9s大,會再finetune一版,整進vimana ..XD
>
> >> ---
>
> >> Let's Blogging...
> >>http://chenkaie.blogspot.com
>
> >> 2009/12/20 Cornelius <cornelius.h...@gmail.com>
>
> >>> 剛剛看到 plugin 的上面寫到:
>
> >>> "I just translated it into vimscript, it works at a low performance:) "
>
> >>> 所以看來還是有一點效能的問題。
>
> >>> 2009/12/20 Cornelius <cornelius.h...@gmail.com>
>
> >>>> 看來不錯耶,不過希望 vim script 的效能夠好 :p
>
> >>>> 這樣好處就是沒有什麼 dependency. :p
>
> >>>> 2009/12/20 Kent Chen <chenk...@gmail.com>
>
> >>>>> google 了一下,c9s大推薦的這個
> >>>>>http://search.cpan.org/dist/JavaScript-Beautifier/lib/JavaScript/Beau...
>
> >>>>> 裡頭提到
> >>>>> This module is mostly a Perl-rewrite of
> >>>>>http://github.com/einars/js-beautify/tree/master/beautify.js
>
> >>>>> <http://github.com/einars/js-beautify/tree/master/beautify.js> source
> >>>>> code裡又提到http://jsbeautifier.org/連過去,裡頭又提到...XD
>
> >>>>> Aj3423 converted the script to vimscript -- and so now there is a vim
> >>>>> plugin <http://www.vim.org/scripts/script.php?script_id=2727> for the
> >>>>> quality javascript beautifying.
> >>>>> 似乎有善心人士port 了vim script的版本了
>
> >>>>> --
> >>>>> Let's Blogging...
> >>>>>http://chenkaie.blogspot.com
> >>>>> Sent from San-Ch'ung, Tpe, Taiwan
>
> >>>>> 2009/12/20 Kent Chen <chenk...@gmail.com>
>
> >>>>> Got it, 來試試 Javascript::Beautifier 效果如何..
>
> >>>>>> 2009/12/20 Cornelius <cornelius.h...@gmail.com>
>
> >>>>>> 我使用外部的 Javascript 來做 tidy
> >>>>>>> 因為 vim 本身的 indentation 有其限制
>
> >>>>>>> 先用 cpan 裝 Javascript::Beautifier
>
> >>>>>>> 我有一段 script:
>
> >>>>>>> -~ % cat ~/bin/js_beautifier
>
> >>>>>>> #!/usr/bin/env perl
> >>>>>>> use JavaScript::Beautifier qw/js_beautify/;
> >>>>>>> local $/;
> >>>>>>> $js_source_code = <STDIN>;
> >>>>>>> my $pretty_js = js_beautify( $js_source_code, {
> >>>>>>> indent_size => 2,
> >>>>>>> indent_character => ' ',
> >>>>>>> } );
> >>>>>>> print $pretty_js;
>
> >>>>>>> 加到 .vimrc:
>
> >>>>>>> 704 fun! s:js_rc()
> >>>>>>> 705 abbr func function
> >>>>>>> 706 setlocal sw=2
> >>>>>>> 707 setlocal equalprg=/Users/c9s/bin/js_beautifier
>
> >>>>>>> au filetype javascript :cal s:js_rc()
>
> >>>>>>> 2009/12/20 Kaie (Tsung-Kai Chen) <chenk...@gmail.com>
>
> >>>>>>>> Dear all,
> >>>>>>>> 除了這個 Javascript Indentation : Indentation for Javascript (
> >>>>>>>>http://www.vim.org/scripts/script.php?script_id=1840)
> >>>>>>>> 還堪用之外,有更好用的嗎?
>
> >>>>>>>> 至於這一個 OOP javascript indentation : This indentation script for OOP
> >>>>>>>> javascript (especially for EXTJS)
> >>>>>>>>http://www.vim.org/scripts/script.php?script_id=1936
> >>>>>>>> 這一個的話,似乎更多問題。 我想應該只有對EXTJS比較有用..
>
> >>>>>>> --
> >>>>>>> Best Regards.
>
> >>>>>>> Cornelius ( Yo-An Lin )
> >>>>>>> E-mail: cornelius.h...@gmail.com
> >>>>>>>http://c9s.blogspot.com/
>
> >>>> --
> >>>> Best Regards.
>
> >>>> Cornelius ( Yo-An Lin )
> >>>> E-mail: cornelius.h...@gmail.com
> >>>>http://c9s.blogspot.com/
>
> >>> --
> >>> Best Regards.
>
> >>> Cornelius ( Yo-An Lin )
> >>> E-mail: cornelius.h...@gmail.com
> >>>http://c9s.blogspot.com/
>
> > --
> > Best Regards.
>
> > Cornelius ( Yo-An Lin )
> > E-mail: cornelius.h...@gmail.com
> >http://c9s.blogspot.com/
On Dec 21, 1:13 am, Kent Chen <chenk...@gmail.com> wrote:
> Great, support github :)
> 突然想到個問題,以Vimana為例,從cpan安裝的,應該會比github上的版本來得舊些,是吧 ?!
>
> 試用了一下這個js
> beautify,似乎無法滿足我的要求,像是底下這類的code,beautify完,append後面那些會被接成"一行"....囧..看來還不夠彈性, 沒有這類參數供彈整
> for (i = 0; i < MD_WINDOW_SIZE; i++)
> {
>
> $("#StreamContainer").append(
> '<div id="MDWindow'+i+'" class="MDW_style">'+
> '<div class="MDW_drag">'+
> '<span title="param"
> class="MDW_title">motion_c0_win_i'+i+'_name</span>'+
> '<a class="ui-dialog-titlebar-close"
> href="#"><span>X</span></a>'+
> '</div>'+
> '</div>')
> }
> --
> Let's Blogging...http://chenkaie.blogspot.com
> Sent from San-Ch'ung, Tpe, Taiwan
>
> 2009/12/20 Cornelius <cornelius.h...@gmail.com>
>
>
>
> > 我本來是想寫一個 c 版本的 js tidy
> > 不過因為有 perl 的版本,所以就直接用 perl 了,用起來還不賴!
> > 應該是不會再 finetune... XD
>
> > 附帶一提 , Vimana 現在可以直接從一個 git repository 裝了
>
> > vimana i git:git://path/to/repository.git
>
> > 也可以直接從 local directory 裝
>
> > vimana i .
>
> > 以上。其他詳細資訊在:http://github.com/c9s/vimana/
>
> > /Thanks/
>
> > 2009/12/20 Kent Chen <chenk...@gmail.com>
>
> >> 看來,容易手癢的c9s大,會再finetune一版,整進vimana ..XD
>
> >> ---
>
> >> Let's Blogging...
> >>http://chenkaie.blogspot.com
>
> >> 2009/12/20 Cornelius <cornelius.h...@gmail.com>
>
> >>> 剛剛看到 plugin 的上面寫到:
>
> >>> "I just translated it into vimscript, it works at a low performance:) "
>
> >>> 所以看來還是有一點效能的問題。
>
> >>> 2009/12/20 Cornelius <cornelius.h...@gmail.com>
>
> >>>> 看來不錯耶,不過希望 vim script 的效能夠好 :p
>
> >>>> 這樣好處就是沒有什麼 dependency. :p
>
> >>>> 2009/12/20 Kent Chen <chenk...@gmail.com>
>
> >>>>> google 了一下,c9s大推薦的這個
> >>>>>http://search.cpan.org/dist/JavaScript-Beautifier/lib/JavaScript/Beau...
>
> >>>>> 裡頭提到
> >>>>> This module is mostly a Perl-rewrite of
> >>>>>http://github.com/einars/js-beautify/tree/master/beautify.js
>
> >>>>> <http://github.com/einars/js-beautify/tree/master/beautify.js> source
> >>>>> code裡又提到http://jsbeautifier.org/連過去,裡頭又提到...XD
>
> >>>>> Aj3423 converted the script to vimscript -- and so now there is a vim
> >>>>> plugin <http://www.vim.org/scripts/script.php?script_id=2727> for the
> >>>>> quality javascript beautifying.
> >>>>> 似乎有善心人士port 了vim script的版本了
>
> >>>>> --
> >>>>> Let's Blogging...
> >>>>>http://chenkaie.blogspot.com
> >>>>> Sent from San-Ch'ung, Tpe, Taiwan
>
> >>>>> 2009/12/20 Kent Chen <chenk...@gmail.com>
>
> >>>>> Got it, 來試試 Javascript::Beautifier 效果如何..
>
> >>>>>> 2009/12/20 Cornelius <cornelius.h...@gmail.com>
>
> >>>>>> 我使用外部的 Javascript 來做 tidy
> >>>>>>> 因為 vim 本身的 indentation 有其限制
>
> >>>>>>> 先用 cpan 裝 Javascript::Beautifier
>
> >>>>>>> 我有一段 script:
>
> >>>>>>> -~ % cat ~/bin/js_beautifier
>
> >>>>>>> #!/usr/bin/env perl
> >>>>>>> use JavaScript::Beautifier qw/js_beautify/;
> >>>>>>> local $/;
> >>>>>>> $js_source_code = <STDIN>;
> >>>>>>> my $pretty_js = js_beautify( $js_source_code, {
> >>>>>>> indent_size => 2,
> >>>>>>> indent_character => ' ',
> >>>>>>> } );
> >>>>>>> print $pretty_js;
>
> >>>>>>> 加到 .vimrc:
>
> >>>>>>> 704 fun! s:js_rc()
> >>>>>>> 705 abbr func function
> >>>>>>> 706 setlocal sw=2
> >>>>>>> 707 setlocal equalprg=/Users/c9s/bin/js_beautifier
>
> >>>>>>> au filetype javascript :cal s:js_rc()
>
> >>>>>>> 2009/12/20 Kaie (Tsung-Kai Chen) <chenk...@gmail.com>
>
> >>>>>>>> Dear all,
> >>>>>>>> 除了這個 Javascript Indentation : Indentation for Javascript (
> >>>>>>>>http://www.vim.org/scripts/script.php?script_id=1840)
> >>>>>>>> 還堪用之外,有更好用的嗎?
>
> >>>>>>>> 至於這一個 OOP javascript indentation : This indentation script for OOP
> >>>>>>>> javascript (especially for EXTJS)
> >>>>>>>>http://www.vim.org/scripts/script.php?script_id=1936
> >>>>>>>> 這一個的話,似乎更多問題。 我想應該只有對EXTJS比較有用..
>
> >>>>>>> --
> >>>>>>> Best Regards.
>
> >>>>>>> Cornelius ( Yo-An Lin )
> >>>>>>> E-mail: cornelius.h...@gmail.com
> >>>>>>>http://c9s.blogspot.com/
>
> >>>> --
> >>>> Best Regards.
>
> >>>> Cornelius ( Yo-An Lin )
> >>>> E-mail: cornelius.h...@gmail.com
> >>>>http://c9s.blogspot.com/
>
> >>> --
> >>> Best Regards.
>
> >>> Cornelius ( Yo-An Lin )
> >>> E-mail: cornelius.h...@gmail.com
> >>>http://c9s.blogspot.com/
>
> > --
> > Best Regards.
>
> > Cornelius ( Yo-An Lin )
> > E-mail: cornelius.h...@gmail.com
> >http://c9s.blogspot.com/
對了,話說如果 vim-js 的實做夠完整,那麼就可以直接使用 beautify.js 了 :p
>
> > Cornelius ( Yo-An Lin )
> > E-mail: cornelius.h...@gmail.com
> >http://c9s.blogspot.com/
對。不過通常都是 stable 才會 release 到 cpan 上。(大部分)
On Dec 21, 1:13 am, Kent Chen <chenk...@gmail.com> wrote:
> Great, support github :)
> 突然想到個問題,以Vimana為例,從cpan安裝的,應該會比github上的版本來得舊些,是吧 ?!
這個時候我只好說,如果沒辦法找到期他好用的 formater ,那只好自己 patch 了 XD
> 試用了一下這個js
> beautify,似乎無法滿足我的要求,像是底下這類的code,beautify完,append後面那些會被接成"一行"....囧..看來還不夠彈性, 沒有這類參數供彈整
> for (i = 0; i < MD_WINDOW_SIZE; i++)
> {
>
> $("#StreamContainer").append(
> '<div id="MDWindow'+i+'" class="MDW_style">'+
> '<div class="MDW_drag">'+
> '<span title="param"
> class="MDW_title">motion_c0_win_i'+i+'_name</span>'+
> '<a class="ui-dialog-titlebar-close"
> href="#"><span>X</span></a>'+
> '</div>'+
> '</div>')
> }
其實你不一定要把整個檔案重新 tidy 呀
equalprg 的好處是他可以只對一個區塊 re-tidy
如果你想要自己寫 vim script 來 re-indent 的話 (只做 indent)
可以參考 *indent-expression* 章節
其實預設的 javascript 是使用 c 的 indent 來方式,好像還堪用
indent method 的實做方式可以參考: $vimruntime/indent/perl.vim
裡面有範例。 你寫好的 indent script 放在 ~/.vim/indent/javascript.vim 就可以用了。
:-)
== current line
=i{ current block
看到上一行又想到c9s大的vim slides,inner的用法...這個贊,但我記得在 multiple/nested {} 情況下會失效, eg:func ()
{
//這邊 =i{ , OK
if()
{
{
test();////這邊 =i{ , 不OK
}
}
}
有什麼見解嗎?
2009/12/21 Kent Chen <chen...@gmail.com>看到上一行又想到c9s大的vim slides,inner的用法...這個贊,但我記得在 multiple/nested {} 情況下會失效, eg:func ()
{
//這邊 =i{ , OK
if()
{
{
test();////這邊 =i{ , 不OK
}
}
}
有什麼見解嗎?因為你在最內層按 = 所以他只會在第一層裡面 reformat
所以要從內層選到外層,你需要 v3i{ 往外選三層 {
基本上 equalprg 的作用機制是 將一段 region pipe 給你的 script ,再從 script 接 stdout ,
stderr 回來
所以你的 script 必須輸出到 stdout, stderr ,這些內容會取代原本的區塊。
除了設置像 perltidy 之外,你也可設置 indent (gnu indent program) 或是 tidy ( xml
tidy ) 等工具為 equalprg
要另外住意的是,需要將他們 ouptput 的 warnings 取消,不然會很惱人。
:.!jsformater
的意思是,把目前這一行送去給 jsformater 然後接 jsformater 的內容回來取代目前行
你說的 javascript 工具是像 javascript beautify 嗎?
btw, 若常寫 javascript ,順便推一套 plugin 叫做 jslint.vim 。
On Dec 23, 10:48 pm, 闲耘(tm) <hotoo...@gmail.com> wrote:
> Javascript有一般效果不错的格式化工具叫
> jsbeautify<http://www.vim.org/scripts/script.php?script_id=2727>也是有效率问题(可能跟vim
> script本身的效率有关)。
>
> 请问一个问题:我为 vim 设置了外部 equalprg 工具,想请问 vim 是如何向这个外部工具传递信息的?
> 我写了个简单的测试程序,比如叫jsformater,简单的将接收到的多个参数每行一个输出,但是在 vim 中
> :set equalprg=jsformater 后,== 快捷键并不能做任何期望的操作,而是直接将当前行删除了,说明没有接收到任何参数,
> 发现命令模式的历史记录中,使用的命令是 :.!jsformater 。
> 请多指教。
>
> 另外我最近在用c++写一个javascript工具,用来对javascript代码进行词法、语法、语义分析,目前大致完成了词法分析部分。
>
> --
> 闲耘(tm) (@hotoo, xianyun.org)
>
> 2009/12/21 Kent Chen <chenk...@gmail.com>
>
>
>
>
>
> > 2009/12/21 Cornelius <cornelius.h...@gmail.com>
>
> >> 2009/12/21 Kent Chen <chenk...@gmail.com>
> >> E-mail: cornelius.h...@gmail.com
> >>http://c9s.blogspot.com/