3

I'm trying to use compose-region with TABs but fail to see difference.

I'd like to get 'sqrt' composed to '√' but taking as much space as original text and aligned to the right.

I tried each of:

(compose-region begin end "√")
(compose-region begin end "\t√")
(compose-region begin end "√\t")
(compose-region begin end "\t√\t")

but fail to see any difference. Is there a way to compose region but keep its width?

Emacs is 24.4.

Gracjan Polak
  • 1,082
  • 6
  • 21

2 Answers2

5

As far as I understand, compose-region and the underlying composition text property can only result in displaying a single glyph (which may be built from several parts). When you pass multiple glyphs, they are assembled together in a single cell. The TAB character says to enlarge the cell so that the composite glyph fits entirely. It doesn't result in enlarging or padding the glyph to fill the cell.

What you want can be done with the display property instead.

(put-text-property begin end 'display "   √")

You may want to put this property in an overlay (especially as modifying overlays doesn't mark the buffer content as modified, unlike direct manipulation of text properties).

2

Better answer is in http://endlessparentheses.com/using-prettify-symbols-in-clojure-and-elisp-without-breaking-indentation.html

One way to fix the width, is to join two spaces together, and then stick the inequality on top of them.

(add-to-list 'endless/clojure-prettify-alist
             '(">=" . (?\s (Br . Bl) ?\s (Bc . Bc) ?≥)))
(add-to-list 'endless/clojure-prettify-alist
             '("<=" . (?\s (Br . Bl) ?\s (Bc . Bc) ?≤)))
Gracjan Polak
  • 1,082
  • 6
  • 21