reddit / emacs
js-mode, js2-mode, javascript-mode... which one?
offby2 · 2022-05-21 15:03
I have never quite understood which of these modes I should use when I open a javascript file. Is there one that is the "right" one to use, and if so... what are the other ones for?
by_wicker · 2022-05-21 16:52
Seems very appropriate that Javascript and variants give us a bewildering array of options without a clear choice, since that's what the whole js/web dev world in a nutshell.
There have to be many people like me who dabble in that world to produce UIs for the meat of our work, and it's pretty frustrating just trying to work out what tools we should use.
FWIW, I'm using `web-mode` (not on your list!) for js/ts/jsx/tsx and it seems to work OK, but I have no idea if it's the best choice.
[deleted] · 2022-05-21 18:14
[deleted]
nv-elisp · 2022-05-21 19:22
Your criticism is often levied against Lisps.
http://www.winestockwebdesign.com/Essays/Lisp_Curse.html
Phil-Hudson · 2022-05-21 19:28
And then there's `json-mode`...
akirakom · 2022-05-21 20:47
While web-mode can be used for almost everything (it can even handle mdx), js-mode and typescript-mode are viable options nowadays, thanks to lsp and tree-sitter.
My recommendation is as follows: When you edit jsx, you should use js-jsx-mode. When you edit json, use json-mode. Otherwise, use js-mode. All of them are based on js-mode. For ts and tsx, use typescript-mode.
TheFrenchPoulp · 2022-05-21 21:08
A comment taken from my configuration so that I can have a look again next time I forget:
> There might be confusion between `js-mode`, `js2-mode` and `js2-minor-mode`. All three are built-in JavaScript modes. The former is the original major mode to edit JavaScript files. The two latters are based on `js-mode`, one major mode with various improvements with regards to syntax highlighting amongst other things and one minor mode for earlier Emacs versions that might still be using `js-mode` as a major mode but willing to take advantage of the AST parsing implementation from `js2-mode` as a minor mode.
Feel free to correct/expand as this is basically my understanding at the time of writing my TypeScript and TSX configurations (which only use `js2-mode` and `typescript-mode`)
redguardtoo · 2022-05-22 05:44
`js2-mode` provides a parser of javascript programming language.It can be used to build useful features. See http://blog.binchen.org/posts/use-js2-mode-to-print-json-path.html
[deleted] · 2022-05-22 06:55
[deleted]
wasamasa · 2022-05-22 08:22
Well, not really. The JS world has the benefit of a large community actually cooperating with each other and can therefore afford working on several solutions at once. The Lisp world doesn't have that luxury. It's mostly lone-wolf efforts with no backing.
nv-elisp · 2022-05-22 08:41
Note I said the criticism is levied against Lisp.
> ...a bewildering array of options without a clear choice
> [For novices] it's pretty frustrating just trying to work out what tools we should use.
I'm not speculating about the causes.
It's also interesting how you frame things. There are certainly more people programming in JS, but that doesn't mean they're a 'community' any more than you and I are part of the 'elisp community'. It's odd to try and contrast two programming languages in terms of what "luxuries" their "communities" can "afford". Seems arbitrary.
pivo · 2022-05-22 13:01
Just fyi, the word you’re looking for is “leveled” not “levied”
djrdjrdjrdjrdjr · 2022-05-22 13:32
I’ve been using tsx-mode for a couple of weeks and finding it pretty good so far
https://github.com/orzechowskid/tsx-mode.el
nv-elisp · 2022-05-22 15:26
No. I was looking for "levied". Past tense of "levy".
https://www.btb.termiumplus.gc.ca/tpv2guides/guides/wrtps/index-eng.html?lang=eng&lettr=indx_catlog_l&page=9rQFx348CyzU.html
holgerschurig · 2022-05-25 10:51
Wait, until you want to know which buildin IRC client you want to use: erc, rcirc, circe?
Or maybe between e-mail systems. Notmuch, Mu4e, GNUS, Wanderlust ?
vidjuheffex · 2022-06-17 01:24
i just use js-mode with lsp-mode on.
Maybe someone can clarify for me, but ever since lsp-mode I don't see what js2-mode and the others bring to the table.