4

I'm using Spacemacs, which by default includes spaceline. I'd like the mode-line to indicate whether I'm in a narrowed buffer or not. So when I do org-narrow-to-subtree, for instance, spaceline could display Narrowed.

How can I direct spaceline to display "Narrow" in the mode-line?

  • Assuming that spaceline processes normal mode-line constructs, you could simply add %n to the appropriate variable. See mode-line-format. – phils Dec 22 '16 at 9:13
4

I struggled with this one for quite a while since I wanted the same thing. This is what I did:

Defining a segment is quite straight forward and the documentation is very good in that sense. But that's not enough to get it to show what you want. So, first define a segment that can show Narrowed when you narrow into some defun, region or whatever:

(spaceline-define-segment narrow
  "Display Narrowed when buffer is narrowed."
  (when (buffer-narrowed-p)
    "Narrowed"))

The documentation isn't quite clear about how you should insert this new segment into the whole thing. I dug around the code and found out that you can pass new segments when initiating the mode line. Since in my case I'm using spaceline-spacemacs-theme it suffices to pass this new segment to that function call:

(spaceline-spacemacs-theme 'narrow)

Note that it will insert this new segment in the right part of the mode-line, next to the line numbers and columns in my case. If you want to reorder the items you'll have to create a new theme.

The code provided here was enough for me, though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.