From e720ae53ac68e4d6f8b0f582fd1cd979942185a4 Mon Sep 17 00:00:00 2001 From: Glenn Morris Date: Wed, 18 Aug 2010 20:45:46 -0700 Subject: [PATCH] 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. --- lisp/org/ChangeLog | 9 +++++++ lisp/org/ob.el | 3 +-- lisp/org/org-macs.el | 60 ++++++++++++++++++++++++++++++++++++++++++++ lisp/org/org.el | 56 ----------------------------------------- 4 files changed, 70 insertions(+), 58 deletions(-) diff --git a/lisp/org/ChangeLog b/lisp/org/ChangeLog index 5b650492442..c0b3fa567c6 100644 --- a/lisp/org/ChangeLog +++ b/lisp/org/ChangeLog @@ -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 --git a/lisp/org/ob.el b/lisp/org/ob.el index 4ae3e4f662c..a58fb4eca8a 100644 --- a/lisp/org/ob.el +++ b/lisp/org/ob.el @@ -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 --git a/lisp/org/org-macs.el b/lisp/org/org-macs.el index abcdcdc94eb..212fae4fcc9 100644 --- a/lisp/org/org-macs.el +++ b/lisp/org/org-macs.el @@ -300,6 +300,66 @@ The number of levels is controlled by `org-inlinetask-min-level'" (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 --git a/lisp/org/org.el b/lisp/org/org.el index 5b37e0aa260..a2965e87d22 100644 --- a/lisp/org/org.el +++ b/lisp/org/org.el @@ -6190,62 +6190,6 @@ Optional argument N means put the headline into the Nth line of the window." (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 -- 2.39.2