emacs prettify-symbols replacing characters at same point

228 Views Asked by At

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))
1

There are 1 best solutions below

3
On

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?