From: Jambunathan K <kjambunathan@gmail.com>
To: Suvayu Ali <fatkasuvayu+linux@gmail.com>
Cc: Emacs help <help-gnu-emacs@gnu.org>
Subject: Re: Saving "relative point" in a paragraph or line
Date: Thu, 12 Sep 2013 14:34:56 +0530 [thread overview]
Message-ID: <8761u6e7gn.fsf@gmail.com> (raw)
In-Reply-To: <20130912080605.GQ20690@kuru.dyndns-at-home.com> (Suvayu Ali's message of "Thu, 12 Sep 2013 10:06:05 +0200")
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,
next prev parent reply other threads:[~2013-09-12 9:04 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-12 8:06 Saving "relative point" in a paragraph or line Suvayu Ali
2013-09-12 8:49 ` Andreas Röhler
2013-09-12 9:51 ` Suvayu Ali
2013-09-12 10:06 ` Andreas Röhler
2013-09-12 11:26 ` Suvayu Ali
2013-09-12 9:04 ` Jambunathan K [this message]
2013-09-12 13:31 ` Suvayu Ali
[not found] ` <mailman.1921.1378976581.10748.help-gnu-emacs@gnu.org>
2013-09-12 9:14 ` Damien Wyart
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8761u6e7gn.fsf@gmail.com \
--to=kjambunathan@gmail.com \
--cc=fatkasuvayu+linux@gmail.com \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.