有推薦的 javascript indent (incuding jQuery support) 嗎 ?

112 views
Skip to first unread message

Kaie (Tsung-Kai Chen)

unread,
Dec 20, 2009, 4:42:54 AM12/20/09
to Vim-Taiwan
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比較有用..


Cornelius

unread,
Dec 20, 2009, 4:51:28 AM12/20/09
to vim-t...@googlegroups.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) <chen...@gmail.com>



--
Best Regards.

Cornelius ( Yo-An Lin )
E-mail: corneli...@gmail.com
http://c9s.blogspot.com/

Kent Chen

unread,
Dec 20, 2009, 5:00:35 AM12/20/09
to vim-t...@googlegroups.com
Got it, 來試試 Javascript::Beautifier 效果如何..

2009/12/20 Cornelius <corneli...@gmail.com>

Kent Chen

unread,
Dec 20, 2009, 5:11:12 AM12/20/09
to vim-t...@googlegroups.com
google 了一下,c9s大推薦的這個 http://search.cpan.org/dist/JavaScript-Beautifier/lib/JavaScript/Beautifier.pm

裡頭提到
This module is mostly a Perl-rewrite of 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 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 <chen...@gmail.com>

Cornelius

unread,
Dec 20, 2009, 5:22:39 AM12/20/09
to vim-t...@googlegroups.com
看來不錯耶,不過希望 vim script 的效能夠好 :p

這樣好處就是沒有什麼 dependency. :p

2009/12/20 Kent Chen <chen...@gmail.com>

Cornelius

unread,
Dec 20, 2009, 5:33:18 AM12/20/09
to vim-t...@googlegroups.com
剛剛看到 plugin 的上面寫到:

"I just translated it into vimscript, it works at a low performance:) "

所以看來還是有一點效能的問題。


2009/12/20 Cornelius <corneli...@gmail.com>

Kent Chen

unread,
Dec 20, 2009, 7:52:55 AM12/20/09
to vim-t...@googlegroups.com
看來,容易手癢的c9s大,會再finetune一版,整進vimana ..XD


---
2009/12/20 Cornelius <corneli...@gmail.com>

Cornelius

unread,
Dec 20, 2009, 8:19:58 AM12/20/09
to vim-t...@googlegroups.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 <chen...@gmail.com>

Kent Chen

unread,
Dec 20, 2009, 12:13:10 PM12/20/09
to vim-t...@googlegroups.com
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 <corneli...@gmail.com>

c9s

unread,
Dec 20, 2009, 1:30:33 PM12/20/09
to Vim-Taiwan

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/

c9s

unread,
Dec 20, 2009, 10:38:38 PM12/20/09
to Vim-Taiwan
對了,話說如果 vim-js 的實做夠完整,那麼就可以直接使用 beautify.js 了 :p

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/

闲耘™

unread,
Dec 20, 2009, 11:13:31 PM12/20/09
to vim-t...@googlegroups.com
请问这个“实做”是什么意思?

--
闲耘™ (@hotoo, xianyun.org)
Sent from Hangzhou, 33, China


2009/12/21 c9s <corneli...@gmail.com>
對了,話說如果 vim-js 的實做夠完整,那麼就可以直接使用 beautify.js 了 :p

>

> > Cornelius ( Yo-An Lin )

Cornelius

unread,
Dec 20, 2009, 11:37:18 PM12/20/09
to vim-t...@googlegroups.com
Hi hotoo,

實做是 "implementation" 的意思
--
Best Regards.


Cornelius ( Yo-An Lin )

Kent Chen

unread,
Dec 20, 2009, 11:49:59 PM12/20/09
to vim-t...@googlegroups.com
沒錯,c9s大加油,rhino就可以丟了...XD,記得那也得patch vim...


2009/12/21 c9s <corneli...@gmail.com>

Kent Chen

unread,
Dec 20, 2009, 11:58:29 PM12/20/09
to vim-t...@googlegroups.com

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

嗯,目前我也是這麼做,只 format V選起來的區域
如果你想要自己寫 vim script 來 re-indent 的話 (只做 indent)

可以參考 *indent-expression* 章節

其實預設的 javascript 是使用 c 的 indent 來方式,好像還堪用
還ok,只有對oop的javascript語法行不通

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
        }
   }
}
有什麼見解嗎?

Cornelius

unread,
Dec 21, 2009, 12:24:09 AM12/21/09
to vim-t...@googlegroups.com


2009/12/21 Kent Chen <chen...@gmail.com>

看到上一行又想到c9s大的vim slides,inner的用法...這個贊,但我記得在 multiple/nested {} 情況下會失效, eg:
func ()
{
      //這邊 =i{   , OK
   if()
   {
      {
         test();//
//這邊 =i{   , 不OK
        }
   }
}
有什麼見解嗎?

因為你在最內層按 = 所以他只會在第一層裡面 reformat 

所以要從內層選到外層,你需要 v3i{    往外選三層 { 
E-mail: corneli...@gmail.com
http://c9s.blogspot.com/

Kent Chen

unread,
Dec 21, 2009, 12:34:18 AM12/21/09
to vim-t...@googlegroups.com

2009/12/21 Cornelius <corneli...@gmail.com>



2009/12/21 Kent Chen <chen...@gmail.com>

看到上一行又想到c9s大的vim slides,inner的用法...這個贊,但我記得在 multiple/nested {} 情況下會失效, eg:
func ()
{
      //這邊 =i{   , OK
   if()
   {
      {
         test();//
//這邊 =i{   , 不OK
        }
   }
}
有什麼見解嗎?

因為你在最內層按 = 所以他只會在第一層裡面 reformat 

所以要從內層選到外層,你需要 v3i{    往外選三層 { 
習得.... 都忘了有這麼多種組合了!

闲耘(tm)

unread,
Dec 23, 2009, 9:48:00 AM12/23/09
to vim-t...@googlegroups.com
Javascript有一般效果不错的格式化工具叫 jsbeautify 也是有效率问题(可能跟vim script本身的效率有关)。

请问一个问题:我为 vim 设置了外部 equalprg 工具,想请问 vim 是如何向这个外部工具传递信息的?
我写了个简单的测试程序,比如叫jsformater,简单的将接收到的多个参数每行一个输出,但是在 vim 中
:set equalprg=jsformater 后,== 快捷键并不能做任何期望的操作,而是直接将当前行删除了,说明没有接收到任何参数,
发现命令模式的历史记录中,使用的命令是 :.!jsformater 。
请多指教。

另外我最近在用c++写一个javascript工具,用来对javascript代码进行词法、语法、语义分析,目前大致完成了词法分析部分。

--
闲耘™ (@hotoo, xianyun.org)



2009/12/21 Kent Chen <chen...@gmail.com>

c9s

unread,
Dec 23, 2009, 7:40:25 PM12/23/09
to Vim-Taiwan
Hi,

基本上 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/

Kent Chen

unread,
Dec 23, 2009, 8:32:23 PM12/23/09
to vim-t...@googlegroups.com
我用的是javaScriptLint.vim,沒有比較過它和 jslint.vim 以及jsl.vim的差別...

我以這個 pclint 為基礎,弄了一個 clint.vim ,使用的lint command是 "PC-lint for C/C++ (NT) Vers. 8.00x"  跑在linux-wine上,有推薦好用的c lint程式嗎


--
Let's Blogging...
http://chenkaie.blogspot.com
Sent from 三重市, 台北縣, 台湾

2009/12/24 c9s <corneli...@gmail.com>

闲耘(tm)

unread,
Dec 23, 2009, 8:36:48 PM12/23/09
to vim-taiwan
会超越 js beautify : )

这个工具会对 js 代码进行精确的词法和语法分析,并尽可能做一些语义分析。
分析之后则可以做包括格式化,压缩,适量的混淆,和大纲视图(增强TagList
对 js 的支持) 等许多事情了。

项目地址是 jstidy.sf.net 欢迎有兴趣的朋友也来参加。

我做这个工具主要是因为对目前大多数js工具都是使用java开发,甚至需要
最新的jre版本从可以运行不满。

目前已经在用javascriptLint.vim

--
闲耘™ (@hotoo, xianyun.org)



2009/12/24 c9s <corneli...@gmail.com>
Reply all
Reply to author
Forward
0 new messages