简体   繁体   中英

Truncation in Emacs Powerline (mode line)

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, eg:

(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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM