Random Figure

Liangcheng Yu

I am interested in systems and networking. This is my homepage and blog.
Email: leoyu@seas.upenn.edu

Awesome Emacs - A minimalistic collection of features

20 Dec 2018 » tips

Spoiled by modern IDEs (and probably the absence of CS background during my undergraduate), I originally treated text editors such as Emacs/Vim as a burden and simply used them reluctantly for terminals. I started to seriously exploit Emacs when I happened to witness during my internship how my mentor, a senior C programmer, live in Emacs. Especially, I was impressed when he fetched technical notes from his decades of experiences recorded by OrgMode, which precisely answered my question, in just several keyboard strokes before I realized it.

I don’t care what OS I use, it’s just a boot loader for Emacs anyway. - Some U. Penn PhD student

Despite the Emacs steep learning curve, I was motivated by OrgMode, the Emacs killer application, whenever I tried to give up. Fortunately, commands and interactions that appeared unintuitive at the beginning gradually made a lot more sense and I was fascinated by the unparalleled power of Emacs. I summarized a short list of Emacs features that benefited me most during my Emacs exploration.

Note Taking

  • Org-drill: I used it to make flashcards (e.g., two-sided cards) with embedded spaced repetition algorithm to recap easy-to-forget knowledge in programming, German vocabulary and so on.
  • Org-capture: It provides an interface of template configuration to snapshot formatted information.
  • Tag management: One could set custom tags for the item via C-c C-q and search targeted tags via C-c a m and proper syntax.
  • Exporting: Emacs supports the compatible translation of org file to Latex, HTML and so forth. One could write equations and formulas as if in tex files.

GTD Workflow

Emacs is an excellent tool for task management. I use org-agenda to manage TODO items and develop regular habits. This tutorial provides detailed steps to set up a personal agenda.

Portable & Scalable Configuration

Emacs can be highly customized. When Emacs starts, it will consider ~/.emacs.d/init.el config file as the point of entry by default. One could place all Emacs configurations under ~/.emacd.d folder and back it up. Emacs also allows scalable configuration. For me, I prefer to use ~/.emacs.d/init.el as the top layer to load config.org file using org-babel feature. The benefit here is that one could combine the Emacs-lisp config code and OrgMode text to provide a self-explanatory configuration file.

(defconst root-path "~/emacs.d/")
(org-babel-load-file (concat root-path "config.org"))

One could place the Emacs-Lisp code to be evaluated in config.org, which then serves as a sub-layer to load my custom config modules classified by their functions.

#+BEGIN_SRC emacs-lisp
((add-to-list 'load-path (concat root-path "modules/"))
(require 'key-bindings)
#+END_SRC

Correspondingly, modules such as ~/.emacs.d/modules/key-bindings.el should end up with (provide 'key-bindings) declaration to enable the import.

Custom Shortcuts and Variable Defaults

One could easily configure the favorable keyboard shortcuts to interact with Emacs. E.g., provide shortcuts to Emacs function comment-region and uncomment-region instead of using M-x to interactively trigger the function, which I found it inconvenient,

(global-set-key "\C-x\M-c" 'comment-region)
(global-set-key "\C-x\M-u" 'uncomment-region)

To set <f2> as a shortcut to open Emacs init.el file, one has to define the function before attaching,

(defun open-init-file()
    (interactive)
    (find-file "~/.emacs.d/init.el"))
(global-set-key (kbd "&ltf2&gt") 'open-init-file)

One could also configure the default variable values to modify the Emacs default behaviors. E.g., to ask Emacs OrgMode to unfold all subsections,

(setq org-startup-folded "showall")

A Nice Welcome Page

I prefer a simplistic default welcome page. Emacs allows us to configure it freely.

;; full screen by default
(setq initial-frame-alist (quote ((fullscreen . maximized))))
;; remove startup screen
(setq inhibit-startup-screen t)
(setq inhibit-startup-message t)

I also used quoted-scratch to pop my favorable saying in the start-up screen.

Handy Preferences

Default Emacs UI interactions suffer me a lot. I put a collection of minimal & comfortable settings in GitHub repo.

Plethora of Possibilities

There is a spectrum of Emacs potentials with Emacs-Lisp Programming1. I also use it (but less often) as a terminal (M-x term), file system (M-x dired), platform to browse the website, read emails and so forth.