3

I am curious to see if it would be possible to write a vim fold expression for fountain.io files. Fountain files are plaintext files used by screenwriters. A good start would be to fold along two different terms that occur commonly in screenplays (INT. and EXT.), obviously I'd like to drill down into blocks of dialogue etc. down the road. But for now I'd like to start with INT. and EXT.

I use a folding expression for markdown as follows:

function! MarkdownFolds()
  let thisline = getline(v:lnum)
  if match(thisline, '^#') >= 0
    return ">1"
  else
    return "="
  endif
endfunction
setlocal foldmethod=expr
setlocal foldexpr=MarkdownFolds()

function! MarkdownFoldText()
  let foldsize = (v:foldend-v:foldstart)
  return getline(v:foldstart).' ('.foldsize.' lines)'
endfunction
setlocal foldtext=MarkdownFoldText()

" SOURCE
" https://gist.github.com/anonymous/4149842

I'm thinking there is a way to modify something like this to do what I want to. Anyone have any ideas, I would greatly appreciate it. If we get this fleshed out, I'll make sure to get this in front of whoever uses vim and fountain in conjunction.

Thanks in advance.

  • 1
    That's a very interesting syntax. It may require some work since their syntax is quite long (notably the sections for power users may be tricky), but it is a well defined syntax therefore it definitely can be done. I just added the comment to add the link to the actual syntax documentation, I need to sleep. – grochmal Jul 31 '16 at 2:15
3

OP here. I figured it out, turns out that even though I don't understand programming all too well, it was totally doable.

function! FountainFolds()
  let thisline = getline(v:lnum)
  if match(thisline, '^INT.') > -1
    return ">1"
  elseif match (thisline, '^EXT.') > -1
    return ">1"
  elseif match (thisline, '^Title:') > -1
    return ">1"
  else
    return "="
  endif
endfunction


setlocal foldmethod=expr
setlocal foldexpr=FountainFolds()

function! FountainFoldText()
  let foldsize = (v:foldend-v:foldstart)
  return getline(v:foldstart).' ('.foldsize.' lines)'
endfunction

setlocal foldtext=FountainFoldText()

Probably not the best or perfect way to do it. But it works. I may work to integrate other hierarchical elements that are common to fountain file. If I do, I will update this. I may also make this a gist on github.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.