Pragmatic Development Notes

2008-11-08

Emacs On Windows – Extensions

Filed under: Emacs,Ruby & RubyOnRails — Boško Ivanišević @ 6:14
Tags: , , , ,

In my previous post I gave basic Emacs customizations. What is really cool about this wonderful editor is that you can easily extend it. But don’t take this literally. It is easy if you know Lisp. Even then you might have to write lot of Lisp code depending on extension you want to make. Fortunately there are lot of extensions available on the net. Some are excellent, others can be better (just as any software, isn’t it) but you will certainly find almost anything you need. At least I did.

If you read my previous article you already know I like to keep things simple. That’s why I put all Emacs extensions in one folder. That way I can easily pack it and copy to another system. Actually that’s how I came up with final Emacs set up. I was changing it on Windows Vista, Ubuntu and Windows XP, moving all my extensions around all the time. Directory where I keep all extensions is in my home folder (see previous post for home folder on various systems) and is named .emacs.d. I’ve made two sub-folders in it – includes and plugins. The first one I use for simple extensions that consist of one or just a few files. The other one is for more complex extensions.

In order to be able to load extensions from includes directory add this to .emacs file:


;; Directory to put various el files.
(add-to-list 'load-path "~/.emacs.d/includes")

and don’t forget to adjust path according to your settings.

Let’s install the first extension. Download ASCII table put it in includes directory and add following lines at the end of your .emacs file:


;; Loading ascii-table
(require 'ascii-table)

You can fire up your Emacs and test plugin. Type M-x ascii-table and in a new buffer you’ll see a table with all ASCII characters, their decimal, octal and hexadecimal values. Useful thing.

Every modern editor has syntax highlighting. Emacs is not different. It handles it through various modes depending on a file currently edited. Actually Emacs’ modes do a little bit more then syntax highlighting, but that’s another story. Anyway, in order to support common modes add following to your .emacs file:


;; Loading collection of generic modes
(require 'generic-x)

File generic-x.el comes with Emacs distribution. It implements collection of generic modes. If you want to change which modes will be loaded you can do it by:

M-x customize-option RET generic-extras-enable-list RET

List of all available modes will be opened and you can select those you need.

If you don’t like original Emacs’ colors ColorTheme is right extension for you. Download it and unpack it in plugins folder. Current version is 6.6.0. As you already know you have to enable this plugin in .emacs file:


;; If you have own color scheme and don't like to
;; use emacs default I recommend to use
;; this package:
;; http:/www.emacswiki.org/cgi-bin/wiki.pl?ColorTheme
(add-to-list 'load-path "~/.emacs.d/plugins/color-theme-6.6.0")
(require 'color-theme)
(setq color-theme-is-global t)
(color-theme-initialize)
;; This is my favorite color theme.
(color-theme-deep-blue)

If you want to see what color themes are available just type:

M-x color-theme- TAB

Emacs will open new buffer with the list of all color themes. Just click on any of them to apply it. After you find the one you like just replace last line in above lines with the its name.

If you frequently edit same files you could find recentf extension useful. It keeps list of recently edited files. Once you install it you can access this list from File->Open Recent menu, or by typing some of the recentf commands which, as usual in Emacs, you can see by typing:

M-x recentf- TAB

By the way command completion is very powerful in Emacs. Just type few letters and hit TAB key and Emacs will either complete command for you or give you the list of possible candidates. Let’s go back to recent files list. You will enable it with following lines of Lisp code:


(require 'recentf)
(recentf-mode 1)

If you want to use Emacs for any development you can find Cedet plugin useful. Using Emacs for Ruby On Rails development will require this plugin. So go on download it and unpack it in your plugins directory. If you downloaded 1.0pre4 version add


(load-file "~/.emacs.d/plugins/cedet-1.0pre4/common/cedet.el")

;; Enabling various SEMANTIC minor modes. See
;; semantic/INSTALL for more ideas.
;; Select one of the following:

;; * This enables the database and idle reparse engines
(semantic-load-enable-minimum-features)

;; * This enables some tools useful for coding, such as summary mode
;; imenu support, and the semantic navigator
(semantic-load-enable-code-helpers)

(setq semanticdb-default-save-directory "~/.semantic.cache")

(setq semantic-load-turn-everything-on t)
(require 'semantic-load)

to your .emacs file. First line will enable cedet tools. Next two lines will turn on some necessary features. After that we prevent semantic to spread cache files all over the disk by putting them all in one common folder. Finally we turn on semantic extension.

All modern IDEs have one common (good) feature – code browsing. It really helps developers to quickly open files from their projects. Of course it comes with the price. Most of modern IDEs need lot of memory and they are much slower than Emacs. Don’t take me wrong. I use IDEs, but after using Eclipse with Aptana or NetBeans I’ve finished with Emacs for everyday Ruby and Ruby On Rails development. It doesn’t have fancy code completion, GUI debugging and some more things but you will see that Emacs’ support for all of that and even more is excellent and not so memory consumable.

So let’s take firs step to make Emacs IDE like. Grab ECB and unpack it into plugins folder. After that add these lines to your .emacs file:


;; This installs ecb - it is activated
;; with M-x ecb-activate
(add-to-list 'load-path "~/.emacs.d/plugins/ecb-2.32")
(require 'ecb-autoloads)

;; This puts ~/ruby folder as root for your Ruby projects
(setq ecb-source-path (quote ("~/ruby")))

Restart Emacs, type:

M-x ecb-activate

and enjoy your new IDE. It is not complete yet. We still have to add few things in order to get complete Ruby and Ruby On Rails support. But before we do that we’ll add some more cosmetics.

Grab tabbar.el from Emhacks, put it in includes folder and add:


(require 'tabbar)
(tabbar-mode)
(global-set-key [(control tab)] 'tabbar-forward)
(global-set-key [(control shift tab)] 'tabbar-backward)
(setq tabbar-cycling-scope "tabs")

This will enable tabs in Emacs. You can switch them with Ctrl-Tab (forward) and Ctrl-Shift-Tab (backward). Since Emacs groups buffers by the their, mode after last tab in one group it will switch to the first buffer in the next group or vice versa.

If you want to use Emacs for editing XML file you might find nXML mode useful. Unpack archive in plugins folder and enable it:


;; nxml
;; /usr/share/emacs/site-lisp/tcc-nxml-emacs:
;; Add these lines
;; to your .emacs to use nxml-mode. For documentation of
;; this mode, see http://www.nmt.edu/tcc/help/pubs/nxml/
;;--
;; Add the nxml files to emacs's search
;; path for loading:
;;--
(setq load-path
(append load-path
'("~/.emacs.d/plugins/nxml-mode-20041004/")))
;;--
;; Make sure nxml-mode can autoload
;;--
;(load "~/.emacs.d/plugins/nxml-mode-20041004/rng-auto.el")
; This is much better way of loading. File rng-auto.el will not be
; loaded until needed (for example by opening some .xml file)
(autoload 'nxml-mode "rng-auto.el" nil t)

;;--
;; Load nxml-mode for files ending in .xml, .xsl, .rng, .xhtml
;;--
(setq auto-mode-alist
(cons '("\\.\\(xml\\|xsl\\|rng\\|xhtml\\)\\'" . nxml-mode)
auto-mode-alist))

Recently I had to work a lot with JavaScript so I was looking for extension that will support it. I’ve found several but the one I’ve chosen is JS2. It is quite good, but if you find better one let me know. As usual download Lisp file and put it in includes folder and enable it in .emacs file:


;; JavaScript mode
(autoload 'js2-mode "js2-20080616a" nil t)
(add-to-list 'auto-mode-alist '("\\.js$" . js2-mode))

And finally mode which made possible to write all these in Emacs – Weblogger. Save Lisp file in includes folder and add:


(require 'weblogger)

to your .emacs file.

That’s all in this part. We have added few extensions and by now you should know now how to add those you need. In the next article I’ll finish setting up Emacs for Ruby and Ruby on Rails and in the final article I’ll write few remarks about Ruby debugging within Emacs.

Advertisements

5 Comments »

  1. really thank you for your work! it helps a lot

    Comment by david — 2009-03-25 @ 20:51

  2. (add-to-list ‘load-path (“~/.emacs.d/plugins/color-theme-6.6.0”))

    should be changed to

    (add-to-list ‘load-path “~/.emacs.d/plugins/color-theme-6.6.0”)

    Comment by thanks — 2010-08-13 @ 21:44

  3. Figure out how to make use of Search engine optimization Wp Plugin…

    […]Emacs On Windows – Extensions « Pragmatic Development Notes[…]…

    Trackback by Figure out how to make use of Search engine optimization Wp Plugin — 2012-03-16 @ 21:38

  4. Hey! Someone in my Facebook group shared this site with us so I came to give it a look.

    I’m definitely enjoying the information. I’m bookmarking and will be tweeting
    this to my followers! Fantastic blog and excellent design and style.

    Comment by pie — 2013-06-30 @ 15:27

  5. You should be a prt of a contest for one oof the highest quality sites on the web.

    I will recommend this site!

    Comment by Lan — 2014-12-11 @ 19:02


RSS feed for comments on this post. TrackBack URI

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

Blog at WordPress.com.

%d bloggers like this: