-
-
Save MicahElliott/3049202 to your computer and use it in GitHub Desktop.
Automagic Clojure folding on defns and defmacros
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" --------------------------------------------------------------------------- | |
" Automagic Clojure folding on defn's and defmacro's | |
" | |
" Blog post: http://writequit.org/blog/?p=413 | |
function GetClojureFold() | |
if getline(v:lnum) =~ '^\s*(defn.*\s' | |
return ">1" | |
elseif getline(v:lnum) =~ '^\s*(def\(macro\|method\|page\|partial\).*\s' | |
return ">1" | |
elseif getline(v:lnum) =~ '^\s*(defmethod.*\s' | |
return ">1" | |
elseif getline(v:lnum) =~ '^\s*$' | |
let my_cljnum = v:lnum | |
let my_cljmax = line("$") | |
while (1) | |
let my_cljnum = my_cljnum + 1 | |
if my_cljnum > my_cljmax | |
return "<1" | |
endif | |
let my_cljdata = getline(my_cljnum) | |
" If we match an empty line, stop folding | |
if my_cljdata =~ '^$' | |
return "<1" | |
else | |
return "=" | |
endif | |
endwhile | |
else | |
return "=" | |
endif | |
endfunction | |
function TurnOnClojureFolding() | |
setlocal foldexpr=GetClojureFold() | |
setlocal foldmethod=expr | |
endfunction | |
" Simplify the fold display | |
function MinimalFoldText() | |
return getline(v:foldstart) | |
endfunction | |
set foldtext=MinimalFoldText() | |
autocmd FileType clojure call TurnOnClojureFolding() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" --------------------------------------------------------------------------- | |
" Automagic Clojure folding on defn's and defmacro's | |
" | |
" Blog post: http://writequit.org/blog/?p=413 | |
function GetClojureFold() | |
if getline(v:lnum) =~ '^\s*(defn.*\s' | |
return ">1" | |
elseif getline(v:lnum) =~ '^\s*(def\(macro\|method\|page\|partial\).*\s' | |
return ">1" | |
elseif getline(v:lnum) =~ '^\s*(defmethod.*\s' | |
return ">1" | |
elseif getline(v:lnum) =~ '^\s*$' | |
let my_cljnum = v:lnum | |
let my_cljmax = line("$") | |
while (1) | |
let my_cljnum = my_cljnum + 1 | |
if my_cljnum > my_cljmax | |
return "<1" | |
endif | |
let my_cljdata = getline(my_cljnum) | |
" If we match an empty line, stop folding | |
if my_cljdata =~ '^$' | |
return "<1" | |
else | |
return "=" | |
endif | |
endwhile | |
else | |
return "=" | |
endif | |
endfunction | |
function TurnOnClojureFolding() | |
setlocal foldexpr=GetClojureFold() | |
setlocal foldmethod=expr | |
endfunction | |
" Simplify the fold display | |
function MinimalFoldText() | |
return getline(v:foldstart) | |
endfunction | |
set foldtext=MinimalFoldText() | |
autocmd FileType clojure call TurnOnClojureFolding() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment