Browse files

Not having the option g:erlangFold any more

It's better to use set foldenable in your vimrc to control when to
activate the folding. It's more standard.
  • Loading branch information...
jimenezrick committed Sep 3, 2010
1 parent 614bb00 commit 40166edd8f29c09f8177b88fbedc0c91e243bbab
Showing with 9 additions and 11 deletions.
  1. +9 −11 ftplugin/erlang.vim
@@ -3,17 +3,17 @@
" Maintainer: Oscar Hellström <>
" URL:
" Contributor: Ricardo Catalinas Jiménez <>
-" Version: 2010-09-02
+" Version: 2010-09-03
" ------------------------------------------------------------------------------
" Usage:
-" To enable folding put in your vimrc
-" let g:erlangFold=1
+" To enable folding put in your vimrc:
+" set foldenable
" Folding will make only one fold for a complete function, even though it has
-" more than one function head and body
+" more than one function head and body.
-" To change this behaviour put in your vimrc file
+" To change this behaviour put in your vimrc file:
" let g:erlangFoldSplitFunction=1
" ------------------------------------------------------------------------------
@@ -34,16 +34,14 @@ let s:doneFunctionDefinitions=1
" Local settings
function s:SetErlangOptions()
- compiler erlang
+ compiler erlang
if version >= 700
setlocal omnifunc=erlangcomplete#Complete
- if (exists("g:erlangFold")) && g:erlangFold
- setlocal foldmethod=expr
- setlocal foldexpr=GetErlangFold(v:lnum)
- setlocal foldtext=ErlangFoldText()
- endif
+ setlocal foldmethod=expr
+ setlocal foldexpr=GetErlangFold(v:lnum)
+ setlocal foldtext=ErlangFoldText()
" Define folding functions

7 comments on commit 40166ed

xevz replied Nov 21, 2011

I found out about this change today when I updated my Vim config.

I disagree with this and vote for the functionality to be re-added.
The reason for it is that it is not really "standard" for language plugins to fold their functions automatically. I do like folds, but not automatically folded functions.


jimenezrick replied Nov 21, 2011

The thing is that Vim enables code folding by default, see'foldenable'. So the standard behavior for most plug-ins which implement folding is to start with the code folded. Most people don't like that, so the standard way to disable this is putting in your .vimrc:

set nofoldenable

Using a script variable was ad-hoc, this is way I removed it. With nofoldenable now you can control this functionality in all your programming languages.

xevz replied Nov 21, 2011

Which other language plugins enable automatic folding on functions/methods?
Vim's default scripts certainly don't and among the (few) plugins I use, only this plugin do.

If I use nofoldenable I lose all my other folds, which I want to retain.

This is now solved by using an after/ftplugin script which resets the folding settings, but I'd rather not use that method, it feels error prone.

EDIT: Vim even have functionality for this, I have foldmethod set to marker. If changed to syntax, functions (and other blocks) are folded.


jimenezrick replied Nov 21, 2011

In my case, Erlang, C/C++, Python and OCaml start by default with code folded. So, I don't like it because of that I use set nofoldenable. But I have to note that I modify foldmethod, so that could explain why you don't see you code automatically folded.

By default, Vim starts with foldenable and foldmethod=manual, so that's way most of the times, folding is enabled but your code is not rellay folded, because Vim waits to be done by you. If you modify foldmethod (like Vimerl does), the folding will take place automatically. So that's is why is necessary to use set nofoldenable. And that's the standard way to do it.

If you need to set different settings for different programming language, then :help autocmd is what you need.

Look in my Vim config and see some example of these:

But going directly to the point, you need:

autocmd FileType erlang setlocal nofoldenable

That's all, and that's the Vim way to make this customization for you language of choice.

xevz replied Nov 21, 2011

Actually, I think the only "Vim way" is to use foldmethod=syntax and define a folding region for functions (but that may be too restrictive).
I don't want to turn off folding, and I've set foldermethod to marker for a reason (I want to support folding markers). I don't think any plugin should override preferences like this by default.

Neither C/C++, Python or O'Caml (OMLet) change it for me. They do for you, since you've told them to.


jimenezrick replied Nov 21, 2011

Mmmm, maybe the best default could be to set foldmethod=manual (the default) and have a global variable to control the behaviour, the same as it was originally.

I think with Erlang is a bit awkward to use foldmethod=syntax as it doesn´t have a so structured grammar like C, furthermore, the syntax file doesn't come with any folding annotation at this moment.

I think I am going to change this in my fork and create g:vimerl_folding.


jimenezrick replied Nov 21, 2011

The variable that controls this behaviour is g:erlang_folding.

Please sign in to comment.