help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how to reverse a region of several words?


From: tyler
Subject: Re: how to reverse a region of several words?
Date: Mon, 28 Jul 2008 12:00:44 -0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux)

sunway <sunwayforever@gmail.com> writes:

> e.g. the region contains words like "aaa bbb ccc ddd",I want to
> reverse it to "ddd ccc bbb aaa"
>

I think you probably want the words themselves to stay in the original
order, i.e., one two => two one? If not, if you want to completely
reverse the text, i.e., one two => owt eno, I use the following
function:

(defun reverse-string (beg1 end2)
  "Reverse the order of characters in a region.
>From a program takes two point or marker arguments, BEG1 and END2."
  (interactive "r")
  (if (> beg1 end2)
      (let (mid) (setq mid end2 end2 beg1 beg1 mid)))
  (while (< beg1 (1- end2))
        (let ((end1 (1+ beg1))
                  (beg2 (1- end2)))
          (transpose-regions beg1 end1 beg2 end2))
        (incf beg1)
        (decf end2)))

Cheers,

Tyler
-- 
Philosophy of science is about as useful to scientists as ornithology is to
birds.                                 --Richard Feynman





reply via email to

[Prev in Thread] Current Thread [Next in Thread]