Kumar Gaurav About

Towards a better Emacs

This post lists some customizations and libs towards a better Emacs IMO. This is an evolving document.

Updated: 4 July 2017

Adding Marmalade

;; In ~/.emacs/init.el
(require 'package)
(add-to-list 'package-archives
             '("marmalade" . "http://marmalade-repo.org/packages/") t)

Better Defaults

M-x package-install[RET] better-defaults [RET]

Github Link


M-x package-install[RET] smex [RET]

;; In ~/.emacs/init.el
;; smex
(global-set-key (kbd "M-x") 'smex)
(global-set-key (kbd "M-X") 'smex-major-mode-commands)
;; This is your old M-x.
(global-set-key (kbd "C-c C-c M-x") 'execute-extended-command)

Github Link

Window Navigation

(global-set-key (kbd "C-x <up>") 'windmove-up)
(global-set-key (kbd "C-x <down>") 'windmove-down)
(global-set-key (kbd "C-x <right>") 'windmove-right)
(global-set-key (kbd "C-x <left>") 'windmove-left)

Find files in git project

M-x package-install [RET] find-file-in-repository [RET]

More info

Ignoring certain files and folders while doing grep

;; Ignoring certain directories while doing rgrep
(eval-after-load "grep"
     (add-to-list 'grep-find-ignored-files "*.tmp")
     (add-to-list 'grep-find-ignored-directories "node_modules")
     (add-to-list 'grep-find-ignored-directories "dist")))

Duplicate a line

(defun duplicate-line()
  (move-beginning-of-line 1)
  (open-line 1)
  (next-line 1)
(global-set-key (kbd "C-d") 'duplicate-line)

Hat Tip

Auto complete

M-x package-install-packages
;; Search for auto-complete in MELPA, mark it to be installed by pressing i at the column and then press x to install

More info

Keep auto save files out of current dir

(setq backup-directory-alist
          `((".*" . ,temporary-file-directory)))
(setq auto-save-file-name-transforms      
          `((".*" ,temporary-file-directory t)))

Running emacs as daemon

I have added the following lines to my shell rc

alias ed="emacs --daemon"
alias ec="emacsclient -t"
alias ek="emacsclient -e '(kill-emacs)'"

Zenburn Theme

M-x package-install zenburn-theme
(load-theme 'zenburn t)

JS editing

M-x package-install[RET] js2-mode [RET]
M-x package-install[RET] ac-js2 [RET]

(add-hook 'js-mode-hook 'js2-minor-mode)
(add-hook 'js2-mode-hook 'ac-js2-mode)
(setq js2-highlight-level 3)


Follow this

Speedbar in the current frame

Speedbar is great for tree navigation. It comes with emacs 24+ by default. To open speedbar in current frame, use this

Find any file in a git project

Use helm and helm-ls-git to get a fast and fantastic project browser.

M-x (global-set-key (kbd "C-x C-d") 'helm-browse-project)