User:Jnc/wiki.e

/* A personal favourite - convert paragraphs to very long lines, and copies the * result to the clipboard - very useful for doing text on Wikipedia. * It knows about Wikipedia syntax, so it supresses the line collection * wherever i) the preceding line ended with a '=' (i.e. it was a section * header line), or the next line starts with a '*' or '#' (i.e.* it's a list * element), a ':' (i.e. it's an indented section), or a '<' (i.e. it's a * comment). */

command wikify_region on reg_tab[ALT('W')]

{	int	obuf, wbuf; char	c, oc, nc;

save_spot point; fix_region;

obuf = bufnum; wbuf = zap("-wiki-"); oc = '\n';

while (point < mark) { c = curchar; point++;

if (c != '\n') { binsert(wbuf, c); if (c == '=') oc = '='; else oc = '+'; continue; }

nc = curchar; if ((oc != '=') && (oc != '\n') &&		   (nc != ':') && (nc != '*') && (nc != '#') && (nc != '<') &&		    (nc != '\n')) { binsert(wbuf, ' '); oc = '-'; continue; }

binsert(wbuf, '\n'); oc = '\n'; }

bufnum = wbuf; point = 0; mark = size; copy_to_clipboard; bufnum = obuf;

say("Region Wikified."); }