rdoc and vim folding

A

Ara.T.Howard

vim lets you do folds like

def method
#{{{
42
#}}}
end

this wreaks havoc on rdoc output, especially when one has

class Foo
#{{{
def bar
end
#}}}
end

any ideas for dealing with this?

-a
--
===============================================================================
| EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
| PHONE :: 303.497.6469
| When you do something, you should burn yourself completely, like a good
| bonfire, leaving no trace of yourself. --Shunryu Suzuki
===============================================================================
 
D

Dave Thomas

this wreaks havoc on rdoc output, especially when one has

class Foo
#{{{
def bar
end
#}}}
end

does this work?

class Fo0
#{{{

# Method comment for bar
def bar
end
#}}}
end

If no, I guess I could add code to ignore them--do many folks use this
feature of vim?


Cheers

Dave
 
A

Ara.T.Howard

does this work?

class Fo0
#{{{

# Method comment for bar
def bar
end
#}}}
end

for that case yes... but when i have

class

#{{{

FOO = 42

#}}}

end

it's tough because this IS not comment for FOO

not really (yes- i'm getting bizarre output

i THINK this will work

class Fo0
#--{{{

# Method comment for bar
def bar
end

#--}}}
end

vim seems to understand it and so does rdoc - i need to convert a bunch of
files en masse first to check... should only take about three days before i
figure out ruby's command line edit in place switches (joking)

i'll get back to you...

If no, I guess I could add code to ignore them--do many folks use this
feature of vim?

i don't think many use them - but you'll never go back once you've started!
it makes reading 3000 lines of code a breeze. i think a generic 'ignore' this
comment line no matter what might be nicer than a vim specific feature.
infact i was going to filter my sources to remove the fold markers before i
(think) i found a fix... what do you think about have a pattern/token that
means 'this line, comment or source, is simply disgarded'. the default
pattern could be

/^\s*##/ (double comment symobl)

or mabye

/^\s*#_/ ('private' comment)

or something in that akin... whatever it would be should also be configurable
via option or api...

cheers.

-a
--
===============================================================================
| EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
| PHONE :: 303.497.6469
| When you do something, you should burn yourself completely, like a good
| bonfire, leaving no trace of yourself. --Shunryu Suzuki
===============================================================================
 
A

Ara.T.Howard

the

#{{{ -> #--{{{

fix works. this is my conversion command for anyone interested:

ruby -p -i -e '$_.sub!(%r/^\s*#(\{\{\{|\}\}\})\s*$/, "#--\\1\n")' `find . -name '*.rb'`

yikes.


next question:

how do i tell rdoc to 'treat files with NO extension as ruby files'?

i've tried

-E =rb

and

-E ''=rb

but no luck. my programs never have an extension of 'rb'.

cheers.

-a
--
===============================================================================
| EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
| PHONE :: 303.497.6469
| When you do something, you should burn yourself completely, like a good
| bonfire, leaving no trace of yourself. --Shunryu Suzuki
===============================================================================
 
A

Ara.T.Howard

I haven't had cause to use markers to do folding in ruby much, but I do use
the feature. I can't remember at the moment whether foldmethod=syntax or
foldmethod=indent works well for ruby code.

IMHO - neither. too many folds. i like to fold class bodies, module bodies,
and function bodies - and that's all. either way above does a LOT more.

-a
--
===============================================================================
| EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
| PHONE :: 303.497.6469
| When you do something, you should burn yourself completely, like a good
| bonfire, leaving no trace of yourself. --Shunryu Suzuki
===============================================================================
 
G

Gavin Sinclair

IMHO - neither. too many folds. i like to fold class bodies, module bodies,
and function bodies - and that's all. either way above does a LOT more.

Isn't there a way to limit the number of folds created by
fm=indent?

I would like to use Vim's folding, but there doesn't seem to be a way
to have it just Do The Right Thing. I certainly don't want explicit
fold markers in the code.

Cheers,
Gavin
 
A

Ara.T.Howard

Isn't there a way to limit the number of folds created by
fm=indent?

yes - but you can say do THIS and THAT level. just a depth
I would like to use Vim's folding, but there doesn't seem to be a way to
have it just Do The Right Thing. I certainly don't want explicit fold
markers in the code.

the markers are nice because they remain when you close/reopen the file...
person opinion i guess...

cheers.

-a
--
===============================================================================
| EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
| PHONE :: 303.497.6469
| When you do something, you should burn yourself completely, like a good
| bonfire, leaving no trace of yourself. --Shunryu Suzuki
===============================================================================
 
G

Gavin Sinclair

yes - but you can say do THIS and THAT level. just a depth

Maybe the fm=syntax option, then? I don't know anything about that,
but it sounds promising.

Gavin
 
G

Gavin Sinclair

Maybe the fm=syntax option, then? I don't know anything about that,
but it sounds promising.

Follow-up: it's not promising. Vim's current syntax definition for
Ruby (http://vim-ruby.rubyforge.org) does enable syntax-based folding,
but it can't be selective about what it folds (i.e. classes and
methods only, per Ara's request).

The following settings should be OK:

set foldmethod=syntax
set foldnestmax=2 " or 3

If anyone knows enough about Vim to make the folding smarter for Ruby
files, please step forward :)

Gavin
 
E

Eric Hodel

Follow-up: it's not promising. Vim's current syntax definition for
Ruby (http://vim-ruby.rubyforge.org) does enable syntax-based folding,
but it can't be selective about what it folds (i.e. classes and
methods only, per Ara's request).

The following settings should be OK:

set foldmethod=syntax
set foldnestmax=2 " or 3

If anyone knows enough about Vim to make the folding smarter for Ruby
files, please step forward :)

If you want to not fold on a particular syntax construct, you need only
remove the 'fold' from the end of the 'syn region'.

:help syn-region should help you out.
 
D

Dave Thomas

how do i tell rdoc to 'treat files with NO extension as ruby files'?

No way that I know of, but if you have a shebang line, it'll notice
that and use Ruby for the files if the shebang contains 'ruby'


Cheers

Dave
 
A

Ara.T.Howard

No way that I know of, but if you have a shebang line, it'll notice
that and use Ruby for the files if the shebang contains 'ruby'


that doesn't seem to happening for my script - it's very strange and i'm at a
loss as to why, but it defintely does not notice the shebang line. here's the
tar ball of all sources i'm doc'ing:

http://www.codeforpeople.com/rq-1.0.0.tgz

and the command i'm using:

rdoc -a -d -F -S -m README -I jpg -N DEPENDS HISTORY README TODO VERSION bin/* lib/rq.rb lib/*/*

the output i'm looking at, for bin/rq, has not recognized 'rq' as a ruby file
even though it starts with

jib:~/eg/ruby/rq/rq-1.0.0 > head -1 bin/rq
#!/dmsp/reference/bin/ruby

so i'm not sure what's going on.

in any case this isn't too important - just thought you might want to check it
out.

cheers.

-a
--
===============================================================================
| EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
| PHONE :: 303.497.6469
| When you do something, you should burn yourself completely, like a good
| bonfire, leaving no trace of yourself. --Shunryu Suzuki
===============================================================================
 
L

Logan Capaldo

set foldlevel (I use foldlevel=2). As for markers, don't use them, use
syntax based folding. I dunno where I found the file (as it was real
difficult to find) but if anyone wants the custom RubyVim files with
support for syntax based folding and matchit support (% for def, end,
etc.) let me know, I can email them to you.
 
L

Logan Capaldo

You can use mkview and loadview to restore the folds


Isn't there a way to limit the number of folds created by
fm=indent?

yes - but you can say do THIS and THAT level. just a depth
I would like to use Vim's folding, but there doesn't seem to be a way to
have it just Do The Right Thing. I certainly don't want explicit fold
markers in the code.

the markers are nice because they remain when you close/reopen the file...
person opinion i guess...

cheers.



-a
--
===============================================================================
| EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
| PHONE :: 303.497.6469
| When you do something, you should burn yourself completely, like a good
| bonfire, leaving no trace of yourself. --Shunryu Suzuki
===============================================================================
 
R

Ralph Amissah

Follow-up: it's not promising. Vim's current syntax definition for
Ruby (http://vim-ruby.rubyforge.org) does enable syntax-based folding,
but it can't be selective about what it folds (i.e. classes and
methods only, per Ara's request).

The following settings should be OK:

set foldmethod=syntax
set foldnestmax=2 " or 3

If anyone knows enough about Vim to make the folding smarter for Ruby
files, please step forward :)

Gavin
I don't know about making folds smarter than you already have.

This is the folding I use with ruby and like, for what that is worth,
as someone who would not like to be without vim folding. I use the
attached folding setup and open ruby (and other files) in folded mode -
it is a bit like having a table of contents. It is made up from things
extracted from vim tips a couple of years back, modified as required
over time.

Lets see what does it include:

<leader>ff folds file

fs after a search, shows only search results all else folded
(no idea whether this feature has become part of mainstream vim)

to open a file in fold mode (i.e. with the fold instructions installed):
gvim -c :R

In additon to folding on def, class, and module (also public protected
private) it folds on #{{ (until the next fold), i use comment markers
and {{ to place folds in all files in which i want fold headings ...
vim setup files included.

There is no recursive (levels of) folding here.

Vim is so flexible how you choose to work with these things is a
matter of taste.
I don't have the time to clean it up, or to extract things (just) ruby
right now but share as is, unedited, (and including some non-ruby folding,
and probably some other superflous bits, actually i did start deleting a bit).
(there may be problems with line breaks). Oh and final caveat, apart from
having figured out what folds i was comfortable with using some time in the
past, (and using that ever since) i can't claim to know much about vim folds.

Vim fold section follows:

" arch-tag: vimrc folds related (e-mail address removed)
:filetype on
:filetype indent on
set foldexpr=Foldexpr_fun('^\\i')
:hi FoldColumn ctermfg=Black ctermbg=magenta
:hi Folded ctermfg=Black ctermbg=magenta
"{{~foldsearchx FoldSearch (opens result of search all else closed)
"mapped to \f & \z t77 late
:set foldexpr=getline(v:lnum-1)!~@/&&getline(v:lnum)!~@/&&getline(v:lnum+1)!~@/
:map fs :set foldmethod=expr foldcolumn=2 foldlevel=0 <cr>
:map <leader>see :set foldmethod=expr foldcolumn=2 foldlevel=0 <cr>
:map <leader>fa :Fa<cr>
function! FoldInst()
if ( &filetype == "ruby" )
"erase folds, first fold then erase, or just use open folds zR
:map <leader>fe :R<cr> zE
:R
else
:map <leader>fe :F<cr> zE
:F
endif
endfunc
:nmap <silent> <leader>ff :silent call FoldInst()<cr>
:map <leader>fO :R <cr>fe<cr> " erase folds
"{{~foldtoggle Fold Toggle mapped to <space>
" Toggle fold state between closed and opened.
" If there is no fold at current line, just moves forward. If it is present,
" reverse it's state.
fun! ToggleFold()
if foldlevel('.') == 0
normal! l
else
if foldclosed('.') < 0
. foldclose
else
. foldopen
endif
endif
" Clear status line
echo
endfun
" Map this function to Space key.
:noremap <space> :call ToggleFold()<cr>
"{{~foldtype Fold? set foldtext
:set foldtext=v:folddashes.substitute(getline(v:foldstart),'{{\\d\\=','','g',)
:set foldexpr=getline(v:lnum-1)!~@/&&getline(v:lnum)!~@/&&getline(v:lnum+1)!~@/
"{{~foldsearch t77: Fold on search result
"(Fs <pattern> or Fc Frb Flm Fp) Fs pattern Fold search #Str (structure)
" ruby program pattern based on module class and def #Strlm (structure)
" lm file pattern based on <!1!> etc.
function! Foldsearch(search)
set fdm=manual
normal zE
normal G$
let folded = 0 "flag to set when a fold is found
let flags = "w" "allow wrapping in the search
let line1 = 0 "set marker for beginning of fold
while search(a:search, flags) > 0
let line2 = line(".")
" echo "pattern found at line # " line2
if (line2 -1 > line1)
: "echo line1 . ":" . (line2-1)
: "echo "A fold goes here."
: execute ":" . line1 . "," . (line2-1) . "fold"
: let folded = 1 "at least one fold has been found
: endif
: let line1 = line2 "update marker
: let flags = "W" "turn off wrapping
: endwhile
" Now create the last fold which goes to the end of the file.
: normal $G
: let line2 = line(".")
" echo "end of file found at line # " line2
: if (line2 > line1 && folded == 1)
" echo line1 . ":" . line2
" echo "A fold goes here."
: execute ":". line1 . "," . line2 . "fold"
: endif
: normal 1G
:endfunction
"{~folds Fold Patterns
"Command is executed as ':Fs pattern'"
:command! -nargs=+ -complete=command Fs call Foldsearch(<q-args>)
:command! -nargs=+ -complete=command Fold call Foldsearch(<q-args>)
"{{~folds :T Fold Patterns exuberant tag list :T
:command! T Fs ^\s*\S\+\s\+(
"{{~folds :R Fold Patterns Ruby :R
:command! R Fs \(^\s*\(\(def\|class\|module\)\s\)\|\
\(\(public\|protected\|private\)\(\s\|$\)\)\)\
\|^[0-9]{\|[#%"]\{1,4\}\s*{\({\|!!\)
:command! Re Fs \(^\s*\(\(def\|class\|module\)\s\)\)\
\|^\s*[ #%"0-9\~]\{0,4\}{\({{\|!!\)
"{{~folds :F Fold Patterns SiSU Markup :F
:command! F Fs [1-8]{\|#\s*{{\|^[#%"0-9]\{0,4\}\s*{[{!]
 
D

Doug Kearns

IMHO - neither. too many folds. i like to fold class bodies, module
bodies, and function bodies - and that's all. either way above does a
LOT more.

You can limit the fold nesting with 'foldnestmax'

:set foldnestmax=2

will achieve what you've asked for above.

Regards,
Doug
 
D

Doug Kearns

Unless you have code like this, right?

Yes! I really should send email at this time... ;-)

Would it be worth making this configurable in syntax file? I expect
Ara's specified usage to be the most common for those not wanting
maximum folding.

<snip>

Regards,
Doug
 
G

Gavin Sinclair

Yes! I really should send email at this time... ;-)
Would it be worth making this configurable in syntax file? I expect
Ara's specified usage to be the most common for those not wanting
maximum folding.

What does making it configurable mean? People can already set their
own folding rules in $HOME/.vim/ftplugin/ruby.vim. The syntax rules
should merely be correct.

Gavin
 
D

Doug Kearns

On Wednesday, November 10, 2004, 3:08:09 AM, Doug wrote:
shouldn't

What does making it configurable mean?

We could limit what is folded based on a variable setting, as we already
do for other syntax features. See :help ruby-syntax
People can already set their own folding rules in
$HOME/.vim/ftplugin/ruby.vim.

I'm not sure what you mean by folding rules. I haven't given it much
thought, but I can't think of a good way to configure the syntax based
folding from there using any of the set options.
The syntax rules should merely be correct.

Sure, but it seems like a shame people aren't using foldmethod=syntax
simply because the folding is too extensive.

Regards,
Doug
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top