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?
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.
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.
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?
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.
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.
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.
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.
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.
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.
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?
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?
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.
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]
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?
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.)
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.
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.
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...
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.
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.
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.
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.
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.
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
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.
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.
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 :-)
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!
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?
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
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.
"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}
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.
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.
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.
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.
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?
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.
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))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.
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.
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.
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?
Regarding auto-updates, please use Tom Tromey's ELPA:
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.
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.
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.
Getting same warning as zhzhqiang in Aquamacs Emacs on Leopard
Sorry all! I've uploaded a fix: js2-20080401a.el
My bad - I'll test new releases more carefully next time.
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.
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.
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.
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!
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:
p.s. oh yes, and jjfoe - thanks for the clarification - fixed the default keybindings in this release.
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?
Yup - mostly when switching to and from buffers in other modes, which treat indentation changes as undoable.
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.
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.
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)))))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]
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?
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.)
@steve.yegge - thanks! You don't know how much this mode has helped me out.
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
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.
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.
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...
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.
Ahh, most awesome thing for Emacs all year. Thanks!
/Mike
I'm having trouble convincing it I've repented of my sins.
Eg if I have a section:
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.
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.
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
with font-lock-function-name-face? Currently the function names are just plain black on white for me.
i use this mode to browse through various extjs files and it's not parsing them right.
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/
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.
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?
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.
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.
Hello, Steve, great work, looking forward for description / implementation of symbol resolving / completion :)
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 :-)
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?
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)
Here is the "right" one (I think):
(defun js2-print-let-stmt-node (n i)
Sorry if I am wrong.
Thanks.
p.s. I tried submit this to Issue Tracker, but I can't do it.
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?
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.
huntermorris -- thanks for the report. I'll see if I can track down why it's happening.
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)
(star)/but works fine for :
/(star) (star) test (star)/
or /(star) test (star)/
That's not very important... Thanks! Thanks! Thanks!
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
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
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.
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}
Bug report: Here is a regex string from real-world code that confounds the syntax highlighting:
foo.match(/[\s|"|']*([\s|\S]*['|"])[\s|"|']$/)1?);
Another simpler one that causes similar problems:
url=url.replace(/['"]/g,'');
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
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?
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.
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
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.