Emacs Workflow Optimization
Emacs is a text editor that does everything. On one hand I'm not the biggest fan, since it's huge and doesn't really follow the UNIX philosophy. On the other hand, I've optimized my entire workflow around Emacs, and love it too much to quit. Besides, it's nowhere near as heavy & bloated as modern Web browsers or Electron programs!
I want to talk about how I use Emacs daily, and how I optimize Emacs to be faster for me.
Speeding things up with ' emacs –daemon'
Emacs takes a long time to start up (almost a second). Now when my computer boots I have it run the command '
emacs --daemon', and from then on I can run the command '
any time. This starts Emacs instantaneously! The Daemon keeps an
instance of Emacs running in the background, but since I run Emacs so
often, it's nice to be able to start it so fast (it doesn't take up much
emacsclient -c' is long to type, I add an alias for it in my
alias em="emacsclient -c" #New emacs acts as emacsclient -c!
I also byte-compile my
/.emacs file with '
M-x byte-compile file RET ~/.emacs', which compiles
.emacs.elc (elc is short for Emacs-Lisp-Compiled). Emacs automatically
uses the compiled file instead of the regular one, which makes the
initial startup faster!
Since I use the i3 tiling window manager, I made some keybinding shortcuts for different Emacs functions:
bindsym $mod+t exec emacsclient -a -c bindsym $mod+F1 exec emacsclient -a -e '(ibuffer)' -c bindsym $mod+F2 exec emacsclient -a -e '(rmail)' -c bindsym $mod+F3 exec emacsclient -a -e '(dired ~/)' -c bindsym $mod+F4 exec emacsclient -a -e '(eshell)' -c bindsym $mod+F4 exec emacsclient -a -e '(eww )' -c
$mod is bound to the
Super key (some people call it the "Windows" key), so if I just want to boot up my computer and read my mail, I press '
Super+F2' and it opens my Emacs mail reader!
Since Emacs is always running in the background, if I quit emacs with '
C-x C-c', my buffers will still exist. If I'm working all day and close Emacs, I can press '
Super + F1'
to open my buffer list, which will still display all of my open files.
Very handy! (If I want to "completely kill" emacs and all the buffers, I
The same shortcuts, but from within Emacs
Although I use the Programmer Dvorak keyboard layout, I never actually changed my Emacs keybindings. I'd say the default bindings work just as well on both QWERTY & Dvorak keyboards.
I did bind some of my favourite functions to the Fx keys, though. If I
currently have an Emacs window open, I don't need to press '
Super+F2' to read my mail, I can just press '
F2' from inside Emacs!
My current bindings look like this in my
;;Emacs has trouble binding dired, ;;so I make a function call dired. (defun my-dired () (interactive) (eval-expression '(dired "~/"))) (global-set-key (kbd "<f1>") 'ibuffer) (global-set-key (kbd "<f2>") 'rmail) (global-set-key (kbd "<f3>") 'my-dired) (global-set-key (kbd "<f4>") 'eshell) (global-set-key (kbd "<f5>") 'eww) (global-set-key (kbd "<f6>") 'run-guile) ;for geiser (global-set-key (kbd "<f7>") 'gnus) (global-set-key (kbd "<f8>") 'info) (global-set-key [(shift f1)] 'byte-compile-file) (global-set-key [(shift f2)] 'kill-emacs) (global-set-key [(shift f3)] 'indent-region) (global-set-key [(shift f4)] 'fill-region) (global-set-key ("C-<backspace>") 'whitespace-cleanup)
As you can see, my in-Emacs and out-of-Emacs bindings are similar,
Super+F2 both open rmail to avoid confusing myself.
Shift+fx keys are for functions I use often and are handy to have as hotkeys.
C-<backspace> gets rid of excess whitespaces at the end of lines (because
M-<backspace> is how I delete full words.)
Reading email with rmail
Rmail is the Emacs email reader. A good introduction can be found by running '
info emacs rmail' at the terminal. I'm just going to talk about how I set my mail up (since, admittedly, I had some trouble setting my mail up)
To send mail I use SMTP. To receive email I use IMAP. Emacs works with a program called Movemail to do stuff. The Movemail command that comes bundled with Emacs doesn't support IMAP, so you may have to install the '
mailutils' package on your own package manager.
Here's what my email config looks like in my .emacs:
(setq send-mail-function 'smtpmail-send-it rmail-primary-inbox-list (list (concat "imaps://mymail%40example.com:" "MyPassw0rd" "@mail.example.com")) rmail-preserve-inbox t rmail-file-name "~/.RMAIL" user-mail-address "firstname.lastname@example.org" user-full-name "Muto")
rmail-primary-inbox-list' variable specifies where my remote mailbox is:
imaps://tells us we are using the IMAPS protocol. This can be replaced with pop:// or pops://
mymail%40example.comis our mail address. %40 is the standard URI way to type the '
@' symbol (corresponding to ASCII Unicode U+0040)
MyPassw0rdis our password. The username & password are separated by a colon.
mail.example.com:993is the hostname we're getting our mail from, followed by the port number (By convention, IMAPS is usually on port 993, but I think this can be different)
rmail-preserve-inbox. By default, even in IMAP, Emacs will
download your emails, then delete all the mail from the server. To stop
this, you can set rmail-preserve-inbox to true. The problem is Emacs
will download duplicates if you reload it twice. The best way to deal
with this is to have a main computer that downloads email, and use
rmail-preserve-inbox on your secondary devices.
rmail-file-name' variable specifies where to store our mail (the default is "RMAIL", but I like it to be hidden, so I specify ".RMAIL")
user-mail-address specifies what your email address should be printed as when you're sending an email to someone.
After all that it becomes easy to invoke '
M-x rmail', which will collect all my mail from my remote inbox. Very nice!
Web Browsing With eww
Start eww with '
M-x eww' and you'll be prompted to make a
websearch (by default, eww uses DuckDuckGo for search results. There are
a few handy features of eww that I use regularly:)
- g reloads the page.
- R switches to "Readable mode", which can be extremely handy, especially for websites that don't support text-based browsers! It determines which part of the page is "readable" content, and only displays that. It doesn't always work, though.
- b adds a page to your bookmarks, and B to view them.
This blog is text browser compatible, and I encourage you to read it with M-x eww.
I'm going to keep this article short. I won't add sections about dired or gnus, as they're well documented in the Emacs manual. I have a lot of things I want to write about on this website, but everything in my oven is barely half-baked. Maybe I'll read a book on how to write interesting articles.