Swaroop C H

blog books about contact subscribe

Tech - Getting started with my own .emacs.d

17 Oct 2013

Ever since I got back into using OrgMode full-time, I've been using Emacs every single minute of using a computer. In fact, these days, I can't even function without Emacs and OrgMode.

Naturally, it follows, that just like the days when I dived deep into Vim, I'm diving into Emacs these days.

I got interested in Emacs again because of BG's dotemacs, but to truly become familiar, I had to create my own configuration files. It was a great way to learn Emacs Lisp. I have breezed through the initial chapters of the Emacs Lisp Manual and after getting introduced to Clojure recently, Lisp and functional programming doesn't seem that alien any more.

I bumped into Cask and Pallet last week (probably via Emacs-Reddit) and that gave me impetus to kickstart my own .emacs.d over the weekend.

This is how I got started - I created the following files under the .emacs.d directory in my home directory, so it looked like this:

$HOME
 |
 \-> .emacs.d
      |
      \-> install.sh
      \-> Cask
      \-> init.el
Contents of the file install.sh :
#!/bin/bash

if [[ ! -e ~/.cask ]]
then
    echo "Cloning Cask repo"
    git clone git@github.com:cask/cask.git ~/.cask
fi

if [[ $(grep "cask/bin" ~/.bash_profile) == "" ]]
then
    echo "Adding \$HOME/.cask/bin to \$PATH in ~/.bash_profile"
    echo '' >> ~/.bash_profile
    echo "# Added by ~/.emacs.d/install.sh" >> ~/.bash_profile
    echo "export PATH=\$HOME/.cask/bin:\$PATH" >> ~/.bash_profile
fi

export PATH=$HOME/.cask/bin:$PATH

cd ~/.emacs.d
cask install

# For Python / ELPY
# Prerequisite: Install Python as per:
# http://docs.python-guide.org/en/latest/#getting-started
pip install --upgrade elpy flake8 rope jedi ipython

Contents of the file Cask initially was (I've added more packages now, but this is the minimal list of packages that I would use, although ELPY is optional if you don't use Python):

(source "gnu" "http://elpa.gnu.org/packages/")
(source "melpa" "http://melpa.milkbox.net/packages/")
(source "marmalade" "http://marmalade-repo.org/packages/")
(source "org" "http://orgmode.org/elpa/")

(depends-on "ack-and-a-half")
(depends-on "cask")
(depends-on "elpy")
(depends-on "exec-path-from-shell")
(depends-on "flx-ido")
(depends-on "magit")
(depends-on "pallet")
(depends-on "projectile")
(depends-on "yasnippet")
(depends-on "zenburn-theme")
A minimal init.el looks like:
;; /This/ file (~init.el~) that you are reading
;; should be in this folder
(add-to-list 'load-path "~/.emacs.d/")

;; Package Manager
;; See ~Cask~ file for its configuration
;; https://github.com/cask/cask
(require 'cask "~/.cask/cask.el")
(cask-initialize)

;; Keeps ~Cask~ file in sync with the packages
;; that you install/uninstall via ~M-x list-packages~
;; https://github.com/rdallasgray/pallet
(require 'pallet)

;; Root directory
(setq root-dir (file-name-directory
                (or (buffer-file-name) load-file-name)))

;; Theme
;; https://github.com/bbatsov/zenburn-emacs
(load-theme 'zenburn t)
(set-cursor-color "firebrick")

;; Font
;; https://www.mozilla.org/en-US/styleguide/products/firefox-os/typeface/#download-primary
(set-frame-font "Fira Mono OT-14" nil t)

;; Don't show startup screen
(setq inhibit-startup-screen t)

;; Show keystrokes
(setq echo-keystrokes 0.02)

;; Path
(require 'exec-path-from-shell)
(when (memq window-system '(mac ns))
  (exec-path-from-shell-initialize))

;; Git
(require 'magit)
(eval-after-load 'magit
  (progn '(global-set-key (kbd "C-x g") 'magit-status)))

;; flx-ido completion system, recommended by Projectile
(require 'flx-ido)
(flx-ido-mode 1)
;; change it if you have a fast processor.
(setq flx-ido-threshhold 1000)

;; Project management
(require 'ack-and-a-half)
(require 'projectile)
(projectile-global-mode)

;; Snippets
;; https://github.com/capitaomorte/yasnippet
(require 'yasnippet)
(yas-load-directory (concat root-dir "snippets"))
(yas-global-mode 1)

;; Python editing
(require 'elpy)
(elpy-enable)
(elpy-use-ipython)

And that's it, a full-fledged Emacs setup is ready.

The best part is to play around with M-x list-packages and browse around and decide which packages you want to try out and use, when you install a package, it automatically gets added to your Cask file (that's what Pallet does), so you can convert this .emacs.d folder into a Git repository and sync anywhere and have the same configuration available on multiple machines.

So far, I have resisted many things like evil-mode and started really enjoying using packages such as org-pomodoro and ace-jump-mode.

Getting back to Emacs after a decade has been so much fun.

Twitter Comments

@arnab_deka says:

@swaroopch did you try prelude or starter kit? I started with that and added customizations on my fork. Lotsa goodies in there.

@vivekbhat9 says:

@swaroopch all the best :) I tried emacs so many times but failed. Happy with VIM, I hope some day ll write A byte of emacs & I ll emacs den

@vivekbhat9 says:

@swaroopch i hope u got my thoughts :) will learn emacs when u will write A Byte of Emacs. Missed few words in last tweet ;)

Comments

[Tech] Eight programming lessons learned in 2013 says:

[…] again, I have to make a commitment to throw familiarity away. That is what pushes me to learn to customize Emacs despite already having spent years mastering Vim and spent so much time using PyCharm, […]

Syndrome says:

I'm almost ending my one year(really short) marriage to Vim. Emacs and elisp gets me more excited than Vimscript. As soon as I 'm fully weaned on Emacs, I'm moving. One thing that'll really miss is tabs. Emacs' split window just doesn't cut it. How do you survive without tabs?

swaroop says:

@Syndrome I can imagine the Elisp > Vimscript situation and I agree with that (although in future, Vim will have more Python integration). I do miss tabs, but I have just replaced with creating new frames (i.e. windows) by using `C-x 5 2`.

Feedback

There's no comment box, but please do email me or tweet me your thoughts and criticisms, and I will publish the relevant ones here.