all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Yuri Khan <yuri.v.khan@gmail.com>
To: "help-gnu-emacs@gnu.org" <help-gnu-emacs@gnu.org>
Subject: Force character display width
Date: Thu, 8 Jun 2017 00:28:16 +0700	[thread overview]
Message-ID: <CAP_d_8U2dVP9db_trB1jLUJbMaydWUxEHwiRWuN_Gjs-ea+P=A@mail.gmail.com> (raw)

Hello, everybody.

I am trying to customize Ibuffer to display the read-only status
differently. By default, it displays a percent sign if the buffer is
read-only, and a space if not. I want it to display a lock character
(🔒 U+1f512 LOCK) instead of the percent sign. Of course this is all
on a GUI frame.

That was the big picture. Now for the XY problem :)

    (define-ibuffer-column yk-read-only (:name "R") nil
      (if (buffer-local-value 'buffer-read-only buffer)
          "🔒"
        " "))

This would work in the ideal world where my font of choice has full
Unicode coverage. That is not the case. My default font is Liberation
Mono and the lock is displayed in Symbola. The widths do not match, so
the columns do not line up perfectly.

This leads me to the idea that I need to somehow tweak the lock
character so that it takes up exactly one character cell; or,
alternatively, tweak the space so it takes as much space as the lock;
or tweak both that they take up the same width.


I can achieve the desired effect by changing font size:

    (propertize "🔒" 'display '(height 0.75))

but this strikes me as inelegant and prone to breaking if I ever change fonts.


I suppose I could calculate the factor dynamically if I could get the
pixel width of the lock character. However, the only thing I can find
on that path is the ‘window-text-pixel-size’ function which requires
the text being  measured to already be in the buffer. I’d prefer to
avoid fiddling with a temporary buffer and window.


I could use the same character for both cases, but propertize it with
different faces. That will solve the display problem at the cost of
breaking semantics.


I could also do this:

    (concat (if (yk-buffer-read-only-p buffer) "🔒" " ")
            (propertize " " 'display '(space . (:align-to 3.5))))

This will break if I ever decide to move the column to a different
position, and is also slightly fragile against font changes.


I also tried using a string of two spaces and the following composition:

    (compose-chars ?\s '(Br . Bc) ?🔒 '(Bc . Bl) ?\s)

which do occupy the same width, but there are visual glitches when
cursor passes that point in the buffer.


Am I overlooking some other option?



             reply	other threads:[~2017-06-07 17:28 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-07 17:28 Yuri Khan [this message]
2017-06-07 18:31 ` Force character display width Eli Zaretskii
2017-06-08 14:52   ` Yuri Khan

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

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

  git send-email \
    --in-reply-to='CAP_d_8U2dVP9db_trB1jLUJbMaydWUxEHwiRWuN_Gjs-ea+P=A@mail.gmail.com' \
    --to=yuri.v.khan@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /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 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.