0

You are an American in a British company. The company requires all your saved files to use the spelling "colour". You can't bear to look at anything other than "color" so you want emacs only to show you that spelling. At the same time you don't want to leave any evidence in the server or fail the mandatory British flyspell checking.

How could you do this do this color/colour transformation?

A hypothetical solution might be: maintain two buffers and when one is edited also update the other using the transformation. Allow viewing and editing the post-transformation one but wrapping all of your functions that would act on the current buffer to act on the other one instead.

  • https://emacs.stackexchange.com/tags/elisp/info – Drew Feb 10 '23 at 21:23
  • The question isn't clear to me. Editing (changing the content) that doesn't affect highlighting or saving? I think you need to give examples - be specific. – Drew Feb 10 '23 at 21:26
  • I have edited the question to address these concerns. – Tumok A. Byrd Feb 10 '23 at 22:19
  • 2
    In principle, yes -- text properties and/or overlays can be used to visually alter/replace the appearance of text with arbitrary other things. Your question is large and woolly though... I recommend that you reduce it to a very simple specific case (color/colour seems a good one) for the purposes of getting a specific answer. – phils Feb 10 '23 at 22:34
  • thank you for the feedback, question amended – Tumok A. Byrd Feb 10 '23 at 22:42
  • *"the editable text is a transformed version"* So there's a transformation of the actual *content* (which is what you edit), and not just the appearance? What @phils said: please simplify the question, specifying something *specific* that you want to know how to do. – Drew Feb 10 '23 at 22:43
  • Thanks, I've amended it again – Tumok A. Byrd Feb 11 '23 at 00:26
  • @phils I've been reading the documentation on overlays and text properties (e.g. https://www.gnu.org/software/emacs/manual/html_node/elisp/Replacing-Specs.html ) and it seems this would not allow editing the transformed text, could you please give further detail? – Tumok A. Byrd Feb 11 '23 at 20:44
  • Correct, you can't edit text which is only being displayed via a display property -- that text doesn't *exist* in the (editable) buffer text at all. (Per your own requirement, the text only *appears* to be something different.) – phils Feb 12 '23 at 05:26
  • I guess [this answer](https://emacs.stackexchange.com/a/71453/26163) provides exactly what you are looking for. Just evaluate the code their in Emacs, but for defining the list use `(setq steno-list '(("colour" . "color")))` instead. Then in any buffer containing the word `colour` toggle how it gets displayed by doing `M-x steno-mode`. – dalanicolai Feb 12 '23 at 22:46
  • @dalanicolai very cool, thank you. If you submit that as an answer I'll accept it. – Tumok A. Byrd Feb 14 '23 at 14:05
  • @TumokA.Byrd Thanks, I gave it a try and I hope that the answer is 'compliant with' the SE guidelines. – dalanicolai Feb 14 '23 at 14:46

1 Answers1

1

A possible solution is to use a slightly modified version of prettify-symbols-mode as explained in the answer here.

You can just use (evaluate in Emacs) the code from that answer, but change the assignment for the steno-list to

(setq steno-list '(("colour" . "color")))`.

Subsequently, in any buffer, you can toggle between the two ways of displaying the word 'colour' by doing M-x steno-mode (here the word 'colour' only gets displayed differently, the actual buffer contents (i.e. the word 'colour') stays the same.

dalanicolai
  • 6,108
  • 7
  • 23