Browse Source

Adapt indentation when bullet width changes.

Commands that modify the bullet style of a plain list, or that
renumber such a list may lead to changes in the width of a bullet.
The indentation of the lines below such a bullet is now automatically
adapted.

Also fixes a bug in bullet style cycling.
Carsten Dominik 16 years ago
parent
commit
461c9df562
2 changed files with 38 additions and 9 deletions
  1. 7 1
      lisp/ChangeLog
  2. 31 8
      lisp/org-list.el

+ 7 - 1
lisp/ChangeLog

@@ -1,3 +1,9 @@
+2008-11-20  Carsten Dominik  <carsten.dominik@gmail.com>
+
+	* org-list.el (org-cycle-list-bullet, org-fix-bullet-type)
+	(org-get-string-indentation): Adapt indentation when the bullet
+	width changes.
+
 2008-11-19  Carsten Dominik  <carsten.dominik@gmail.com>
 2008-11-19  Carsten Dominik  <carsten.dominik@gmail.com>
 
 
 	* org-remember.el (org-remember-finalize): Make interactive.
 	* org-remember.el (org-remember-finalize): Make interactive.
@@ -5,7 +11,7 @@
 	(org-remember-finish-immediately): Call `org-remember-finalize'
 	(org-remember-finish-immediately): Call `org-remember-finalize'
 	directly.
 	directly.
 	(org-remember-finalize): Make `org-remember-finalize' an interactive
 	(org-remember-finalize): Make `org-remember-finalize' an interactive
-	function. 
+	function.
 
 
 2008-11-18  Carsten Dominik  <carsten.dominik@gmail.com>
 2008-11-18  Carsten Dominik  <carsten.dominik@gmail.com>
 
 

+ 31 - 8
lisp/org-list.el

@@ -589,7 +589,7 @@ If WHICH is a string, use that as the new bullet.  If WHICH is an integer,
    (beginning-of-line 1)
    (beginning-of-line 1)
    (let ((current (match-string 0))
    (let ((current (match-string 0))
 	 (prevp (eq which 'previous))
 	 (prevp (eq which 'previous))
-	 new)
+	 new old)
      (setq new (cond
      (setq new (cond
 		((and (numberp which)
 		((and (numberp which)
 		      (nth (1- which) '("-" "+" "*" "1." "1)"))))
 		      (nth (1- which) '("-" "+" "*" "1." "1)"))))
@@ -597,10 +597,14 @@ If WHICH is a string, use that as the new bullet.  If WHICH is an integer,
 		((string-match "\\+" current)
 		((string-match "\\+" current)
 		 (if prevp "-" (if (looking-at "\\S-") "1." "*")))
 		 (if prevp "-" (if (looking-at "\\S-") "1." "*")))
 		((string-match "\\*" current) (if prevp "+" "1."))
 		((string-match "\\*" current) (if prevp "+" "1."))
-		((string-match "\\." current) (if prevp "*" "1)"))
+		((string-match "\\." current)
+		 (if prevp (if (looking-at "\\S-") "+" "*") "1)"))
 		((string-match ")" current) (if prevp "1." "-"))
 		((string-match ")" current) (if prevp "1." "-"))
 		(t (error "This should not happen"))))
 		(t (error "This should not happen"))))
-     (and (looking-at "\\([ \t]*\\)\\S-+") (replace-match (concat "\\1" new)))
+     (and (looking-at "\\([ \t]*\\)\\(\\S-+\\)")
+	  (setq old (match-string 2))
+	  (replace-match (concat "\\1" new)))
+     (org-shift-item-indentation (- (length new) (length old)))
      (org-fix-bullet-type)
      (org-fix-bullet-type)
      (org-maybe-renumber-ordered-list))))
      (org-maybe-renumber-ordered-list))))
 
 
@@ -629,7 +633,7 @@ with something like \"1.\" or \"2)\"."
 	      (buffer-substring (point-at-bol) (match-beginning 3))))
 	      (buffer-substring (point-at-bol) (match-beginning 3))))
 	;; (term (substring (match-string 3) -1))
 	;; (term (substring (match-string 3) -1))
 	ind1 (n (1- arg))
 	ind1 (n (1- arg))
-	fmt bobp)
+	fmt bobp old new)
     ;; find where this list begins
     ;; find where this list begins
     (org-beginning-of-item-list)
     (org-beginning-of-item-list)
     (setq bobp (bobp))
     (setq bobp (bobp))
@@ -647,20 +651,23 @@ with something like \"1.\" or \"2)\"."
 	  (if (> ind1 ind) (throw 'next t))
 	  (if (> ind1 ind) (throw 'next t))
 	  (if (< ind1 ind) (throw 'exit t))
 	  (if (< ind1 ind) (throw 'exit t))
 	  (if (not (org-at-item-p)) (throw 'exit nil))
 	  (if (not (org-at-item-p)) (throw 'exit nil))
+	  (setq old (match-string 2))
 	  (delete-region (match-beginning 2) (match-end 2))
 	  (delete-region (match-beginning 2) (match-end 2))
 	  (goto-char (match-beginning 2))
 	  (goto-char (match-beginning 2))
-	  (insert (format fmt (setq n (1+ n)))))))
+	  (insert (setq new (format fmt (setq n (1+ n)))))
+	  (org-shift-item-indentation (- (length new) (length old))))))
     (goto-line line)
     (goto-line line)
     (org-move-to-column col)))
     (org-move-to-column col)))
 
 
 (defun org-fix-bullet-type ()
 (defun org-fix-bullet-type ()
-  "Make sure all items in this list have the same bullet as the firsst item."
+  "Make sure all items in this list have the same bullet as the first item.
+Also, fix the indentation."
   (interactive)
   (interactive)
   (unless (org-at-item-p) (error "This is not a list"))
   (unless (org-at-item-p) (error "This is not a list"))
   (let ((line (org-current-line))
   (let ((line (org-current-line))
 	(col (current-column))
 	(col (current-column))
 	(ind (current-indentation))
 	(ind (current-indentation))
-	ind1 bullet)
+	ind1 bullet oldbullet)
     ;; find where this list begins
     ;; find where this list begins
     (org-beginning-of-item-list)
     (org-beginning-of-item-list)
     (beginning-of-line 1)
     (beginning-of-line 1)
@@ -681,12 +688,28 @@ with something like \"1.\" or \"2)\"."
 	  (if (not (org-at-item-p)) (throw 'exit nil))
 	  (if (not (org-at-item-p)) (throw 'exit nil))
 	  (skip-chars-forward " \t")
 	  (skip-chars-forward " \t")
 	  (looking-at "\\S-+")
 	  (looking-at "\\S-+")
-	  (replace-match bullet))))
+	  (setq oldbullet (match-string 0))
+	  (replace-match bullet)
+	  (org-shift-item-indentation (- (length bullet) (length oldbullet))))))
     (goto-line line)
     (goto-line line)
     (org-move-to-column col)
     (org-move-to-column col)
     (if (string-match "[0-9]" bullet)
     (if (string-match "[0-9]" bullet)
 	(org-renumber-ordered-list 1))))
 	(org-renumber-ordered-list 1))))
 
 
+(defun org-shift-item-indentation (delta)
+  "Shift the indentation in current item by DELTA."
+  (save-excursion
+    (let ((beg (point-at-bol)) (end (progn (org-end-of-item) (point))))
+      (goto-char end)
+      (beginning-of-line 0)
+      (while (> (point) beg)
+	(when (looking-at "[ \t]*\\S-")
+	  ;; this is not an empty line
+	  (setq i (org-get-indentation))
+	  (if (and (> i 0) (> (setq i (+ i delta)) 0))
+	      (indent-line-to i)))
+	(beginning-of-line 0)))))
+
 (defun org-beginning-of-item-list ()
 (defun org-beginning-of-item-list ()
   "Go to the beginning of the current item list.
   "Go to the beginning of the current item list.
 I.e. to the first item in this list."
 I.e. to the first item in this list."