From mboxrd@z Thu Jan 1 00:00:00 1970 From: Christian Moe Subject: [Workaround] Escaping false list items Date: Fri, 11 Mar 2011 15:12:56 +0100 Message-ID: <4D7A2DE8.4030709@christianmoe.com> Reply-To: mail@christianmoe.com Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Return-path: Received: from [140.186.70.92] (port=45362 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Py32m-0006J0-8E for emacs-orgmode@gnu.org; Fri, 11 Mar 2011 09:10:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Py32l-0003UU-9U for emacs-orgmode@gnu.org; Fri, 11 Mar 2011 09:10:16 -0500 Received: from mars.hitrost.net ([91.185.211.18]:24982) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Py32l-0003KL-37 for emacs-orgmode@gnu.org; Fri, 11 Mar 2011 09:10:15 -0500 Received: from lk.92.63.17.213.dc.cable.static.lj-kabel.net ([92.63.17.213] helo=Celebrian-2.local) by mars.hitrost.net with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.73) (envelope-from ) id 1Py328-0001BI-Nw for emacs-orgmode@gnu.org; Fri, 11 Mar 2011 15:09:36 +0100 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Org Mode 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