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

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

Re: Saving "relative point" in a paragraph or line


From: Jambunathan K
Subject: Re: Saving "relative point" in a paragraph or line
Date: Thu, 12 Sep 2013 14:34:56 +0530
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

Suvayu Ali <fatkasuvayu+linux@gmail.com> writes:

> Hi,
>
> I'm trying to write a few wrappers for transpose functions.  I would
> like to restore the point to the relative position of the element I am
> trying to transpose.  Are there any standard ways/functions people use
> for something like this?
>
> An example (cursor at -!-):
>
> - Lorem ipsum dolor -!- sit amet, consectetur adipiscing elit.
> - Vestibulum porttitor metus sed est varius, id dapibus est rhoncus.
>
>                            |
>                            v
>
> - Vestibulum porttitor metus sed est varius, id dapibus est rhoncus.
> - Lorem ipsum dolor -!- sit amet, consectetur adipiscing elit.

This snippet comes with Zero warranty but illustrates how one may
achieve it.

    (defadvice transpose-lines
        (around transpose-lines-preserve-context activate)
      "Transpose lines but preserve the surrounding text context."
      ;; Add a bookmark at current char.
      (add-text-properties (point) (1+ (point)) '(bookmark t))
      ;; Transpose.
      ad-do-it
      ;; Visit the bookmark.  Assumes that the bookmark is at a position
      ;; behind where the cursor is at the end of the transposition.
      (goto-char (1- (previous-single-property-change (point) 'bookmark)))
      ;; Remove it.
      (remove-text-properties (point) (1+ (point)) '(bookmark)))

>
> Thanks for any ideas.
>
> Cheers,



reply via email to

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