[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: eliding in mode-line-format
From: |
Stephen Berman |
Subject: |
Re: eliding in mode-line-format |
Date: |
Fri, 01 Oct 2021 18:49:54 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
On Fri, 1 Oct 2021 21:23:08 +0700 Yuri Khan <yuri.v.khan@gmail.com> wrote:
> On Fri, 1 Oct 2021 at 21:02, Manuel Giraud <manuel@ledu-giraud.fr> wrote:
>
>> I'd like to have some kind eliding feature in the mode line.
>>
>> As a usage example, I'd like to be able to have "a buffer with a really
>> long and meaning full name" that I'm able to track down (with icomplete
>> for instance) but I want its "%b" mode line representation to be
>> truncated to say n characters ("a buffer with…" for instance).
>
> $ emacs -Q
>
> (setq-default mode-line-buffer-identification
> '(-15 (:eval (propertized-buffer-identification "%b"))))
>
> Now you have buffer names truncated to 15 characters.
>
> (See documentation on mode-line-format, also see the default value of
> mode-line-format and all the parts it gets built from.)
>
> Instead of using a list with a negative number at the front, you might
> prefer defining a function to ellipsize a string. You then get to
> choose an ellipsis character and whether to truncate from the start,
> end or middle.
E.g., I use this:
(defun srb-truncate-mode-line-buf-ident (&optional n)
"Display first N characters of buffer name in mode line."
(interactive "P")
(let* ((b (buffer-name))
(s (unless n (read-string "" b))))
(setq mode-line-buffer-identification
(propertized-buffer-identification (or s (substring b 0 n))))))
Steve Berman