My checkbox list appears as shown below
I would like to have it like this.
As you can see the number of digits for the numbered list is two, starting at 01.
I do not see an opportunity where we might need 001, so 01 should be good.
The following modifications allow bullets with leading zeros in org-mode version 8.3.6:
--- ~/.emacs.d/elpa/org-20160425/org-list.el Sun May 1 10:12:55 2016
+++ /tmp/org-list.el Tue Oct 25 22:49:47 2016
@@ -367,6 +367,14 @@
(list (symbol :tag "Major mode")
(string :tag "Format"))))
+(defcustom org-list-keep-leading-zeros t
+ "Keep leading zeros in numeric list bullets, i.e.:
+ 01. [X]
+ 02. [X]"
+ :group 'org-plain-lists
+ :type 'boolean)
+
+
(defvar org-list-forbidden-blocks '("example" "verse" "src" "ascii" "beamer"
"html" "latex" "odt")
"Names of blocks where lists are not allowed.
@@ -1656,10 +1664,13 @@
(let ((case-fold-search nil))
(cond
;; Num bullet: increment it.
- ((string-match "[0-9]+" bullet)
- (replace-match
- (number-to-string (1+ (string-to-number (match-string 0 bullet))))
- nil nil bullet))
+ ((string-match "\\([0]*\\)\\([1-9][0-9]*\\)" bullet)
+ (replace-match (format
+ (if (match-string 1 bullet)
+ (concat "%0" (number-to-string (length (match-string 0 bullet))) "d")
+ "%d")
+ (1+ (string-to-number (match-string 2 bullet))))
+ nil nil bullet))
;; Alpha bullet: increment it.
((string-match "[A-Za-z]" bullet)
(replace-match
@@ -1731,7 +1742,12 @@
((and alphap (string-match "[a-z]" bullet))
(replace-match "a" nil nil bullet))
;; First bullet is num: use "1".
- ((string-match "\\([0-9]+\\|[A-Za-z]\\)" bullet)
+ ((string-match (concat "\\("
+ (if org-list-keep-leading-zeros
+ "[1-9][0-9]+"
+ "[0-9]+")
+ "\\|[A-Za-z]\\)")
+ bullet)
(replace-match "1" nil nil bullet))
;; Not an ordered list: keep bullet.
(t bullet)))))))))
The relevant code which you can use to override the org-mode definitions is:
(defcustom org-list-keep-leading-zeros t
"Keep leading zeros in numeric list bullets, i.e.:
01. [X]
02. [X]"
:group 'org-plain-lists
:type 'boolean)
(defun org-list-inc-bullet-maybe (bullet)
"Increment BULLET if applicable."
(let ((case-fold-search nil))
(cond
;; Num bullet: increment it.
((string-match "\\([0]*\\)\\([1-9][0-9]*\\)" bullet)
(replace-match (format
(if (match-string 1 bullet)
(concat "%0" (number-to-string (length (match-string 0 bullet))) "d")
"%d")
(1+ (string-to-number (match-string 2 bullet))))
nil nil bullet))
;; Alpha bullet: increment it.
((string-match "[A-Za-z]" bullet)
(replace-match
(char-to-string (1+ (string-to-char (match-string 0 bullet))))
nil nil bullet))
;; Unordered bullet: leave it.
(t bullet))))
(defun org-list-struct-fix-bul (struct prevs)
"Verify and correct bullets in STRUCT.
PREVS is the alist of previous items, as returned by
`org-list-prevs-alist'.
This function modifies STRUCT."
(let ((case-fold-search nil)
(fix-bul
(function
;; Set bullet of ITEM in STRUCT, depending on the type of
;; first item of the list, the previous bullet and counter
;; if any.
(lambda (item)
(let* ((prev (org-list-get-prev-item item struct prevs))
(prev-bul (and prev (org-list-get-bullet prev struct)))
(counter (org-list-get-counter item struct))
(bullet (org-list-get-bullet item struct))
(alphap (and (not prev)
(org-list-use-alpha-bul-p item struct prevs))))
(org-list-set-bullet
item struct
(org-list-bullet-string
(cond
;; Alpha counter in alpha list: use counter.
((and prev counter
(string-match "[a-zA-Z]" counter)
(string-match "[a-zA-Z]" prev-bul))
;; Use cond to be sure `string-match' is used in
;; both cases.
(let ((real-count
(cond
((string-match "[a-z]" prev-bul) (downcase counter))
((string-match "[A-Z]" prev-bul) (upcase counter)))))
(replace-match real-count nil nil prev-bul)))
;; Num counter in a num list: use counter.
((and prev counter
(string-match "[0-9]+" counter)
(string-match "[0-9]+" prev-bul))
(replace-match counter nil nil prev-bul))
;; No counter: increase, if needed, previous bullet.
(prev
(org-list-inc-bullet-maybe (org-list-get-bullet prev struct)))
;; Alpha counter at first item: use counter.
((and counter (org-list-use-alpha-bul-p item struct prevs)
(string-match "[A-Za-z]" counter)
(string-match "[A-Za-z]" bullet))
(let ((real-count
(cond
((string-match "[a-z]" bullet) (downcase counter))
((string-match "[A-Z]" bullet) (upcase counter)))))
(replace-match real-count nil nil bullet)))
;; Num counter at first item: use counter.
((and counter
(string-match "[0-9]+" counter)
(string-match "[0-9]+" bullet))
(replace-match counter nil nil bullet))
;; First bullet is alpha uppercase: use "A".
((and alphap (string-match "[A-Z]" bullet))
(replace-match "A" nil nil bullet))
;; First bullet is alpha lowercase: use "a".
((and alphap (string-match "[a-z]" bullet))
(replace-match "a" nil nil bullet))
;; First bullet is num: use "1".
((string-match (concat "\\("
(if org-list-keep-leading-zeros
"[1-9][0-9]+"
"[0-9]+")
"\\|[A-Za-z]\\)")
bullet)
(replace-match "1" nil nil bullet))
;; Not an ordered list: keep bullet.
(t bullet)))))))))
(mapc fix-bul (mapcar #'car struct))))
Install this code in your init-file -- maybe after (require 'org-list)
.
Afterwards, you can insert your first bullet with the right number of zeros at the front and all other bullets are formatted accordinly by keystrokes like C-c C-c or M-return