3

I'd like to find all occurrences of == in a buffer and overlay them with Unicode , keeping width of two chars and centered in the space.

I know about replacing text visual representation:

(put-text-property 1 10 'display "replacement")

about keeping known width

(put-text-property 1 10 'display '(space :width (119)))

I do not know how to put this together and keep it centered.

1
  • I don't have an answer to your question, but one option would be to create a custom XPM image that is the width of two characters and center that image when designing it. You can have a function that calculates and adds/removes pixels / columns as needed based upon the frame character width, and frame character height.
    – lawlist
    Commented Mar 14, 2015 at 3:33

1 Answer 1

4

While my solution doesn't really center, it comes close enough I hope. There is a display property that adjusts the width of all spaces, if I use the string and make its spaces half the width, it will look centered and two characters wide. The only downside I could find so far is that putting the cursor on the propertized string highlights its first space.

Here's a demonstration that should produce two lines of code lining up perfectly upon evaluating it with C-x C-e and point after the end of the expression:

(insert "\na == b\n"
        "a " (propertize "=" 'display
                         (propertize " ≡ " 'display '(space-width 0.5)))
        " b\n")
2
  • By judicious use of the cursor text-property, you should be able to make Emacs draw the cursor over the ≡ sign instead of drawing it over the preceding space.
    – Stefan
    Commented Mar 14, 2015 at 13:25
  • @Stefan I doubt it's worth it though.
    – wasamasa
    Commented Mar 14, 2015 at 15:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.