My Emacs Config

My config for emacs and ensime usage. Emacs looks for a file called init.el under ~/.emacs.d to load all the required plugins,settings and config. In this post Im detailing my emacs configuration. The varios sections are explain one by one so as a reader you can just copy the contents from top to bottom and paste it in your init.el file before you start using Ensime in Emacs.

Disclaimer : The steps explained here are done in my Macbook. The same should work for linux machines as well excpet for few configs

Defining Package Management and archives

Like any other text editor emacs also have a lot of plugins solving various purposes. Package are hosted in a repository called melpa. The first thing is to configure those repository and install use-package whcih is like the seed package to download others.

;; the package manager
;; ===================
(require 'package)
 package-archives '(("gnu" . "")
                    ("org" . "")
                    ("melpa" . "")
                    ("melpa-stable" . ""))
 package-archive-priorities '(("melpa-stable" . 1)))

(when (not package-archive-contents)
  (package-install 'use-package))

(require 'use-package)

Configuring packages

the below section details about the various plugins which I’ve configured. This section is heavily inpired from here. Thanks to Fommil the maintainer of Ensime project / comminity.


the fist package we are going to install is ensime which pulls out the ensime server and other goodies like code autocompletion, formatting and sbt compatibility etc. The complete features and functionalities of ensime is listed here

(use-package ensime
  :ensure t
  :pin melpa-stable)


simple project management as seen in Eclispe,IDEA but without lot of config files .idea or .project etc its similar to .gitconfig.

(use-package projectile
  :init   (setq projectile-use-git-grep t)
  :config (projectile-global-mode t)
  :bind   (("s-f" . projectile-find-file)
           ("s-F" . projectile-grep)))

Undo Tree

simple visualization of changes happed to the buffer undo-tree

(use-package undo-tree
  :diminish undo-tree-mode
  :config (global-undo-tree-mode)
  :bind ("C-S-t" . undo-tree-visualize))


emacs minor mode auto complete

(use-package flx-ido
   ido-enable-flex-matching t
   ido-show-dot-for-dired nil
   ido-enable-dot-prefix t)
  (ido-mode 1)
  (ido-everywhere 1)
  (flx-ido-mode 1))


(use-package highlight-symbol
  :diminish highlight-symbol-mode
  :commands highlight-symbol
  :bind ("C-S-h" . highlight-symbol)

(use-package goto-chg
  :commands goto-last-change
  :bind (("C-." . goto-last-change)
         ("C-," . goto-last-change-reverse)))

(use-package popup-imenu
  :commands popup-imenu
  :bind ("M-i" . popup-imenu))


the awesome git client for emacs

(use-package magit
  :commands magit-status magit-blame
  :init (setq
         magit-revert-buffers nil))

(use-package git-gutter)

helm & helm projectile

its documentation provides much more info and its a worthy read :)

;; the great helm mode
(use-package helm
  :diminish helm-mode
    (require 'helm-config)
    (setq helm-candidate-number-limit 100)
    ;; From
    (setq helm-idle-delay 0.0 ; update fast sources immediately (doesn't).
          helm-input-idle-delay 0.01  ; this actually updates things
                                        ; reeeelatively quickly.
          helm-yas-display-key-on-candidate t
          helm-quick-update t
          helm-M-x-requires-pattern nil
          helm-ff-skip-boring-files t
          helm-autoresize-mode t)
  :bind (("C-c h" . helm-mini)
         ("C-h a" . helm-apropos)
         ("C-x C-b" . helm-buffers-list)
         ("C-x b" . helm-buffers-list)
         ("M-y" . helm-show-kill-ring)
         ("M-x" . helm-M-x)
         ("C-x c o" . helm-occur)
         ("C-x c s" . helm-swoop)
         ("C-x c y" . helm-yas-complete)
         ("C-x c Y" . helm-yas-create-snippet-on-region)
         ("C-x c b" . my/helm-do-grep-book-notes)
         ("C-x c SPC" . helm-all-mark-rings)))

(use-package helm-projectile
    (require 'helm-projectile)
  :bind (("C-x t" . helm-projectile)))

move or swap lines

move lines or selection up and down

;; move lines with ease
(use-package drag-stuff
    (drag-stuff-mode t)
    (drag-stuff-global-mode 1)))

smooth scrolling

This is not required on Mac if using RailwayCat fork of Emacs RailwayCat

much refined scrolling in emacs

(use-package smooth-scrolling
    (require 'smooth-scrolling)
    (smooth-scrolling-mode 1)))

persistent scratch

(use-package persistent-scratch

only for Mac users

emacs confuses between the command , option and control keys in Mac keyboard, hence we can remap them using the following config. We also enable copy paste by cmd + c and cmd + v like any other mac app.

;; changing the command to control mac specific 
(setq mac-command-modifier 'control)
(setq mac-option-modifier 'meta)

;; mac specific 
(cua-mode t)

Configuring the Plugins

now that we have installed the plugins though most of them does not really need special configurations but few of them needs. The comments in-line explain their purpose.

;; show line numbers globally 
(global-linum-mode 1)

;; let the buffer fringe on the left  show git status 
(global-git-gutter-mode +1)

;; highlight matching parenthesis
(show-paren-mode 1)

(column-number-mode 1) 

;; don't show tool bar : use more screen space 
(tool-bar-mode -1)

;; modes
(electric-indent-mode 0)

;; global keybindings
(global-unset-key (kbd "C-z"))

;; keep emacs maximised while startup
(add-to-list 'default-frame-alist '(fullscreen . maximized))

;; use default font across buffer, replace with your fav one 
;; My Choice is Fira Code, SF Mono and Pragmata Pro
(set-frame-font "PragmataPro 14")


line any IDE emacs has many many shortcuts for various actions. Besides the stock ones its also let us to define our own and here are the ones which I configured , feel free to configure your own :)

;; setting shortcut to find file
(fset `yes-or-no-p `y-or-n-p)

(global-set-key (kbd "C-x g") 'magit-status)
(global-set-key (kbd "C-c d") 'kill-whole-line)
(global-set-key (kbd "C-x e") 'ensime)
(global-set-key (kbd "C-x o") 'ensime-refactor-organize-imports)
(global-set-key (kbd "C-x a") 'org-agenda)
(global-set-key (kbd "<C-up>") 'shrink-window)
(global-set-key (kbd "<C-down>") 'enlarge-window)
(global-set-key (kbd "<C-left>") 'shrink-window-horizontally)
(global-set-key (kbd "<C-right>") 'enlarge-window-horizontally)
(global-set-key (kbd "C-c <left>")  'windmove-left)
(global-set-key (kbd "C-c <right>") 'windmove-right)
(global-set-key (kbd "C-c <up>")    'windmove-up)
(global-set-key (kbd "C-c <down>")  'windmove-down)
(global-set-key (kbd "M-x") 'helm-M-x)
(global-set-key (kbd "<C-S-up>")     'buf-move-up)
(global-set-key (kbd "<C-S-down>")   'buf-move-down)
(global-set-key (kbd "<C-S-left>")   'buf-move-left)
(global-set-key (kbd "<C-S-right>")  'buf-move-right)

Spaceline Config

This spaceline config works well with prassee-theme

(set-face-attribute 'mode-line nil :font "Fira Code-12" :weight 'bold )
(setq ns-use-srgb-colorspace nil)
(setq powerline-default-separator 'arrow)
(setq spaceline-separator-dir-left '(left . left))
(setq spaceline-separator-dir-right '(right . right))
(setq powerline-height 27)
(setq spaceline-highlight-face-func 'spaceline-highlight-face-modified)
(spaceline-helm-mode +1)
Publised on August 26, 2019