1

I know about compose-region and have used it for other purposes, but am trying to figure out how to display a character reversed. like transforming c to . Is this possible?

1

I'm not sure about the feasibility of this.

First, I believe this requires a backwards font on the system. I'm no expert on how text is actually rendered but, speaking generally, text is rendered using a "base description", such as a vector mapping. This base information is contained in a font file, such as a .ttf. Without some mapping, Emacs doesn't have a way to translate a key code into an image on the screen.

Assuming you have the Time New Roman.ttf font installed, you can change the default buffer font in Emacs using the following code1:

;; Make the default buffer font Times New Roman
(set-face-attribute 'default nil :font "Times New Roman")

Second, if you're looking to change the font for a region, this is where it gets difficult. Emacs assigns fonts using faces. A face, as far as I can tell, is like an object. In order for you to change the font for a region, you'd need a corresponding face. I'm not sure what face you could use so that the font change "sticks".

To illustrate, the following code changes the face for a highlighted line:

;; Highlight current line
(global-hl-line-mode 1)
;; Change the face for the highlight to be Comic Sans font
(set-face-attribute 'highlight nil :font "Comic Sans MS")

After running the code, the font of the highlighted line should be Comic Sans. The point I'm trying to illustrate is that the font is defined for the face. In this case, the face is the highlighted line. When the face changes, as when you move up/down a line, the font changes.

If you can identify a face corresponding to a region, the above snippet should work simply by replacing highlight with the appropriate face name. The describe-face function will be invaluable to you in finding the right face. I like to bind it to a key for easy use:

(global-set-key (kbd "C-h j") 'describe-face)

1Apologies for the Microsoft-centric response. I'm stuck on a Windows machine at the moment... ☹ You'll need to find a different font name to try if you're on Linux or OSX.

  • This seems enough to answer my question. Basically, no this is not possible within emacs. – Prgrm.celeritas Feb 1 at 13:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.