26 Oct 2026

M-x keep-lines

I used to work as a freelancer. And of course I did my bookkeeping in Emacs. One task was noting down the time I spent on each project each day.

I can already hear you saying: "Sure thing, use org-clock!" But org-clock was more machinery than I needed. Especially because I wasn't always in Emacs (yes, sad, but true) when I worked for my clients. Sometimes I was running workshops or coaching sessions away from the keyboard.

I just had an org-file with a simple list like this:

+ [ ] [2026-10-21 Wed] project A; 0,5 h; status meeting
+ [ ] [2026-10-22 Thu] project B; 1,5 h; coaching

At the end of each month, I would turn this list into invoices for my different clients. And since every client had their own specific template and invoicing requirements, I didn't bother to set up an automated workflow in Emacs. I just had this list and a little macro that converted it into CSV and I handled the rest manually. (Maybe today, with the power of LLMs, I would try to vibe-code some automation.)

Now, to prepare an invoice, I only needed the lines for that particular client. I did know about the wonderful function flush-lines. It just removes lines matching a regexp. I was already wondering how to negate my regexp used for flush-lines … then I thought: "Maybe there's a sibling function for this purpose?" And behold, Emacs had me covered: M-x keep-lines exists and does exactly what I wanted.

This might sound too small to bother mentioning. And maybe my workflow makes you cringe. But that's that two things that I love about Emacs: You can do things your very own way. And sometimes, improving your workflow doesn't take a package or a custom function. Just finding the command that's already there.

And that is so satisfying about living in Emacs!

Other posts

Contact: emacs@tutanota.de

Text and images: © 2026 Badore, CC BY-SA 4.0. Code examples written for this blog: © 2026 Badore, GPL-3.0-or-later. Code from third-party projects remains under its original license and is attributed in the relevant post.