Hi,
Back to the problem with e.g. "2011. " being interpreted as a list
item when it happens to be at the beginning of a line:
After a bad experience with a document that had a lot of those, I came
up with this function to easily escape false list items. Maybe some of
you will find it helpful, or better yet, have suggestions for
improvements.
(defun my/org-list-escape-nonitems ()
(interactive)
(let ((nonitem "[0-9]\\{4\\}") ; Unlikely list numbers
; here: four-digit numbers (years)
(term (cond
((eq org-plain-list-ordered-item-terminator t) "[.)]")
((= org-plain-list-ordered-item-terminator ?\)) ")")
((= org-plain-list-ordered-item-terminator ?.) "\\.")
(t "[.)]"))))
(goto-char (point-min))
(query-replace-regexp
(concat "^\\(" nonitem "\\)\\(" term "\\) ")
(concat "\\1\\2" (string ?\240)))))
It calls query-replace-regexp, so the user can confirm each
replacement interactively, on apparent list items where the numbering
matches the NONITEM regexp. If confirmed, it replaces the space after
the item terminator with a non-breaking space.
In the code above, NONITEM is simply hard-coded as four digits,
matching years. It could be made a customizable variable.
The adventurous might want to call it automatically before export,
though currently this does not work well with subtree exports:
(add-hook 'org-export-first-hook 'my/org-list-escape-nonitems)
Feedback welcome.
Yours,
Christian