I want to implement dynamical text replacement (only the display is replaced, the actual stored file is not replaced) for Emacs, using Elisp.
For example, in LaTeX documents, I want to type \alpha
, and let Emacs display it just as α
, so it is easier to read. But in the result .tex
file, I still want \alpha
, instead of α
to be saved. (Remark: I could use XeTeX or LuaTeX myself to support UTF-8 directly. But for the reason of collaboration and journal requirements, I don't want the UTF-8 characters to be directly saved in the .tex
files. Alternatively I could use preview in AUCTeX. But that doesn't help when I am editing the formula)
An existing example is in org-mode, when we type [[link][name]]
, right after typing the last ]
, the displayed text is replaced by just the name, with hyperlink. On the other hand, when saving this file, the saved content is the original [[link][name]]
, different from the displayed one.
Any ideas how this could be implemented?
PS: The Display Specs That Replace The Text section of Emacs manual goes close. However, I need to specify the start and end points, instead of the desired string for the replacements. This means I need to do search after every user input to decide the start and end points. This looks unrealistic due to performance and complexity of algorithm.
compose-region
seems to only work when the display result should be a single character. So e.g. if I pass"bar"
as the result-string parameter,compose-region
collapses all 3 letters to a single one. IOW, passing a"α"
and"ααα"
both will get the same result. – Implement