I have been using js2-mode (an Emacs Javascript mode) for a couple of weeks now. I started using it out of curiosity, at the time I gave up on TextMate as all-purpose editor and turned back to Emacs, mainly because Emacs has so much better Erlang support. Now I consider js2-mode as the second most important Javascript tool (nothing can beat Firebug of course, and Firebug 1.2B1 on Firefox 3RC1 really rocks !). It fits perfectly into my work flow, you don't have to learn anything specifically to use it, it shows on-the-fly any syntax errors, global variables (which usually are unintentional), does a great job of line indenting, but because line indenting is often a question of personal style, js2-mode offers several possibilities you can cycle through via TAB. And in case you don't like how js2-mode works out-of-the-box, there are tons of customization options.
The only thing I am missing: I would like to use js2-mode as well as minor mode in HTML, but that doesn't seem to work yet.
Update: After writing this post, I just discovered another recent article about js2-mode with focus on syntax highlighting.
Showing posts with label emacs. Show all posts
Showing posts with label emacs. Show all posts
Saturday, May 24, 2008
Wednesday, April 02, 2008
Easy git on Emacs with emacs-git
I have been using emacs-git for the last few days and and it proved incredible useful. It let's you do interactively most of the basic git operations such as creating, cloning or importing a repository, it inidcates graphically the git status of the current file with a colored LED-like icon at the Emacs bottom status line and it also facilitates adding / removing files to the repo, ignoring files, tagging, merging and conflict resolution.Emacs-git works only on Emacs (and not on X Emacs) and requires a very recent version of Emacs (I am using it on a nightly build of aquamacs, which is based on Emacs from CVS).
Monday, March 31, 2008
Emacs on Ajax with Steve Yegge's new js2-mode
Steve Yegge just released a new Javascript Emacs mode. I installed it and played around a bit and syntax highlighting and indention seemed to work perfectly. The feature list is impressive (copy-pasted from project page):- it offers the usual features from other Emacs modes
- it supports the JavaScript language up through version 1.7
- it has a real recursive-descent parser
- it highlights syntax errors and underlines warnings
- it supports collapsing function-body and block-comment definitions
- it has some preliminary support for IMenu (to be improved soon)
- it knows about jsdoc and highlights tags in jsdoc comments
- it has a set of typing helpers to make editing easier
This is part of a larger project, in progress, to permit writing Emacs extensions in JavaScript instead of Emacs-Lisp. Lest ye judge: hey, some people swing that way. The larger project is well underway, but probably won't be out until late summer or early fall.Plenty of reason to switch back to Emacs for those like me who thought that TextMate was the future.
My new editing mode is called js2-mode, because eventually I plan to support JavaScript 2, also known as ECMAScript Edition 4. Currently, however, it only supports up through JavaScript 1.7, so the name is something of a misnomer for now.
Monday, October 08, 2007
Erlang refactoring with Emacs / Wrangler
With Wrangler, an extension to distel, one can now easily refactor Erlang programs with Emacs. Currently the following refactorings are supported:- rename variable/function
- rename module
- generalize definition
- move a function definition to another module
Sunday, October 07, 2007
Erlang compilation with Emacs
Since I switched to a Mac as my primary development platform I am using aquamacs for all my my coding needs. It is a fast native app, looks good, is highly customizable and together with distel it integrates very well with Erlang. Just one thing was giving me a headache:
Compiling from within Emacs based on an Emakefile
I tried some script by Alexey Lebedeff recently discussed on the Erlang mailing list, but at first try I did not manage to adapt the script to fit my needs. The situation got worse when I started to use non-Erlang source files such as templates and lexer / parser grammars which all get compiled to beam files and need to be reloaded when compilation was successful. After digging a bit into Emacs Lisp I came up with the following approach:
By pressing a function key (F13 in my case) emacs invokes via RPC at the Erlang application a custom compile command which in case of an Erlang source file switches to the directory of the Emakefile, runs a make:all([load]). and switches back to the original directory of the currently edited file. If the source file is a non-Erlang, than custom code gets called to perform all the necessary steps until beam file reloading.
There are two implications which need to be considered before adapting this approach:
With the elisp snippet from above, the corresponding Erlang application must contain a module myapp_make which implements the function all/1 :
Compiling from within Emacs based on an Emakefile
I tried some script by Alexey Lebedeff recently discussed on the Erlang mailing list, but at first try I did not manage to adapt the script to fit my needs. The situation got worse when I started to use non-Erlang source files such as templates and lexer / parser grammars which all get compiled to beam files and need to be reloaded when compilation was successful. After digging a bit into Emacs Lisp I came up with the following approach:
By pressing a function key (F13 in my case) emacs invokes via RPC at the Erlang application a custom compile command which in case of an Erlang source file switches to the directory of the Emakefile, runs a make:all([load]). and switches back to the original directory of the currently edited file. If the source file is a non-Erlang, than custom code gets called to perform all the necessary steps until beam file reloading.
There are two implications which need to be considered before adapting this approach:
- An application must contain specific code which can be called by emacs and that code must be able to determine the location of the Emakefile.
- The approach can't be used for initial compilation, because emacs calls a function from an application module, which must be compiled already.
(defun my-erlang-compile ()
(interactive)
(save-some-buffers (not compilation-ask-about-save) nil)
(save-excursion
(let ((thisdir default-directory))
(setq src-file-name buffer-file-name)
(with-current-buffer (get-buffer-create "*erl-output*")
(setq default-directory thisdir)
(erase-buffer)
(compilation-mode)
(toggle-read-only nil)
(setq compilation-current-error nil)
(display-buffer (current-buffer))
(erl-spawn
(erl-send-rpc (erl-target-node)
'distel
'eval_expression
(list (format "myapp_make:all(%S)." src-file-name)))
(erl-receive ()
((['rex ['ok string]]
(insert string))
(['rex ['error reason]]
(insert reason))
(other
(message "Unexpected: %S" other)))))))))
(add-hook 'erlang-mode-hook 'my-erlang-mode-hook)
(defun my-erlang-mode-hook ()
;; when starting an Erlang shell in Emacs, default in the node name
(setq inferior-erlang-machine-options '("-sname" "emacs"))
(define-key erlang-mode-map [f13]
(lambda () (interactive)
(progn
(my-erlang-compile))))
)
;; just to illustrate how to use custom erlang compilation
;; from within other modes
(add-hook 'foo-helper-mode-hook
(lambda ()
(define-key foo-helper-mode-map [f13]
(lambda () (interactive)
(progn
(my-erlang-compile))))))
With the elisp snippet from above, the corresponding Erlang application must contain a module myapp_make which implements the function all/1 :
all(Path) ->
case filename:extension(Path) of
".erl" ->
{ok, OldDir} = file:get_cwd(),
ok = file:set_cwd(my_find_emakefile_dir()),
make:all([load]),
ok = file:set_cwd(OldDir);
Ext ->
maybe_my_custom_stuff
end.
Subscribe to:
Posts (Atom)