Author: Chen Bin (redguardtoo) Master Emacs in one year
Created: [2012-01-31 Tue 15:08]
Copyright: This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.
I was a Microsoft fan because I was born in China. There was no Unix culture when I was young. My professor knew as much as I knew about Unix. Basically it’s nothing. I believed Microsoft Windows was the only platform worth developing software on. I believed Visual Studio was the best IDE in the world. I was so loyal to Microsoft that I used Visual Studio to edit the code running on Linux server in my first job.
Besides, computers scared me to death. I’m ashamed to admit now that when I graduated from university I didn’t know clipboard. If I need input duplicated texts, I typed them character by character. I chose an IT career simply for money.
My point is if a computer dummy like me can be good at Emacs in one year, you can do better.
Here is the structure of the article:
- Why Emacs matters? You can skip this part if you are familiar with Linux/Unix
- The key point of guide is take full advantage of Master’s work. Don’t re-invent the wheel
- The steps to master Emacs
- How to improve after grasping basics by learning from community and books
- What matters is people
- FAQ and Summary
Why Emacs (OPTIONAL)
I intend to keep this section short because my focus is HOW instead of WHY.
Emacs master is good at other editors naturally
Master has already known the best, so she/he has higher expectation.
For example, the master expects:
- a good editor should have a package manager bundled. She/He is surprised that package manager is NOT bundled in some editor.
- Broken package could be fixed without touching the package’s original code.
- When remote repository is down, she/he can create a repository in the memory stick in one minute.
In summary, she/he knows more than Emacs’ competitors can implement.
Community is strong
IDE is optimized for one framework. Emacs can do everything in great way.
It lives forever
The installer is a 50M bytes zip file. The program is portable.
What matters is attitude
If I could only give one piece of advice, it would be being open minded.
Newbies may be surprised by following facts:
- I don’t know 80% “newbie-must-know” key bindings because I don’t need to
- I don’t start from my own simple setup at the beginning
- I actually don’t fully understand Lisp “if” statement after I’ve already developed useful Emacs plugins and written hardcore Emacs articles.
- I use my spare time in one year to master Emacs
Step by Step Guide
- “C” means “Ctrl” and “M” means “Alt”
- “M-x my-command” means press “Alt” and “x” together, enter “my-command”
Quick start for greenhorns of Linux/Unix (OPTIONAL)
Here are the steps:
- Install Emacs 24
- Don’t install any plugins
- Learn basic knowledge about environment variable and pipe
- Read the official tutorial
- Use org-mode
- The only hotkey you need learn in org-mode is TAB key
Use Emacs in this way for several days in order to understand:
- Why people love Emacs
- How Emacs interact with other programs
Read the official tutorial
Steps to read tutorial
- Start Emacs with minimum setup. I suggest running command “emacs -nw -Q” in shell
- “M-x help-with-tutorial”
This tutorial takes half an hour. Not too much time for a life time skill.
Please do not skip it.
At minimum, you need learn help commands:
- “M-x describe-variable”, hotkey “C-h v”, display documentation of variable
- “M-x describe-function”, hotkey “C-h f”, display documentation of function
- “M-x describe-key”, hotkey “C-h k”, display documentation of function invoke by key
Start from practical problem
Most newbies need a notes taking tool. So Org-mode is the answer.
If you don’t start by solving real world problem you will lose interest soon. Many people started the journey by learning Lisp. They gave up in the midway.
Set the priorities
Focus on your most critical issue only. Ignore other issues temporarily. Sometimes compromise is a better strategy.
For example, I always use Emacs in terminal because at the beginning my most urgent problem is to edit the file on the remote server.
After a happy year with Emacs, I’m curious why other people keep complaining that their Emacs issues, especially on OSX (font not rendered properly, window not maximized, cannot increase font size, etc). It turns out they are using GUI version while I’m using terminal version. My terminal application already take over and solve these issues perfectly.
On the shoulders of giants
This is the most important section!
I learned the lesson the hard way. At the beginning, I regarded Emacs as a toy. I dug around the internet for cool code I can copy.
That’s totally a waste of time if my goal is to become an Emacs master!
I should have used Steve Purcell’s setup at the beginning!
Please don’t repeat my mistake. Just follow Steven Purcell!
Let me be blunt. You are a newbie, you’d better study top geek’s code. Don’t try to be “creative” at this stage. You won’t create anything when re-inventing the wheel.
For example, some readers tell me that Emacs has too many hotkeys. They can’t memorize all of them. This is typical in newbies who assume that top geeks can remember more key bindings.
If you have studied any master’s setup, you will find that she uses Smex, as it is more efficient than pressing hotkeys.
Since Steve Purcell loves new technologies and update his setup frequently, it may be a little harder to follow him for beginners.
That’s actually great. I’m lucky to stick to his setup because pulling from his git branch gets me updated with the latest cool things in community.
When I say “on the shoulders of giants”, I’m stressing that you need set your standard higher. I’m NOT saying the master’s setup is “newbie friendly”. If it happens to be “friendly”, it’s just the coincidence.
This section is discussing the best way to be good, not the easiest way.
There is a difference between best and easiest. For example, a setup using Vim key bindings is NOT easy but definitely best.
If you are still not convinced, consider my reasons:
- Those giants are more intelligent than me. They are harder working than me. How can I reach their level as quickly as possible?
- The obvious way is to join them.
- If you can report a bug about the master’s setup, at least in that moment, you have proven you are better at a certain issue than the master.
- You will get guidance from the master when he/she analyzes your bug report.
For example, I learned some advanced Lisp skill by reporting a bug. The bonus is that bug report is actually a case study. Knowledge from such a case study is hard to forget.
Better yourself everyday
I was inspired by Steve Yegges’ article. Here is the text quoted:
Go look over Paul Nordstrom's shoulder while he works sometime, if you don't believe me. It's a real eye-opener for someone who's used Visual Blub .NET-like IDEs their whole career.
After reading the text, I decided to be as good as Paul Nordstrom. It’s mission impossible considering who Paul Nordstrom is. The reason to set a goal I can never reach is to make me not to stop. Whatever minor task I take, I always ask myself how Paul Nordstrom will handle it. Is my operation efficient enough that Steve Yegge will be surprised?
For example, switch focus between sub-windows in Emacs is not efficient by default. I need press
Ctrl-x O several times to jump to a sub-window. After some investigation, I found switch-window. Press
Ctrl-x O plus number key to finish the operation. I kept searching and found window-numbering. ALT key plus number key is enough. That’s 60% productivity improvement. Alt key is still a little bit far away from my fingers. Another improvement is to use Evil-mode and evil-leader, I need only press comma key and number key to switch window.
Join the community
I suggest focusing on Emacs only in order to take full advantage of communities.
For example, although Quora.com has lots of interesting stuff, do not read/subscribe/follow them unless it’s related to Emacs.
Emacs community on Google+ is the best. The average quality of discussion on Google+ is better.
Reddit is as good as Google+. The advantage of Reddit is that it’s usually NOT blocked by the corporate firewall.
It’s a social network for developers.
You can search https://github.com/languages/Emacs%20Lisp for latest Emacs Lisp code.
If you agrees with my “follow master” strategy, you may like following tip.
I avoid the pain of maintaining by watching other masters’ emacs.d repositories. I get notified by the bugs and fix automatically. All I need to do is clicking “Watch” button on the right top of GitHub page.
Planet Emacsen is the best collection of Emacs related blogs.
Follow the question on specific topic instead general one. For example, “What’s the best Emacs addon” is more useful than “How to learn Emacs”.
Everybody can say something about a general question. But to answer a specific question, you need first-hand experience.
Even if you are only interested in general questions, starting from more practical question is still better. Find the people who provides the best and the shortest answer and follow her.
I use keyword “emacs :en” to search latest news. The reason to search English only twitter is that there are lots of Japanese post and I don’t know Japanese.
Insert “emacs-related-keywords site:stackoverflow.com” in Google search engine.
The quality on stackoverflow discussion is good but there are not many new questions there.
http://emacs.stackexchange.com is a Q&A site dedicated to Emacs.
Some videos are great.
For example, Emacs Org-mode - a system for note-taking and project planning is the best tutorial on org-mode. Carsten proved that org-mode is simple. The only thing to remember is pressing “TAB” key to expand a text node. That’s the killer feature of org-mode. Other stuff are bonus.
Youtube lists the best matched results at the top. So you will always see the same things. I suggest sorting the results by upload date.
EmacsWiki has all the tips you need for tweaking the Emacs. It’s actively maintained by the community.
People complains that it’s not properly organized so it’s hard to find the valuable information.
Actually, most documents on EmacsWiki is still far better than any other resources. Please be patient and read the full content at specific page.
Emacs Lisp book
I recommend Writing GNU Emacs Extensions by Bob Glickstein. I like his writing style and the way he organizes chapters.
Xah Lee’s Emacs Lisp tutorial is practical and easy to read.
Steve Yegge’s Emergency Elisp is short but it includes the necessary information for writing Emacs Lisp.
Don’t study the Lisp at the beginning until you are confident about your Emacs mastery.
Place your setup at GitHub, publicly
I uploaded my setup onto https://github.com/redguardtoo/emacs.d.
GitHub is the most efficient way of knowledge management because you will never lose the setup.
GitHub is also a wonderful tool for sharing. I benefit a lot by sharing. People who use my setup are actually helping me perfect my setup. I am the first guy who benefits from a better setup.
For example, people reported that I mixed my personal stuff (email address, full path of my hobby project) into my setup which they need remove. They expected it usable out of the box.
So I re-organized it and placed private stuff into a independent file named “privacy.el”. That file is outside of my Emacs configuration. Then it occurred to me that in corporate environment it was not safe to store plain privacy.el on a shared computer without encryption. After some research, I found Emacs already provided a perfect solution since version 23.
In order to get the most benefit of sharing, you need make sure your setup is qualified to share publicly. Never mix your personal things into it.
I use Dropbox to back up documents. Since dropbox will synchronize the documents into the mobile devices, I can study Emacs when commuting.
My favorite Emacs addons
They are not must-have addons. There are many other alternatives which are as good as the listed.
New users have two problems on plugins:
- use plugins out of maintenance
- use not-the-best plugins
So I list the actively-maintained-and-high-quality plugins to help newbies start:
|Evil||convert Emacs into vim||none|
|Org||Get Things Done (GTD)||none|
|expand-region||selection region efficiently||none|
|smex||Input command efficiently||none|
|ivy or helm||a framework to choose candidates||ido|
|smartparens||auto insert matched parens||autopair|
|window-numbering.el||jump focus between sub-windows||switch-window.el|
|web-mode||everything for edit HTML templates||nxml-mode|
|magit||Everything about git||None|
|git-gutter.el||Mark the VCS (git, subversion …) diff||None|
If some plugin is not included in above list and you are not sure about its quality, please go to MELPA’s website to check its number of downloads.
Emacs is a way of life
So what benefit can I get after knowing the Emacs way?
After mastering Emacs, I could not endure the default key bindings of Firefox. So I installed an addon Keysnail to convert Firefox into Emacs. That doubled my speed in browser navigation. As a web developer, I am doing the browser navigation thing everyday.
Then I realized that Keysnail was awesome because its developer mooz was awesome. I followed him and used whatever he used. His percol made all my operations (git, file navigation, database management …) under shell ten times faster.
Things that used to be important become trivial now. For example, I don’t care which text editor has better file explorer. Why should I use any file explorer if I am ten times faster in shell?
We are living in the world of science and engineering. I improve myself more quickly by sharing to the best, by learning from the best. Knowledge is not black magic. Hiding knowledge will make it stale.
All roads lead to Rome. It doesn’t matter which road you choose. What matters is walking on the road right now.
But please make sure you actually understand the key points of this article at first.
For example, do you realize that previous sections imply following actions:
- Find all the developers of the Emacs plugins I listed
- Follow them on Quora/Twitter/GitHub/Reddit/Google+
- Read all their old posts on Quora/Reddit/Google+
I’m Emacs dummy. How to start?
Any documentation on Steve Purcell’s setup?
Nope. Read its README and code comment. The header of the code file usually has some guide and the developer’s email.
Is Master’s setup too heavy weight?
No. It is lightweight actually. Masters know how to optimize their Elisp code.
For example, they use a technique called Autoload. It will load a module when and only when module is actually used. I’m 100% sure all the setup I mentioned has applied this technique.
Any other setup you can recommend except Purcell’s?
I did search at github, here is the list of top ones:
- Bozhidar Batsov’s emacs.d
- Sylvain Benner’s spacemacs (Spacemacs focus on Evil, so it might not be good for non-vim users)
- Eric Schulte’s Emacs Starter Kit.
Which version I should use?
v24.3.1 is the latest stable version, it has been released for more than one year without any big issue. It can be installed easily on any platform.
I’ve watched too many people failed because they started from un-stable version!
Though v24.4 is released, it has some compatibility issues with third party plugins. I suggest you wait at least half a year before switching to the new version.
As a Vi person, why should I turn to Emacs?
Evil, the best of the best!
Why some Vim users cannot accept Evil?
It’s because their customized key bindings conflict with Emacs/Evil default key bindings.
The solution is to use Leader Key in both Emacs and Vim.
Please note in Emacs you need install a third party plugin for this solution.
The other solution is to stay inside the comfort zone of vim.
That’s totally fine if you are OK with the life without Org-mode and Lisp. ;)
Or maybe you can read the section “What matters is attitude”?
I am die-hard Vi user with 14 year experience. After realizing the potential of Evil and Leader key, I re-assign all my vim key bindings according to Emacs configuration.
Another more brilliant example is a guy who earning tons of Github stars.
I don’t like default key bindings
ergoemacs if you prefer Microsoft’s key bindings.
Too many key bindings to memorize
Use Smex. It’s a myth that a Emacs guru must remember many key bindings.
I am not comfortable with other people’s setup. Can I modify it?
Try to understand the master’s setup at first. Don’t make judgment too early. It’s easy to make judgment. But understanding needs wisdom and hard work.
For example, some people reported that there was some weird character at column 80 when editing a file. That’s actually a feature to remind the user not to create any line with width more than 80 columns. Here is the reason.
I’ve cloned the master’s setup but the package is not upgraded.
Remove the file .emacs in your HOME directory. The ~/.emacs.d/init.el has same functionality.
I have some specific question about Emacs
- read official tutorial
For example, google “emacswiki init.el” to understand what’s the init.el.
I got some error message when starting Emacs with master’s setup
That message could be ignored. It’s just the warning message when Emacs can’t find some OPTIONAL command line tool.
If you need install that missing tool, search the list in my readme.
If you are sure it’s actually an error message,
- Run “emacs -nw –debug-init” in terminal
- Send the output to the author of the setup
- Please use bug tracker if possible
My own setup is more controllable
That’s what I thought at the beginning. After several months I realized that I could never be as good as a master like Steve Purcell if keeping this way.
While I spend several weeks to overcome some minor issues in Emacs setup, Purcell has already installed/developed dozens of cool plugins.
If I cannot win, the only strategy is to join him, that’s why I clone his setup and start to report bug for him. Here is first issue I reported. Besides, reporting bugs also gives me the opportunity to talk with the master.
So don’t run away from the master’s huge setup. Regard it as a challenge to improve yourself.
Why I cannot add my own plugins into master’s setup
Though the quality of Emacs plugins are generally good, they may have compatibility issues. It’s usually because plugins are developed by different people. For example, both auto-complete and yasnippet will use TAB key to expand code. So there is conflict if I use both plugins.
That’s another reason to stick to the master’s setup at the beginning.
How to use Emacs on windows
When you have enough knowledge about environment variables and pipe. You can check My answer at stackoverflow to use native windows version.
At minimum, you need set the environment variables HOME and PATH if you prefer non-cygwin way.
What about code-navigation and code-completion?
I suggesting you using IDE when dealing with Java and C# in big projects.
What about web browsing?
I strongly recommend Firefox plus Keysnail. This is the perfect solution for Emacs fans. Trust me, I’ve already investigated every solution.
Firefox v57+ broke some APIs so Keysnail’s development was forced to stop. You can use Google Chrome plus Surfingkeys instead.
I also use Popfile to sort emails. Davmail+Popfile is the best solution!
Why Emacs cannot download packages?
If you are living in North Korea, Iran or China, you need below command line to start Emacs:
http_proxy=your-proxy-server-ip:port emacs -nw
How to configure proxy server is not covered here.
As a greenhorn of Emacs, should I learn Emacs Lisp at first?
Most people lose the interest in Lisp because there its strange syntax and there not many Lisp jobs.
That’s why I stress that you need avoid tweaking Emacs at the beginning. Please copy the master’s setup at first.
Unless you have seen how Lisp gets your job done, you will not have the enough stimulus to finish the its course.
Me, for example, never feel pressed to learning Lisp. Actually, my initial plan is being great without touching Lisp.
As a proof, please visit my github account. Check all the issues I reported at the beginning. As you can see, I know little about Emacs Lisp for a very long time.
After knowing the basics, what to do next?
Find your practical problem which only Emacs can do best. Trust me, Emacs is much more powerful than your wildest imagination.
Here is my example:
- When I use Wordpress blog, I use org2blog to post articles. It’s ten times faster than any other client.
- I installed cmake-mode to do the cross-platform development with cmake.
- window-numbering.el is useful when jumping focus between sub-windows.
- When I work for some huge projects, I use evil-nerd-commenter to comment code lines because I need deal with too many programming languages.
Do I need learn keyboard macros?
No. Emacs Lisp is enough.
But, studying the Lisp code created by macro does help to understand some interesting problems. So I suggest you learn keyboard macro after mastering Lisp.
What do you think “Emacs can do everything”?
I suggest being practical. Sometimes other tools are simply better in real world.
For example, a developer had difficulties to sort a big dictionary file with pure Emacs Lisp. It’s too slow.
After consulting with me, he found that the GNU Sort is much better in this case.
So be practical. Richard Stallman created a whole GNU ecosystem for you. Emacs is only one component. Why not take full advantage of the system?
My blog is at http://blog.binchen.org.
Please don’t ask basic questions, since I’ve already shown you how to find the answer.
- Start from real world problem
- Follow the master
- Report bugs to the master you follow
- Read and practice while following master
This article is published at https://github.com/redguardtoo/mastering-emacs-in-one-year-guide.
Please use GitHub’s bug tracker instead of emailing me directly. GitHub notification mail is always in my first priority folder.
Emacs is actually a platform. Cool people keep appearing. I will update this article from time to time in the future.