emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [Workaround] Escaping false list items
@ 2011-03-11 14:12 Christian Moe
  2011-03-11 15:20 ` Nicolas
  0 siblings, 1 reply; 6+ messages in thread
From: Christian Moe @ 2011-03-11 14:12 UTC (permalink / raw)
  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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Workaround] Escaping false list items
  2011-03-11 14:12 [Workaround] Escaping false list items Christian Moe
@ 2011-03-11 15:20 ` Nicolas
  2011-03-11 18:02   ` Samuel Wales
  2011-03-11 18:15   ` Christian Moe
  0 siblings, 2 replies; 6+ messages in thread
From: Nicolas @ 2011-03-11 15:20 UTC (permalink / raw)
  To: mail; +Cc: Org Mode

Hello,

Christian Moe <mail@christianmoe.com> writes:

> 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:

Did you read my suggestion to avoid filling at such positions? While it
won't help on existing documents, I think it is a more general approach
to the problem.

Regards,

-- 
Nicolas

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Re: [Workaround] Escaping false list items
  2011-03-11 15:20 ` Nicolas
@ 2011-03-11 18:02   ` Samuel Wales
  2011-03-11 18:15   ` Christian Moe
  1 sibling, 0 replies; 6+ messages in thread
From: Samuel Wales @ 2011-03-11 18:02 UTC (permalink / raw)
  To: mail, Org Mode

Here are 2 alternatives.  The second, for me, is probably pretty
bulletproof (pun intended after it was made :)).  I like solution 2.

Solution 1:

Is it the case that you have text at the same column on the
line before?  Perhaps that could be considered invalid for
lists.  Of course there will still be problems with
e.g. partial lists of references.  And perhaps this will
break people's habits.  Not sure I like this solution, but thought to
mention it.

Solution 2:

  1) I always start my lists at column 2, without
     exception.
  2) I always have paragraphs at column 0, unless they are
     in a list or are manual insets (such as quotes).  I am
     willing to put manual quotes some place other than
     column 2.


All that's required is for the list code to (optionally):

  1) start lists at column 2
  2) never assume anything at column 0 is a list item


Perhaps a combination of solutions would work.

Samuel

-- 
AIDS 2.0 is here now:
  http://thekafkapandemic.blogspot.com/2010/12/welcome-to-kafka-pandemic-two-forces_9182.html
I support the Whittemore-Peterson Institute (WPI)
===
I want to see the original (pre-hold) Lo et al. 2010 NIH/FDA/Harvard MRV paper.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Re: [Workaround] Escaping false list items
  2011-03-11 15:20 ` Nicolas
  2011-03-11 18:02   ` Samuel Wales
@ 2011-03-11 18:15   ` Christian Moe
  2011-03-11 18:22     ` Nicolas
  1 sibling, 1 reply; 6+ messages in thread
From: Christian Moe @ 2011-03-11 18:15 UTC (permalink / raw)
  To: Org Mode, Nicolas Goaziou

On 3/11/11 4:20 PM, Nicolas wrote:
> Hello,
>
> Christian Moe <mail@...>  writes:
>
>> 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:
>
> Did you read my suggestion to avoid filling at such positions? While it
> won't help on existing documents, I think it is a more general approach
> to the problem.

I must have missed that, sorry. I remember you suggesting either to 
use right-paren as item terminator, or manually insert a non-breaking 
space after the dot.

Did you have a particular trick in mind, or just to avoid filling 
manually? I tend to have auto-fill on by default.

The little utility function I posted makes the non-breaking-space 
solution more workable for me. It wasn't intended as a contribution to 
Org-mode, just as something some people might want to put in their 
.emacs and try out, so I didn't put much thought into generalizing it.

Yours,
Christian

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Workaround] Escaping false list items
  2011-03-11 18:15   ` Christian Moe
@ 2011-03-11 18:22     ` Nicolas
  2011-03-11 21:18       ` Christian Moe
  0 siblings, 1 reply; 6+ messages in thread
From: Nicolas @ 2011-03-11 18:22 UTC (permalink / raw)
  To: mail; +Cc: Org Mode

Christian Moe <mail@christianmoe.com> writes:

> Did you have a particular trick in mind, or just to avoid filling
> manually? I tend to have auto-fill on by default.

I meant automatically. Please have a look at:

           http://article.gmane.org/gmane.emacs.orgmode/39149

Regards,

-- 
Nicolas

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Workaround] Escaping false list items
  2011-03-11 18:22     ` Nicolas
@ 2011-03-11 21:18       ` Christian Moe
  0 siblings, 0 replies; 6+ messages in thread
From: Christian Moe @ 2011-03-11 21:18 UTC (permalink / raw)
  To: Org Mode

On 3/11/11 7:22 PM, Nicolas wrote:
> Christian Moe<mail@christianmoe.com>  writes:
>
>> Did you have a particular trick in mind, or just to avoid filling
>> manually? I tend to have auto-fill on by default.
>
> I meant automatically. Please have a look at:
>
>             http://article.gmane.org/gmane.emacs.orgmode/39149
>
> Regards,
>

Magic! Thanks a lot for this, it's far and away a better solution.

Yours,
Christian

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2011-03-11 21:15 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-11 14:12 [Workaround] Escaping false list items Christian Moe
2011-03-11 15:20 ` 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

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).