Use save-excursion to remember position when updating dblocks
commit93af0ec92530ba53688e95a178c941d22dbd3890
authorCarsten Dominik <carsten.dominik@gmail.com>
Wed, 24 Mar 2010 21:25:35 +0000 (24 22:25 +0100)
committerCarsten Dominik <carsten.dominik@gmail.com>
Wed, 24 Mar 2010 21:25:35 +0000 (24 22:25 +0100)
tree4250a70b40f94f971909e22a9d86d1ea2e7a7322
parent80d0b06fbf3d33e6b1dc2b3cd29ec389c73f619b
Use save-excursion to remember position when updating dblocks

Magnus Henoch writes:

> This patch has been sitting in my tree for a while...  It's a fix to
> org-map-dblocks, to make it use save-excursion instead of remembering
> position values.  I need this since I have a dblock function that
> asynchronously updates dblocks from HTTP responses, and some dblocks
> ended up getting updated twice or thrice.

[...]

> My dblock-write function calls url-retrieve, to asynchronously retrieve an
> HTML page.  The callback function I pass to url-retrieve will then fill
> in the information I need into the dynamic block.
>
> So in the following case:
>
> * Find start of dblock 1, store as pos
> * Make HTTP request for dblock 1
> * Go back to pos
> * Find end of dblock 1
> * Find start of dblock 2, store as pos
> * Make HTTP request for dblock 2
> * Asynchronous event: HTTP response for dblock 1 arrives, insert lots of
>  data in dblock 1
> * Go back to pos
> * Find end of dblock 2
>
> the last step will actually find the end of dblock 1, if the amount of
> data inserted in dblock 1 is great enough that pos suddenly points
> inside it.  (Then it will of course find dblock 2 again, request its HTML
> page again, and thus insert the data twice.)
>
> An equivalent fix would be to make pos a marker instead.
lisp/ChangeLog
lisp/org.el