all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [PATCH] Use save-excursion in org-map-dblocks
@ 2010-03-23 17:37 Magnus Henoch
  2010-03-24 11:16 ` Carsten Dominik
  0 siblings, 1 reply; 5+ messages in thread
From: Magnus Henoch @ 2010-03-23 17:37 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 317 bytes --]

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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org.el-org-map-dblocks-Use-save-excursion.patch --]
[-- Type: text/x-patch, Size: 1361 bytes --]

From 8fa75fb5174f93cc6990b605901891c2191c64f0 Mon Sep 17 00:00:00 2001
From: Magnus Henoch <magnus.henoch@gmail.com>
Date: Wed, 21 Oct 2009 12:37:32 +0100
Subject: [PATCH] * org.el (org-map-dblocks): Use save-excursion.

---
 lisp/org.el |   13 ++++++-------
 1 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index 7b2e95b..249aad4 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -9306,16 +9306,15 @@ the property list including an extra property :name with the block name."
 (defun org-map-dblocks (&optional command)
   "Apply COMMAND to all dynamic blocks in the current buffer.
 If COMMAND is not given, use `org-update-dblock'."
-  (let ((cmd (or command 'org-update-dblock))
-	pos)
+  (let ((cmd (or command 'org-update-dblock)))
     (save-excursion
       (goto-char (point-min))
       (while (re-search-forward org-dblock-start-re nil t)
-	(goto-char (setq pos (match-beginning 0)))
-	(condition-case nil
-	    (funcall cmd)
-	  (error (message "Error during update of dynamic block")))
-	(goto-char pos)
+	(goto-char (match-beginning 0))
+        (save-excursion
+          (condition-case nil
+              (funcall cmd)
+            (error (message "Error during update of dynamic block"))))
 	(unless (re-search-forward org-dblock-end-re nil t)
 	  (error "Dynamic block not terminated"))))))
 
-- 
1.6.4.4


[-- Attachment #3: Type: text/plain, Size: 19 bytes --]


-- 
Magnus Henoch

[-- Attachment #4: Type: text/plain, Size: 201 bytes --]

_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] Use save-excursion in org-map-dblocks
  2010-03-23 17:37 [PATCH] Use save-excursion in org-map-dblocks Magnus Henoch
@ 2010-03-24 11:16 ` Carsten Dominik
  2010-03-24 13:47   ` Magnus Henoch
  0 siblings, 1 reply; 5+ messages in thread
From: Carsten Dominik @ 2010-03-24 11:16 UTC (permalink / raw)
  To: Magnus Henoch; +Cc: emacs-orgmode

Hi Magnus,

this looks like an OK patch and I don't have any problems applying it.
However, I do not quite understand the need for it.  Can you please  
try to
explain a bit better?  Do you have two processes running over the same  
file
at the same time, or why is there a conflict?

Thanks for your time.

- Carsten

On Mar 23, 2010, at 6:37 PM, Magnus Henoch wrote:

> 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.
>
> From 8fa75fb5174f93cc6990b605901891c2191c64f0 Mon Sep 17 00:00:00 2001
> From: Magnus Henoch <magnus.henoch@gmail.com>
> Date: Wed, 21 Oct 2009 12:37:32 +0100
> Subject: [PATCH] * org.el (org-map-dblocks): Use save-excursion.
>
> ---
> lisp/org.el |   13 ++++++-------
> 1 files changed, 6 insertions(+), 7 deletions(-)
>
> diff --git a/lisp/org.el b/lisp/org.el
> index 7b2e95b..249aad4 100644
> --- a/lisp/org.el
> +++ b/lisp/org.el
> @@ -9306,16 +9306,15 @@ the property list including an extra  
> property :name with the block name."
> (defun org-map-dblocks (&optional command)
>   "Apply COMMAND to all dynamic blocks in the current buffer.
> If COMMAND is not given, use `org-update-dblock'."
> -  (let ((cmd (or command 'org-update-dblock))
> -	pos)
> +  (let ((cmd (or command 'org-update-dblock)))
>     (save-excursion
>       (goto-char (point-min))
>       (while (re-search-forward org-dblock-start-re nil t)
> -	(goto-char (setq pos (match-beginning 0)))
> -	(condition-case nil
> -	    (funcall cmd)
> -	  (error (message "Error during update of dynamic block")))
> -	(goto-char pos)
> +	(goto-char (match-beginning 0))
> +        (save-excursion
> +          (condition-case nil
> +              (funcall cmd)
> +            (error (message "Error during update of dynamic  
> block"))))
> 	(unless (re-search-forward org-dblock-end-re nil t)
> 	  (error "Dynamic block not terminated"))))))
>
> -- 
> 1.6.4.4
>
>
> -- 
> Magnus Henoch
> _______________________________________________
> Emacs-orgmode mailing list
> Please use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode

- Carsten

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Use save-excursion in org-map-dblocks
  2010-03-24 11:16 ` Carsten Dominik
@ 2010-03-24 13:47   ` Magnus Henoch
  2010-03-24 21:27     ` Carsten Dominik
  0 siblings, 1 reply; 5+ messages in thread
From: Magnus Henoch @ 2010-03-24 13:47 UTC (permalink / raw)
  To: emacs-orgmode

Carsten Dominik <carsten.dominik@gmail.com> writes:

> this looks like an OK patch and I don't have any problems applying it.
> However, I do not quite understand the need for it.  Can you please
> try to explain a bit better?  Do you have two processes running over
> the same file at the same time, or why is there a conflict?

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.

-- 
Magnus Henoch

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Re: [PATCH] Use save-excursion in org-map-dblocks
  2010-03-24 13:47   ` Magnus Henoch
@ 2010-03-24 21:27     ` Carsten Dominik
  2010-03-24 22:03       ` Magnus Henoch
  0 siblings, 1 reply; 5+ messages in thread
From: Carsten Dominik @ 2010-03-24 21:27 UTC (permalink / raw)
  To: Magnus Henoch; +Cc: emacs-orgmode


On Mar 24, 2010, at 2:47 PM, Magnus Henoch wrote:

> Carsten Dominik <carsten.dominik@gmail.com> writes:
>
>> this looks like an OK patch and I don't have any problems applying  
>> it.
>> However, I do not quite understand the need for it.  Can you please
>> try to explain a bit better?  Do you have two processes running over
>> the same file at the same time, or why is there a conflict?
>
> 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.

Yes, that would be the same.

I have applied the patch, thanks.

Can I ask you to sign the FSF papers for future patches which might be  
more than a few lines?

Thanks.

- Carsten

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Use save-excursion in org-map-dblocks
  2010-03-24 21:27     ` Carsten Dominik
@ 2010-03-24 22:03       ` Magnus Henoch
  0 siblings, 0 replies; 5+ messages in thread
From: Magnus Henoch @ 2010-03-24 22:03 UTC (permalink / raw)
  To: emacs-orgmode

Carsten Dominik <carsten.dominik@gmail.com> writes:

> Can I ask you to sign the FSF papers for future patches which might be
> more than a few lines?

I've assigned all past and future changes to Emacs to the FSF already.
That happened a few computers ago, so I don't have that email at hand,
but I think I have a backup somewhere...  I'll try to dig it out this
weekend.

-- 
Magnus Henoch

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2010-03-24 22:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-23 17:37 [PATCH] Use save-excursion in org-map-dblocks Magnus Henoch
2010-03-24 11:16 ` Carsten Dominik
2010-03-24 13:47   ` Magnus Henoch
2010-03-24 21:27     ` Carsten Dominik
2010-03-24 22:03       ` Magnus Henoch

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.