Todoist Vim



Todoは更新し続ける。 やることができず、期日を超えてしまったタスクは、それが残っている事自体がやる気を下げるし、常態化することで本当にやらなければいけないことかどうかわからなくなって麻痺してくる。 期日までにTodoができなかったということは、タスクがそれだけではやる気が. I haven’t opened Vim in 3 days. In fact, I’ve aliased it to launch Emacs instead. My search history includes terms like “Todoist in Emacs”, “Web browser in Emacs” and “Email client in Emacs”. I’m turning into one of those people, and I’m loving it.

I’ve been a staunch Vim user for a long time now, and recently switched over toEmacs. Time to fight the other side of thewar!

I’ve got years worth of muscle memory tied up to Vim Key Bindings, so it’sunlikely that I’d have considered this change if it weren’t forevil-mode.

Before we start, an obligatory xkcd comic:

Sections in this article:

  • Spacemacs: The Good
  • News from the dark side

Emacs Distribution vs Vanilla Emacs

I went for an Emacs distribution over vanilla Emacs because there were twothings I didn’t want to have to configure for scratch:

Todoist Visual Board

  • A modern-looking UI
  • Vim emulation layer

I ended up picking Spacemacs, because the READMEresonated with what I was looking for, and it was pretty popular. I did feelthat it was likely to be too bloated for my use case, but spacemacs-base (aminimal set of packages that you can build upon) seemed to solve that problem.

Spacemacs: The Good

A few features in Spacemacs that came as pleasant surprises:

1. Find/Replace Live Preview

Best explained with an asciicast:

Todoist Vim

Compared to this, find/replace in Vim feels like working with a blindfold on!(Yes, I do use :incsearch)

2. Case-sensitive substitution

Substitution in Spacemacs is case-sensitive by default, unlike in Vim where Ihad to use vim-abolish.

For a good explanation as to why this is useful, read vim-abolish’sREADME. A quick excerpt:

One time I had an application with a domain model called “facility” that neededto be renamed to “building”. So, a simple search and replace, right?

  • :%s/facility/building/g

Oh, but the case variants!

  • :%s/Facility/Building/g

  • :%s/FACILITY/BUILDING/g

vim-abolish combines all of these into one command.

3. Live Documentation

Learning key-bindings in Spacemacs is surprisingly easy, because it shows yousuggestions as you start a key sequence.

I later learnt that this is powered by thewhich-key package.

Spacemacs: The Bad

Spacemacs shows a prompt on the first install that asks you whether you want touse spacemacs, the full-featured distribution, or spacemacs-base, a minimalset of packages that you can then build upon.

Since I wanted a minimalist setup that I could later configure as needed, I wentwith spacemacs-base.

When I did reach out for configuration options though, problems startedcropping up.

Todoist View All Tasks

While the Spacemacs config file is well-documented, a lot of the options inthere only apply to spacemacs, and not spacemacs-base. Toggling configoptions felt something like this:

me: changes config value

Hmm, that didn’t work. Maybe I’m using the wrong value?

me: re-reads documentation

Doesn’t look like my mistake. Maybe a restart would help?

me: restarts Emacs

Still doesn’t work.

me: greps for config key in Spacemacs source code

me: finds the layer that uses it

me: tries to open layer documentation

Vim

spacemacs: layer not enabled

Oh, spacemacs-base 🤦

After a couple of encounters like this, it started to become clear thatspacemacs-base was an afterthought, not a first-class citizen.1

I then switched to spacemacs instead of spacemacs-base. My mistake wasapparent seconds later. After the reload, spacemacs installed ~140packages (iirc). Opening a project was noticeably slower, and when I startedediting files Spacemacs just kept freezing up randomly in the middle. Speak ofbloat 🙄. I’m fine with not-so-fast startup times, but this was affecting basicoperations like navigating through a file. (For context, I’m running a prettylean setup: Arch Linux on an Macbook Air with 8 gigs of RAM)

I quickly course-corrected and switched back to spacemacs-base. Maybe thewrangling with disabled layers wasn’t so bad?

Spacemacs: The Ugly

Throughout my experience, the spacemacs documentation had always felt a bitrough on the edges. I was able to note down 3-4 mistakes (simple ones) in thefirst couple of hours. I didn’t make much of this at first, just assumed that itwas because the project had a large amount of changes going in.

At the end of my first day with Spacemacs, I sat down to fix the documentationmistakes I had identified. As the contributingguidementioned, I switched to develop. To my surprise, the fixes I intended to makewere already present!

Todoist Vim

Assuming that these were recent fixes that hadn’t made it to master yet, Ichecked the date on those commits. They were created 2 years ago. I thenchecked the latest stable release for Spacemacs - turns out it was released morethan a year ago. Something was wrong here. This isn’t what one would expect froma “community-driven” Emacs distribution.

I asked for help on Gitter, and was toldto use develop instead of master. That didn’t sound right - The READMEdidn’t mention anything about develop, and the online documentation was stillwired to master.

I then asked about this onReddit,and got this answer:

This is a persistent issue in the spacemacs community. I think only syl20bnrhas commit access to master and so only he gets to decide what commits areworthy of being cherry picked into master. Master hasn’t had a version bumb in2 years despite the v0.300 milestone being reached awhileago. Here’s some githubissues that raise your question:#12418,#11191

The deeper issue of maintainers and repository access was addressed two yearsago. Unfortunately thingshaven’t improved much since then since than. While there are fewer open PRs,there are now over 2.3k open issues and that number only ever seems to grow.This continues to prompt questions of more active forks/bettermerging.

- reddit link

DOOM Emacs to the rescue

The fiasco with Spacemacs was enough to have me looking around for otheralternatives. A quick search yielded a lot of praise forDOOM Emacs. I didn’t want to get ridof Spacemacs altogether just yet, so I used chemacs(an Emacs profile switcher) to install both side-by-side.

DOOM Emacs was far faster to boot, and had a more appealing & minimalist UI(IMHO). When I ran into installation troubles, doom doctor always had friendlyerror messages. I was also impressed by the quality of answers in theirFAQ.

I did have to customize DOOM Emacs a bit to get it running the way I wanted itto though. Spacemacs, in comparison, was more useable out-of-the-box.

News from the dark side

I’ve now gotten to a point where I’m comfortable using Emacs as my primaryeditor. I’m typing this article out in Emacs, with my web server processrunning in a terminal inside Emacs.

I haven’t opened Vim in 3 days. In fact, I’ve aliasedit to launch Emacsinstead.

My search history includes terms like “Todoist in Emacs”, “Web browser in Emacs”and “Email client in Emacs”.

Todoist Video Tutorial

I’m turning into one of those people, and I’m loving it.

  1. If this was designed better, I’d expect that in some form Spacemacs wouldbe able to communicate the fact that a config option isn’t going to takeeffect because the requisite layers weren’t enabled. ↩

I’ve been using the gunicorn WSGI server lately while I work on my next project. gunicorn is fantastic, except for one tiny nuisance. I have to restart gunicorn as I change my app code. At the beginning, this meant I would switch over to the terminal where gunicorn was running. Then I’d kill the parent process by hitting CTRL+C, and then start it up again, by typing:

Todolist Vim

gunicorn crazyproject.webapp:make_application

Other frameworks often have a development mode that forks off a helper process that watches the source code folder. When some file changes, the helper tells the server to reload.

I’m not using any frameworks this time, so I don’t have that feature. I never really liked the fact that every time I saved a file, I would restart the server during development. Instead, in this case, I want to easily restart gunicorn, but only when I want to, and I don’t want to leave my editor.

It turned out to be pretty easy to do.

First I read in the excellent gunicorn docs how to tell gunicorn to reload my app:

How do I reload my application in Gunicorn?

You can gracefully reload by sending HUP signal to gunicorn:

$ kill -HUP masterpid

Next I added a –pid /tmp/gunicorn.pid option to the command that I use to start gunicorn, so that gunicorn would write the parent’s process ID into /tmp/gunicorn.pid.

Todoist Vimeo

Now any time I want gunicorn to reload, I can do this little command in a terminal window:

Todoist

$ kill -HUP `cat /tmp/gunicorn.pid`

Those backticks around cat /tmp/gunicorn.pid tell the shell to do that part of the command first, and then feed the result into the rest of the command.

You can always use ! in vim to run some command-line program. If I had to explain the difference between vim and emacs, the one difference that is most interesting to me is that vim makes it super-easy to send buffer contents to other programs or read buffer contents from other programs, while the people behind emacs seem to think that any external dependency should ultimately be moved into emacs itself. I get the feeling that vim wants to be my text editor, but emacs wants to be my OS.

Anyhow, while I’m in vim, I run that command to restart like this:

: !kill -HUP `cat /tmp/gunicorn.pid`

Todoist Views

After using that code for a while, and feeling confident it worked right, I mapped F12 in vim to do that action for me by adding this little thing to the end of my ~/.vimrc:

:map :!kill -HUP `cat /tmp/gunicorn.pid`

Todoist Video

Now that means I hit F12 when I want to reload gunicorn.