unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Commenting out some JSX code section with Emacs 27 js-mode
@ 2020-10-02 19:07 Christian Jauvin
  2020-10-02 20:34 ` Stefan Monnier
  0 siblings, 1 reply; 4+ messages in thread
From: Christian Jauvin @ 2020-10-02 19:07 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 845 bytes --]

Hi everyone,

When I comment out (`M-x comment-dwim`) some section of JSX code with the
new js-mode in Emacs 27, it gives:

// <Grid rows={rows} columns={columns}>
//   <Table />
//   <TableHeaderRow />
// </Grid>

Is there any way to make js-mode behave like it does with rjsx-mode:

{/* <Grid rows={rows} columns={columns}> */}
{/*   <Table /> */}
{/*   <TableHeaderRow /> */}
{/* </Grid> */}

Supposing that this is not currently possible, and that js-mode is really
the way to go forward for JS/JSX code (from the older rjsx-mode and
js2-mode, as I vaguely understand), where could I begin to study the code
and possibly suggest a pull request to make it work? I tried to find a few
tutorials dedicated to programming modes but it's not obvious how to adapt
it to this particular problem.

Any help or advice would be appreciate,

Christian

[-- Attachment #2: Type: text/html, Size: 1063 bytes --]

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

* Re: Commenting out some JSX code section with Emacs 27 js-mode
  2020-10-02 19:07 Commenting out some JSX code section with Emacs 27 js-mode Christian Jauvin
@ 2020-10-02 20:34 ` Stefan Monnier
  2020-10-02 21:01   ` Christian Jauvin
  0 siblings, 1 reply; 4+ messages in thread
From: Stefan Monnier @ 2020-10-02 20:34 UTC (permalink / raw)
  To: Christian Jauvin; +Cc: emacs-devel

> Is there any way to make js-mode behave like it does with rjsx-mode:
>
> {/* <Grid rows={rows} columns={columns}> */}
> {/*   <Table /> */}
> {/*   <TableHeaderRow /> */}
> {/* </Grid> */}

(add-hook 'js-mode-hook
          (lambda ()
            (setq-local comment-start "{/* ")
            (setq-local comment-end   " */}")))


-- Stefan




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

* Re: Commenting out some JSX code section with Emacs 27 js-mode
  2020-10-02 20:34 ` Stefan Monnier
@ 2020-10-02 21:01   ` Christian Jauvin
  2020-10-07 10:42     ` Stephen Leake
  0 siblings, 1 reply; 4+ messages in thread
From: Christian Jauvin @ 2020-10-02 21:01 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 568 bytes --]

>
> (add-hook 'js-mode-hook
>           (lambda ()
>             (setq-local comment-start "{/* ")
>             (setq-local comment-end   " */}")))
>

It now works for JSX, but breaks on regular JS code (inside the same .jsx
file):

const [open, setOpen] = React.useState(false);
const [options, setOptions] = React.useState([]);

becomes:

{/* const [open, setOpen] = React.useState(false); */}
{/* const [options, setOptions] = React.useState([]); */}

Would there be a way for the comment function to know whether it is in a
JSX block or not, and act accordingly?

[-- Attachment #2: Type: text/html, Size: 984 bytes --]

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

* Re: Commenting out some JSX code section with Emacs 27 js-mode
  2020-10-02 21:01   ` Christian Jauvin
@ 2020-10-07 10:42     ` Stephen Leake
  0 siblings, 0 replies; 4+ messages in thread
From: Stephen Leake @ 2020-10-07 10:42 UTC (permalink / raw)
  To: Christian Jauvin; +Cc: Stefan Monnier, emacs-devel

Christian Jauvin <cjauvin@gmail.com> writes:

>>
>> (add-hook 'js-mode-hook
>>           (lambda ()
>>             (setq-local comment-start "{/* ")
>>             (setq-local comment-end   " */}")))
>>
>
> It now works for JSX, but breaks on regular JS code (inside the same .jsx
> file):

You need to change js-mode to use the ELPA package mmm-mode (multi-major-mode).


-- 
-- Stephe



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

end of thread, other threads:[~2020-10-07 10:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-02 19:07 Commenting out some JSX code section with Emacs 27 js-mode Christian Jauvin
2020-10-02 20:34 ` Stefan Monnier
2020-10-02 21:01   ` Christian Jauvin
2020-10-07 10:42     ` Stephen Leake

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).