summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarsten Dominik <carsten.dominik@gmail.com>2009-01-14 21:22:37 +0100
committerCarsten Dominik <carsten.dominik@gmail.com>2009-01-14 21:22:37 +0100
commit8cb1d66f8683ea38a09096cbba3a736c1ce70fe3 (patch)
tree05da8524673edbe621e74a71e5822239c27c0812
parentd075718333d50cf582359162a89d3bab72b030f2 (diff)
downloadorg-mode-8cb1d66f8683ea38a09096cbba3a736c1ce70fe3.tar.gz
Mapping: Restore point and restriction in current buffer.
Daniel Clemente writes: Hi. After you eval this (for instance to count the number of headlines under a tree): (org-map-entries 'ignore t 'tree) you end up with a different view of the buffer because (org-narrow-to-subtree) was called. This seems an unwanted side effect since narrowing is not org-map-entries' job. Should (save-excursion) be used inside (org-map-entries ... 'tree) ? He is right, and save-restriction is needed as well. This is what this commit implements.
-rwxr-xr-xlisp/ChangeLog5
-rw-r--r--lisp/org.el66
2 files changed, 39 insertions, 32 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 2c1f400..8c7ae7a 100755
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,8 @@
+2009-01-14 Carsten Dominik <carsten.dominik@gmail.com>
+
+ * org.el (org-map-entries): Restore point and restriction after
+ `org-map-entries'.
+
2009-01-13 Carsten Dominik <carsten.dominik@gmail.com>
* org.el (org-time=, org-time<, org-time<=, org-time>)
diff --git a/lisp/org.el b/lisp/org.el
index 125c4f3..e769bd0 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -10166,39 +10166,41 @@ the scanner. The following items can be given here:
((eq match nil) (setq matcher t))
(t (setq matcher (if match (cdr (org-make-tags-matcher match)) t))))
- (when (eq scope 'tree)
- (org-back-to-heading t)
- (org-narrow-to-subtree)
- (setq scope nil))
+ (save-excursion
+ (save-restriction
+ (when (eq scope 'tree)
+ (org-back-to-heading t)
+ (org-narrow-to-subtree)
+ (setq scope nil))
- (if (not scope)
- (progn
- (org-prepare-agenda-buffers
- (list (buffer-file-name (current-buffer))))
- (org-scan-tags func matcher))
- ;; Get the right scope
- (setq pos (point))
- (cond
- ((and scope (listp scope) (symbolp (car scope)))
- (setq scope (eval scope)))
- ((eq scope 'agenda)
- (setq scope (org-agenda-files t)))
- ((eq scope 'agenda-with-archives)
- (setq scope (org-agenda-files t))
- (setq scope (org-add-archive-files scope)))
- ((eq scope 'file)
- (setq scope (list (buffer-file-name))))
- ((eq scope 'file-with-archives)
- (setq scope (org-add-archive-files (list (buffer-file-name))))))
- (org-prepare-agenda-buffers scope)
- (while (setq file (pop scope))
- (with-current-buffer (org-find-base-buffer-visiting file)
- (save-excursion
- (save-restriction
- (widen)
- (goto-char (point-min))
- (setq res (append res (org-scan-tags func matcher)))))))
- res)))
+ (if (not scope)
+ (progn
+ (org-prepare-agenda-buffers
+ (list (buffer-file-name (current-buffer))))
+ (setq res (org-scan-tags func matcher)))
+ ;; Get the right scope
+ (setq pos (point))
+ (cond
+ ((and scope (listp scope) (symbolp (car scope)))
+ (setq scope (eval scope)))
+ ((eq scope 'agenda)
+ (setq scope (org-agenda-files t)))
+ ((eq scope 'agenda-with-archives)
+ (setq scope (org-agenda-files t))
+ (setq scope (org-add-archive-files scope)))
+ ((eq scope 'file)
+ (setq scope (list (buffer-file-name))))
+ ((eq scope 'file-with-archives)
+ (setq scope (org-add-archive-files (list (buffer-file-name))))))
+ (org-prepare-agenda-buffers scope)
+ (while (setq file (pop scope))
+ (with-current-buffer (org-find-base-buffer-visiting file)
+ (save-excursion
+ (save-restriction
+ (widen)
+ (goto-char (point-min))
+ (setq res (append res (org-scan-tags func matcher))))))))))
+ res))
;;;; Properties