Ask HN: Resources to grok Emacs and use it well?
With reference to the other post here (https://news.ycombinator.com/item?id=22875106), I’m once again fascinated by Emacs and the following it has. I know vi (learned it quite sometime ago) and though I’m not a power user, I can do a lot of things in vi without putting in much effort or searching online for solutions.
So I’m here to ask for resources — text based tutorials, video tutorials and what not — that would help someone grok Emacs (from a novice level) and get into the Emacs way of doing things (including elisp?).
I would also like recommendations on what (package/source) you consider as the best to install on macOS and on Linux.
178 comments
[ 0.21 ms ] story [ 1257 ms ] threadAlso emacs is largely self-documenting. Learn the keys for querying documentation first thing. You can search for current keybindings, what a given function _does_, etc all live while you're using it.
On the evil front there is also Doom Emacs (https://github.com/hlissner/doom-emacs) which is better optimized and is still pretty full-featured.
Pretty good resources right at the top.
Start with plain Emacs. Print/write out the popular cheatsheets. Just make sure you know how to exit, access the documentation, and move around the windows/frames/buffers. Get Melpa & install some packages. Play with the config, adding keybindings, figure out hooks and so on. Copy some elisp functions from dotfiles on Github. Spam the documentation command on everything. Get frustrated with how much tinkering you need to do to get the crazy setups you've seen on blogposts. Stay motivated by consuming more content about custom setups. Discover the magic of magit and parinfer and dired. Look up some of the org-mode/PIM heroes on github, usernames: novoid, alphapapa, karlicoss
Install Doom. Tinker with it a bit. Take notes of your learning in an org file. Tinker some more. Go back to plain emacs for a bit. Then try spacemacs. Go straight back to Doom because it's faster and you now understand enough about emacs to be scared of spacemacs' layers.
Below are some links to help you along the way.
http://ergoemacs.org/emacs/blog.html
https://sachachua.com/blog/
https://www.gnu.org/software/emacs/refcards/pdf/refcard.pdf
https://orgmode.org/worg/orgcard.html
https://cestlaz.github.io/stories/emacs/
https://www.youtube.com/watch?v=0g9BcZvQbXU
https://zaiste.net/doomcasts/
If you want something close to what most users probably have setup and yet still close to vanilla you can give Emacs Prelude a try: https://prelude.emacsredux.com/en/latest/
I started with it, tried out the package selection, but then started a smaller config from scratch with what I liked from it.
Also good links: https://www.masteringemacs.org/reading-guide http://emacsrocks.com
I don't believe one should restrict oneself to a single editor, but rather follow a path of least resistance - Emacs is actually the path of least resistance when you want to have a custom editing experience.
Overall I use four editors Emacs, vi, notepad++ and VS Code. Emacs when doing Clojure or any other code so I can have something that is very convenient for me, vi and notepad++ on machines where I don't want to setup a config or where I do only simple text editing and VS Code where I would ocasionally need to install a plug-in, but I don't need to use it often.
So after about a year I started over, resetting my config and using Emacs customization over custom elisp writing to get a working init file. It helped me learn a lot. This is the path I recommend: do small customizations using Emacs' built-in features, then learn elisp later.
I learned a lot from this CS prof's videos, and it's a good, practical learning path I'd recommend: https://www.youtube.com/watch?v=49kBWM3RQQ8&list=PL9KxKa8NpF...
If you're into writing, I maintain a list of resources for writing with Emacs: https://github.com/thinkhuman/writingwithemacs
Unless your passion is in going meta and focus on building the tools instead of using them, chances are that your current tools can do what you need just fine.
I used TECO to get grades back in the day, on a DEC-10. People used to write BASIC interpreters in TECO for fun. Then I went into the wilderness, where every system I used was uncustomizable. And then DOS, where Turbo C and Brief were kings. Eventually the system I used was Windows, and MS Developer Studio (before Visual Studio) had some macro recording capability. Then I joined a company where everything was just more convenient if you put Linux on your desktop, and for my limited Windows work, one of the Windows ports of Emacs was adequate, and a couple of our brightest were always using Emacs. These were the guys I wanted to emulate so I started using Emacs. But then I branched off and started using Eclipse, because I couldn't get ctags to work well enough with all the C++ code I was working with. Eclipse's remote solution seems to be dead so now I'm using Code.
I don't miss TECO.
My biggest increase in productivity was to stop tweaking and just switch to a mainstream OS and use a mainstream editor using the stock config as much as possible (I only changed a handful of settings). I honestly can't think of anything in my current workflow that is a bottleneck to my productivity; the tools are fast enough that the bottleneck is now my brain and thoughts and tweaking the tools won't fix that.
But, even if that were the case, the recommendation would be to either (a) find a lighter alternative to the used IDE or (b) switch to an IDE that is plugin-based to remove all of the "bloatware". At no point I would be telling people that the first alternative for them to "be fast" is to join the church of Emacs.
Fuck, I worked with junior developers who were more comfortable after I showed them they could work with gedit + terminal instead of cargo-culting whatever tool some nerdy senior used.
All I am asking is to not be like those photographers that spend more time on forums discussing about equipment than actually taking pictures, or audiophiles that focus so much on testing their equipment that they forget to enjoy the music. Unless you are a camera maker/speaker designer/software tool developer, focusing on the tools instead of the product is quite a stupid way to live.
Find an expert Emacs user who's willing to help, and have them watch you in person, even for just a short time, as you use Emacs to do things. Lather, rinse, repeat. Make sure they show you how to use the built-in help and feature-exploration mechanisms (but they'll know to do that anyway, if they're an expert).
(https://clojure.org/news/2020/02/20/state-of-clojure-2020)
edit: If you use MacOS, Yamamoto Mitsuharu‘s emacs-mac [3] is my recommendation, as for linux the version from your distros package manager should be apt. ;)
[0] https://github.com/hlissner/doom-emacs
[1] https://github.com/syl20bnr/spacemacs
[2] https://github.com/emacs-evil/evil
[3] https://bitbucket.org/mituharu/emacs-mac
I have a few customizations, not many. My .emacs file is 63 lines long, doesn't include any other files, and mostly just tweaks some key bindings and turns off features that I don't like. The only modes I use are built-in ones (e.g., C-mode, auto-wrapping text mode, etc.). I can't write elisp without a reference manual, and I think that's okay.
I suggest:
- not installing a bunch of random stuff until you're comfortable with the core experience or you simply have to adjust or disable something that bugs you
- just using Emacs, and not customizing the crap out of it, ditto
If you haven't gone through the Emacs tutorial, it's how I learned it (at 300 baud, uphill both ways and in the snow -- not kidding about the 300 baud thing, though).
Beyond that, add language modes for anything you need that's not already included.
If you use 'git', 'magit' is very nice.
Beyond that, helm is interesting, though very large and kind of mind-blowing.
Recommend these in your ~/.emacs.d/init.el, to avoid being that guy:
If you're talking about production hosts, they shouldn't really have vanilla emacs installed either. Not having your creature comforts present on production machines is a feature, like the red shell prompt / terminal background some people use, a reminder to get you to think twice and try to not do things directly in production. If you really must, just use TRAMP, it's amazing.
If, on the other hand, you're talking about using somebody else's laptop to do anything, that doesn't make sense to optimize for, at least in my experience. I prefer not to even touch other peoples' laptops/keyboards.
Tramp is great, but not all such hosts are reachable that way.
> I prefer not to even touch other peoples' laptops/keyboards.
Me too, but that's why they call it work.
I wonder if I'm weird, but I use a highly customized Emacs on my dev machine, but if I have to ssh into a host and edit something I just use vi there. The correct answer to vi or emacs has always been "both" for me.
; try not to use tab characters ever when formatting code (setq-default indent-tabs-mode nil)
(add-hook 'before-save-hook 'delete-trailing-whitespace)
This deletes all whitespace when you save a buffer.
evil is also great, and it might actually be the most popular option for new users at this point, thanks to Spacemacs and Doom.
- Using the spacebar to invoke functionality is a massive physical boon to usage. Stock emacs wrecks me from fingers to neck for an real amounts of usage. This is a purely subjective weakness.
- Spacemacs vi emulation. I drank the modal Kook-aid. Especially if one has to SSH into headless instances in the cloud. vi is part of the POSIX standard, so you know it's there and it's robust.
- Spacemacs engineering. Great package integration in the form of layers.
[1] https://www.spacemacs.org/
https://github.com/emacs-evil/evil-collection
Which provides evil bindings for a lot of modes
The WORST thing about spacemacs though is their absolutely broken release process. The master branch rarely upgrades with fixes applied to the develop branch, and the tacit recommendation is just to run "on the bleeding edge." I have no idea why spacemacs users tolerate this, but my productivity has since improved after ditching it.
I can kinda agree the C++ layer was definitely a bit of a pain, but I had general pain setting up a good workflow for C++ in emacs with the project I was working on (most of the emacs packages assumed a different layout, so couldn't understand my CMakeLists to generate the files it would need to look at for smart completion).
Overall, I quite like spacemacs, I used to hack on it a bit to make it suit my needs better, but now I rarely have anything I need to do it "just works" now.
I particularly appreciate that almost any language I want to use, I can just download a layer (I think it often prompts you to install one when you open the file automatically!) and a lot of the common across languages editor functions you want have similar keybindings, and the `which-key` popup will tell you anything you're missing. It makes a very short ramp up to being productive in your editor for a new language.
Because it's so old, no one bothers to maintain compatibility with it anymore, and almost all modern elisp will break in some way if it's loaded in 22.1. Somewhat fortunately, it seems like Apple has removed this emacs binary from Catalina, so it won't be an issue on future versions of macOS.
To get a modern Emacs: https://emacsformacosx.com/ has binary builds of the official Emacs releases, with some additional scripts that let you launch it from Launchpad, etc.
More than simple fun; I've saved people from hours and sometimes days of drudgery with just a few minutes of mucking about in Emacs. Teaching someone simple automation is pretty rewarding. Even if they are not technically capable of repeating your solution, at least they go away with a problem solved AND the knowledge that there are usually better options available than drudgery.
That and white space mode for examining files..
And, of course, if you do any programming at all, you should install magit immediately. It is the best git experience anywhere, on any platform, period. It is an unbelievable productivity booster, and people who haven't used it do not even appreciate what it can do (ever wanted to quickly apply a single diff from one of your stashes to your current code tree? it's two keystrokes).
Approach emacs like you would a musical instrument: you are not expected to play the piano on your first day, and the first year will require some patience and training, but eventually you'll start playing those sonatas.
[context: my Emacs init file has lines that are 27 years old]
If so, I might want to try it.
1. Go through the Emacs Tutorial. Just start emacs, put the cursor on the text 'Emacs Tutorial' and hit enter. It will only take 30 mins max.
2. Go through the first chapter in the Practical Common Lisp book here: http://gigamonkeys.com/book/lather-rinse-repeat-a-tour-of-th...
3. By now you are comfortable navigating around and editing text, opening files, running emacs commands with M-x etc... so you can now install packages for syntax highlighting for your language etc... via M-x package-install <enter> -> search for your language (usually LANGUAGE-mode), and install it.
4. Use emacs to edit all your files for at least 1 day.
5. Use emacs keybindings to navigate around in other apps if you're on Mac or Linux, those are standard keybindings that work everywhere in Terminal, bash, Textedit, Chrome, etc...
6. Learn how to use vim, download a vim cheatsheet and have it handy for reference, edit some files in vim (git commit messages will also do).
7. Install evil-mode and edit your .emacs.d/init.el file to bind a key to toggle evil-mode on/off
8. In maybe one day max, you're very comfortable in emacs now, and may be well on your way to writing your own extension functions. You're pretty much an emacs expert by now, in only 2 days max!
9. Try out different emacs configs. You can try mine out here: https://github.com/sufyanadam/.emacs.d it's setup for all major languages, Ruby, Python, React, JSX, etc... It also has some soundboard keys bound, try C-c-n-m when you want to greet someone new but don't want to be interrupted (you have to have mplayer installed on your system for it to work).
I will mention cmd-c / cmd-w is still an anomaly. I sometimes capitalize stuff or close windows.
I'd say it depends on what your aim is: (1) would be the way to go if you primarily want to get fluent with emacs, or are content to use tools you already know for other work, and learn plain emacs gradually in the background. (2) would be best if you want to get productive quickly using emacs for real work, at the risk of a more occluded understanding of emacs per se.
I'd put in a word for Prelude (https://github.com/bbatsov/prelude) as a possible compromise, making emacs immediately usable but without putting many layers between you and it. Some might consider it a little old-fashioned however (no use-package etc).
I've used vanilla emacs on and off for many years for quick edits, but only recently for actual programming (using Prelude, and prompted by learning Clojure). It's taking over my computing lifestyle. I've laughed in the past at people using it for email, but found myself using mu4e lately. Scary.
Credentials established, I cannot recommend this tutorial enough:
https://david.rothlis.net/emacs/tutorial.html
He walks you through most of the core of what makes Emacs great by showing you how to make a change to a project in the idiomatic Emacs way.
I would have learned it years faster had I started there.
Beyond that, learn basic Emacs keybindings via the tutorial, as others have suggested.
I started in Emacs but installed evil-mode a few years ago and have never looked back.
I do not recommend Spacemacs. Install the tools you want as you find you want them, so that you know what's doing what, and so you have a decent chance of knowing what broke things when something stops working.
Keep your packages in version control as part of your .emacs.d repository. That keeps updates and deleted packages from screwing you.
Use "use-package" (https://github.com/jwiegley/use-package) for configuring what you install. It's written by one of the Emacs maintainers and will help you do things right by default.
I'm not the best Emacser out there, but if you're curious, my config is on my GitHub account: https://github.com/NateEag/.emacs.d
Happy hacking.
I'm committed to modal editing and vim keybindings already, so spacemacs introduced me to emacs and got me to convert, but it is a 90% for everyone solution. It adds tons of stuff that mostly works, stuff which you specifically mostly don't need.
It mostly works, but coming from vim spacemacs is a big black box for the most part. I think it is a fantastic first step if you need to get something mostly working.
Going through and building up my own .emacs with the parts I wanted was the way I finally learned to grok emacs for real. It took that step to actually be able to understand what's happening when something unexpected happens. I also discovered a lot of alternatives to the spacemacs packages, well known by real emacs users, that I much prefer to the choices made by the spacemacs team.
Once you have a decent idea how the parts fit together, you don't really need Spacemacs, IMO.
I think the last time I tinkered with it at all was about a year and a half ago?
I am currently a spacemacs user (holy mode, ya dirty heathens) and I like a lot of the built in functionality. However, I think that I will eventually build up my own config from vanilla.
https://sites.google.com/site/steveyegge2/effective-emacs
http://steve-yegge.blogspot.com/2006/06/shiny-and-new-emacs-...
http://steve-yegge.blogspot.com/2008/01/emergency-elisp.html
They are at: https://www.youtube.com/channel/UC0uTPqBCFIpZxlz_Lv1tk_g/vid...
Most of the videos are focused on practical tasks you would want to do. It's one of the few really good Emacs focused channels IMO.
* Motivation
This is inspired by an ongoing conversation about emacs with a friend and a debugging interview that I really enjoyed.
* Exchanging emacs tips with a friend
A friend of mine is pretty proficient in emacs: org-mode all the things, written >500 LoC of elisp, tried several distributions. We still regularly teach each other about existing emacs functionality and exchange messages along the lines of: - I just found that there is a function foo, which I have made a keybinding foo and can now search open a tab with a SO search with text from the clipboard - whaaat? That's super useful! - I know, right?
He works with a couple of greybeards, who also seem to be constantly finding emacs functionality that makes their lives easier, which suggests it would be beneficial for all of us to watch others in emacs.
* Interview
I was given a real git repo that I needed to load into my environment (spacemacs on Linux) to debug and fix failing tests. They sat me down during the onsite (the days when we would go to interview in person), told me to download the repo from the URL, told me how to run the tests (after activating the python venv) and watched me debug and fix failing tests - only 5 were failing from about 100. The interviewers were not proficient in emacs, but I felt that they could follow my thought process and workflow. I had only recently set up python dap-mode and felt clunky navigating in pdb through dap, so ended up print debugging.
It made me think how interesting it would be to watch other people with different backgrounds and experiences debug the same problem and how often I would learn new tricks or debugging techniques. Having a good understanding of the problem and the code allows you to focus on the activity of programming and watch out for new ways of tackling the same problem.
* What will we investigate
Furthermore, it might be interesting to see what debugging practices are statistically more succesful in tracking down the bug faster (and control them for overall years of programming experience and emacs proficiency).
If our sample is big enough we can answer questions like: Correlation between overall years of programming experience and debugging time? Who is faster at debugging: printf or gdb debugger people? Which keybindings and modes are most frequent across users? Is there a correlation between having custom elisp functions and debugging time?
* Format
I will prepare a representative repo in the most popular language (I am most comfortable in Python, happy to consider other languages, if people prefer), bury some bugs in it (that will be easy), administer the study and summarise the findings in a spreadsheet/write-up.
Following the debugging session outlined above. Every participant:
starts recording their screen
Starts a fresh emacs instance with their config and loads a emacs lisp script that we provide for printing keypresses and recording keypresses + function calls to a log file.
download the prepared repo
run tests
investigate failing tests
fix them
commit their changes
The participant ends the screen recording session before sending me
I appreciate logging keypresses/function calls might feel intrusive, so if you are uncomfortable doing that - don't! At the same time, if we want to share good debugging practices and general emacs tricks - I see this as the most impactful way to share techniques and elisp snippets.I watch it, sumarise the findings and present a write-up.
Who is interested?
I'll have more comments later, but the first two, slightly related to each other, would be:
1. Are you sure using just one language for the code is a good idea? It's going to instantly turn off large segments of people who would otherwise like to contribute - no matter which language you choose. Further, "the most popular language" may not even be appropriate: there's probably less Java, C#, and C++ programmers who use Emacs compared to the general population. I think the first step here should be a poll to see which languages are actually popular among Emacsers. Once we have the list, we can prepare a couple of codebases using the top 5 entries (for example.) I think I can contribute here - I don't think there'll be a language I'm unfamiliar with on the list. I'm also reasonably confident that, in case the improbable happened, I'll be able to learn that language in a few days. (Assuming there are docs available and so on, the usual disclaimers :))
2. Another consideration: how much time would participants have to prepare? I believe this is crucial. In my case, I have a bunch of "first-class" lang configurations, for the ones I spent the most time with, and "the rest," with configs just barely above bare-bones. If you give me a month, I guarantee I'll have all the possible tools you could use with the lang prepared, and I'll have quite a few hours of practicing their usage. If I had to go for it right now, and the implementation language happened to be outside of ~10-15 languages I use regularly or used extensively in the past - I don't think I'd be up for it.
> Starts a fresh emacs instance
Why a fresh one? Do you want to measure startup time (and later, performance in general)? But then people on the latest and greatest would have an advantage over someone working on a netbook.
> a emacs lisp script
I wonder if this wouldn't be better handled by an external tool. I don't know which, but it might be worth considering.
> logging keypresses/function calls might feel intrusive
You don't need keypresses - commands and functions would be quite enough. To be honest, I'd prefer a short chat with a participant afterward, maybe coupled viewing the replay at 10x the speed. What is valuable, I think, is the thought process behind the chains of commands, and "decompiling" those out of the "assembler" (key presses) of people's minds might prove quite hard.
That's it for now, I'll be happy to talk more about the idea, though I think we should take the conversation off the HN. My email is in my profile :)
I remember checking the thread several hours after posting my comment and assumed that it was so offtopic people didn't engage, hence the delayed reply.
> Are you sure using just one language for the code is a good idea?
The more languages the better, I was only assuming that I would be preparing the codebase myself, hence wanted to maximise ROI by choosing a popular language that I can write.
Adding more languages would be great, however, we would need to keep the code + tests + failures as consistent as possible i.e. no language-specific test failures due to multi-threading unsafety of C++, which Python's GIL prevents. Also I am not sure how useful cross-language comparisons are.
> how much time would participants have to prepare?
Prepare what? Ideally nothing in their language + emacs setup. The whole point is to learn about people's natural emacs workflow and what tricks they use when in the state of flow. I think each participant should only do it once in their "first-class" language, otherwise participants won't enter flow. That way, we control for no previous familiarity with the problem and get the best emacs knowledge and maybe even some elisp snippets others can follow.
To borrow a sports metaphor - I am sure that Tiger Woods can play a decent game of tennis, I would rather get tips from him to improve my golf swing.
> Starts a fresh emacs instance
That was a suggestion born from my workflow that minimises the risk of other buffers getting in the way of the test and preventing users' from leaking personal data during the screen recording.
> commands and functions would be quite enough
Yes and no. Some of Mike Zamansky's youtube videos have an on-screen feed of keypresses, which is interesting to watch for evil-vimlike navigation practices. I cannot promise I will be good at analysing a stream of keypresses and extracting meaningful analyses though, so commands and functions is what I can promise to analyse.
> I'd prefer a short chat with a participant afterward, maybe coupled viewing the replay at 10x the speed.
A chat is a great idea, however, if we manage to get a decent number of participants (ideally 40+ for each language for meaningful stats), my availability for a sync chat will become the bottleneck of the experiment.
I am thinking about replacing it with an async Q&A that the participant can add after completiion.
Helm is pretty amazing and almost worth the cost of Emacs by itself: https://emacs-helm.github.io/helm/
S. Chua's blog is the best "zine" I think: https://sachachua.com/blog/
To avoid "but vi/vim and the shell…" which is a sort of "mental flu" every Emacser has to go through at least once in his life, understand this:
"the UI paradigm of Emacs" is also called a roguelike interface by ESR, vi's too: "In Chapter 11 we described the effect of the absence of standard arrow keys on early roguelike programs; vi was one of these. " http://www.catb.org/esr/writings/taoup/html/ch13s03.html