How can one reverse the letters/characters in a selected region?
xyz --> zyx
ab cde --> edc ba
Emacs doesn't seem to provide any function to do this out of the box, but implementing one isn't that hard:
(defun my-reverse-region (beg end)
"Reverse characters between BEG and END."
(interactive "r")
(let ((region (buffer-substring beg end)))
(delete-region beg end)
(insert (nreverse region))))
delete-and-extract-region
, i.e., (insert (nreverse (delete-and-extract-region beg end)))
.
Commented
Jan 17, 2018 at 19:32
Meta + x
? If I highlight a region (e.g. the abc
string) and then execute it, I get the following error: Wrong type argument: listp, #("abc" 0 3 (fontified t))
Commented
Sep 14, 2019 at 20:47
Since emacs can call the shell on a region of text, and since shell can reverse text I believe there's an alternative/elegant(?) solution to the OPs problem,.
That's a comment but not an answer
okay how about
;; select the region, then
C-u M-|
;; Shell command on region:
rev<enter>