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?

incandescentman
  • 4,111
  • 16
  • 53
  • 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 09:13

1 Answers1

5

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.

anachronic
  • 186
  • 1
  • 4