# HG changeset patch # User Glenn Morris # Date 1282189546 25200 # Node ID 80192451ba3482e4d672a0ec666b048ceb58ebbf # Parent dce0738d09efc96b8848888e80cd0d17c73748df Fix previous Org change. * org.el (org-outline-overlay-data, org-set-outline-overlay-data) (org-save-outline-visibility): Move to org-macs. * org-macs.el (org-outline-overlay-data, org-set-outline-overlay-data) (org-save-outline-visibility): Move here from org.el. (show-all): Autoload it. * ob.el: Don't require org when compiling. diff -r dce0738d09ef -r 80192451ba34 lisp/org/ChangeLog --- a/lisp/org/ChangeLog Thu Aug 19 01:25:36 2010 +0200 +++ b/lisp/org/ChangeLog Wed Aug 18 20:45:46 2010 -0700 @@ -1,3 +1,12 @@ +2010-08-19 Glenn Morris + + * org.el (org-outline-overlay-data, org-set-outline-overlay-data) + (org-save-outline-visibility): Move to org-macs. + * org-macs.el (org-outline-overlay-data, org-set-outline-overlay-data) + (org-save-outline-visibility): Move here from org.el. + (show-all): Autoload it. + * ob.el: Don't require org when compiling. + 2010-08-18 Glenn Morris * ob.el: Require org when compiling. diff -r dce0738d09ef -r 80192451ba34 lisp/org/ob.el --- a/lisp/org/ob.el Thu Aug 19 01:25:36 2010 +0200 +++ b/lisp/org/ob.el Wed Aug 18 20:45:46 2010 -0700 @@ -30,8 +30,7 @@ ;;; Code: (eval-when-compile - (require 'cl) - (require 'org)) ; org-save-outline-visibility macro + (require 'cl)) (require 'org-macs) (defvar org-babel-call-process-region-original) diff -r dce0738d09ef -r 80192451ba34 lisp/org/org-macs.el --- a/lisp/org/org-macs.el Thu Aug 19 01:25:36 2010 +0200 +++ b/lisp/org/org-macs.el Wed Aug 18 20:45:46 2010 -0700 @@ -300,6 +300,66 @@ (nstars (if org-odd-levels-only (1- (* limit-level 2)) limit-level))) (format "\\*\\{1,%d\\} " nstars)))) + +;;; Saving and restoring visibility + +(defun org-outline-overlay-data (&optional use-markers) + "Return a list of the locations of all outline overlays. +The are overlays with the `invisible' property value `outline'. +The return values is a list of cons cells, with start and stop +positions for each overlay. +If USE-MARKERS is set, return the positions as markers." + (let (beg end) + (save-excursion + (save-restriction + (widen) + (delq nil + (mapcar (lambda (o) + (when (eq (overlay-get o 'invisible) 'outline) + (setq beg (overlay-start o) + end (overlay-end o)) + (and beg end (> end beg) + (if use-markers + (cons (move-marker (make-marker) beg) + (move-marker (make-marker) end)) + (cons beg end))))) + (overlays-in (point-min) (point-max)))))))) + +(autoload 'show-all "outline" nil t) + +(defun org-set-outline-overlay-data (data) + "Create visibility overlays for all positions in DATA. +DATA should have been made by `org-outline-overlay-data'." + (let (o) + (save-excursion + (save-restriction + (widen) + (show-all) + (mapc (lambda (c) + (setq o (make-overlay (car c) (cdr c))) + (overlay-put o 'invisible 'outline)) + data))))) + +(defmacro org-save-outline-visibility (use-markers &rest body) + "Save and restore outline visibility around BODY. +If USE-MARKERS is non-nil, use markers for the positions. +This means that the buffer may change while running BODY, +but it also means that the buffer should stay alive +during the operation, because otherwise all these markers will +point nowhere." + (declare (indent 1)) + `(let ((data (org-outline-overlay-data ,use-markers))) + (unwind-protect + (progn + ,@body + (org-set-outline-overlay-data data)) + (when ,use-markers + (mapc (lambda (c) + (and (markerp (car c)) (move-marker (car c) nil)) + (and (markerp (cdr c)) (move-marker (cdr c) nil))) + data))))) + + (provide 'org-macs) ;; arch-tag: 7e6a73ce-aac9-4fc0-9b30-ce6f89dc6668 diff -r dce0738d09ef -r 80192451ba34 lisp/org/org.el --- a/lisp/org/org.el Thu Aug 19 01:25:36 2010 +0200 +++ b/lisp/org/org.el Wed Aug 18 20:45:46 2010 -0700 @@ -6190,62 +6190,6 @@ (beginning-of-line) (recenter (prefix-numeric-value N)))) -;;; Saving and restoring visibility - -(defun org-outline-overlay-data (&optional use-markers) - "Return a list of the locations of all outline overlays. -The are overlays with the `invisible' property value `outline'. -The return values is a list of cons cells, with start and stop -positions for each overlay. -If USE-MARKERS is set, return the positions as markers." - (let (beg end) - (save-excursion - (save-restriction - (widen) - (delq nil - (mapcar (lambda (o) - (when (eq (overlay-get o 'invisible) 'outline) - (setq beg (overlay-start o) - end (overlay-end o)) - (and beg end (> end beg) - (if use-markers - (cons (move-marker (make-marker) beg) - (move-marker (make-marker) end)) - (cons beg end))))) - (overlays-in (point-min) (point-max)))))))) - -(defun org-set-outline-overlay-data (data) - "Create visibility overlays for all positions in DATA. -DATA should have been made by `org-outline-overlay-data'." - (let (o) - (save-excursion - (save-restriction - (widen) - (show-all) - (mapc (lambda (c) - (setq o (make-overlay (car c) (cdr c))) - (overlay-put o 'invisible 'outline)) - data))))) - -(defmacro org-save-outline-visibility (use-markers &rest body) - "Save and restore outline visibility around BODY. -If USE-MARKERS is non-nil, use markers for the positions. -This means that the buffer may change while running BODY, -but it also means that the buffer should stay alive -during the operation, because otherwise all these markers will -point nowhere." - (declare (indent 1)) - `(let ((data (org-outline-overlay-data ,use-markers))) - (unwind-protect - (progn - ,@body - (org-set-outline-overlay-data data)) - (when ,use-markers - (mapc (lambda (c) - (and (markerp (car c)) (move-marker (car c) nil)) - (and (markerp (cdr c)) (move-marker (cdr c) nil))) - data))))) - ;;; Folding of blocks