Skip to content

Latest commit

 

History

History
167 lines (142 loc) · 6.53 KB

MyEmacsSetup.org

File metadata and controls

167 lines (142 loc) · 6.53 KB

Emacs From Scratch

This document describes me setting up my Emacs on an Ubuntu system. It walks through from install all the way to configuring it for my use. The following is a backstory to why I use Emacs.

In my early days, I was looking for a universal text editor. The trend was and still is to use specialized IDEs. For Matlab, use the inbuilt Matlab editor, for LaTeX use Texmaker, Texworks etc, for C use Geany or some other IDE, C# use VSTS code etc. This got tiring after a while. Researching into this, I realized that Emacs could be the solution. So I took the plunge and it was cold! As stated by many people before me, this editor has a steep learning curve but learning more about this editor and it never disappoints.

So during the days of my PhD, I used Emacs to edit my papers, Python code, C code and even some Matlab code but Matlab’s IDE just can’t be beat for now. I met with some hiccups along the way but every time, the features offered by Emacs didn’t disappoint. For example, I’m yet to come across something akin to preview-mode in Auctex or something as convenient as Reftex. Also using Emacs s but I was convinced that this would be my next editor as it was just so slick.

Fast forward to May 2017 when I first started my real job at a startup. I was given a Windows machine and with the refusal of the IT manager to format my machine and install Ubuntu, my problems began. Forced used to Virtualbox, I installed Ubuntu MATE and set about replicating the install on my PhD computer. Turns out, all these modern editors, Atom, Sublime, VSTS etc. are a hog for RAM and graphics. With limited RAM and graphics capabilities, I found all these editors to be laggy. At that point, I realized the price of being slick and cool. My trusty old Emacs however had no such issues. It would work just fine on a Desktop, a VM or over an ssh tunnel. It was functional, wasn’t bloated. At that point, I knew that I was going to spend the rest of my life looking for ways to live inside Emacs.

Installation

The following holds from Ubuntu 17.10 onwards. First let us install the basic emacs packages from the repositories

	sudo apt install emacs emacs-goodies-el emacs25-common-non-dfsg	

Let’s start up Emacs and change some settings. From Options -> Highlight Matching Parantheses, Options -> Show/Hide -> Column Numbers. Save all the options, Options –> Save Options to save your first .emacs file. Themes that I like Light

  • leuven

Dark

  • monokai, solarized dark

Add MELPA repository to your package repos

(require 'package)
(add-to-list 'package-archives '("melpa-stable" . "https://stable.melpa.org/packages/"))

ELPA packages present in the Debian repo I use later

sudo apt install elpa-company elpa-highlight-indentation elpa-yasnippet elpa-s elpa-ivy elpa-org elpa-org-bullets elpa-solarized-theme elpa-monokai-theme elpa-zenburn-theme elpa-magit elpa-markdown-mode elpa-magit elpa-pyvenv

Programming

Python

I’m going to choose Elpy as my Python IDE. First we install some required Python packages

sudo apt install python-rope python3-rope python-jedi python3-jedi flake8 python-flake8 python3-flake8 yapf yapf3 virtualenv 

Add the MELPA repo to your packages-list. Refer to Productivity section. Edit your .emacs file Make sure the ELPY packages are installed. Add the following to your .emacs

(package-initialize)
(elpy-enable)
(elpy-use-ipython)
(elpy-rpc-python-command "python3")

The last two lines is to use the ipython3 interpreter by default and to use python3 for as the rpc backend. This is because there is an issue with the function elpy-goto-definition when using the default python(python2) as the rpc backend. Consider the following snippet

   def print_text(text: str) -> None:
	 print(text)
	 return None

   print_text('hello world')

Putting the cursor at the beginning of print_text() and pressing `Alt-.` will fail with message “No definition found”. However removing the type annotation as follows works.

   def print_text(text):
	 print(text)
	 return None

   print_text('hello world')

The issue is with correctly resolving type annotations or more generally function annotations introduced as features in python3 PEP484 and PEP3107 respectively.

R

Let’s install ESS

LaTeX

For this, we need to install Auctex

sudo apt install auctex

Add the following to your .emacs file

;;------------------------Auctex Config---------------------------------;;
;; use pdftex by default
(setq TeX-PDF-mode t)
(setq TeX-auto-save t)
(setq TeX-parse-self t)
(setq-default TeX-master nil)
(add-hook 'LaTeX-mode-hook 'visual-line-mode)
(add-hook 'LaTeX-mode-hook 'flyspell-mode)
(add-hook 'LaTeX-mode-hook 'LaTeX-math-mode)
(add-hook 'LaTeX-mode-hook 'turn-on-reftex)
(setq reftex-plug-into-AUCTeX t)
;; for synctex
(setq TeX-source-correlate-mode t)
;;-----------------------------------------------------------------------;;

YAML

Install YAML mode

sudo apt install yaml-mode

Productivity

Org Mode

Install ORG mode

sudo apt install org-mode org-mode-doc

Here should be tweaks to ORG mode over the years How to sync across multiple devices

Magit

Git poreclain for emacs

Part of my emacs file

The following are different small productivity items that help me. Just read the comments.

;;-----------Turn on certain things by default.----------------------;;
;; Recent File Mode
(recentf-mode 1)
(setq recentf-max-menu-items 50)
(global-set-key "\C-x\ \C-r" 'recentf-open-files)

;; Tabbar
(tabbar-mode 1)

;; save/restore opened files and windows config
(desktop-save-mode 0) ; 0 for off

;; Saves mini-buffer history upon exit
(savehist-mode 1)

;; start server at startup
(server-start)

;; line numbers only for programming modes
(add-hook 'prog-mode-hook 'linum-mode)

;; Custom buffer menu function because the default one doesn't put the cursor
;; in the buffer window
(global-set-key (kbd "C-x C-b") 'buffer-menu)