--- ../org-mode/lisp/org-list.el	Thu Oct 28 00:12:17 2010
+++ org-mode/lisp/org-list.el	Thu Oct 28 00:12:05 2010
@@ -240,6 +240,11 @@
   :group 'org-plain-lists
   :type 'boolean)
 
+(defcustom org-alphabetical-lists nil
+  "Non-nil means alphabetical lists are activated."
+  :group 'org-plain-lists
+  :type 'boolean)
+
 (defcustom org-description-max-indent 20
   "Maximum indentation for the second line of a description list.
 When the indentation would be larger than this, it will become
@@ -288,16 +293,23 @@
 If GENERAL is non-nil, return the general regexp independent of the value
 of `org-plain-list-ordered-item-terminator'."
   (cond
+   ((and org-alphabetical-lists (or general (eq org-plain-list-ordered-item-terminator t)))
+    "\\([ \t]*\\([-+]\\|\\(\\([0-9]+\\|[A-Za-z]\\)[.)]\\)\\)\\|[ \t]+\\*\\)\\( \\|$\\)")
+   ((and org-alphabetical-lists (= org-plain-list-ordered-item-terminator ?.))
+    "\\([ \t]*\\([-+]\\|\\(\\([0-9]+\\|[A-Za-z]\\)\\.\\)\\)\\|[ \t]+\\*\\)\\( \\|$\\)")
+   ((and org-alphabetical-lists (= org-plain-list-ordered-item-terminator ?\)))
+    "\\([ \t]*\\([-+]\\|\\(\\([0-9]+\\|[A-Za-z]\\))\\)\\)\\|[ \t]+\\*\\)\\([ \t]+\\|$\\)")
    ((or general (eq org-plain-list-ordered-item-terminator t))
-    "\\([ \t]*\\([-+]\\|\\([0-9]+[.)]\\)\\)\\|[ \t]+\\*\\)\\([ \t]+\\|$\\)")
+    "\\([ \t]*\\([-+]\\|\\(\\([0-9]+\\)[.)]\\)\\)\\|[ \t]+\\*\\)\\( \\|$\\)")
    ((= org-plain-list-ordered-item-terminator ?.)
-    "\\([ \t]*\\([-+]\\|\\([0-9]+\\.\\)\\)\\|[ \t]+\\*\\)\\([ \t]+\\|$\\)")
+    "\\([ \t]*\\([-+]\\|\\(\\([0-9]+)\\.\\)\\)\\|[ \t]+\\*\\)\\( \\|$\\)")
    ((= org-plain-list-ordered-item-terminator ?\))
-    "\\([ \t]*\\([-+]\\|\\([0-9]+)\\)\\)\\|[ \t]+\\*\\)\\([ \t]+\\|$\\)")
+    "\\([ \t]*\\([-+]\\|\\(\\([0-9]+\\))\\)\\)\\|[ \t]+\\*\\)\\([ \t]+\\|$\\)")
    (t (error "Invalid value of `org-plain-list-ordered-item-terminator'"))))
 
-(defconst org-item-beginning-re (concat "^" (org-item-re))
-  "Regexp matching the beginning of a plain list item.")
+(defun org-item-beginning-re ()
+  "Regexp matching the beginning of a plain list item."
+  (concat "^" (org-item-re)))
 
 (defun org-list-ending-between (min max &optional firstp)
   "Find the position of a list ending between MIN and MAX, or nil.
@@ -385,7 +397,7 @@
 	       ;; Ensure there is at least an item above
 	       (up-item-p (save-excursion
 			    (org-search-backward-unenclosed
-			     org-item-beginning-re limit t))))
+			     (org-item-beginning-re) limit t))))
 	  (and up-item-p
 	       (catch 'exit
 		 (while t
@@ -413,7 +425,7 @@
 	   ;; `org-item-re'.
 	   (last-item-start (save-excursion
 			      (org-search-backward-unenclosed
-			       org-item-beginning-re limit t)))
+			       (org-item-beginning-re) limit t)))
 	   (list-ender (org-list-ending-between
 			last-item-start actual-pos)))
       ;; We are in a list when we are on an item line or when we can
@@ -433,7 +445,7 @@
       ;; Otherwise, go back to the heading above or bob.
       (goto-char (or (org-list-ending-between limit pos) limit))
       ;; From there, search down our list.
-      (org-search-forward-unenclosed org-item-beginning-re pos t)
+      (org-search-forward-unenclosed (org-item-beginning-re) pos t)
       (point-at-bol))))
 
 (defun org-list-bottom-point-with-regexp (limit)
@@ -530,7 +542,7 @@
        (save-excursion
 	 (goto-char (match-end 0))
          ;; Ignore counter if any
-         (when (looking-at "\\(?:\\[@\\(?:start:\\)?[0-9]+\\][ \t]*\\)?")
+         (when (looking-at "\\(?:\\[@\\(?:start:\\)?\\(?:[0-9]+\\|[A-Za-z]\\)\\][ \t]*\\)?")
            (goto-char (match-end 0)))
 	 (looking-at regexp))))
 
@@ -545,7 +557,7 @@
       ;; We don't want to match the current line.
       (funcall pre-move)
       ;; Skip any sublist on the way
-      (while (and (funcall search-fun org-item-beginning-re limit t)
+      (while (and (funcall search-fun (org-item-beginning-re) limit t)
 		  (> (org-get-indentation) ind)))
       (when (and (/= (point-at-bol) start) ; Have we moved ?
 		 (= (org-get-indentation) ind))
@@ -606,7 +618,7 @@
   (goto-char pos)
   ;; Is point in a special block?
   (when (org-in-regexps-block-p
-	 "^[ \t]*#\\+\\(begin\\|BEGIN\\)_\\([a-zA-Z0-9_]+\\)"
+	 "^[ \t]*#\\+\\(begin\\|BEGIN\\)_\\(\\(?:[a-zA-Z]\\|[0-9_]+\\)\\)"
 	 '(concat "^[ \t]*#\\+\\(end\\|END\\)_" (match-string 2)))
     (if (not (cdr (assq 'insert org-list-automatic-rules)))
 	;; Rule in `org-list-automatic-rules' forbids insertion.
@@ -704,7 +716,7 @@
     (cond
      ((and regionp
 	   (goto-char rbeg)
-	   (not (org-search-forward-unenclosed org-item-beginning-re rend t)))
+	   (not (org-search-forward-unenclosed (org-item-beginning-re) rend t)))
       (error "No item in region"))
      ((not (org-at-item-p))
       (error "Not on an item"))
@@ -802,13 +814,13 @@
   (save-excursion
     (beginning-of-line)
     (let ((ind (org-get-indentation)))
-      (or (not (org-search-backward-unenclosed org-item-beginning-re top t))
+      (or (not (org-search-backward-unenclosed (org-item-beginning-re) top t))
 	  (< (org-get-indentation) ind)))))
 
 (defun org-at-item-p ()
   "Is point in a line starting a hand-formatted item?"
   (save-excursion
-    (beginning-of-line) (looking-at org-item-beginning-re)))
+    (beginning-of-line) (looking-at (org-item-beginning-re))))
 
 (defun org-at-item-bullet-p ()
   "Is point at the bullet of a plain list item?"
@@ -907,7 +919,7 @@
   (save-excursion
     ;; possibly match current line
     (end-of-line)
-    (org-search-backward-unenclosed org-item-beginning-re nil t)
+    (org-search-backward-unenclosed (org-item-beginning-re) nil t)
     (point-at-bol)))
 
 (defun org-beginning-of-item ()
@@ -943,7 +955,7 @@
     (let ((ind (org-get-indentation)))
       (while (and (/= (point) bottom)
 		  (>= (org-get-indentation) ind))
-	(org-search-forward-unenclosed org-item-beginning-re bottom 'move))
+	(org-search-forward-unenclosed (org-item-beginning-re) bottom 'move))
       (if (= (point) bottom) bottom (point-at-bol)))))
 
 (defun org-end-of-item-list ()
@@ -973,7 +985,7 @@
 BOTTOM is the position at list ending."
   (end-of-line)
   (goto-char
-   (if (org-search-forward-unenclosed org-item-beginning-re bottom t)
+   (if (org-search-forward-unenclosed (org-item-beginning-re) bottom t)
        (point-at-bol)
      (org-get-end-of-item bottom))))
 
@@ -1135,11 +1147,11 @@
     (list (point-at-bol)
           (org-get-indentation)
           (progn
-            (looking-at "^[ \t]*\\([-+*0-9.)]+[ \t]+\\)")
+            (looking-at "^[ \t]*\\([-+*0-9A-Za-z.)]+[ \t]+\\)")
             (match-string 1))
           (progn
             (goto-char (match-end 0))
-            (and (looking-at "\\[@\\(?:start:\\)?\\([0-9]+\\)\\]")
+            (and (looking-at "\\[@\\(?:start:\\)?\\(\\(?:[0-9]+\\|[A-Za-z]\\)\\)\\]")
                  (match-string 1))))))
 
 (defun org-list-struct (begin end top bottom &optional outdent)
@@ -1168,7 +1180,7 @@
                 (goto-char begin)
                 ;; Find beginning of most outdented list (min list)
                 (while (and (org-search-backward-unenclosed
-			     org-item-beginning-re top t)
+			     (org-item-beginning-re) top t)
                             (>= (org-get-indentation) ind-min))
                   (setq pre-list (cons (org-list-struct-assoc-at-point)
 				       pre-list)))
@@ -1182,7 +1194,7 @@
                 (goto-char end)
                 (end-of-line)
                 (while (and (org-search-forward-unenclosed
-			     org-item-beginning-re bottom 'move)
+			     (org-item-beginning-re) bottom 'move)
                             (>= (org-get-indentation) ind-min))
                   (setq post-list (cons (org-list-struct-assoc-at-point)
 					post-list)))
@@ -1191,13 +1203,13 @@
 		(when (and (= (caar pre-list) 0) (< (point) bottom))
 		  (beginning-of-line)
 		  (while (org-search-forward-unenclosed
-			  org-item-beginning-re bottom t)
+			  (org-item-beginning-re) bottom t)
 		    (setq post-list (cons (org-list-struct-assoc-at-point)
 					  post-list))))
                 (append pre-list struct (reverse post-list))))))
       ;; Here we start: first get the core zone...
       (goto-char end)
-      (while (org-search-backward-unenclosed org-item-beginning-re begin t)
+      (while (org-search-backward-unenclosed (org-item-beginning-re) begin t)
 	(setq struct (cons (org-list-struct-assoc-at-point) struct)))
       ;; ... then, extend it to make it a structure...
       (let ((extended (funcall extend struct)))
@@ -1259,16 +1271,21 @@
 		     (let ((counter (nth 3 item))
 			   (bullet (org-list-bullet-string (nth 2 item))))
 		       (cond
-			((and (string-match "[0-9]+" bullet) counter)
+			((and (string-match "[0-9]+\\|[A-Za-z]" bullet) counter)
 			 (replace-match counter nil nil bullet))
 			((string-match "[0-9]+" bullet)
 			 (replace-match "1" nil nil bullet))
+			((and (save-excursion (goto-char (nth 0 item)) (org-list-can-be-alphabetical))
+			      (string-match "[A-Za-z]" bullet))
+			 (replace-match "a" nil nil bullet))
+			((string-match "[A-Za-z]" bullet)
+			 (replace-match "1" nil nil bullet))
 			(t bullet)))))
 	 (set-bul (lambda (item bullet)
 		    (setcdr item (list (nth 1 item) bullet (nth 3 item)))))
 	 (get-bul (lambda (item bullet)
 		    (let* ((counter (nth 3 item)))
-		      (if (and counter (string-match "[0-9]+" bullet))
+		      (if (and counter (string-match "[0-9]+\\|[A-Za-z]" bullet))
 			  (replace-match counter nil nil bullet)
 			bullet))))
 	 (fix-bul
@@ -1582,13 +1599,63 @@
           " ")))
      nil nil bullet 1)))
 
+(defun org-increment-string (str cap)
+  "Increments str (a->a, b->b, z->aa, aa->ab etc).  If cap is non-nil, then
+   the letters are capitalized."
+  (let ((res (org-convert-num-to-alpha-str
+	      (1+ (org-convert-alpha-str-to-num str 1 (length str) cap)) cap))
+	(z (if cap ?Z ?z))
+	(b (if cap ?B ?b))
+	(a (if cap ?A ?a)))
+    (if (and(= (string-to-char str) z)
+	    (= (string-to-char res) b))
+	(concat (if cap "A" "a")  (substring res 1))
+      (concat (make-string (- (length str) (length res)) a)  res))))
+
+(defun org-convert-alpha-str-to-num (str n pos cap)
+  "Converts the substring consisting of locations pos to pos-n to a
+   numeric representation."
+  (let ((a (if cap ?A ?a)))
+    (if (= pos 1) (* (- (string-to-char str) a) n)
+      (+ (* (- (nth (1- pos) (string-to-list str)) a) n)
+	 (org-convert-alpha-str-to-num str (* 26 n) (1- pos) cap)))))
+
+(defun org-convert-num-to-alpha-str (n cap)
+  "Converts the number n to a alphabetical, base-26 representation."
+  (if (= n 0) ""
+    (concat (org-convert-num-to-alpha-str (/ n 26) cap)
+	    (string (+ (if cap ?A ?a) (% n 26))))))
+
+(defun org-list-can-be-alphabetical ()
+  "Returns t if the list has only 26 elements."
+  (save-excursion
+    (goto-char (org-beginning-of-item-list))
+    (and org-alphabetical-lists
+	 (let ((retn 1))
+	   (condition-case nil
+	       (progn (while (< retn 27)
+			(org-next-item)
+			(setq retn (1+ retn))
+			nil))
+	     (error t))))))
+
 (defun org-list-inc-bullet-maybe (bullet)
   "Increment BULLET if applicable."
-  (if (string-match "[0-9]+" bullet)
+  (let ((case-fold-search nil))
+    (cond
+     ((string-match "[0-9]+" bullet)
       (replace-match
        (number-to-string (1+ (string-to-number (match-string 0 bullet))))
-       nil nil bullet)
-    bullet))
+       nil nil bullet))
+     ((string-match "[a-z]" bullet)
+      (replace-match
+       (org-increment-string (match-string 0 bullet) nil)
+       nil nil bullet))
+     ((string-match "[A-Z]" bullet)
+      (replace-match
+       (org-increment-string (match-string 0 bullet) t)
+       nil nil bullet))
+     (t bullet))))
 
 (defun org-list-repair (&optional force-bullet top bottom)
   "Make sure all items are correctly indented, with the right bullet.
@@ -1633,10 +1700,15 @@
 	 (bullet (save-excursion
 		   (goto-char (org-get-beginning-of-list top))
 		   (org-get-bullet)))
-	 (current (cond
-		   ((string-match "\\." bullet) "1.")
-		   ((string-match ")" bullet) "1)")
-		   (t bullet)))
+	 (current (let ((case-fold-search nil))
+		    (cond
+		     ((string-match "[0-9]+\\." bullet) "1.")
+		     ((string-match "[0-9]+)" bullet) "1)")
+		     ((string-match "[a-z]\\." bullet) "a.")
+		     ((string-match "[a-z])" bullet) "a)")
+		     ((string-match "[A-Z]\\." bullet) "A.")
+		     ((string-match "[A-Z])" bullet) "A)")
+		     (t bullet))))
 	 (bullet-rule-p (cdr (assq 'bullet org-list-automatic-rules)))
 	 (bullet-list (append '("-" "+" )
 			      ;; *-bullets are not allowed at column 0
@@ -1644,11 +1716,21 @@
 					   (looking-at "\\S-")) '("*"))
 			      ;; Description items cannot be numbered
 			      (unless (and bullet-rule-p
+					   (or (eq org-plain-list-ordered-item-terminator ?.)
+					       (org-at-item-description-p))) '("1)"))
+			      (unless (and bullet-rule-p
 					   (or (eq org-plain-list-ordered-item-terminator ?\))
 					       (org-at-item-description-p))) '("1."))
+			      (when (and org-alphabetical-lists	(org-list-can-be-alphabetical))
+				(append
 			      (unless (and bullet-rule-p
 					   (or (eq org-plain-list-ordered-item-terminator ?.)
-					       (org-at-item-description-p))) '("1)"))))
+						  (org-at-item-description-p)))
+				   '("A)" "a)"))
+				 (unless (and bullet-rule-p
+					      (or (eq org-plain-list-ordered-item-terminator ?\))
+						  (org-at-item-description-p)))
+				   '("A." "a."))))))
 	 (len (length bullet-list))
 	 (item-index (- len (length (member current bullet-list))))
 	 (get-value (lambda (index) (nth (mod index len) bullet-list)))
@@ -1684,7 +1766,7 @@
 		  (rend (region-end)))
 	      (save-excursion
 		(goto-char rbeg)
-		(if (org-search-forward-unenclosed org-item-beginning-re rend 'move)
+		(if (org-search-forward-unenclosed (org-item-beginning-re) rend 'move)
 		    (list (point-at-bol) rend nil)
 		  (error "No item in region")))))
            ((org-on-heading-p)
@@ -1696,7 +1778,7 @@
 		(goto-char limit)
 		(org-search-backward-unenclosed ":END:" pos 'move)
                 (org-search-forward-unenclosed
-		 org-item-beginning-re limit 'move)
+		 (org-item-beginning-re) limit 'move)
                 (list (point) limit nil))))
            ((org-at-item-p)
             (list (point-at-bol) (1+ (point-at-eol)) t))
@@ -1744,7 +1826,7 @@
       (goto-char beg)
       (while (< (point) end)
         (funcall act-on-item ref-presence ref-status)
-        (org-search-forward-unenclosed org-item-beginning-re end 'move)))
+        (org-search-forward-unenclosed (org-item-beginning-re) end 'move)))
     (org-update-checkbox-count-maybe)))
 
 (defun org-reset-checkbox-state-subtree ()
@@ -1853,7 +1935,7 @@
 			    (goto-char (or (org-get-next-item (point) lim) lim))
 			  (end-of-line)
 			  (when (org-search-forward-unenclosed
-				 org-item-beginning-re lim t)
+				 (org-item-beginning-re) lim t)
 			    (beginning-of-line)))
 			(setq next-ind (org-get-indentation)))))
 		(goto-char continue-from)
@@ -2025,10 +2107,10 @@
   (let* ((start (goto-char (org-list-top-point)))
 	 (end (org-list-bottom-point))
 	 output itemsep ltype)
-    (while (org-search-forward-unenclosed org-item-beginning-re end t)
+    (while (org-search-forward-unenclosed (org-item-beginning-re) end t)
       (save-excursion
 	(beginning-of-line)
-	(setq ltype (cond ((looking-at-p "^[ \t]*[0-9]") 'ordered)
+	(setq ltype (cond ((looking-at-p "^[ \t]*\\([0-9]+\\|[A-Za-z]\\)") 'ordered)
 			  ((org-at-item-description-p) 'descriptive)
 			  (t 'unordered))))
       (let* ((indent1 (org-get-indentation))
@@ -2037,7 +2119,7 @@
 					       (org-end-of-item-or-at-child end))))
 	     (nextindent (if (= (point) end) 0 (org-get-indentation)))
 	     (item (if (string-match
-			"^\\(?:\\[@\\(?:start:\\)?[0-9]+\\][ \t]*\\)?\\[\\([xX ]\\)\\]"
+			"^\\(?:\\[@\\(?:start:\\)?\\(?:[0-9]+\\|[A-Za-z]\\)\\][ \t]*\\)?\\[\\([xX ]\\)\\]"
 			item)
 		       (replace-match (if (equal (match-string 1 item) " ")
 					  "CBOFF"
@@ -2122,7 +2204,7 @@
 	   (top-point
 	    (progn
 	      (re-search-backward "#\\+ORGLST" nil t)
-	      (re-search-forward org-item-beginning-re bottom-point t)
+	      (re-search-forward (org-item-beginning-re) bottom-point t)
 	      (match-beginning 0)))
 	   (list (save-restriction
 		   (narrow-to-region top-point bottom-point)
