otl to headline numbering conversion program?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

otl to headline numbering conversion program?

Steve Litt
Hi all,

I've just contributed a program to the NoSQL project, and now need to document
it. I'll author the doc as an outline with lots of body text. What I'd like
to do is have a program convert something like this:

Updmerge documentation
        Philosophy
                : A horse is a horse of course of course
                : but noone can talk to a horse of course
                The Need for Speed
                        : Users get nervous if an update
                        : takes more than 1/2 second,  so
                        : updates must be fast.

INTO THIS:

1: Updmerge documentation ********

1.1: Philosophy ******
A horse is a horse of course of course but noone can talk
to a horse of course

1.1.1: The Need for Speed  ****
Users get nervous if an update takes more than 1/2 second,
so updates must be fast.

Has anyone written anything like that yet? If so, please let me know. I'm
gonna write the docs now, and when I'm finished, if nobody's written this
program already, I'll write it using Node.rb.

Thanks

SteveT


--
Steve Litt
Author: Universal Troubleshooting Process books and courseware
http://www.troubleshooters.com/

(Legal Disclaimer) Follow these suggestions at your own risk.
_______________________________________________
VimOutliner mailing list
[hidden email]
http://www.lists.vimoutliner.org/mailman/listinfo/vimoutliner
Reply | Threaded
Open this post in threaded view
|

Re: otl to headline numbering conversion program?

Stefan Schmiedl
Steve Litt (30.03. 09:31):

> Has anyone written anything like that yet? If so, please let me know. I'm
> gonna write the docs now, and when I'm finished, if nobody's written this
> program already, I'll write it using Node.rb.

I did ... not quite ... and waaaay back in 2004:

-rw-r--r--  1 stefan users     658 2004-03-16 09:30 vo_numbers.vim

As far as I can see, it only numbers a single level, as I am not a
friend of too many numbers in headings. But using the prefix mechanism,
you could generate nested numbers, too, I guess.

The following is totally unsupported, don't even think of asking me why
I did something the way I did. I haven't touched vimscript for years.

function! Number() range
  let l:prefix = input("Prefix: ")
  let l:postfix = input("Postfix: ", " ")
  let l:count = 1
  let l:indent = indent(a:firstline)
  let l:current = a:firstline
  while l:current <= a:lastline
    if indent(l:current) == l:indent
      let l:line = getline(l:current)
      let l:line_ = substitute(l:line, '^\(\t*\)\(.*\)$', '\1'.l:prefix.l:count.l:postfix.'\2', "")
      call setline(l:current, l:line_)
      let l:count = l:count + 1
    endif
    let l:current = l:current + 1
  endwhile
endfunction

function! Denumber()
  silent! s/^\(\t*\)[0-9.]* \(.*\)/\1\2/
endfunction

map ,,n :call Number()
map ,,N :call Denumber()

Have fun,
s.
--
Stefan Schmiedl
+-------------------------------+----------------------------------------+
|Approximity GmbH               | EDV-Beratung Schmiedl                  |
|http://www.approximity.com     | Am Bräuweiher 4, 93499 Zandt, Germany  |
|mailto:[hidden email]  | Tel. (09944) 3068-98, Fax -97          |
+-------------------------------+----------------------------------------+
_______________________________________________
VimOutliner mailing list
[hidden email]
http://www.lists.vimoutliner.org/mailman/listinfo/vimoutliner
Reply | Threaded
Open this post in threaded view
|

Re: otl to headline numbering conversion program?

Steve Litt
On Friday 30 March 2007 09:41, Stefan Schmiedl wrote:

> Steve Litt (30.03. 09:31):
> > Has anyone written anything like that yet? If so, please let me know. I'm
> > gonna write the docs now, and when I'm finished, if nobody's written this
> > program already, I'll write it using Node.rb.
>
> I did ... not quite ... and waaaay back in 2004:
>
> -rw-r--r--  1 stefan users     658 2004-03-16 09:30 vo_numbers.vim
>
> As far as I can see, it only numbers a single level, as I am not a
> friend of too many numbers in headings. But using the prefix mechanism,
> you could generate nested numbers, too, I guess.
>
> The following is totally unsupported, don't even think of asking me why
> I did something the way I did. I haven't touched vimscript for years.
>
> function! Number() range
>   let l:prefix = input("Prefix: ")
>   let l:postfix = input("Postfix: ", " ")
>   let l:count = 1
>   let l:indent = indent(a:firstline)
>   let l:current = a:firstline
>   while l:current <= a:lastline
>     if indent(l:current) == l:indent
>       let l:line = getline(l:current)
>       let l:line_ = substitute(l:line, '^\(\t*\)\(.*\)$',
> '\1'.l:prefix.l:count.l:postfix.'\2', "") call setline(l:current, l:line_)
>       let l:count = l:count + 1
>     endif
>     let l:current = l:current + 1
>   endwhile
> endfunction
>
> function! Denumber()
>   silent! s/^\(\t*\)[0-9.]* \(.*\)/\1\2/
> endfunction
>
> map ,,n :call Number()
> map ,,N :call Denumber()
>
> Have fun,

I'll have lots of fun Stefan. I don't know Vim language :-) Into what file
would I stick this function?

By the way, this is no longer urgent. I submitted my docs as a .otl file,
after doing a ,,B to get rid of the colons. Hey, if they can't take a
joke :-)

Thanks Stefan,

SteveT
_______________________________________________
VimOutliner mailing list
[hidden email]
http://www.lists.vimoutliner.org/mailman/listinfo/vimoutliner
Reply | Threaded
Open this post in threaded view
|

Re: otl to headline numbering conversion program?

Stefan Schmiedl
Steve Litt (30.03. 10:07):

> > function! Number() range
> >   let l:prefix = input("Prefix: ")
> >   let l:postfix = input("Postfix: ", " ")
> >   let l:count = 1
> >   let l:indent = indent(a:firstline)
> >   let l:current = a:firstline
> >   while l:current <= a:lastline
> >     if indent(l:current) == l:indent
> >       let l:line = getline(l:current)
> >       let l:line_ = substitute(l:line, '^\(\t*\)\(.*\)$',
> > '\1'.l:prefix.l:count.l:postfix.'\2', "") call setline(l:current, l:line_)
> >       let l:count = l:count + 1
> >     endif
> >     let l:current = l:current + 1
> >   endwhile
> > endfunction
> >
> > function! Denumber()
> >   silent! s/^\(\t*\)[0-9.]* \(.*\)/\1\2/
> > endfunction
> >
> > map ,,n :call Number()
> > map ,,N :call Denumber()

> I'll have lots of fun Stefan. I don't know Vim language :-) Into what file
> would I stick this function?

The vim stuff above (minus mail quoting characters) could be appended
to .vimoutlinerrc, so it will be available whenever outlines are
available. Or you save it to a file and :source the_file when you need
it.

The function needs to be invoked via :range call Number(), e.g.
:%call Number() or :.,+30call Number(), it even accepts a visual range.

s.
_______________________________________________
VimOutliner mailing list
[hidden email]
http://www.lists.vimoutliner.org/mailman/listinfo/vimoutliner