Sunday, February 25, 2007

How to install emacs major mode for javascript

As emacs is a harsh way of life, having documented things for other people is a good way to give back. Too bad it's hard for first timers. But I guess that's why people stick with it...it's a point of pride.

So how do you install a major mode for emacs? First, you need to find out what your emacs load path is.

C-h v load-path

Then you go and find a major mode file (javascript-mode.el) and put it in one of those directories. Since I don't know better, I put it in '/usr/local/share/site-lisp'. (Anyone else know a better place to put javascript major modes?)

Then put the following in your ".emacs" file. This file exists in your home directory, and if it doesn't exist, create it.

;; for javascript files
(autoload 'javascript-mode "javascript-mode" "JavaScript mode" t)
(setq auto-mode-alist (append '(("\\.js$" . javascript-mode))
auto-mode-alist))

And there you go, emacs major mode for javascript. If there's already a package in your favorite distribution of linux, install that package instead. It's way easier.

2 comments:

  1. Anonymous8:29 AM

    Add your mode files to a custom folder, and add that folder to your load_path:

    (add-to-list 'load-path "~/my_emacs_stuff")

    ReplyDelete
  2. Anonymous7:50 PM

    Note that the line that Anonymous posted needs to be added to your .emacs file.

    ReplyDelete