Learning and setting up Emacs can be intimidating and while some folks find much use in using a pre-configured setup like - Emacs Prelude, I personally think it is better that someone new to Emacs installs each and every module himself and learns from it. I am assuming OSX as development environment here but the instructions should work well enough on Linux as well.
brew install emacs --use-git-head --cocoa --srgb
There is a bug in Emacs HEAD that prevents it to be working with Cask and thus try not to use Emacs HEAD.
Install a Package Manager : I use pallet for managing various packages. Think of pallet as Bundler/Maven for Emacs. Follow instructions available in section For newly installed Emacs. Once you have pallet installed each package you install via
package-installcommand will automatically update the
Caskand you can checkin the file in version control system and carry it around.
Sometimes you have to install a package directly from git. I personally use Git Subtrees for adding packages from git. Feel free to use
submodulesor directly copying files as well.
Structuring your Customization : Over last couple of years I personally have been using following style of structuring my emacs setup.
.emacs.d/ init.el -> The real .emacs file. custom/ 01ruby.el 02org.el 03auto-complete.el 04web-mode.el
The .emacs file : Contents of
init.ellooks something like this:
(require 'cask "~/.cask/cask.el") (cask-initialize) (require 'pallet) (add-to-list 'load-path "~/.emacs.d/custom") (add-to-list 'load-path "~/.emacs.d/other_paths) .. .. (load "00common-setup.el") (load "01ruby.el") (load "02org.el")
Global Config : I use a lot of global configuration stuff which isn’t mode specific, some important ones are:
;; Navigate between windows using Alt-1, Alt-2, Shift-left, shift-up, shift-right (windmove-default-keybindings) ;; Enable copy and pasting from clipboard (setq x-select-enable-clipboard t)
You can see complete file on, 00common-setup.el. If you are completely new to Emacs you should use
C-h t(That is press Control-h and then t) to launch inbuilt Emacs tutorial from within Emacs.
Packages You need
For complete list of package see my Caskfile. Also some packages I use straight from git and hence may not be listed in Caskfile. With that out of the way, I will try to cover most important packages I love and use everyday:
auto-complete : You can install it via
package-installand below is my configuration of
(require 'auto-complete-config) (add-to-list 'ac-dictionary-directories "~/.emacs.d/.cask/220.127.116.11/elpa/auto-complete-20130724.1750/dict") (ac-config-default) (setq ac-ignore-case nil) (add-to-list 'ac-modes 'enh-ruby-mode) (add-to-list 'ac-modes 'web-mode)
It gives me access to all powerful auto-completion system for Emacs. Below is a screenshot.
enh-ruby-mode : Personally I am big fan of Enhanced Ruby Mode. It gives you better syntax highligting, better indentation schemes and code intelligence without running
flymakekind of thing.
You can see rest of my enh-ruby-mode specific configuration in file 01ruby.el. You will notice that I have included a mini
rspec-modethere , which allows me to run specs of a complete file or just spec under the cursor.
smartparens : smartparens mode is too much of a moving target and hence I always use it from git. My
(require 'smartparens-config) (require 'smartparens-ruby) (smartparens-global-mode) (show-smartparens-global-mode t) (sp-with-modes '(rhtml-mode) (sp-local-pair "<" ">") (sp-local-pair "<%" "%>"))
SmartParens mode is many things. It automatically inserts closing parethesis, tags, end’s depending on major-mode. Highlights them, allows you to move between them. Allows you to wrap existing texts. However you may not even have to go through their documentation, it mostly just works.
Projectile Mode : Projectile is one among many ways of handling projects in Emacs. My projectile configuration looks like:
(require 'grizzl) (projectile-global-mode) (setq projectile-enable-caching t) (setq projectile-completion-system 'grizzl) ;; Press Command-p for fuzzy find in project (global-set-key (kbd "s-p") 'projectile-find-file) ;; Press Command-b for fuzzy switch buffer (global-set-key (kbd "s-b") 'projectile-switch-to-buffer)
Rainbow Mode : Add color to your css/scss. Check screenshot below:
Robe Mode : Robe mode is what makes Emacs full featured IDE even comparable to likes of RubyMine etc.
Robe can also integrate with
auto-completemode to provide more intelligent auto-completion. I personally do not use that feature because it makes things slower.
Highlight indentation for Emacs : Highlight Indentation mode allows you to see indentation guides. My setup for the mode is:
(require 'highlight-indentation) (add-hook 'enh-ruby-mode-hook (lambda () (highlight-indentation-current-column-mode))) (add-hook 'coffee-mode-hook (lambda () (highlight-indentation-current-column-mode)))
Yasnippet : Yasnippet is Emacs snippet library. Out of box it won’t work with
enh-ruby-modebecause it searches for
ruby-mode. You can make it work by copying
Flyspell : If you are like me, you make lot of typos in code comments, strings etc. Using
Flyspellmode you need not worry about it - interfering with programming language keywords etc. My setup for
(require 'flyspell) (setq flyspell-issue-message-flg nil) (add-hook 'enh-ruby-mode-hook (lambda () (flyspell-prog-mode))) (add-hook 'web-mode-hook (lambda () (flyspell-prog-mode))) ;; flyspell mode breaks auto-complete mode without this. (ac-flyspell-workaround)
If you are on OSX you may have to run
brew install ispellto make it work.
Rinari : With Projectile mode, I am finding less and less use of this mode. But this is your canonical rails mode for Emacs. Get it via
package-installor Rinari Github repo.
textmate.el : textmate.el allows me to quickly move between methods in a file, independent of programming language mode (and without ctags). It has many other utilities.
WebMode : For a long time Emacs users were mostly stuck with half-assed multi-language mode when editing html templates. WebMode is like breath of fresh air for those who mix - ruby/js/css/coffee in their HTML!
Learning Emacs in a way is - as deep as you are willing go. For resources I recommend: