all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* How to get decent java-script support
@ 2015-06-25  1:23 Rasmus
  2015-06-25  9:25 ` Dmitry Gutov
  0 siblings, 1 reply; 9+ messages in thread
From: Rasmus @ 2015-06-25  1:23 UTC (permalink / raw)
  To: help-gnu-emacs

Hi,

I have been working with d3.js.  I'd prefer to retain the same workflow as
with other programming languages, namely having source-code and REPL in
Emacs.

I have tried js and js2 mode.  However, I don't like indentation of these
two modes, including when js2-bounce-indent-p is non-nil.  I cannot get
indentation to respect the "chain-syntax" of d3 (supposedly also used by
jQuery).  Also, it inserts lots of newlines e.g. for "{}" pairs, which is
annoying for inline functions (e.g. in .map arguments).  I tried to turn
off electricity, but that didn't make it stop with the excessive newlines.

Some question on JS in Emacs:

First, is it possible to get js(2) mode to allow chain-style indentation
and be less, or more, clever about braces and semicolons?

Second, can one somehow connect hook into some sort of documentation
system with java-script?  At least for standard ECMAScript?  Like
"help(fun)" in Python and C-h for Emacs Lisp etc etc.  At this point, I
could even live with it "just" opening Mozilla dev. pages in eww or
Firefox.

Third, related to two, can eldoc somehow be taught to work with JS?

Fourth, REPL.  I tried skewer-mode.  It was OK.  But not great compared to
the REPL in Firefox.  For instance, auto-completion (M-TAB) did not work
at all.  It seems it has some completion support with auto-complete.
Really, I just want M-tab completion...

I would appreciate any hints.

Thanks,
Rasmus


PS: Other modes I tried.

Web-Mode: Indentation seems to work perfectly, and the fact that it can
handle JS, HTML and CSS in one buffer is awesome, but it's too opinionated
in weird areas.  Coloring does not following the normal color names, key
movements do not respect {sub,super}-word-mode, and it uses "/* ⋯ */"
commenting instead of "// ⋯", making comment-dwim not working....

I tried something called tern since it supposedly offer completion for
company.  I don't remember why I dropped it...

I haven't tried js-comint or MozRepl.  Maybe they provide better REPL
experience?

-- 
A clever person solves a problem. A wise person avoids it




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: How to get decent java-script support
  2015-06-25  1:23 How to get decent java-script support Rasmus
@ 2015-06-25  9:25 ` Dmitry Gutov
  2015-06-25 15:03   ` Rasmus
  0 siblings, 1 reply; 9+ messages in thread
From: Dmitry Gutov @ 2015-06-25  9:25 UTC (permalink / raw)
  To: Rasmus, help-gnu-emacs

On 06/25/2015 04:23 AM, Rasmus wrote:
> Also, it inserts lots of newlines e.g. for "{}" pairs, which is
> annoying for inline functions (e.g. in .map arguments).  I tried to turn
> off electricity, but that didn't make it stop with the excessive newlines.

This sounds like you're turned on electric-layout-mode, somewhere in 
your config.

> Some question on JS in Emacs:
>
> First, is it possible to get js(2) mode to allow chain-style indentation
> and be less, or more, clever about braces and semicolons?

There are some vars you can customize, but probably not enough.

> Second, can one somehow connect hook into some sort of documentation
> system with java-script?  At least for standard ECMAScript?  Like
> "help(fun)" in Python and C-h for Emacs Lisp etc etc.  At this point, I
> could even live with it "just" opening Mozilla dev. pages in eww or
> Firefox.

Tern supports completion and documentation lookup.

> Third, related to two, can eldoc somehow be taught to work with JS?

That may be a good feature request for tern-mode.

> I tried something called tern since it supposedly offer completion for
> company.  I don't remember why I dropped it...

Try it again, maybe.



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: How to get decent java-script support
  2015-06-25  9:25 ` Dmitry Gutov
@ 2015-06-25 15:03   ` Rasmus
  2015-06-25 15:14     ` Dmitry Gutov
  0 siblings, 1 reply; 9+ messages in thread
From: Rasmus @ 2015-06-25 15:03 UTC (permalink / raw)
  To: dgutov; +Cc: help-gnu-emacs

Hi Dmitry,

Thanks for your pointers.

Dmitry Gutov <dgutov@yandex.ru> writes:

> On 06/25/2015 04:23 AM, Rasmus wrote:
>> Also, it inserts lots of newlines e.g. for "{}" pairs, which is
>> annoying for inline functions (e.g. in .map arguments).  I tried to turn
>> off electricity, but that didn't make it stop with the excessive newlines.
>
> This sounds like you're turned on electric-layout-mode, somewhere in
> your config.

Spot on.  Thanks.

>> Some question on JS in Emacs:
>>
>> First, is it possible to get js(2) mode to allow chain-style indentation
>> and be less, or more, clever about braces and semicolons?
>
> There are some vars you can customize, but probably not enough.

Would you mind if I open a bug on that on github?  I don't know if it's a
d3 thing or something that is generally useful for JS.

It's can get pretty nasty so I don't know if rules can be written.
E.g.

var myvar = d3.select("#whatever")
              .somefun(arg)
              .call(d3.something_else(arg)
                      .anotherfun(arg));

You'd not actually write code like that of course (the something_else call
would be factored out to a separate var), so for the majority of code it
would be enough to just align on the first dot.

>> Second, can one somehow connect hook into some sort of documentation
>> system with java-script?  At least for standard ECMAScript?  Like
>> "help(fun)" in Python and C-h for Emacs Lisp etc etc.  At this point, I
>> could even live with it "just" opening Mozilla dev. pages in eww or
>> Firefox.
>
> Tern supports completion and documentation lookup.

OK, I will have to give it another shot.

>> Third, related to two, can eldoc somehow be taught to work with JS?
>
> That may be a good feature request for tern-mode.

OK.  I will open a bug.

Rasmus

-- 
In theory, practice and theory are the same. In practice they are not








^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: How to get decent java-script support
  2015-06-25 15:03   ` Rasmus
@ 2015-06-25 15:14     ` Dmitry Gutov
  2015-06-25 18:27       ` Rasmus
  0 siblings, 1 reply; 9+ messages in thread
From: Dmitry Gutov @ 2015-06-25 15:14 UTC (permalink / raw)
  To: Rasmus; +Cc: help-gnu-emacs

On 06/25/2015 06:03 PM, Rasmus wrote:

> Would you mind if I open a bug on that on github?  I don't know if it's a
> d3 thing or something that is generally useful for JS.

If you want to open a bug, do it for js-mode, via M-x report-emacs-bug.

js2-mode intends to reuse its indentation engine.

> It's can get pretty nasty so I don't know if rules can be written.
> E.g.
>
> var myvar = d3.select("#whatever")
>                .somefun(arg)
>                .call(d3.something_else(arg)
>                        .anotherfun(arg));
>
> You'd not actually write code like that of course (the something_else call
> would be factored out to a separate var), so for the majority of code it
> would be enough to just align on the first dot.

Yes, that could be non-trivial. I haven't looked into it much, though.



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: How to get decent java-script support
  2015-06-25 15:14     ` Dmitry Gutov
@ 2015-06-25 18:27       ` Rasmus
  2015-06-25 18:34         ` Dmitry Gutov
  2015-06-25 23:49         ` Rasmus
  0 siblings, 2 replies; 9+ messages in thread
From: Rasmus @ 2015-06-25 18:27 UTC (permalink / raw)
  To: dgutov; +Cc: help-gnu-emacs

Dmitry Gutov <dgutov@yandex.ru> writes:

> On 06/25/2015 06:03 PM, Rasmus wrote:
>
>> Would you mind if I open a bug on that on github?  I don't know if it's a
>> d3 thing or something that is generally useful for JS.
>
> If you want to open a bug, do it for js-mode, via M-x report-emacs-bug.
>
> js2-mode intends to reuse its indentation engine.

Done.

Let me tap on your knowledge once more.  I still get undesirable
electricity on ";" even when electric layout is off.

Consider this example

plot.axes.xAxis = d3.svg.axis()
                    .scale(plot.axes.xScale)
                    .orient('bottom')

When I insert ";" after the .orient call I get 

plot.axes.xAxis = d3.svg.axis()
                    .scale(plot.axes.xScale)
    .orient('bottom');

Can I keep the indent in general, but not call it on ";"?

Thanks,
Rasmus

-- 
When in doubt, do it!



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: How to get decent java-script support
  2015-06-25 18:27       ` Rasmus
@ 2015-06-25 18:34         ` Dmitry Gutov
  2015-06-25 19:12           ` John Mastro
  2015-06-25 21:40           ` Rasmus
  2015-06-25 23:49         ` Rasmus
  1 sibling, 2 replies; 9+ messages in thread
From: Dmitry Gutov @ 2015-06-25 18:34 UTC (permalink / raw)
  To: Rasmus; +Cc: help-gnu-emacs

On 06/25/2015 09:27 PM, Rasmus wrote:

>> If you want to open a bug, do it for js-mode, via M-x report-emacs-bug.
>>
>> js2-mode intends to reuse its indentation engine.
>
> Done.

Thanks. I'm rather busy, so here's hoping somebody else will get to it soon.

> Can I keep the indent in general, but not call it on ";"?

Disable electric-indent-mode? Or electric-indent-local-mode, if your 
Emacs is recent enough.



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: How to get decent java-script support
  2015-06-25 18:34         ` Dmitry Gutov
@ 2015-06-25 19:12           ` John Mastro
  2015-06-25 21:40           ` Rasmus
  1 sibling, 0 replies; 9+ messages in thread
From: John Mastro @ 2015-06-25 19:12 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: help-gnu-emacs@gnu.org, Rasmus

>> Can I keep the indent in general, but not call it on ";"?
>
> Disable electric-indent-mode? Or electric-indent-local-mode, if your Emacs is recent enough.

Something like this should also work, if you do want electric indent on
other chars:

(add-hook 'js2-mode-hook
          (lambda ()
            (setq-local electric-indent-chars
                        (remq ?\; electric-indent-chars))))

See `C-h v electric-indent-chars' for what else is in there.

-- 
john



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: How to get decent java-script support
  2015-06-25 18:34         ` Dmitry Gutov
  2015-06-25 19:12           ` John Mastro
@ 2015-06-25 21:40           ` Rasmus
  1 sibling, 0 replies; 9+ messages in thread
From: Rasmus @ 2015-06-25 21:40 UTC (permalink / raw)
  To: help-gnu-emacs

Thanks Dimitry & John!

Dmitry Gutov <dgutov@yandex.ru> writes:

> Thanks. I'm rather busy, so here's hoping somebody else will get to it soon.

Me too (busy and hoping, that is).

I'm also having weird issues with company and python, and surrounding text
being deleted on completion, but probably it's a company-jedi issue.  I
haven't had time to debug it properly.

>> Can I keep the indent in general, but not call it on ";"?
>
> Disable electric-indent-mode? Or electric-indent-local-mode, if your
> Emacs is recent enough.

Right.  It's awesome that it relies on default settings and modes.  I hope
we'll be able to move Org in this direction as well over time.

John Mastro <john.b.mastro@gmail.com> writes:

> Something like this should also work, if you do want electric indent on
> other chars:
>
> (add-hook 'js2-mode-hook
>           (lambda ()
>             (setq-local electric-indent-chars
>                         (remq ?\; electric-indent-chars))))

That's a great solution, John!  Thanks a lot for sharing.

Rasmus

-- 
Lasciate ogni speranza, voi che leggete questo.




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: How to get decent java-script support
  2015-06-25 18:27       ` Rasmus
  2015-06-25 18:34         ` Dmitry Gutov
@ 2015-06-25 23:49         ` Rasmus
  1 sibling, 0 replies; 9+ messages in thread
From: Rasmus @ 2015-06-25 23:49 UTC (permalink / raw)
  To: dgutov; +Cc: help-gnu-emacs

Rasmus <rasmus@gmx.us> writes:

> Dmitry Gutov <dgutov@yandex.ru> writes:
>
>> On 06/25/2015 06:03 PM, Rasmus wrote:
>>
>>> Would you mind if I open a bug on that on github?  I don't know if it's a
>>> d3 thing or something that is generally useful for JS.
>>
>> If you want to open a bug, do it for js-mode, via M-x report-emacs-bug.
>>
>> js2-mode intends to reuse its indentation engine.
>
> Done.
>
> Let me tap on your knowledge once more.  I still get undesirable
> electricity on ";" even when electric layout is off.
>
> Consider this example
>
> plot.axes.xAxis = d3.svg.axis()
>                     .scale(plot.axes.xScale)
>                     .orient('bottom')
>
> When I insert ";" after the .orient call I get 
>
> plot.axes.xAxis = d3.svg.axis()
>                     .scale(plot.axes.xScale)
>     .orient('bottom');
>
> Can I keep the indent in general, but not call it on ";"?

Ah: electric-indent-chars.

Though in general a fan of electricity, I'm find that a lot of the
electricity mode gets in the way...

Rasmus

-- 
May the Force be with you



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2015-06-25 23:49 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-25  1:23 How to get decent java-script support Rasmus
2015-06-25  9:25 ` Dmitry Gutov
2015-06-25 15:03   ` Rasmus
2015-06-25 15:14     ` Dmitry Gutov
2015-06-25 18:27       ` Rasmus
2015-06-25 18:34         ` Dmitry Gutov
2015-06-25 19:12           ` John Mastro
2015-06-25 21:40           ` Rasmus
2015-06-25 23:49         ` Rasmus

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.