TIL: Distraction free editing in Emacs via "C-x n"(narrow commands)

I dread noisy, busy interfaces. I always preferred minimalist interfaces for my day to day work, and that's why I found the terminal so appealing before switching to emacs.

Today, I was thrilled to find the "narrow" subset of commands under C-x n. (I am still fumbling my way around emacs… like any typical emacs user I guess!)

"Narrow" commands allow you to narrow your buffer down to an entity, such as a block, an org subtree or even a function.

They are very effective at reducing the noise on your screen by showing only what you are working on and hiding the rest away.

For example, in org-mode C-x n s (org-narrow-to-subtree) will narrow your view down to a subtree, hiding away anything outside of your subtree.

For those that enjoy a distraction-free environment, it's an incredibly ally.

Let's say you're working on a task on Project B. You have the following org file.

 * Projects
 ** Project A
  [lots of content here...]
 *** Project B
 **** Meeting last month
[lots of content here...]
 **** TODO /The Task I'm Working On/
-!- This is what I am are currently interested in -!-
 **** Future tasks
[lots of content here...]

In this example, anything outside of "Project B > The Task I'm Working On" is a distraction.

With emacs, you can hide the rest of the buffer very simply. Move your point onto the desired target hit "C-x n s" or "M-x org-narrow-to-subtree".

Now, all you see is in your buffer is the subtree:

**** TODO /The Task I'm Working On/
-!- This is what I am are currently interested in -!-

You can even use "C-x n e" to narrow the view down to the element:

-!-This is what I am are currently interested in -!-

This reduces distraction and noise drastically. I absolutely love this. It is an amazing focus mode that only show what matters to you, at that moment.

Once you are finished, you can "widen" your buffer again using "C-x n w".

What's also fantastic, is applies to programming as well.

For example, you can narrow a file down to a defun with "C-x n d". When working with JavaScript for example, a defun is a essentially a function.

By typing "C-x n d", only the function under the point remains visible. I find that very neat, for example if you want to focus on a HTTP handler, or a certain algorithm, without being distracted by the rest of the file.

Finally, "C-x n n" narrows to the region, which give you the flexibility to narrow down to any region by marking the area you wish to keep on the screen.

These are the types of features that makes enjoy using emacs.

I can see myself coming up with interesting way of combining narrow-to-region with custom selectors to deal with some large legacy files I sometimes encounter at work (once I've leveled-up my elisp skills!).