打开了org的标题自动编号功能,但是数字的位数不同导致了标题不能对齐,如何自动对齐
The following diff on org-list.el
does the trick!
diff --git a/lisp/org-list.el b/lisp/org-list.el
index b1d47c9..509e79f 100644
--- a/lisp/org-list.el
+++ b/lisp/org-list.el
@@ -1641,7 +1641,8 @@ as returned by `org-list-prevs-alist'."
;; Num bullet: increment it.
((string-match "[0-9]+" bullet)
(replace-match
- (number-to-string (1+ (string-to-number (match-string 0 bullet))))
+ (format (format "%%0%dd" (length (match-string 0 bullet)))
+ (1+ (string-to-number (match-string 0 bullet))))
nil nil bullet))
;; Alpha bullet: increment it.
((string-match "[A-Za-z]" bullet)
@@ -1715,7 +1716,7 @@ This function modifies STRUCT."
(replace-match "a" nil nil bullet))
;; First bullet is num: use "1".
((string-match "\\([0-9]+\\|[A-Za-z]\\)" bullet)
- (replace-match "1" nil nil bullet))
+ (replace-match (format (format "%%0%dd" (1+ (log (length struct) 10))) 1) nil nil bullet))
;; Not an ordered list: keep bullet.
(t bullet)))))))))
(mapc fix-bul (mapcar 'car struct))))
The first chunk patches function org-list-inc-bullet-maybe
to keep the padding used on the first item. The second chunk patches function org-list-struct-fix-bul
to calculate the padding based on the number of elements in the list.
1 个赞