7

I'm using emacs 24.

How can I replace all occurrences of the non-printable Unicode bidi character RTL, whose hexadecimal number is 202e? I want to replace it with the non-printable Unicode bidi character LTR, whose hexadecimal number is 202d?

Could someone give me some guidance?

4 Answers 4

6

This requires enable-recursive-minibuffers is set to non-nil:

M-x replace-regexp RET C-x 8 RET 202e RET RET C-x 8 RET 202d RET RET

4
  • I didn't know about C-x 8 RET!
    – user4815162342
    Nov 12, 2012 at 20:54
  • Thanks, but unfortunately this solution doesn't work. I still get the message "Replaced 0 occurrences".
    – Evan Aad
    Nov 13, 2012 at 6:45
  • 1
    @EvanAad: Is it possible the point was after the character to be replaced?
    – npostavs
    Nov 18, 2012 at 5:09
  • You can also pre-compose the strings in another buffer and then yank it into the minibuffer without changing enable-recursive-minibuffers.
    – remcycles
    Apr 9, 2023 at 15:43
3
  1. Add the following piece of emacs Lisp code at the beginning of the buffer:

    (while (re-search-forward "\u202e" nil t)
            (replace-match     "\u202d"))

  2. Place the cursor just after the last parenthesis and type C-xC-e to execute the code.

1
M-x replace-regexp RET \u202e RET \u202d
3
  • You'd think, wouldn't you!? Unfortunately, running this command on a file that consists of a single unicode character, whose hex number is 202e, yields the following message: "Replaced 0 occurrences"
    – Evan Aad
    Nov 12, 2012 at 18:55
  • This one doesn't work for me either, and I don't see why it should be expected to work.
    – npostavs
    Nov 18, 2012 at 5:15
  • Well, Elisp strings do have \uXXXX escape sequences for Unicode text. So (string-match-p "[\u4E00-\u9FFF]+" "中国") returns t. But minibuffer input strings don't go through that quoting process.
    – remcycles
    Apr 9, 2023 at 15:40
1

Type the following:

M-% C-q 20056 RET RET C-q 20055 RET RET

C-q followed by an octal number and RET will insert the character represented by the octal number and discard the RET. To quickly convert hex to octal, type #x202e in a M-: prompt, which will print the resulting number in decimal, octal, and hex.

To enable easier input of decimal numbers, a la GTK's C-S-u binding, I use this in my .emacs:

(global-set-key [(control shift u)]
                (lambda ()
                  (interactive)
                  (let ((read-quoted-char-radix 16))
                    (call-interactively 'quoted-insert))))
3
  • Thanks, but i still get "Replaced 0 occurrences".
    – Evan Aad
    Nov 13, 2012 at 6:47
  • This does work for me. But I wonder why not just have read-quoted-char-radix always be 16?
    – npostavs
    Nov 18, 2012 at 5:14
  • @npostavs I've retried and it still doesn't work for me.
    – Evan Aad
    Nov 21, 2012 at 14:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .