0

I am using prettify-symbols to switch between the following words and shortcuts. The problem is that when the replacement is more than a single character, all letters are being inserted at the same point.

For instance when little is replaced I get a single l, rather than ll.

    (defvar cluster
      '(
         ("all" . "l")     ("as" . "as")      ("can" . "k")
         ("do" . "do")     ("for" . "f")      ("in" . "n")
         ("is" . "s")      ("it" . "t")       ("know" . "no")
         ("like" . "lk")   ("little" . "ll")  ("more" . "mo")
         ("some" . "so")   ("than" . "n")     ("that" . "ta")
         ("there" . "tr")  ("this" . "th")    ("time" . "ti")
         ("to" . "to")     ("we" . "w")       ("well" . "l")
         ("will" . "l")    ("work" . "wk")    ("you" . "u"))
    
      "List of replacements for specific words.")

    (defun prettify-cluster ()
      "Set keywords and corresponding glyph."
      (setq-local prettify-symbols-alist cluster))
Dilna
  • 405
  • 1
  • 6
  • What's the question? That's the way `prettify-symbols-mode` works, I believe. Maybe you want to submit an enhancement request? If so, `M-x report-emacs-bug`. – Drew Apr 23 '22 at 16:37
  • Have be trying to turn a word into another word, rather than a single glyph. Example, change `little` with `ll`. Currently, I get a single `l`. Is turning a word to a single glyph the way `prettify-symbols-mode` works? – Dilna Apr 23 '22 at 21:31
  • Yes, I believe so. – Drew Apr 23 '22 at 21:49

1 Answers1

1

The doc string of variable prettify-symbols-alist tells you that each alist entry is (SYMBOL . CHARACTER), where SYMBOL is a string.

In your alist, you have instead (STRING . STRING) entries.

prettify-symbols-alist is a variable defined in prog-mode.el.

Its value is nil

Automatically becomes buffer-local when set.

Documentation:

Alist of symbol prettifications.

Each element looks like (SYMBOL . CHARACTER), where the symbol matching SYMBOL (a string, not a regexp) will be shown as CHARACTER instead.

CHARACTER can be a character, or it can be a list or vector, in which case it will be used to compose the new symbol as per the third argument of compose-region.

Furthermore, if you use a list or vector of chars for CHARACTER then those chars are composed.

I think that what you want is maybe something like abbrev-mode?

Drew
  • 29,895
  • 7
  • 74
  • 104
  • Would need to think about that. The intention is the ability to display the full text with the stenographic version. But then be able to go back to the original text. Similar to the way one changes from `\alpha` to the alpha symbol and back again to the actual command `\alpha`. I can test the capabilities of `abbrev-mode`, if I have an little example about how to convert from the sample words and replacements illustrated. – Dilna Apr 25 '22 at 01:38
  • Do you know whether the backward display of the original `\alpha` from the symbol is another replacement, or does it remember the original `\alpha`? I ask because I might have two words (e.g. `than` and `on`) that use tho same stenographic abbreviation (`n`). I would want to revert to the original (`than` or `on`). The advantage of `prettify-symbols-alist` in that the original source code remains unmodified. Would be grateful if can correct me if I am wrong about my assessment. – Dilna Apr 25 '22 at 02:13
  • Sorry; someone else can perhaps help with that. – Drew Apr 25 '22 at 02:17