|
@@ -1093,6 +1093,61 @@ It determines the number of whitespaces to append by looking at
|
|
(string-match "\\S-+\\([ \t]*\\)" bullet)
|
|
(string-match "\\S-+\\([ \t]*\\)" bullet)
|
|
(replace-match spaces nil nil bullet 1))))
|
|
(replace-match spaces nil nil bullet 1))))
|
|
|
|
|
|
|
|
+(defun org-list-swap-items (beg-A beg-B 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.
|
|
|
|
+
|
|
|
|
+Assume BEG-A is lesser than BEG-B and that BEG-A and BEG-B belong
|
|
|
|
+to the same sub-list.
|
|
|
|
+
|
|
|
|
+This function modifies STRUCT."
|
|
|
|
+ (save-excursion
|
|
|
|
+ (let* ((end-A-no-blank (org-list-get-item-end-before-blank beg-A struct))
|
|
|
|
+ (end-B-no-blank (org-list-get-item-end-before-blank beg-B struct))
|
|
|
|
+ (end-A (org-list-get-item-end beg-A struct))
|
|
|
|
+ (end-B (org-list-get-item-end beg-B struct))
|
|
|
|
+ (size-A (- end-A-no-blank beg-A))
|
|
|
|
+ (size-B (- end-B-no-blank beg-B))
|
|
|
|
+ (body-A (buffer-substring beg-A end-A-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))
|
|
|
|
+ (sub-A (cons beg-A (org-list-get-subtree beg-A struct)))
|
|
|
|
+ (sub-B (cons beg-B (org-list-get-subtree beg-B struct))))
|
|
|
|
+ ;; 1. Move effectively items in buffer.
|
|
|
|
+ (goto-char beg-A)
|
|
|
|
+ (delete-region beg-A end-B-no-blank)
|
|
|
|
+ (insert (concat body-B between-A-no-blank-and-B body-A))
|
|
|
|
+ ;; 2. Now modify struct. No need to re-read the list, the
|
|
|
|
+ ;; transformation is just a shift of positions. Some special
|
|
|
|
+ ;; attention is required for items ending at END-A and END-B
|
|
|
|
+ ;; as empty spaces are not moved there. In others words,
|
|
|
|
+ ;; item BEG-A will end with whitespaces that were at the end
|
|
|
|
+ ;; of BEG-B and the same applies to BEG-B.
|
|
|
|
+ (mapc (lambda (e)
|
|
|
|
+ (let ((pos (car e)))
|
|
|
|
+ (cond
|
|
|
|
+ ((< pos beg-A))
|
|
|
|
+ ((memq pos sub-A)
|
|
|
|
+ (let ((end-e (nth 6 e)))
|
|
|
|
+ (setcar e (+ pos (- end-B-no-blank end-A-no-blank)))
|
|
|
|
+ (setcar (nthcdr 6 e)
|
|
|
|
+ (+ end-e (- end-B-no-blank end-A-no-blank)))
|
|
|
|
+ (when (= end-e end-A) (setcar (nthcdr 6 e) end-B))))
|
|
|
|
+ ((memq pos sub-B)
|
|
|
|
+ (let ((end-e (nth 6 e)))
|
|
|
|
+ (setcar e (- (+ pos beg-A) beg-B))
|
|
|
|
+ (setcar (nthcdr 6 e) (+ end-e (- beg-A beg-B)))
|
|
|
|
+ (when (= end-e end-B)
|
|
|
|
+ (setcar (nthcdr 6 e)
|
|
|
|
+ (+ beg-A size-B (- end-A end-A-no-blank))))))
|
|
|
|
+ ((< pos beg-B)
|
|
|
|
+ (let ((end-e (nth 6 e)))
|
|
|
|
+ (setcar e (+ pos (- size-B size-A)))
|
|
|
|
+ (setcar (nthcdr 6 e) (+ end-e (- size-B size-A))))))))
|
|
|
|
+ struct)
|
|
|
|
+ (sort struct (lambda (e1 e2) (< (car e1) (car e2)))))))
|
|
|
|
+
|
|
(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.
|
|
|
|
|
|
@@ -1246,7 +1301,7 @@ This function modifies STRUCT."
|
|
;; after bullet, counter, checkbox, and label.
|
|
;; after bullet, counter, checkbox, and label.
|
|
(if beforep
|
|
(if beforep
|
|
(goto-char item)
|
|
(goto-char item)
|
|
- (setq struct (org-list-exchange-items item (+ item item-size) struct))
|
|
|
|
|
|
+ (setq struct (org-list-swap-items item (+ item item-size) struct))
|
|
(goto-char (org-list-get-next-item
|
|
(goto-char (org-list-get-next-item
|
|
item struct (org-list-prevs-alist struct))))
|
|
item struct (org-list-prevs-alist struct))))
|
|
struct)))
|
|
struct)))
|
|
@@ -1394,61 +1449,6 @@ This function returns, destructively, the new list structure."
|
|
(move-marker item nil)))
|
|
(move-marker item nil)))
|
|
(t struct))))
|
|
(t struct))))
|
|
|
|
|
|
-(defun org-list-exchange-items (beg-A beg-B 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.
|
|
|
|
-
|
|
|
|
-Assume BEG-A is lesser than BEG-B and that BEG-A and BEG-B belong
|
|
|
|
-to the same sub-list.
|
|
|
|
-
|
|
|
|
-This function modifies STRUCT."
|
|
|
|
- (save-excursion
|
|
|
|
- (let* ((end-A-no-blank (org-list-get-item-end-before-blank beg-A struct))
|
|
|
|
- (end-B-no-blank (org-list-get-item-end-before-blank beg-B struct))
|
|
|
|
- (end-A (org-list-get-item-end beg-A struct))
|
|
|
|
- (end-B (org-list-get-item-end beg-B struct))
|
|
|
|
- (size-A (- end-A-no-blank beg-A))
|
|
|
|
- (size-B (- end-B-no-blank beg-B))
|
|
|
|
- (body-A (buffer-substring beg-A end-A-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))
|
|
|
|
- (sub-A (cons beg-A (org-list-get-subtree beg-A struct)))
|
|
|
|
- (sub-B (cons beg-B (org-list-get-subtree beg-B struct))))
|
|
|
|
- ;; 1. Move effectively items in buffer.
|
|
|
|
- (goto-char beg-A)
|
|
|
|
- (delete-region beg-A end-B-no-blank)
|
|
|
|
- (insert (concat body-B between-A-no-blank-and-B body-A))
|
|
|
|
- ;; 2. Now modify struct. No need to re-read the list, the
|
|
|
|
- ;; transformation is just a shift of positions. Some special
|
|
|
|
- ;; attention is required for items ending at END-A and END-B
|
|
|
|
- ;; as empty spaces are not moved there. In others words,
|
|
|
|
- ;; item BEG-A will end with whitespaces that were at the end
|
|
|
|
- ;; of BEG-B and the same applies to BEG-B.
|
|
|
|
- (mapc (lambda (e)
|
|
|
|
- (let ((pos (car e)))
|
|
|
|
- (cond
|
|
|
|
- ((< pos beg-A))
|
|
|
|
- ((memq pos sub-A)
|
|
|
|
- (let ((end-e (nth 6 e)))
|
|
|
|
- (setcar e (+ pos (- end-B-no-blank end-A-no-blank)))
|
|
|
|
- (setcar (nthcdr 6 e)
|
|
|
|
- (+ end-e (- end-B-no-blank end-A-no-blank)))
|
|
|
|
- (when (= end-e end-A) (setcar (nthcdr 6 e) end-B))))
|
|
|
|
- ((memq pos sub-B)
|
|
|
|
- (let ((end-e (nth 6 e)))
|
|
|
|
- (setcar e (- (+ pos beg-A) beg-B))
|
|
|
|
- (setcar (nthcdr 6 e) (+ end-e (- beg-A beg-B)))
|
|
|
|
- (when (= end-e end-B)
|
|
|
|
- (setcar (nthcdr 6 e)
|
|
|
|
- (+ beg-A size-B (- end-A end-A-no-blank))))))
|
|
|
|
- ((< pos beg-B)
|
|
|
|
- (let ((end-e (nth 6 e)))
|
|
|
|
- (setcar e (+ pos (- size-B size-A)))
|
|
|
|
- (setcar (nthcdr 6 e) (+ end-e (- size-B size-A))))))))
|
|
|
|
- struct)
|
|
|
|
- (sort struct (lambda (e1 e2) (< (car e1) (car e2)))))))
|
|
|
|
-
|
|
|
|
(defun org-list-struct-outdent (start end struct parents)
|
|
(defun org-list-struct-outdent (start end struct parents)
|
|
"Outdent items between positions START and END.
|
|
"Outdent items between positions START and END.
|
|
|
|
|
|
@@ -2066,7 +2066,7 @@ the item, so this really moves item trees."
|
|
(error "Cannot move this item further down"))
|
|
(error "Cannot move this item further down"))
|
|
(if (not next-item)
|
|
(if (not next-item)
|
|
(setq struct (org-list-send-item item 'begin struct))
|
|
(setq struct (org-list-send-item item 'begin struct))
|
|
- (setq struct (org-list-exchange-items item next-item struct))
|
|
|
|
|
|
+ (setq struct (org-list-swap-items item next-item struct))
|
|
(goto-char
|
|
(goto-char
|
|
(org-list-get-next-item item struct (org-list-prevs-alist struct))))
|
|
(org-list-get-next-item item struct (org-list-prevs-alist struct))))
|
|
(org-list-write-struct struct (org-list-parents-alist struct))
|
|
(org-list-write-struct struct (org-list-parents-alist struct))
|
|
@@ -2087,7 +2087,7 @@ the item, so this really moves item trees."
|
|
(error "Cannot move this item further up"))
|
|
(error "Cannot move this item further up"))
|
|
(if (not prev-item)
|
|
(if (not prev-item)
|
|
(setq struct (org-list-send-item item 'end struct))
|
|
(setq struct (org-list-send-item item 'end struct))
|
|
- (setq struct (org-list-exchange-items prev-item item struct)))
|
|
|
|
|
|
+ (setq struct (org-list-swap-items prev-item item struct)))
|
|
(org-list-write-struct struct (org-list-parents-alist struct))
|
|
(org-list-write-struct struct (org-list-parents-alist struct))
|
|
(org-move-to-column col)))
|
|
(org-move-to-column col)))
|
|
|
|
|