Is there a way to get some elements truncated in the (excellent) Emacs Powerline? I'm thinking, in particular, at the which-func-mode
section in the default mode line. It'd be good to see only the first N characters of a function name or section name (when in Org mode), N to be defined.
A side question is: can we simply get components being disabled (that is, not displayed) if the frame is too narrow (80 chars wide, for example)?
Generally you can customize which-func-format
accordingly, e.g.:
(setq which-func-format
`("["
(:propertize (:eval (my-which-func-current))
local-map ,which-func-keymap
face which-func
mouse-face mode-line-highlight
help-echo "mouse-1: go to beginning\n\
mouse-2: toggle rest visibility\n\
mouse-3: go to end")
"]")
)
Where my-which-func-current
is a function that truncates the current function name accordingly:
(defun my-which-func-current ()
(let ((current (gethash (selected-window) which-func-table)))
(if current
(truncate-string-to-width current 20 nil nil "…")
which-func-unknown)))
This approach works with the standard mode line, and with any mode line extension package that supports standard mode line data. I know that Smart Mode Line does, but I am not sure of Powerline. I don't use either of these packages.