org-list: Preserve visibility when moving items
* lisp/org-list.el (org-list-swap-items, org-list-send-item): Preserve visibility when moving items.
This commit is contained in:
parent
f6745ff2d0
commit
200cf5efe1
|
@ -1071,8 +1071,10 @@ It determines the number of whitespaces to append by looking at
|
||||||
|
|
||||||
(defun org-list-swap-items (beg-A beg-B struct)
|
(defun org-list-swap-items (beg-A beg-B struct)
|
||||||
"Swap item starting at BEG-A with item starting at BEG-B in STRUCT.
|
"Swap item starting at BEG-A with item starting at BEG-B in STRUCT.
|
||||||
Blank lines at the end of items are left in place. Return the
|
|
||||||
new structure after the changes.
|
Blank lines at the end of items are left in place. Item
|
||||||
|
visibility is preserved. Return the new structure after the
|
||||||
|
changes.
|
||||||
|
|
||||||
Assume BEG-A is lesser than BEG-B and that BEG-A and BEG-B belong
|
Assume BEG-A is lesser than BEG-B and that BEG-A and BEG-B belong
|
||||||
to the same sub-list.
|
to the same sub-list.
|
||||||
|
@ -1089,7 +1091,14 @@ This function modifies STRUCT."
|
||||||
(body-B (buffer-substring beg-B end-B-no-blank))
|
(body-B (buffer-substring beg-B end-B-no-blank))
|
||||||
(between-A-no-blank-and-B (buffer-substring end-A-no-blank beg-B))
|
(between-A-no-blank-and-B (buffer-substring end-A-no-blank beg-B))
|
||||||
(sub-A (cons beg-A (org-list-get-subtree beg-A struct)))
|
(sub-A (cons beg-A (org-list-get-subtree beg-A struct)))
|
||||||
(sub-B (cons beg-B (org-list-get-subtree beg-B struct))))
|
(sub-B (cons beg-B (org-list-get-subtree beg-B struct)))
|
||||||
|
;; Store visibility status.
|
||||||
|
(overlays (mapcar
|
||||||
|
(lambda (ov) (cond ((not ov) 'subtree)
|
||||||
|
((cdr ov) 'children)
|
||||||
|
(t 'folded)))
|
||||||
|
(list (overlays-in beg-A end-A)
|
||||||
|
(overlays-in beg-B end-B)))))
|
||||||
;; 1. Move effectively items in buffer.
|
;; 1. Move effectively items in buffer.
|
||||||
(goto-char beg-A)
|
(goto-char beg-A)
|
||||||
(delete-region beg-A end-B-no-blank)
|
(delete-region beg-A end-B-no-blank)
|
||||||
|
@ -1122,7 +1131,15 @@ This function modifies STRUCT."
|
||||||
(setcar e (+ pos (- size-B size-A)))
|
(setcar e (+ pos (- size-B size-A)))
|
||||||
(setcar (nthcdr 6 e) (+ end-e (- size-B size-A))))))))
|
(setcar (nthcdr 6 e) (+ end-e (- size-B size-A))))))))
|
||||||
struct)
|
struct)
|
||||||
(sort struct (lambda (e1 e2) (< (car e1) (car e2)))))))
|
(setq struct (sort struct (lambda (e1 e2) (< (car e1) (car e2)))))
|
||||||
|
;; Restore visibility status, if needed.
|
||||||
|
(unless (eq (car overlays) 'subtree)
|
||||||
|
(org-list-set-item-visibility
|
||||||
|
(+ beg-B (- size-B size-A)) struct (car overlays)))
|
||||||
|
(unless (eq (nth 1 overlays) 'subtree)
|
||||||
|
(org-list-set-item-visibility beg-A struct (nth 1 overlays)))
|
||||||
|
;; Return structure.
|
||||||
|
struct)))
|
||||||
|
|
||||||
(defun org-list-separating-blank-lines-number (pos struct prevs)
|
(defun org-list-separating-blank-lines-number (pos struct prevs)
|
||||||
"Return number of blank lines that should separate items in list.
|
"Return number of blank lines that should separate items in list.
|
||||||
|
@ -1351,6 +1368,8 @@ added to the kill-ring.
|
||||||
|
|
||||||
If DEST is `delete', ITEM will be deleted.
|
If DEST is `delete', ITEM will be deleted.
|
||||||
|
|
||||||
|
Visibility of item is preserved.
|
||||||
|
|
||||||
This function returns, destructively, the new list structure."
|
This function returns, destructively, the new list structure."
|
||||||
(let* ((prevs (org-list-prevs-alist struct))
|
(let* ((prevs (org-list-prevs-alist struct))
|
||||||
(item-end (org-list-get-item-end item struct))
|
(item-end (org-list-get-item-end item struct))
|
||||||
|
@ -1393,7 +1412,12 @@ This function returns, destructively, the new list structure."
|
||||||
(org-list-get-last-item item struct prevs))
|
(org-list-get-last-item item struct prevs))
|
||||||
(point-at-eol)))))
|
(point-at-eol)))))
|
||||||
(t dest)))
|
(t dest)))
|
||||||
(org-M-RET-may-split-line nil))
|
(org-M-RET-may-split-line nil)
|
||||||
|
;; Store visibility.
|
||||||
|
(visibility (let ((ovs (overlays-in item item-end)))
|
||||||
|
(cond ((not ovs) 'subtree)
|
||||||
|
((cdr ovs) 'children)
|
||||||
|
(t 'folded)))))
|
||||||
(cond
|
(cond
|
||||||
((eq dest 'delete) (org-list-delete-item item struct))
|
((eq dest 'delete) (org-list-delete-item item struct))
|
||||||
((eq dest 'kill)
|
((eq dest 'kill)
|
||||||
|
@ -1429,9 +1453,11 @@ This function returns, destructively, the new list structure."
|
||||||
(+ end shift)))))))
|
(+ end shift)))))))
|
||||||
moved-items))
|
moved-items))
|
||||||
(lambda (e1 e2) (< (car e1) (car e2))))))
|
(lambda (e1 e2) (< (car e1) (car e2))))))
|
||||||
;; 2. Eventually delete extra copy of the item and clean marker.
|
;; 2. Restore visibility if appropriate.
|
||||||
(prog1
|
(unless (eq visibility 'subtree)
|
||||||
(org-list-delete-item (marker-position item) struct)
|
(org-list-set-item-visibility (point) struct visibility))
|
||||||
|
;; 3. Eventually delete extra copy of the item and clean marker.
|
||||||
|
(prog1 (org-list-delete-item (marker-position item) struct)
|
||||||
(move-marker item nil)))
|
(move-marker item nil)))
|
||||||
(t struct))))
|
(t struct))))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue