5 ms·
This is really interesting. But wouldn't it work better as an Emacs or Vim plugin? It ought to work at the editor level, and would be really easy to make this
by JacksonGariety 12y ago
This is really interesting. But wouldn't it work better as an Emacs or Vim plugin?
It ought to work at the editor level, and would be really easy to make this work with Emacs with a little lisp magic and the Emacs js interpreter.
- phlyingpenguin 12y agoI can't speak to emacs, but vim has no problems with a program like this operating on the BufWritePre event. I use whitespace trimming and js-beautify that way already. This may or may not do a better job than js-beautify for it. I have it set as the equalprg so that vim will use beautify to format code on = when a visual selection is made. From my vimrc: > au FileType javascript setlocal equalprg=/usr/local/share/npm/bin/js-beautify\ -f\ -\ -q\ -t\ -j\ -w\ 140\ --good-stuff\ -b\ \"end-expand\" edit: The same event (BufWritePre) is what I've got set for go fmt too. That IS a plugin, but it makes no significant difference as compared to js-beautify.
- awda 12y agoThis is an equally valid criticism of `gofmt`. I think the rational is two-fold: you aren't tied to any one editor to use the formatting tool, and the authors of the fmt tool may not know enough (or care to know enough) about the editor to integrate it.
- saraid216 12y agoUNIX philosophy. Do one thing right. Editor integration is a second thing.
- sinkasapa 12y agoSome of the go developers are also acme users so they get both. The Plan9 philosophy, I guess.
- ryanlbrown 12y agoIt's nice that the go distribution comes with editor integrations though. It would be nice if there was a similar standard toolset for js that you could get up and running with if you were new to it.
- brnstz 12y agoA command line utility can form the basis of an editor plugin. Go/vim users typically run `gofmt` on save, and the reformatted code appears within the editor.
- Jare 12y agoIt works better as a standalone tool because then everyone can use it.
- rxaxm 12y agoemacs js2-mode uses recursive-descent parser to build up js ast with full recognition of Ecma-262 language standard and exposes ast for use in other pugins https://github.com/mooz/js2-mode/blob/master/js2-mode.el https://github.com/mooz/js2-mode/blob/master/js2-mode.el 11k amazing loc
- JacksonGariety 12y agoUsing it right now. One of my favorite things installed on my computer.
- hughw 12y agoYes. Many thanks to Steve Yegge. js2-mode is why I use emacs.
- chongli 12y agoPlugin? Both Emacs and Vim make it trivial to round-trip a buffer through an external command.