As commented below already, I am not aware of any feature that provides this functionality out of the box. However, while looking at prettify-symbols-mode
to look for an alternative, it looked like adapting it to achieve what you ask for, would not be so much work.
So here is the code for steno-mode
, an adaption of prettify-symbols-mode
that uses the display text property instead of the compose text property:
(setq steno-list '(("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")))
;; adapted from `prettify-symbols--compose-symbol'
(defun steno--display-symbol (alist)
"Add paired string as display property to relevant regions"
;; Check that the chars should really be composed into a symbol.
(let ((start (match-beginning 0))
(end (match-end 0))
(match (match-string 0)))
(if (and (not (equal prettify-symbols--current-symbol-bounds (list start end)))
(funcall prettify-symbols-compose-predicate start end match))
(with-silent-modifications
(add-text-properties
start end
`(steno-start ,start steno-end ,end display ,(cdr (assoc match alist)))))
(remove-list-of-text-properties start end
'(steno-start
steno-end
display))))
;; Return nil because we're not adding any face property.
nil)
(defun steno--make-keywords ()
(interactive)
`((,(regexp-opt (mapcar 'car steno-list) t)
(0 (steno--display-symbol ',steno-list)))))
(defvar-local steno--keywords nil)
(define-minor-mode steno-mode
"Toggle Steno mode.
When Steno mode and font-locking are enabled, symbols are
prettified according to the rules in
`steno-alist' (which see), which are locally defined
by major modes supporting prettifying. To add further
customizations for a given major mode, you can modify
`steno-alist' thus:
(add-hook \\='emacs-lisp-mode-hook
(lambda ()
(push \\='(\"<=\" . ?≤) steno-alist)))
You can enable this mode locally in desired buffers, or use
`global-steno-mode' to enable it for all modes that
support it."
:init-value nil
(when steno--keywords
(font-lock-remove-keywords nil steno--keywords)
(setq steno--keywords nil))
(if steno-mode
;; Turn on
(when (setq steno--keywords (steno--make-keywords))
(font-lock-add-keywords nil steno--keywords)
(when prettify-symbols-unprettify-at-point
(add-hook 'post-command-hook
#'prettify-symbols--post-command-hook nil t))
(font-lock-flush))
;; Turn off
(remove-hook 'post-command-hook #'prettify-symbols--post-command-hook t)
(with-silent-modifications
(remove-text-properties (point-min) (point-max) '(display nil)))))
Use it like how you would use prettify-symbols-mode
.
I am not sure what the remaining prettify-symbols...
functions are doing, but from the comments in the code it seems that they are required. Therefore, I have left them in to be safe.
prettify-symbols
.?
is emacs lisp syntax for characters. See the elisp manual.prettify-symbols
is the wrong tool, or you want overlays to change the appearance of the unchanged text, in which caseprettify-symbols
may be appropriate. Please give real-world usage before-and-after examples.