Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I add multi-character replacements to prettify-symbols-alist? #201

Closed
anton-trunov opened this issue Jun 21, 2018 · 3 comments · Fixed by #202
Closed

How do I add multi-character replacements to prettify-symbols-alist? #201

anton-trunov opened this issue Jun 21, 2018 · 3 comments · Fixed by #202

Comments

@anton-trunov
Copy link
Contributor

anton-trunov commented Jun 21, 2018

I'd like [** to be rendered as [△.

What would be the correct way of adding something like ("[**" . "[△") to prettify-symbols-alist? I don't want ** to be rendered as in all contexts.

@cpitclaudel
Copy link
Owner

cpitclaudel commented Jun 21, 2018

It's tricky. There are multiple ways to do this:

  • Use a font-lock rule with a display property (that is, don't use prettify-symbols-mode directly)
  • Change the prettify-symbols-compose-predicate to only apply this prettification when preceded by a [
  • Use a composition string. It's documented in the docstring of compose-region and reference-point-alist, which are a bit complex. The relevant part is this:
If it is a vector or list, it is a sequence of alternate characters and
composition rules, where (2N)th elements are characters and (2N+1)th
elements are composition rules to specify how to compose (2N+2)th
elements with previously composed N glyphs.

So you want this: (setq prettify-symbols-alist '(("[**" . (?\[ (Br . Bl) ?△)))). See https://emacs.stackexchange.com/questions/34808/using-prettify-symbols-with-strings-instead-of-characters

@anton-trunov
Copy link
Contributor Author

anton-trunov commented Jun 21, 2018

Wow! It works. Thank you very much!

Do you think it is worth adding your example to README.md? For instance, to this section?

@cpitclaudel
Copy link
Owner

I think a brief link to this issue would be perfect, yes. Can you prepare a PR? :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants