My favorites | Sign in
Project Logo
                
Search
for
Updated Mar 30, 2008 by steve.yegge
Labels: Featured, Phase-Requirements
Discussion  

Discussion, bug reports, feature requests

Introduction

Please add your comments and feedback here!


Comment by oleg.pavliv, Mar 31, 2008

I got the following error "File mode specification error: (invalid-function (js2-mode))" when trying to open a js file. If I type M-x find-function js2-mode it finds it correctly. What can be wrong in my installation?

Comment by ted.zlatanov, Mar 31, 2008

Great code, it's nice to have such a good tool available. It would be nice if the installation explained how to make it work with Javascript embedded in HTML through mmm mode. Also, an auto-update function would be nice to let the user know a newer release is available.

Comment by jwinter, Mar 31, 2008

Oleg, I was getting the same error until I saw the comments on the Installation page.

Use:

(add-to-list 'auto-mode-alist '("\\.js$" . js2-mode))

instead of:

(add-to-list 'auto-mode-alist '("\\.js$" js2-mode))
Comment by steve.yegge, Mar 31, 2008

Oops, I'll update the instructions - thanks.

Unfortunately it does NOT work with mmm-mode at this time. It's going to be a fair amount of work (and I'm reasonably familiar with mmm-mode's internals). The problem is that each buffer can only have one parse tree, but mmm-mode calls you separately for each region. So it's going to require a bunch of hacks and workarounds.

I'm very interested in getting this working, however, so I'll keep trying.

Comment by steve.yegge, Mar 31, 2008

I like the idea of the auto-update function. I'm asking the Google Code guys if there's a programmatic (e.g. web services) interface I can query.

Comment by jjfoe...@earthlink.net, Mar 31, 2008

I have tried all the javascript modes out there and this one looks like a dream come true. Thanks Steve!

Lower case letters in the C-c keymap are supposed to be reserved for the user in Emacs.

To the people asking about mmm, your time would be better spent getting this to work with mumamo. Mumamo is much better than mmm.

Comment by titus.byronicus, Mar 31, 2008

This is really nice. Thanks Steve!

My one request is that the indentation-cycling behavior when you hit tab shouldn't add an undo entry. Or maybe each <tab> should just replace the last undo entry, if it was part of the same indent cycle. Is that possible?

Comment by sdeasey, Mar 31, 2008

Regarding auto-updates, please use Tom Tromey's ELPA:

http://tromey.com/elpa/index.html
Comment by ojarjur, Mar 31, 2008

If you are using a continuation-based parser, then you should be able to do a simple form of incremental parsing by saving the current parsing continuation into a buffer at regular intervals.

So, for instance, if you save N parsing continuations for a file and a change is made at the beginning of the file, then the whole thing gets re-parsed. However, if a change is made towards the end of the file, then only the last 1/Nth gets re-parsed.

This is basically just ripping off the way that back-tracking debuggers work.

Comment by steve.yegge, Apr 01, 2008

jjfoe: it's true that Emacs documentation says letters in the C-c keymap are normally reserved for users, but in practice this rule is rarely followed, even in the standard Emacs distribution. Examples of built-in modes and packages that bind \C-c letter sequences include sgml-mode, picture-mode, tex-mode, comint, cmuscheme, term, shell, wdired, diff-mode, cc-mode, python-mode, cperl-mode, antlr-mode and sh-script mode.

sdeasey: thanks for the link to ELPA - I'll get it integrated.

Several folks have pointed me at mumamo, so I need to investigate it asap.

ojarjur: Emacs does not have continuations! I made this clear in my blog entry. With continuations, your comments become trivial.

titus: I'll see about disabling Undo around indentation-cycling.

Comment by zhzhqiang, Apr 01, 2008

when i compile the file,the emacs warns "js2.el:864:7:Warning: reference to free variable `emacs22'" and it seems this script can not work on my emacs since when i try to enter this mode emacs always complain :"execute-extended-command: Symbol's value as variable is void: emacs22"

My Emacs version info is :GNU Emacs 22.1.1 (i486-pc-linux-gnu, GTK+ Version 2.12.3) of 2008-03-03 on raven, modified by Debian

and as you see, it runs under a debian distribute.

Comment by neilrahilly, Apr 01, 2008

Getting same warning as zhzhqiang in Aquamacs Emacs on Leopard

Comment by steve.yegge, Apr 01, 2008

Sorry all! I've uploaded a fix: js2-20080401a.el

My bad - I'll test new releases more carefully next time.

Comment by ojarjur, Apr 01, 2008

Steve: Any language with higher order functions has continuations, you just have to write your code in continuation passing style.

I'm confused by your statement that you made it clear in your blog entry that Emacs does not have continuations. The only reason I brought it up was that you said they were in your todo list.

Comment by cybcode, Apr 02, 2008

re jequery, the problem is in the following character class in the regex on line 850 of the jquery source code:

   [\\w\u0128-\uFFFF*_-]
       ^^^^^^

It's complaining about the unicode escape highlighted above.

Comment by davidgreenspan, Apr 02, 2008

Thank you for this great piece of work! A few small gripes:

With bouncing indentation, I was expecting "tab" in general to indent the current line to the most likely place (if it isn't already), and repeated tab to start cycling; that's what I'm used to from other modes. It's good feedback compared to the tab key always changing the current indentation.

Whenever I type the semicolon at the end of a line, I get an error about a missing semicolon. It seems like a strange time for that error.

The top of the buffer doesn't seem to be handled correctly. For example, pressing return in a blank buffer produces an error. If bouncing is on, the next return will indent by two spaces. Typing a function declaration on the second line of a blank document produces lots of errors.

Again, though, fantastic job, I've been wanting a better JS mode for a long time.

Comment by jjfoe...@earthlink.net, Apr 02, 2008

Hi Steve,

I think I was not clear- the policy refers to unmodified lower case letters in the C-c prefix. All the modes you mention follow the policy, as far as I can tell, from a quick search through their files. Sgml-mode does indeed include an option, disabled by default, called html-quick-keys, that causes it to bind this range of key combos.

Thanks!

Comment by steve.yegge, Apr 02, 2008

New release today to fix some of the issues brought up here.

ojarjur: sorry for the confusion. Emacs does not have continuations, so I will eventually have to implement a pseudo-continuation for a specific point in my parser, by saving all the parsing state.

cybcode: haven't fixed it yet, but hopefully will soon.

davidgreenspan:

  • you're welcome!
  • I've made a partial fix for the first gripe in the latest release. It ignores the first press of the TAB key on a given line if we're already in one of the computed indentation spots. Should help a little.
  • fixed the bug warning about missing-semi after typing a semi. Oops!
  • I can't reproduce the top-of-buffer problem at all. Can you (setq debug-on-error t) then reproduce the error and send me the backtrace?

Comment by steve.yegge, Apr 02, 2008

p.s. oh yes, and jjfoe - thanks for the clarification - fixed the default keybindings in this release.

Comment by titus.byronicus, Apr 02, 2008

Hey Steve. Thanks for putting in the indent-inhibit-undo feature, I'm really happy with it.

I'm interested in UI, so I'm curious about your decision to remove it as a default behavior and make it configurable. Did it trip people up because the behavior was unexpected?

Comment by steve.yegge, Apr 02, 2008

Yup - mostly when switching to and from buffers in other modes, which treat indentation changes as undoable.

Comment by Thomas.Mayfield, Apr 03, 2008

There seem to be an issue with parsing deeply nested functions. Loading a file with functions nested more than 14 deep (not all that outlandish), I get the error: Variable binding depth exceeds max-specpdl-size Bumping the size of max-specpdl-size up seems to clear up this issue.

Comment by slackorama, Apr 03, 2008

Err, I must be a tool or something...How do I prevent the last curly brace from getting indented when I type function "foobar() {"?

The only way it seems to bounce back to the proper level of indentation is if I put a semi-colon after it.

Comment by steve.yegge, Apr 03, 2008

Thomas - I'll bump it up to 3000 in the next release. Thanks.

slackorama -- oops! That's a bug in the latest release. I'll fix it in the next release. If you can't wait, put this in your .emacs file:

(require 'js2-mode)

(defun js2-mode-match-curly ()
  "Insert matching curly-brace."
  (interactive)
  (insert "{")
  (unless (or (not (looking-at "\\s-*$"))
              (js2-mode-inside-comment-or-string))
    (insert "\n")
    (js2-indent-line)
    (save-excursion
      (insert "\n}")
      (let ((js2-bounce-indent-flag nil))
        (js2-indent-line)))))
Comment by Deepak.Gulati, Apr 04, 2008

Hi Steve, I am running with (setq js2-use-font-lock-faces t) in my .emacs, and indeed it works like a charm. The problem begins when I open a file that is not a .js file and revert back to the buffer which had the .js file open. js2 now reverts to its default faces and doesn't respect my font-lock-faces.

I am using Aquamacs which comes pre-installed with ColorThemes?. I use CharcoalBlack? for all modes except outline-mode which has Scintilla defined as its theme. This problem begins when I open a file that triggers the outline-mode specific color theme.

Reopening the js file or toggling between fundamental-mode and js2-mode doesn't help. Turning font-lock on and off doesn't help either. I end up restarting emacs.

Btw - your default theme is a little hard to read on dark backgrounds. May be you can bundle another one for those with non-white background :) low-priority-nice-to-have?

Comment by ceesaxp, Apr 04, 2008

Imenu does not pick up bla = function() {...} function declarations. To be fair, I don't think that any other JavaScript? mode works with these either, but if a real parser is used, then that should be possible, no?

Comment by davidgreenspan, Apr 04, 2008

Here's the result of a return followed by function( in a new buffer. (Some of the other beginning-of-buffer issues I mentioned seem to have been caused by interactions with other stuff in my .emacs file.)

Debugger entered--Lisp error: (beginning-of-buffer)
  js-continued-expression-p()
  js-proper-indentation((0 nil nil nil nil nil 0 nil nil nil))
  js2-indent-line()
  js2-mode-match-paren()
  call-interactively(js2-mode-match-paren)
Comment by slackorama, Apr 04, 2008

@steve.yegge - thanks! You don't know how much this mode has helped me out.

Comment by zhzhqiang, Apr 05, 2008

I've tested it for few days, here are some of my complains: 1.could it be compatible with other emacs scripts such as snippet,or smart-snippet?They realy help me a lot when i code. And i dont think re-build wheel is a good idea. It seems they can not work with js2-mode 2.the curly-brace seems have some unproper actions. One time when i want to enter a "]",the mode insist display a ")" for me. This is an unacceptable mistake.

I really preciate steve's great idea and work. However, there seems to be lots of things should improve.

Best Regards

Comment by vagn.johansen, Apr 07, 2008

A single quote in a comment confuses the paren and brace mathing. For example

function f() {

    // ' 

    } 

Placing the cursor after } causes the show-paren-match face to be displayed. There are also some indentation problems.

Comment by steve.yegge, Apr 07, 2008

zhzhqiang - I will take a look at snippet and smart-snippet.

The entering "]" and getting ")" was fixed several releases ago - please download and install the latest version.

Your other reports are too vague for me to act on. I'm happy to try to fix specific, detailed complaints.

vagn.johansen: thanks for the report about the comment single-quote. I'll fix it in an upcoming release.

Please submit specific indentation problems and I will try to fix them. Keep in mind that indentation (as per my blog) is a VERY hard problem, and it will never be perfect - but it should be at least as good as the indentation in other JavaScript? modes, AND you can hit TAB repeatedly to get bounce-indentation. I'm trying to solve the indentation problem as best I can without writing another 15,000 lines of code.

Comment by Nex342, Apr 08, 2008

Just to make sure - you are aware that people are also posting bug reports to the issues page as well, right? Because it looks like bug reports posted here are getting dealt with much faster...

Comment by vagn.johansen, Apr 08, 2008

I meant the show-paren-MISmatch face, of course.

There is a problem with non-ASCII characters. Example

var obj = {pære: "pear"};

Red lines under æ and bit further.

Buffer coding: iso-latin-1-dos

Another problem:

I have some js files with a UTF-8 BOM. This seems to cause the entire parsing to fail (no colors). I don't really understand why Emacs does not hide the BOM. I have the same problem with nxml mode.

Comment by m...@vee.net, Apr 08, 2008

Ahh, most awesome thing for Emacs all year. Thanks!

/Mike

Comment by mpstevensuk, Apr 08, 2008

I'm having trouble convincing it I've repented of my sins.

Eg if I have a section:

var foo = "a
b" + c;

js2-mode complains, rightfully.

If I then join the string onto one line it now ought to be fine, but I can't find a way to convince js2-mode that the problem has gone away short of closing and reopening the file.

Comment by mehul.sanghvi, Apr 08, 2008

I use Javascript as a scripting language outside of web pages. I've got Mozilla's SpiderMonkey? installed on my system and like all scripts, the JS scripts also begin with a #!/bin/smjs as the first line.

That makes js2-mode spit out illegal character [2 times] into the mini-buffer and it stops doing the syntax highlighting. The ecmascript-mode that I was using before worked just fine in handling it.

Comment by sebastia...@gmx.de, Apr 09, 2008

Just came accross this fantastic JavaScript? mode on emacs-devel. Very good work!

I'm just missing one little feature though: Is it possible to fontify

CLASSNAME.prototype.functionname

with font-lock-function-name-face? Currently the function names are just plain black on white for me.

Comment by emailmac, Apr 10, 2008

i use this mode to browse through various extjs files and it's not parsing them right.

Comment by hugows, Apr 10, 2008

zhzhqiang: please take a look at yasnippet before having to mess with js2. i moved from smart-snippet to yasnippet and found it much easier to config, featureful and actively developed.

btw, there was a new release yesterday: http://code.google.com/p/yasnippet/

Comment by atkinson.steven, Apr 11, 2008

Nice work.

It'd be nice to have some sort of scriptable way of pulling updates. I'd prefer just checking the thing out from a scm (git would be my choice, buy anything works).

Having 6 machines to maintain between home and work, I use a script to sniff for updates, download, and install all the various emacs packages I use. Packages in an SCM make this easy. I'd have to do some screenscraping to get js2-mode.

Again, nice work.

Comment by zzygan, Apr 13, 2008

Overall I think its a great mode, so much nicer for getting useful feedback.

A few minor gripes. The main one that is bugging me at the moment is if i have a huge js file open in one buffer (such as ext-all-debug.js, which i keep open for reference) and a file I'm working on, when i stop typing in the file i'm working and go for a detour out to my web browser, i go back to emacs and it is locked up doing the parsing, unable to let me go back to work until the parsing of the huge buffer is finished even if that buffer isn't the active buffer. Is there anyway to stop parsing if any event is entered in an emacs frame (such as activating the window)

The second is a minor indenting problem. When cycling through indentations for a n anonymous function it never gives the choice i actually want. eg

            var totalCols = this.getColumnModel().getColumnsBy( function(colConfig, index) {
                                                            if(colConfig['totalable'] !== undefined) return true;
                                                            else return false;
                                                          });

when what i want is

      var totalCols = this.getColumnModel().getColumnsBy( function(colConfig, index) {
          if(colConfig['totalable'] !== undefined) return true;
            else return false;
      });

Is there a way to add indentation options for specific forms?

Comment by FredericMora, Apr 14, 2008

Very nice work. I like it! Since I am just starting to play with it, I have a beginners' question: what is the easiest way to override a default indentation if you're not happy with any of the indentation levels that TAB lets you cylce through? Manually indenting lines seems very fragile.

Comment by steve.yegge, Apr 16, 2008

Hello all, and thanks for the feedback and bug reports.

Please use the Issues tab for reporting bugs and adding feature requests - I've been paying a LOT of attention to the Issues list lately, and not enough attention to this Wiki.

I'm afraid I have no good solution for notifying people of updates. I believe Google Code may have a solution for this in a month or two. In the meantime, check back at least weekly. The Emacs maintainers have pinged me about including js2-mode in the next version of Emacs, and their timeline is pretty tight (June), so I'm working a little bit every day on features and fixes. I'll consolidate them into a new release at least once a week, hopefully twice a week, for the forseeable future.

zzygan - I've added a bug report for trying to improve the responsiveness for large buffers. As for indentation, there's a new hook you can use, but you need some mad elisp skills to write new indentation rules. As I mentioned in my blog, indentation is the single hardest problem, period, and there will be unsatisfying edge cases for a long time to come. I've burned many, many weeks of my life on this problem, and I'm throwing in the towel for a while. Maybe when this gets bundled with Emacs, someone else will tackle the problem.

Comment by Maxim.Mo...@gmail.com, Apr 24, 2008

Hello, Steve, great work, looking forward for description / implementation of symbol resolving / completion :)

Comment by 0x01BC, Apr 28, 2008

Hi,

wow I really like the cycle-indentation. I think this is more convenient than a forced level of indentation. All in all js2 is nice to use. Thanks for creating it :-)

Comment by huntermorris, Apr 30, 2008

The following code gives a Code has no side effects warning:

function foo() {
  while (bar) {
    function baz(x) {
      return function() {
        x.qux();
      };
    }; // warning underlined here

    window.setTimeout(baz(o), 0);
  }
};

However, this code gives no warning:

function foo() {
  while (bar) {
    var baz = function(x) {
      return function() {
        x.qux();
      };
    };

    window.setTimeout(baz(o), 0);
  }
};

Is this behaviour expected?

Comment by masanori...@gmail.com, May 03, 2008

Hello.

Sorry for my broken English.

I'm reading js2-ast.el for my interest, then I find them:

(defun js2-print-let-stmt-node (n i)

(let ((pad (js2-make-pad i))
body (js2-let-stmt-node-body))

Here is the "right" one (I think):

(defun js2-print-let-stmt-node (n i)

(let ((pad (js2-make-pad i))
(body (js2-let-stmt-node-body n)))

Sorry if I am wrong.

Thanks.

p.s. I tried submit this to Issue Tracker, but I can't do it.

Comment by nishad, May 14, 2008

Hi, I tried to byte-compile both js2-20080413.el and js2-20080424.el with GNU Emacs 20.7.1 on Solaris 10 and it tells me this:

Compiling file blahblah/.emacs_libraries/js2.el at Wed May 14 15:43:17 2008

!! Invalid read syntax (("#"))

Does anyone know what gives?

Comment by steve.yegge, May 14, 2008

nishad, it only runs on Emacs 21 and higher. 20's too buggy. Sorry!

masanoriogino -- thanks for the report. It'll be fixed in the next release.

Comment by steve.yegge, May 14, 2008

huntermorris -- thanks for the report. I'll see if I can track down why it's happening.

Comment by christophe.ruelle, May 21, 2008

Thanks for this great xemacs module. It's changing my life! So happy now. Just a little bug : The comment hide/show (C-c C-t) does not work for comments like :

/(star)

test
(star)/

but works fine for :

/(star) (star) test (star)/

or /(star) test (star)/

That's not very important... Thanks! Thanks! Thanks!

Comment by mihai.bazon, May 25, 2008

Here's a mode that uses cc-mode for indentation (originally written by Steven Champeon and Ville Skyttä). I spent like 2 days to make the indentation proper for JavaScript?. It currently Does What I Mean, but since the cc-mode indentation engine is highly customizable, it should DWYM too. :-)

I'd love it if I could integrate the indentation part with js2-mode -- do you think there is any chance?

http://mihai.bazon.net/projects/emacs-javascript-mode

Comment by Meddix, May 26, 2008

Hi all. I tried to use the module, thinking that something coming out from Steve's hands deserves a try, but Emacs 22.2.1 complains when I switch to js2-mode: byte-code: Wrong type argument: symbolp, (progn (or (memq (aref scope 0) cl-struct-js2-scope-tags) (error "js2-scope-symbols accessing a non-js2-scope")) (aref scope 2)) Has this happened to anyone? Thanks in advance

Comment by nelhage, May 31, 2008

js2-mode doesn't seem to handle hash keys (or whatever js calls them) named default properly -- it tries to parse a default namespace declaration, instead. So, for instance, the object literal {default: 7} results in a parse error that will sometimes throw off parsing of the entire rest of the file.

Comment by mihai.bazon, Jun 11, 2008

RE: Comment by nelhage, May 31, 2008

"default" is a reserved keyword and you can't use it in hash literals as is—you have to quote it. That is, {default: 7} is invalid JS and it's a Good Thing if the mode warns you about it. The correct way is {"default": 7}

Comment by dc...@sabiainc.com, Jun 12, 2008

Bug report: Here is a regex string from real-world code that confounds the syntax highlighting:

foo.match(/[\s|"|']*([\s|\S]*['|"])[\s|"|']$/)1?);

Comment by dc...@sabiainc.com, Jun 12, 2008

Another simpler one that causes similar problems:

url=url.replace(/['"]/g,'');

Comment by steve.yegge, Jun 16, 2008

dc...@sabiainc.com: the second one causes no problems for me with the latest js2-mode release.

The first (longer) one does cause a syntax error, but it doesn't compile in Rhino or SpiderMonkey? either. Take a look at the printed version on the page -- has the Wiki markup corrupted it? If so, I think you should be able to put backquotes around it to make sure it's not changed, so I can see the original.

Or just email it to me.

Thanks --steve

Comment by steve.yegge, Jun 16, 2008

Meddix -- sorry, but I haven't been able to reproduce it. I've tried with various versions of Carbon Emacs 22.1.1 and GNU Emacs 22.1 on Ubuntu.

What is the output of M-x emacs-version for you?

Comment by steve.yegge, Jun 16, 2008

nelhage and mihai -- you're both right. Technically Ecma-262 doesn't allow it, but many browsers do. It's configured via the js2-allow-keywords-as-property-names variable.

Comment by Meddix, Jun 24, 2008

Steve: Thanks for trying but I think something in my .emacs messed up. I switched to Emacs 23 and downloaded the last version of js2 (20080616) but the problem was still there. Then I recompiled and launched with an empty .emacs and everything has been fine.

That's what happens with a really ugly .emacs

Thanks again

Comment by eostrom, Jun 26, 2008

js2-mode flags the following useless code with a syntax error:

function() {
  ^M // not a caret and an M but a literal carriage return
}

The error message shows up at the open brace, and says "missing } after function body". Of course, there is a close brace, but it seems the parser doesn't see it because of the carriage return.

I'm not sure if carriage returns are actually legal whitespace in JavaScript?. If they are, there should be no syntax error. If they aren't, it would be nice to flag the carriage-return itself as the error, instead of the supposedly missing close brace.

Comment by bob.spamnot, Jul 22, 2008

Are you still planning on moving js2-mode into GNU emacs 23.1? If so now is the time to do it. See:

http://www.nabble.com/Release-plans-td18445925.html

Sorry is this is old new to you.

Comment by hippely, Aug 20, 2008

I have M-x byte-coompile-file /path/to/to/my/js2.el but I am still getting the error: You must byte-compile js2 mode before using it. I read this comment "Also, I noticed that js2-mode is included now, but I missed this in the changes file. I was confused for a while, trying to figure out why Emacs wouldn't go into js2-mode for files that ended in ".js". After looking around, I realized that the included js2 was overriding my local copy, and the included version was not byte-compiled (which js2 requires to work)." here: http://sachachua.com/wp/2008/07/30/emacs-and-php-theres-more-than-one-way-to-do-it-of-course/ Does anyone know how I can override the default js2.el and use the latest version in my home directory?

Comment by david.nolen, Sep 01, 2008

Just found out about this today! SWEET. This plus MozRepl? is going to change my life.

I'm noticing that the following form doesn't work with imenu

var obj = function() {
  function x() {};
  function y() {};
};

I'm a big fan of MooTools? and this form also does not work

var obj = new Class({
   x: function() {},
   y: function() {}
});
Comment by torstein.k.johansen, Sep 18, 2008

Just installed js2-mode from unstable today. This is really cool! Thanks for your efforts, I'm looking forward to the next release(s) - but will probably start using it straight away :-)

Cheers

Comment by matthew.feinberg, Oct 02, 2008

What would make a javascript editing much more useful for web development is the ability to embed WebKit?? or some other useful rendering engine in a buffer.

Does anybody know if the emacs source code would reasonably allow somebody to embed an out of process window inside of a buffer. The ability for an emacs buffer to act like a window manager would be superb. I'd be willing to help code if anybody knows where to get started.

Even better would be the ability to hook into one of the other browser's development tools. Chrome already separates the backend rendering process from the view, so if it's possible to implement a RenderViewHost?? inside of an emacs buffer, perhaps the chrome tools such as the debugger could also be used. If the chrome debugger output information to a file, then you could have WebKit?? or other rendering in one frame, and in another frame, your code with breakpoints in js2-mode.

Thoughts? Again, I'd be happy to help code if anybody knows where to begin.

Comment by ibwhite, Oct 16, 2008

I make extensive use of the forEach() Array function in my code. To save on redundant vertical space, I like to stick the function() on the same line as the forEach(), like so:

myarray.forEach(function(element) {
  mycode.goes.here(element);
});

Unfortunately, js2-mode interprets the indent to be here:

myarray.forEach(function(element) {
                  mycode.goes.here(element);
                });

That's way too far out for me, I frequently run out of horizontal space. And sure, I can cycle-tab the code back in, but then the next line jumps back to the curly-brace indent rather than the indent of the line before it. I can move the function() down a line, but this wastes vertical space.

Is there any way I can hack it to support what I want? I don't know emacs/elisp very well.

Comment by shidai.liu, Oct 28, 2008

Looks like js2-mode is going to be another killer app for Emacs. Do you plan to have it included in GNU Emacs for release 23.2? Thanks.

Comment by i...@triin.net, Dec 07, 2008

I read from the 20080330 release notes:

Fixed default indentation for first line of an object literal being passed as the first parameter to a function: most people want this indented from previous line, not from the curly-brace. Example:
foo.bar.baz({
  a: 1     // most people want this line indented here

So this seems to be fixed, but in my machine it still wants to indent like that:

foo.bar.baz({
              a: 1,
              b: 2
            });

Using version 20080616. Any ideas?

Comment by oyasumi, Dec 15, 2008

Two notes on false-positives in E4X literal error reporting: the closing tag in

var x = <x>{ 1 ? <y/> : <z/> } <a/></x>;

gets reddened and hinted as "unterminated regular expression literal", and in

var x = <x>{ 1 ? <y/> : <z/> }</x>;

the hinting is "illegally formed XML syntax". (Both variants work just fine in SpiderMonkey?.)

Comment by sebastia...@gmx.de, Jan 16, 2009

I love js2-mode and use it a lot. My comments:

To un-emacs-ish in some ways.

I don't like/use/need indentation cycling. Why not inherit the c-mode indentation and adjust it for JavaScript?? That's what most of the prog-modes do (C++, Java...). All those other prog-modes make it possible to keep the TAB key for expanding yas/snippets. Which is a great thing to have. I think they let the event bubble up, if the indentation is right (which can't ever be the case in js2-mode's philosophy - sad sad).

Marking and cutting a region with the right mouse button does not work reliably (sometimes does, sometimes not). Just in case you've not been an emacs user before: click somewhere in a buffer with the left mouse button. Then double-click somewhere else with the right mouse button. This should cut the region. This is, what is not working correctly in js2-mode. I can't find a reason for this, since the mouse is not bound to anything special in js2-mode.

I'd love to have a compile command (many progmodes provide one) like

java -jar yuicompressor.jar FILE-minified.js
and a customizable path to yuicompressor.jar and a filename extenseion ('-minified' in this example). Bind it to the menu <menu-bar> <tools> <compile>, just as the others do.

I can't find out what the modes name is the usual way. 'C-h m' just gives me two lines of documentation. All the minor modes show me more. No description of any hooks provided, nothing. Not even the modes name (I now it's NOT 'JavaScript-IDE/lw' as written in the mode's help).

Comment by ben.combee, Mar 16, 2009

Using js2 byte-compiled from js2-20080616a.el, I get a trailing comma warning when I've got code for JavaScript? 1.7 that looks like

function foo() { return 2?; } var a,? = foo();

That's a destructuring assignment and the comma is indicating that the second return value from foo isn't being used. Is there any way to turn this off while keeping other cases?

Comment by aymanshamma, Mar 26, 2009

I noticed a slight indentation error (which you cant bounce out of):

function foobar() {
  if (!(true) &&
    true) {
  }
}

seems to happen only on the first condition in parens()

function foobar() {
  if ((true) &&
    !(true) &&
      true) {
  }
}
Comment by metaperl, Apr 07, 2009

When byte-compiling on emacs21, I get:

Compiling file /home/tbrannon/emacs/js2.el at Tue Apr  7 11:32:57 2009
  ** `(car (prog1 js2-loop-set (setq js2-loop-set (cdr js2-loop-set))))'
     called for effect
  ** `(car (prog1 js2-loop-and-switch-set (setq js2-loop-and-switch-set (cdr
     js2-loop-and-switch-set))))' called for effect

While compiling the end of the data:
  ** The following functions are not known to be defined: copy-overlay,
    looking-back, remove-overlays

But it does work, unlike espresso.el and js.el.

Thank you very much for your work.

Comment by metaperl, Apr 07, 2009

Oh, it mentions nothing about JSON formatting in the .el file itself, but that works perfectly as well, with font-locking and indentation... awesome.

Comment by mitch.special, Apr 17, 2009

has anyone gotten this mode to work under xemacs, and if so, how?

Comment by nick.aschberger, Jul 01, 2009

hi folks, As suggested I have added: (add-to-list 'auto-mode-alist '("\\.js$" . js2-mode)) (autoload 'js2-mode "js2" nil t)

to my .emacs file.

The auto-mode is not working - Files are opened in "Javascript-Generic". What on earth is the problem?

The autoload is clearly working because I can manually enter js2 in "M-x js2-mode". Strangest thing ever.

Anyone else seen this/know what to do?

Comment by stevo.lists, Jul 01, 2009

Latest version freezes my terminal when typing a '#' character.

I have just reproduced this 5 times consecutively before I posted this report. Yes this is real, and doesn't happen in any other mode. Had to resort to switching off js2mode in order to type the '#' character.

Running js2(june2008 release) emacs22.2.1 -nw screen4.00.03 Centos5

bizarre

Comment by a...@boinkor.net, Jul 21, 2009

I have patched js2-mark-defun to include any assignment/variable initialization statements that concern the current function, so that it can be compatible with the javascript REPL from moz.el:

--- js2-orig.el 2008-06-16 10:48:58.000000000 +0200
+++ js2.el      2009-07-21 17:11:45.000000000 +0200
@@ -11632,6 +11632,10 @@
                             (js2-ast-root-p fn))
                         (js2-mode-find-first-stmt node))
                parent (or stmt fn)))
+       ;; Expand point to include any assignment statements.
+       (when (or (js2-assign-node-p (js2-node-parent parent))
+                 (js2-var-init-node-p (js2-node-parent parent)))
+         (setq parent (js2-node-parent parent)))
        (setq beg (js2-node-abs-pos parent)
              end (+ beg (js2-node-len parent)))
        (push-mark beg)

This allows you to mark stuff like

Node.prototype.funname = function () {
    alert('foo');
}

blocks, and allows moz.el (with a little defadvice to mark-defun) to send these function definitions over to Firefox interactively. Much better now!

Comment by d...@dondwiggins.net, Jul 27, 2009

I find that js2-mode-forward-sexp doesn't work when navigating code like

var viewPanel = new Ext.Panel({
    frame:true,
    title: 'Search',
    items: [fooPanel, taskActions]
});

If you put the cursor on the first left curly brace, the function will move it just after the semicolon; ditto with the left square bracket. The code I'm working with has a lot of these structures, several levels deep, and I use forward-sexp frequently, both for navigation and to be sure I've got the nesting right. This flaw is keeping me from moving to js2 mode.

Comment by mihai.bazon, Aug 05, 2009

Feature request: highlight all occurrences of a variable

It would be nice to have the possibility to highlight all occurrences of a variable in the current scope when the caret is idling over an occurrence. I found a generic "highlight-symbol" mode but it doesn't seem to work very well (it doesn't know what's a variable, it just highlights occurrences of whatever is under the caret). Moreover, it doesn't work well with js2-mode because it's based on standard font locking.

Thanks to its rigorous parser, JS2 knows what are variables and their scope so presumably it would be easy to implement this... I'm looking through the source right now, but not being good at Lisp I'm not sure I'll manage to do it.

Comment by mihai.bazon, Aug 05, 2009

Small fix (= expects number args):

Index: js2-mode.el
===================================================================
--- js2-mode.el (revision 78)
+++ js2-mode.el (working copy)
@@ -3341,11 +3341,11 @@
   (insert (js2-make-pad i)
           (let ((tt (js2-node-type n)))
             (cond
-             ((= tt 'js2-THIS) "this")
-             ((= tt 'js2-NULL) "null")
-             ((= tt 'js2-TRUE) "true")
-             ((= tt 'js2-FALSE) "false")
-             ((= tt 'js2-DEBUGGER) "debugger")
+             ((= tt js2-THIS) "this")
+             ((= tt js2-NULL) "null")
+             ((= tt js2-TRUE) "true")
+             ((= tt js2-FALSE) "false")
+             ((= tt js2-DEBUGGER) "debugger")
              (t (error "Invalid keyword literal type: %d" tt))))))

 (defsubst js2-this-node-p (node)
Comment by mihai.bazon, Aug 05, 2009

Well, here's what I came up with after some embarrassing amount of time:

(defun js2-highlight-vars ()
  "Highlight variable under cursor within the enclosing scope"
  (interactive)
  (let ((node (js2-node-at-point))
        name
        scope)
    (when (and node (js2-name-node-p node))
      (setq scope (js2-node-get-enclosing-scope node)
            name (js2-name-node-name node))
      (js2-with-unmodifying-text-property-changes ;; good stuff ;-)
        (js2-visit-block
         (js2-function-node-body scope)
         (lambda (node end-p)
           (when (and (not end-p)
                      (js2-name-node-p node)
                      (string= name (js2-name-node-name node)))
             (let* ((beg (js2-node-abs-pos node))
                    (end (+ beg (js2-node-len node)))
                    (ovl (make-overlay beg end)))
               (overlay-put ovl 'face 'highlight)
               (overlay-put ovl 'js2-temporary-highlight t)
               (put-text-property beg end 'point-left #'js2-remove-temporary-overlays)))
           t))))))

;; (defun js2-remove-temporary-overlays (&rest ignore)
;;   "Remove overlays from buffer that have a `js2-temporary-highlight' property."
;;   (let ((beg (point-min))
;;         (end (point-max)))
;;     (save-excursion
;;       (dolist (o (overlays-in beg end))
;;         (when (overlay-get o 'js2-temporary-highlight)
;;           (delete-overlay o))))))

;; the following is shorter, could be used to improve
;; js2-remove-overlays from the distro
(defun js2-remove-temporary-overlays (&rest ignore)
  (remove-overlays (point-min) (point-max) 'js2-temporary-highlight t))

;; call the following in a js2-mode buffer
(defun js2-highlight-vars-with-timer ()
  (interactive)
  (run-with-idle-timer 0.5 t #'js2-highlight-vars))

It doesn't do exactly what I want, but it's getting close. Hope to be able to hack more on it.

Comment by tomlong, Aug 05, 2009

I have a problem with js2-mode mangling the following code, which I believe is completely correct javascript:

// Simple JavaScript? Templating // John Resig - http://ejohn.org/ - MIT Licensed (function(){

var cache = {};
this.tmpl = function tmpl(str, data){
// Figure out if we're getting a template, or if we need to // load the template - and be sure to cache the result. var fn = !/\W/.test(str) ?
cachestr? = cachestr?
tmpl(document.getElementById(str).innerHTML) :
// Generate a reusable function that will serve as a template // generator (and which will be cached). new Function("obj",
"var p=,print=function(){p.push.apply(p,arguments);};" +
// Introduce the data as local variables using with(){} "with(obj){p.push('" +
// Convert the template into pure JavaScript? str
.replace(/\r\t\n?/g, " ") .split("<%").join("\t") .replace(/((|%>)[\t])'/g, "$1\r") .replace(/\t=(.?)%>/g, "',$1,'") .split("\t").join("');") .split("%>").join("p.push('") .split("\r").join("\\'")
+ "');}return p.join('');");
// Provide some basic currying to the user return data ? fn( data ) : fn;
};
})();

Any help would be appreciated!

Comment by mihai.bazon, Aug 06, 2009

Found another small error, here's the updated patch:

Index: js2-mode.el
===================================================================
--- js2-mode.el (revision 78)
+++ js2-mode.el (working copy)
@@ -3341,11 +3341,11 @@
   (insert (js2-make-pad i)
           (let ((tt (js2-node-type n)))
             (cond
-             ((= tt 'js2-THIS) "this")
-             ((= tt 'js2-NULL) "null")
-             ((= tt 'js2-TRUE) "true")
-             ((= tt 'js2-FALSE) "false")
-             ((= tt 'js2-DEBUGGER) "debugger")
+             ((= tt js2-THIS) "this")
+             ((= tt js2-NULL) "null")
+             ((= tt js2-TRUE) "true")
+             ((= tt js2-FALSE) "false")
+             ((= tt js2-DEBUGGER) "debugger")
              (t (error "Invalid keyword literal type: %d" tt))))))

 (defsubst js2-this-node-p (node)
@@ -3434,7 +3434,7 @@

 (defun js2-print-number-node (n i)
   (insert (js2-make-pad i)
-          (number-to-string (js2-number-node-value n))))
+          (number-to-string (js2-number-node-num-value n))))

 (defstruct (js2-regexp-node
             (:include js2-node)

I'm not sure how useful are the js2-print- functions, but they're definitely good for debugging.

Lots of stuff that I can't figure out, I'd appreciate some help. Steve, do you still read this wiki? :-)

Comment by mihai.bazon, Aug 07, 2009

OK, I finally found the source of the problems I encountered. js2-node-at-point sometimes returned totally weird results, i.e. instead returning the actual node under the cursor, it returned a large parent js2-scope node. Also, when visiting a scope node it didn't trigger my callback for all its children. Seems to be because of this line:

(put 'cl-struct-js2-scope 'js2-visitor 'js2-visit-none)

If I put 'js2-visit-block instead of 'js2-visit-none the problem goes away. I'm not sure it's the correct fix, but it does seem to do what I need. It's interesting that the print visitor is set to js2-print-none, and still it prints fine.

Great code Steve, thank you for your efforts! Back to more important stuff now such as ruling the world. :-p

Comment by slawek.zak, Sep 12, 2009

I have a problem with byte-compiling last version. I hit max-specpdl-size and max-lisp-eval-depth when running byte-compile-file. Tried to bump both to 4000, but it's the same story. I use GNU Emacs 23.0.91.1. Any ideas?

Thanks, /S

Comment by markhj, Sep 16, 2009

slawek: I think you are probably trying to compile it after trying to "require" the uncompiled version. The simplest thing to do is probably just to restart Emacs and re-compile, or you can do it on the command line with something like:

emacs --batch --eval '(byte-compile-file "js2-mode.el")'
Comment by ben.butlercole, Oct 20, 2009

I'd like to help get the latest version of js2-mode added to ELPA. Can I do this myself? Were any changes needed to get the original version (20080616) uploaded?

Ben

Comment by ddellacosta, Oct 27, 2009

I'm relatively new to hacking on Emacs, so I'm confused by something very basic with this mode: how can I set it so that it doesn't use tabs to indent? I've tried changing the settings for Js2 Basic Offset but that doesn't seem to change whether spaces or tabs are used. Is this something in Emacs settings, or in JS2 settings, can anyone help me?

Thank you!


Sign in to add a comment
Hosted by Google Code