Hacker News new | past | comments | ask | show | jobs | submit login

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.




This 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.


It'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.


UNIX philosophy. Do one thing right. Editor integration is a second thing.


Some of the go developers are also acme users so they get both. The Plan9 philosophy, I guess.


I 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.


emacs 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

11k amazing loc


Using it right now.

One of my favorite things installed on my computer.


Yes. Many thanks to Steve Yegge. js2-mode is why I use emacs.


Plugin? Both Emacs and Vim make it trivial to round-trip a buffer through an external command.


A 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.


It works better as a standalone tool because then everyone can use it.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: