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.
This commit is contained in:
Carsten Dominik 2009-01-14 21:22:37 +01:00
parent d075718333
commit 8cb1d66f86
2 changed files with 39 additions and 32 deletions

View File

@ -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> 2009-01-13 Carsten Dominik <carsten.dominik@gmail.com>
* org.el (org-time=, org-time<, org-time<=, org-time>) * org.el (org-time=, org-time<, org-time<=, org-time>)

View File

@ -10166,39 +10166,41 @@ the scanner. The following items can be given here:
((eq match nil) (setq matcher t)) ((eq match nil) (setq matcher t))
(t (setq matcher (if match (cdr (org-make-tags-matcher match)) t)))) (t (setq matcher (if match (cdr (org-make-tags-matcher match)) t))))
(when (eq scope 'tree) (save-excursion
(org-back-to-heading t) (save-restriction
(org-narrow-to-subtree) (when (eq scope 'tree)
(setq scope nil)) (org-back-to-heading t)
(org-narrow-to-subtree)
(setq scope nil))
(if (not scope) (if (not scope)
(progn (progn
(org-prepare-agenda-buffers (org-prepare-agenda-buffers
(list (buffer-file-name (current-buffer)))) (list (buffer-file-name (current-buffer))))
(org-scan-tags func matcher)) (setq res (org-scan-tags func matcher)))
;; Get the right scope ;; Get the right scope
(setq pos (point)) (setq pos (point))
(cond (cond
((and scope (listp scope) (symbolp (car scope))) ((and scope (listp scope) (symbolp (car scope)))
(setq scope (eval scope))) (setq scope (eval scope)))
((eq scope 'agenda) ((eq scope 'agenda)
(setq scope (org-agenda-files t))) (setq scope (org-agenda-files t)))
((eq scope 'agenda-with-archives) ((eq scope 'agenda-with-archives)
(setq scope (org-agenda-files t)) (setq scope (org-agenda-files t))
(setq scope (org-add-archive-files scope))) (setq scope (org-add-archive-files scope)))
((eq scope 'file) ((eq scope 'file)
(setq scope (list (buffer-file-name)))) (setq scope (list (buffer-file-name))))
((eq scope 'file-with-archives) ((eq scope 'file-with-archives)
(setq scope (org-add-archive-files (list (buffer-file-name)))))) (setq scope (org-add-archive-files (list (buffer-file-name))))))
(org-prepare-agenda-buffers scope) (org-prepare-agenda-buffers scope)
(while (setq file (pop scope)) (while (setq file (pop scope))
(with-current-buffer (org-find-base-buffer-visiting file) (with-current-buffer (org-find-base-buffer-visiting file)
(save-excursion (save-excursion
(save-restriction (save-restriction
(widen) (widen)
(goto-char (point-min)) (goto-char (point-min))
(setq res (append res (org-scan-tags func matcher))))))) (setq res (append res (org-scan-tags func matcher))))))))))
res))) res))
;;;; Properties ;;;; Properties