emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nathaniel Flath <flat0103@gmail.com>
To: Carsten Dominik <carsten.dominik@gmail.com>
Cc: Bernt Hansen <bernt@norang.ca>,
	Jacob Mitchell <jacob.d.mitchell@gmail.com>,
	org-mode List <emacs-orgmode@gnu.org>,
	Nicolas Goaziou <n.goaziou@gmail.com>
Subject: Re: Re: [PATCH] Alphabetical ordered lists
Date: Thu, 21 Oct 2010 22:30:27 -0700	[thread overview]
Message-ID: <AANLkTi=2KW_r1C76Z0uqXD2xF-_42zLYwakrsRWMDdYG@mail.gmail.com> (raw)
In-Reply-To: <AANLkTimuPCY3ur0LN6=bBBzaokRt+SaP9Wzqo8+wtKL9@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1248 bytes --]

I think I've fixed the issues brought up with this new patch.  Please
let me know what you think.

On Wed, Oct 20, 2010 at 9:44 PM, Nathaniel Flath <flat0103@gmail.com> wrote:
>>
>>>
>>> But I can't help thinking this could lead to unexpected results in
>>> some cases (admittedly less than when alpha bullets could be any size
>>> long).
>>
>> It definitely will.
>>
>> Here is an alternative idea.  Nathaniel, what do you
>> think about this: We could keep the numbering as we
>> have it in the Org file, but introduce something like [@a]
>> in the first item that will convert the numbering
>> into a,b,... upon export to ASCII, HTML, maybe even LaTeX
>> (even though I think LaTeX demands some consistency here
>> and prefers to have the global setup decide how lists work).
>> Hell, we could even use [@A] for capitals and [@i] and [@I]
>> for roman numbering :)
>>
>> - Carsten
>>
>
> Sorry for the late response - got swamped with work for a bit.
>
> I'd much prefer the approach I've been going with, mostly since I
> don't usually export my notes and mostly view them in org-mode.  I'll
> work on the patch tonight - should send a patch either later tonight
> or tomorow.
>
> Thanks,
> Nathaniel Flath
>

[-- Attachment #2: ordered-list.patch --]
[-- Type: application/octet-stream, Size: 9246 bytes --]

diff --git a/lisp/org-list.el b/lisp/org-list.el
index d9fc24e..6942eed 100644
--- a/lisp/org-list.el
+++ b/lisp/org-list.el
@@ -240,6 +240,11 @@ with the word \"recursive\" in the value."
   :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,13 +293,13 @@ It depends on `org-empty-line-terminates-plain-lists'."
 If GENERAL is non-nil, return the general regexp independent of the value
 of `org-plain-list-ordered-item-terminator'."
   (cond
-   ((or general (eq org-plain-list-ordered-item-terminator t))
-    "\\([ \t]*\\([-+]\\|\\([0-9]+[.)]\\)\\)\\|[ \t]+\\*\\)\\([ \t]+\\|$\\)")
-   ((= org-plain-list-ordered-item-terminator ?.)
-    "\\([ \t]*\\([-+]\\|\\([0-9]+\\.\\)\\)\\|[ \t]+\\*\\)\\([ \t]+\\|$\\)")
-   ((= org-plain-list-ordered-item-terminator ?\))
-    "\\([ \t]*\\([-+]\\|\\([0-9]+)\\)\\)\\|[ \t]+\\*\\)\\([ \t]+\\|$\\)")
-   (t (error "Invalid value of `org-plain-list-ordered-item-terminator'"))))
+    ((or general (eq org-plain-list-ordered-item-terminator t))
+       "\\([ \t]*\\([-+]\\|\\(\\([0-9]+\\|[A-Za-z]\\)[.)]\\)\\)\\|[ \t]+\\*\\)\\( \\|$\\)")
+      ((= org-plain-list-ordered-item-terminator ?.)
+       "\\([ \t]*\\([-+]\\|\\(\\([0-9]+\\|[A-Za-z]\\)\\.\\)\\)\\|[ \t]+\\*\\)\\( \\|$\\)")
+    ((= org-plain-list-ordered-item-terminator ?\))
+     "\\([ \t]*\\([-+]\\|\\(\\([0-9]+\\|[A-Za-z]\\))\\)\\)\\|[ \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.")
@@ -530,8 +535,8 @@ List ending is determined by the indentation of text. See
        (save-excursion
 	 (goto-char (match-end 0))
          ;; Ignore counter if any
-         (when (looking-at "\\(?:\\[@\\(?:start:\\)?[0-9]+\\][ \t]*\\)?")
-           (goto-char (match-end 0)))
+         (when (looking-at "\\(?:\\[@\\(?:start:\\)?\\(?:[0-9]+\\|[A-Za-z]\\)\\][ \t]*\\)?")
+	   (goto-char (match-end 0)))
 	 (looking-at regexp))))
 
 (defun org-list-get-item-same-level (search-fun pos limit pre-move)
@@ -1135,11 +1140,11 @@ bullet string and bullet counter, if any."
     (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-9A-Za-z]+\\)\\]")
                  (match-string 1))))))
 
 (defun org-list-struct (begin end top bottom &optional outdent)
@@ -1259,16 +1264,20 @@ This function modifies STRUCT."
 		     (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-9A-Za-z]+" bullet) counter)
 			 (replace-match counter nil nil bullet))
 			((string-match "[0-9]+" bullet)
 			 (replace-match "1" nil nil bullet))
+			((and (string-match "[A-Za-z]" bullet) (> 28 (length struct)))
+			 (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-9A-Za-z]+" bullet))
 			  (replace-match counter nil nil bullet)
 			bullet))))
 	 (fix-bul
@@ -1582,13 +1591,50 @@ It determines the number of whitespaces to append by looking at
           " ")))
      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-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.
@@ -1629,14 +1675,29 @@ If WHICH is a valid string, use that as the new bullet. If WHICH
 is an integer, 0 means `-', 1 means `+' etc. If WHICH is
 'previous, cycle backwards."
   (interactive "P")
-  (let* ((top (org-list-top-point))
+   (let* ((top (org-list-top-point))
+	  (alpha-possible (save-excursion
+			    (goto-char (org-list-top-point))
+			    (and org-alphabetical-lists
+				 (let ((retn 1))
+				  (condition-case nil
+				      (progn (while (< retn 27)
+					       (org-next-item)
+					(setq retn (1+ retn))
+					nil))
+				    (error t))))))
 	 (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
@@ -1645,10 +1706,22 @@ is an integer, 0 means `-', 1 means `+' etc. If WHICH is
 			      ;; Description items cannot be numbered
 			      (unless (and bullet-rule-p
 					   (or (eq org-plain-list-ordered-item-terminator ?.)
-					       (org-at-item-description-p))) '("1)"))
+					       (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."))))
+					       (org-at-item-description-p)))
+				'("1."))
+			      (when (and org-alphabetical-lists	alpha-possible)
+				(append
+				 (unless (and bullet-rule-p
+					      (or (eq org-plain-list-ordered-item-terminator ?.)
+						  (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)))
@@ -2028,7 +2101,7 @@ sublevels as a list of strings."
     (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-9A-Za-z]+") 'ordered)
 			  ((org-at-item-description-p) 'descriptive)
 			  (t 'unordered))))
       (let* ((indent1 (org-get-indentation))
@@ -2037,7 +2110,7 @@ sublevels as a list of strings."
 					       (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-9A-Za-z]+\\][ \t]*\\)?\\[\\([xX ]\\)\\]"
 			item)
 		       (replace-match (if (equal (match-string 1 item) " ")
 					  "CBOFF"

[-- Attachment #3: Type: text/plain, Size: 201 bytes --]

_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

  reply	other threads:[~2010-10-22  5:30 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-29 20:27 [PATCH] Alphabetical ordered lists Nathaniel Flath
2010-07-29 21:07 ` Nick Dokos
2010-08-01 18:33   ` David Maus
2010-08-02  9:31 ` Nicolas Goaziou
2010-08-27  8:11 ` Carsten Dominik
2010-08-27 10:53   ` Bernt Hansen
2010-08-27 12:44     ` Jacob Mitchell
2010-08-27 13:01       ` Nathaniel Flath
2010-09-18  7:43         ` Nathaniel Flath
2010-09-21 12:48           ` Carsten Dominik
2010-09-21 16:46             ` Nicolas Goaziou
2010-09-26 17:36             ` Nicolas Goaziou
2010-09-26 22:16               ` Nathaniel Flath
2010-09-27  6:55                 ` Nicolas Goaziou
2010-09-28 16:12                   ` Carsten Dominik
2010-09-29 15:49                     ` Carsten Dominik
2010-09-29 16:50                       ` Nathaniel Flath
2010-09-29 17:46                       ` Nicolas Goaziou
2010-10-01  1:13                         ` Nathaniel Flath
2010-10-04  8:33                           ` Carsten Dominik
2010-10-04 17:18                             ` Nicolas Goaziou
2010-10-05  0:07                               ` Sebastian Rose
2010-10-05  0:21                                 ` Nathaniel Flath
2010-10-05  7:40                               ` Carsten Dominik
2010-10-21  4:44                                 ` Nathaniel Flath
2010-10-22  5:30                                   ` Nathaniel Flath [this message]
2010-10-22  8:13                                     ` Carsten Dominik
2010-10-23  1:04                                       ` Nathaniel Flath
2010-10-26  8:21                                     ` Nicolas Goaziou
2010-10-26  8:23                                       ` Carsten Dominik
2010-10-28  7:17                                         ` Nathaniel Flath
2010-11-11  7:16                                           ` Nathaniel Flath
2010-11-11  8:57                                             ` Nicolas Goaziou
2010-11-13 15:16                                             ` Nicolas Goaziou
2010-11-22  4:45                                               ` Nathaniel Flath
2010-11-22 13:37                                                 ` Bernt Hansen
2010-11-22 18:37                                                 ` Nicolas Goaziou
2010-11-27  4:39                                                   ` Nathaniel Flath
2010-12-11  2:41                                                     ` Nathaniel Flath
2010-12-20 18:25                                                       ` Nicolas Goaziou
2011-01-12 20:05                                                         ` Nathaniel Flath

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='AANLkTi=2KW_r1C76Z0uqXD2xF-_42zLYwakrsRWMDdYG@mail.gmail.com' \
    --to=flat0103@gmail.com \
    --cc=bernt@norang.ca \
    --cc=carsten.dominik@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=jacob.d.mitchell@gmail.com \
    --cc=n.goaziou@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).