unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Stephen Berman <stephen.berman@gmx.net>
To: Yuri Khan <yuri.v.khan@gmail.com>
Cc: Manuel Giraud <manuel@ledu-giraud.fr>, emacs-devel <emacs-devel@gnu.org>
Subject: Re: eliding in mode-line-format
Date: Fri, 01 Oct 2021 18:49:54 +0200	[thread overview]
Message-ID: <87v92g666l.fsf@rub.de> (raw)
In-Reply-To: <CAP_d_8VnOD90T8mxVqDstdw0ZMoUqBDGgu6ZM3dCeHfU3Ha8Tw@mail.gmail.com> (Yuri Khan's message of "Fri, 1 Oct 2021 21:23:08 +0700")

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



      reply	other threads:[~2021-10-01 16:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87v92g666l.fsf@rub.de \
    --to=stephen.berman@gmx.net \
    --cc=emacs-devel@gnu.org \
    --cc=manuel@ledu-giraud.fr \
    --cc=yuri.v.khan@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).