Browse Source

Optimize writing of structure to buffer.

* org-list.el (org-list-struct-apply-struct): No longer shift item's
  body twice: one after replacing bullet and one after changing
  indentation.
Nicolas Goaziou 14 years ago
parent
commit
8385393fe6
1 changed files with 19 additions and 31 deletions
  1. 19 31
      lisp/org-list.el

+ 19 - 31
lisp/org-list.el

@@ -996,9 +996,25 @@ Initial position is restored after the changes."
 	 (ancestor (caar struct))
 	 (ancestor (caar struct))
          (modify
          (modify
           (lambda (item)
           (lambda (item)
-            (goto-char (car item))
-	    (org-list-indent-item (nth 1 item))
-	    (org-list-replace-bullet (org-list-bullet-string (nth 2 item)))))
+	    (goto-char (car item))
+            (let* ((new-ind (nth 1 item))
+		   (new-bul (org-list-bullet-string (nth 2 item)))
+		   (old-ind (org-get-indentation))
+		   (old-bul (progn
+			      (looking-at "[ \t]*\\(\\S-+[ \t]*\\)")
+			      (match-string 1)))
+		   (old-body-ind (+ (length old-bul) old-ind))
+		   (new-body-ind (+ (length new-bul) new-ind)))
+	      ;; Replace bullet
+	      (unless (equal new-bul old-bul)
+		(save-excursion (replace-match new-bul nil nil nil 1)))
+	      ;; Indent item to appropriate column
+	      (unless (= new-ind old-ind)
+		(delete-region (point-at-bol) (match-beginning 1))
+		(indent-to new-ind))
+	      ;; Shift item's body
+	      (unless (= old-body-ind new-body-ind)
+		(org-shift-item-indentation (- new-body-ind old-body-ind))))))
 	 ;; Remove ancestor if it is left.
 	 ;; Remove ancestor if it is left.
 	 (struct-to-apply (if (or (not ancestor) (= 0 ancestor)) (cdr struct) struct)))
 	 (struct-to-apply (if (or (not ancestor) (= 0 ancestor)) (cdr struct) struct)))
     ;; Apply changes from bottom to top
     ;; Apply changes from bottom to top
@@ -1033,18 +1049,6 @@ Sub-items are not moved."
               (indent-line-to (+ i delta)))))
               (indent-line-to (+ i delta)))))
         (beginning-of-line 0)))))
         (beginning-of-line 0)))))
 
 
-(defun org-list-indent-item (ind)
-  "Change indentation of item at point to IND.
-It does not move sub-lists."
-  (save-excursion
-    (beginning-of-line)
-    (let ((old-ind (org-get-indentation)))
-      (unless (= ind old-ind)
-        (org-shift-item-indentation (- ind old-ind))
-        (skip-chars-forward " \t")
-        (delete-region (point-at-bol) (point))
-        (org-indent-to-column ind)))))
-
 (defun org-outdent-item (arg)
 (defun org-outdent-item (arg)
   "Outdent a local list item, but not its children."
   "Outdent a local list item, but not its children."
   (interactive "p")
   (interactive "p")
@@ -1190,22 +1194,6 @@ It determines the number of whitespaces to append by looking at
        (number-to-string (1+ (string-to-number (match-string 0 bullet)))) nil nil bullet)
        (number-to-string (1+ (string-to-number (match-string 0 bullet)))) nil nil bullet)
     bullet))
     bullet))
 
 
-(defun org-list-replace-bullet (new-bullet)
-  "Replace current item's bullet with NEW-BULLET.
-Item body is re-indented, but sub-lists are not moved. Assume
-point is at item."
-  (save-excursion
-    (beginning-of-line)
-    (let ((old (progn
-                 (looking-at "[ \t]*\\(\\S-+[ \t]*\\)")
-                 (match-string 1))))
-      (unless (equal new-bullet old)
-        (replace-match new-bullet nil nil nil 1)
-        ;; When bullet lengths are differents, move the whole
-        ;; sublist accordingly
-        (org-shift-item-indentation
-         (- (length new-bullet) (length old)))))))
-
 (defun org-fix-bullet-type (&optional force-bullet)
 (defun org-fix-bullet-type (&optional force-bullet)
   "Make sure all items in this list have the same bullet as the first item.
   "Make sure all items in this list have the same bullet as the first item.
 Also, fix the indentation."
 Also, fix the indentation."