emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Christian Moe <mail@christianmoe.com>
To: Org Mode <emacs-orgmode@gnu.org>
Subject: [Workaround] Escaping false list items
Date: Fri, 11 Mar 2011 15:12:56 +0100	[thread overview]
Message-ID: <4D7A2DE8.4030709@christianmoe.com> (raw)

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	other threads:[~2011-03-11 14:10 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-11 14:12 Christian Moe [this message]
2011-03-11 15:20 ` [Workaround] Escaping false list items Nicolas
2011-03-11 18:02   ` Samuel Wales
2011-03-11 18:15   ` Christian Moe
2011-03-11 18:22     ` Nicolas
2011-03-11 21:18       ` Christian Moe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4D7A2DE8.4030709@christianmoe.com \
    --to=mail@christianmoe.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).