Closed wyuenho closed 11 years ago
If you install js2-mode from MELPA -- which is the case if you get Skewer from MELPA -- you're actually getting mooz/js2-mode rather than the ELPA version. This js2-mode fork is under active development, with the last commit being less than a week ago.
More importantly, js2-mode is a full JavaScript parser, and Skewer relies on the AST provided by the mode. Honestly, js2-mode is probably the most advanced mode ever written for Emacs. While extending Skewer to support CSS and HTML, I really wished these other modes were this complete.
Skewer could theoretically be used in a js-mode buffer with few changes, but to evaluate an expression it would still need to use js2-mode to parse the buffer (in a temp buffer copy) and extract the expression. If by "heavy" you mean that js2-mode is slow, evaluating expressions with Skewer will still be very slow. Is this something you'd be interested in?
Alternatively someone could write some Elisp functions to imprecisely extract JS expressions without a full parser, similar to what skewer-css does. I'm not personally interested in writing these functions, but I'd accept such commits from someone else as something like a "skewer-light" mode that would go with js-mode.
Ah ok. I think I can see why switching to js-mode is hard. skewer-mode uses its own http server, instead of a separate node process so you can't even sent a region to a JS process to parse out an AST with esprima or whatever. I'll give js2-mode a try. Thanks.
If you just want to evaluate the region, here's a skewer-eval-region,
(defun skewer-eval-region (start end)
"Evaluate the region as JavaScript code."
(interactive "r")
(skewer-eval (buffer-substring-no-properties start end)
#'skewer-post-minibuffer))
That's an interesting idea to use Esprima. Skewer could be extended to use that as the parser (see skewer-js-hook
). To evaluate an expression, it would send the entire buffer and the point location, letting the JavaScript in the browser decide what to do.
Not everyone likes js2-mode, it's heavy and under very little development. Is it possible to make this awesome mode work with the default js-mode that comes with emacs 24.x?