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.
spaceline
processes normal mode-line constructs, you could simply add%n
to the appropriate variable. Seemode-line-format
.