all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* eliding in mode-line-format
@ 2021-10-01 14:00 Manuel Giraud
  2021-10-01 14:23 ` Yuri Khan
  0 siblings, 1 reply; 3+ messages in thread
From: Manuel Giraud @ 2021-10-01 14:00 UTC (permalink / raw)
  To: emacs-devel

Hi,

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

Before I start digging into 'xdisp.c', I'd like to know if maybe there
is already a way to do it in emacs and if it is something that could be
interesting to some?
-- 
Manuel Giraud



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: eliding in mode-line-format
  2021-10-01 14:00 eliding in mode-line-format Manuel Giraud
@ 2021-10-01 14:23 ` Yuri Khan
  2021-10-01 16:49   ` Stephen Berman
  0 siblings, 1 reply; 3+ messages in thread
From: Yuri Khan @ 2021-10-01 14:23 UTC (permalink / raw)
  To: Manuel Giraud; +Cc: emacs-devel

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.



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: eliding in mode-line-format
  2021-10-01 14:23 ` Yuri Khan
@ 2021-10-01 16:49   ` Stephen Berman
  0 siblings, 0 replies; 3+ messages in thread
From: Stephen Berman @ 2021-10-01 16:49 UTC (permalink / raw)
  To: Yuri Khan; +Cc: Manuel Giraud, emacs-devel

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



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-10-01 16:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-10-01 14:00 eliding in mode-line-format Manuel Giraud
2021-10-01 14:23 ` Yuri Khan
2021-10-01 16:49   ` Stephen Berman

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.