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.

Advertisements

2 thoughts on “How to install emacs major mode for javascript

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

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s