emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] org-macs: store evaluated version of pom
@ 2011-02-25 13:30 Julien Danjou
  2011-02-26 17:25 ` Bastien
  0 siblings, 1 reply; 4+ messages in thread
From: Julien Danjou @ 2011-02-25 13:30 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: Julien Danjou

* lisp/org-macs.el (org-with-point-at): Store evaluated version of pom. This
fixes a potential bug when using (org-with-point-at (func) …), where (func)
would be evaluated multiple times, therefore might return different results
if a marker was returned and different each time.

Signed-off-by: Julien Danjou <julien@danjou.info>
---
 lisp/org-macs.el |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/lisp/org-macs.el b/lisp/org-macs.el
index 9c161e3..2090ca7 100644
--- a/lisp/org-macs.el
+++ b/lisp/org-macs.el
@@ -134,11 +134,12 @@ We use a macro so that the test can happen at compilation time."
 
 (defmacro org-with-point-at (pom &rest body)
   "Move to buffer and point of point-or-marker POM for the duration of BODY."
-  `(save-excursion
-     (if (markerp ,pom) (set-buffer (marker-buffer ,pom)))
+  `(let ((pom ,pom))
      (save-excursion
-       (goto-char (or ,pom (point)))
-       ,@body)))
+       (if (markerp pom) (set-buffer (marker-buffer pom)))
+       (save-excursion
+	 (goto-char (or pom (point)))
+	 ,@body))))
 (put 'org-with-point-at 'lisp-indent-function 1)
 
 (defmacro org-no-warnings (&rest body)
-- 
1.7.4.1

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

* Re: [PATCH] org-macs: store evaluated version of pom
  2011-02-25 13:30 [PATCH] org-macs: store evaluated version of pom Julien Danjou
@ 2011-02-26 17:25 ` Bastien
  2011-02-26 18:15   ` Julien Danjou
  0 siblings, 1 reply; 4+ messages in thread
From: Bastien @ 2011-02-26 17:25 UTC (permalink / raw)
  To: Julien Danjou; +Cc: emacs-orgmode

Hi Julien,

Julien Danjou <julien@danjou.info> writes:

> * lisp/org-macs.el (org-with-point-at): Store evaluated version of pom. This
> fixes a potential bug when using (org-with-point-at (func) …), where (func)
> would be evaluated multiple times

I'm not sure I understand this patch.

Can you show an actual use of org-with-point-at as the one you describe?

Maybe that's related to some code your are working on?

Thanks,

-- 
 Bastien

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

* Re: [PATCH] org-macs: store evaluated version of pom
  2011-02-26 17:25 ` Bastien
@ 2011-02-26 18:15   ` Julien Danjou
  2011-02-27 11:46     ` Bastien
  0 siblings, 1 reply; 4+ messages in thread
From: Julien Danjou @ 2011-02-26 18:15 UTC (permalink / raw)
  To: Bastien; +Cc: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 899 bytes --]

On Sat, Feb 26 2011, Bastien wrote:

>> * lisp/org-macs.el (org-with-point-at): Store evaluated version of pom. This
>> fixes a potential bug when using (org-with-point-at (func) …), where (func)
>> would be evaluated multiple times
>
> I'm not sure I understand this patch.
>
> Can you show an actual use of org-with-point-at as the one you describe?
>
> Maybe that's related to some code your are working on?

Yes it is. This patch just fix one problem. Without it, what is set
with pom is evaluated multiple times:

(org-with-point-at (function-that-return-some-marker)
  (do-stuff))

(function-that-return-some-marker) will be called several times, which
can causes a lot of problem, as you imagine just by reading the current
code.

This patch evalute the function, store it to `pom' and use this variable
instead.

-- 
Julien Danjou
❱ http://julien.danjou.info

[-- Attachment #1.2: Type: application/pgp-signature, Size: 835 bytes --]

[-- Attachment #2: 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	[flat|nested] 4+ messages in thread

* Re: [PATCH] org-macs: store evaluated version of pom
  2011-02-26 18:15   ` Julien Danjou
@ 2011-02-27 11:46     ` Bastien
  0 siblings, 0 replies; 4+ messages in thread
From: Bastien @ 2011-02-27 11:46 UTC (permalink / raw)
  To: emacs-orgmode

Hi Julien,

Julien Danjou <julien@danjou.info> writes:

> Yes it is. This patch just fix one problem. Without it, what is set
> with pom is evaluated multiple times:
>
> (org-with-point-at (function-that-return-some-marker)
>   (do-stuff))
>
> (function-that-return-some-marker) will be called several times, which
> can causes a lot of problem, as you imagine just by reading the current
> code.
>
> This patch evalute the function, store it to `pom' and use this variable
> instead.

Many thanks for the explanations.

I've now applied this patch.

-- 
 Bastien

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

end of thread, other threads:[~2011-02-27 12:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-25 13:30 [PATCH] org-macs: store evaluated version of pom Julien Danjou
2011-02-26 17:25 ` Bastien
2011-02-26 18:15   ` Julien Danjou
2011-02-27 11:46     ` Bastien

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).