emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[O] [Workaround] Escaping false list items


From: Christian Moe
Subject: [O] [Workaround] Escaping false list items
Date: Fri, 11 Mar 2011 15:12:56 +0100
User-agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10.5; en-US; rv:1.9.2.15) Gecko/20110303 Thunderbird/3.1.9

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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]