all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Force character display width
@ 2017-06-07 17:28 Yuri Khan
  2017-06-07 18:31 ` Eli Zaretskii
  0 siblings, 1 reply; 3+ messages in thread
From: Yuri Khan @ 2017-06-07 17:28 UTC (permalink / raw)
  To: help-gnu-emacs@gnu.org

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?



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

* Re: Force character display width
  2017-06-07 17:28 Force character display width Yuri Khan
@ 2017-06-07 18:31 ` Eli Zaretskii
  2017-06-08 14:52   ` Yuri Khan
  0 siblings, 1 reply; 3+ messages in thread
From: Eli Zaretskii @ 2017-06-07 18:31 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Yuri Khan <yuri.v.khan@gmail.com>
> Date: Thu, 8 Jun 2017 00:28:16 +0700
> 
> Am I overlooking some other option?

font-get-glyphs comes to mind.  (If you wonder how to get the font, I
think font-at will help.)



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

* Re: Force character display width
  2017-06-07 18:31 ` Eli Zaretskii
@ 2017-06-08 14:52   ` Yuri Khan
  0 siblings, 0 replies; 3+ messages in thread
From: Yuri Khan @ 2017-06-08 14:52 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: help-gnu-emacs@gnu.org

On Thu, Jun 8, 2017 at 1:31 AM, Eli Zaretskii <eliz@gnu.org> wrote:

>> Am I overlooking some other option?
>
> font-get-glyphs comes to mind.  (If you wonder how to get the font, I
> think font-at will help.)

Thanks! That works.



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

end of thread, other threads:[~2017-06-08 14:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-06-07 17:28 Force character display width Yuri Khan
2017-06-07 18:31 ` Eli Zaretskii
2017-06-08 14:52   ` Yuri Khan

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.