summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2018-02-11 11:37:50 +0100
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2018-02-11 11:37:50 +0100
commit013941de86e0f70554ecc5a87abd53562f4be897 (patch)
treeb426a6c78cfa7f6902581ff022a2048771d78fc3
parent2956408f7559a21c2ddfc747dc3580747bcbb02f (diff)
downloadorg-mode-013941de86e0f70554ecc5a87abd53562f4be897.tar.gz
`org-save-outline-visibility' preserve outline, blocks and drawers
* lisp/org-macs.el (org-save-outline-visibility): Also preserve blocks and drawers visibility. Re-implement without helper functions. (org-outline-overlay-data): (org-set-outline-overlay-data): Remove functions.
-rw-r--r--etc/ORG-NEWS4
-rw-r--r--lisp/ob-core.el1
-rw-r--r--lisp/org-macs.el70
3 files changed, 33 insertions, 42 deletions
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index aedede2..cbd3a47 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -212,6 +212,10 @@ See docstring for details.
See docstring for details.
** Removed functions
+*** ~org-outline-overlay-data~
+Use ~org-save-outline-visibility~ instead.
+*** ~org-set-outline-overlay-data~
+Use ~org-save-outline-visibility~ instead.
*** ~org-get-string-indentation~
It was not used throughout the code base.
*** ~org-fix-indentation~
diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index cf18399..ecf610b 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -78,7 +78,6 @@
(declare-function org-previous-block "org" (arg &optional block-regexp))
(declare-function org-remove-indentation "org" (code &optional n))
(declare-function org-reverse-string "org" (string))
-(declare-function org-set-outline-overlay-data "org" (data))
(declare-function org-show-context "org" (&optional key))
(declare-function org-src-coderef-format "org-src" (&optional element))
(declare-function org-src-coderef-regexp "org-src" (fmt &optional label))
diff --git a/lisp/org-macs.el b/lisp/org-macs.el
index a032dfe..e2e1857 100644
--- a/lisp/org-macs.el
+++ b/lisp/org-macs.el
@@ -33,7 +33,6 @@
(declare-function org-defkey "org" (keymap key def))
-
;;; Macros
@@ -122,21 +121,36 @@
(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."
+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 to nowhere."
(declare (debug (form body)) (indent 1))
- (org-with-gensyms (data)
- `(let ((,data (org-outline-overlay-data ,use-markers)))
- (unwind-protect
- (prog1 (progn ,@body)
- (org-set-outline-overlay-data ,data))
- (when ,use-markers
- (dolist (c ,data)
- (when (markerp (car c)) (move-marker (car c) nil))
- (when (markerp (cdr c)) (move-marker (cdr c) nil))))))))
+ (org-with-gensyms (data invisible-types markers?)
+ `(let* ((,invisible-types '(org-hide-block org-hide-drawer outline))
+ (,markers? ,use-markers)
+ (,data
+ (mapcar (lambda (o)
+ (let ((beg (overlay-start o))
+ (end (overlay-end o))
+ (type (overlay-get o 'invisible)))
+ (and beg end
+ (> end beg)
+ (memq type ,invisible-types)
+ (list (if ,markers? (copy-marker beg) beg)
+ (if ,markers? (copy-marker end t) end)
+ type))))
+ (org-with-wide-buffer
+ (overlays-in (point-min) (point-max))))))
+ (unwind-protect (progn ,@body)
+ (org-with-wide-buffer
+ (dolist (type ,invisible-types)
+ (remove-overlays (point-min) (point-max) 'invisible type))
+ (pcase-dolist (`(,beg ,end ,type) (delq nil ,data))
+ (org-flag-region beg end t type)
+ (when ,markers?
+ (set-marker beg nil)
+ (set-marker end nil))))))))
(defmacro org-with-wide-buffer (&rest body)
"Execute body while temporarily widening the buffer."
@@ -770,32 +784,6 @@ SPEC is the invisibility spec, as a symbol."
(overlay-put o 'invisible spec)
(overlay-put o 'isearch-open-invisible #'delete-overlay))))
-(defun org-outline-overlay-data (&optional use-markers)
- "Return a list of the locations of all outline overlays.
-These are overlays with the `invisible' property value `outline'.
-The return value 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)
- (org-with-wide-buffer
- (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 (copy-marker beg)
- (copy-marker end t))
- (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'."
- (org-with-wide-buffer
- (org-show-all)
- (dolist (c data) (org-flag-region (car c) (cdr c) t 'outline))))
;;; Miscellaneous