From ebbc3efac27c0e037cadbc90ead3be082ec06f5b Mon Sep 17 00:00:00 2001 From: Alex Vear Date: Sat, 4 Jan 2020 20:11:52 +0000 Subject: [PATCH] Add `org_clean_folds` option --- TODO | 1 - autoload/org.vim | 18 ++++++++++++++++-- doc/org.txt | 39 ++++++++++++++++++++++++++++++++++++++- ftplugin/org.vim | 18 ++++++++---------- ftplugin/outline.vim | 18 ++++++++---------- 5 files changed, 70 insertions(+), 24 deletions(-) diff --git a/TODO b/TODO index c83270e..5a0713b 100644 --- a/TODO +++ b/TODO @@ -1,7 +1,6 @@ MAYBE: - Better link syntax highlighting (more similar to links in vim-markdown) - Syntax highlight bullets and checkboxes - - Option to enable/disable folding (similar to g:markdown_folding) - Different syntax group for heading delimiters - Change log in Vim doc diff --git a/autoload/org.vim b/autoload/org.vim index 3bcda28..ec4f5f8 100644 --- a/autoload/org.vim +++ b/autoload/org.vim @@ -4,9 +4,23 @@ " License: Vim (see `:help license`) " Location: autoload/org.vim " Website: https://github.com/axvr/org.vim -" Last Change: 2019-09-22 +" Last Change: 2020-01-04 " Fallback chain for options. Buffer local --> Global --> default. -function org#option(name, default) +function org#option(name, default) abort return get(b:, a:name, get(g:, a:name, a:default)) endfunction + +" Emacs-like fold text. +function org#fold_text() abort + return getline(v:foldstart) . '...' +endfunction + +" Check fold depth of a line. +function org#fold_expr() + let l:depth = match(getline(v:lnum), '\(^\*\+\)\@<=\( .*$\)\@=') + if l:depth > 0 && synIDattr(synID(v:lnum, 1, 1), 'name') =~# '\m^o\(rg\|utline\)Heading' + return ">" . l:depth + endif + return "=" +endfunction diff --git a/doc/org.txt b/doc/org.txt index 5782c5b..3cdc253 100644 --- a/doc/org.txt +++ b/doc/org.txt @@ -106,6 +106,23 @@ following command. ============================================================================== 4. CONFIGURATION *org-configuration* + *org-folding* + +To control how Org.vim handles folding, just use the standard Vim |folding| +options and commands. + +For example if you want to enable or disable folding, use 'foldenable'. +> + autocmd FileType org,outline setlocal nofoldenable +< +Or if you want folding enabled and all folds opened by default, use +'foldlevelstart'. +> + autocmd FileType org,outline setlocal foldenable foldlevelstart=99 +< +For more information on folding in Vim, refer to |fold.txt|. + +------------------------------------------------------------------------------ *'b:org_state_keywords'* *'g:org_state_keywords'* Value: list of strings~ Default: ['TODO', 'NEXT', 'DONE']~ @@ -149,6 +166,26 @@ an |autocmd| like so. > autocmd FileType org setlocal conceallevel=2 concealcursor=nc < +------------------------------------------------------------------------------ + *'b:org_clean_folds'* *'g:org_clean_folds'* +Value: numeric~ +Default: 0~ + +Vim's default styling for folds is quite ugly. Enabling this option will +remove much of the visual noise and suffix the folded heading text with an +ellipsis (`...`) making folds look the same as they do in Emacs' Org mode (and +Outline mode). +> + * Heading 1... +< +This option can be enabled for all buffers like so: +> + let g:org_clean_folds = 1 +< +Alternatively it can be enabled for specific buffers: +> + let b:org_clean_folds = 1 +< ------------------------------------------------------------------------------ *'b:org_use_italics'* *'g:org_use_italics'* Value: numeric~ @@ -180,7 +217,7 @@ works are: Org.vim is distributed under the same terms as Vim itself. -Copyright (c) 2018-2019, Alex Vear. +Copyright (c) 2018-2020, Alex Vear. A copy of the full licence text should have been provided with this extension in the `LICENCE` file. The license can also be viewed on the web [3] or by diff --git a/ftplugin/org.vim b/ftplugin/org.vim index 70650e1..237ca2c 100644 --- a/ftplugin/org.vim +++ b/ftplugin/org.vim @@ -4,7 +4,7 @@ " License: Vim (see `:help license`) " Location: ftplugin/org.vim " Website: https://github.com/axvr/org.vim -" Last Change: 2019-09-22 +" Last Change: 2020-01-04 " " Reference Specification: Org mode manual " GNU Info: `$ info Org` @@ -12,17 +12,15 @@ setlocal commentstring=#%s -function! OrgFold() - let l:depth = match(getline(v:lnum), '\(^\*\+\)\@<=\( .*$\)\@=') - if l:depth > 0 && synIDattr(synID(v:lnum, 1, 1), 'name') =~# 'orgHeading' - return ">" . l:depth - endif - return "=" -endfunction - -setlocal foldexpr=OrgFold() +setlocal foldexpr=org#fold_expr() setlocal foldmethod=expr +if org#option('org_clean_folds', 0) + setlocal foldtext=org#fold_text() + setlocal fillchars-=fold:- + setlocal fillchars-=fold:\ +endif + " Conceal Org mode link syntax if org#option('org_conceal_links', 1) setlocal conceallevel=2 diff --git a/ftplugin/outline.vim b/ftplugin/outline.vim index de29bd3..3ae97f2 100644 --- a/ftplugin/outline.vim +++ b/ftplugin/outline.vim @@ -4,19 +4,17 @@ " License: Vim (see `:help license`) " Location: ftplugin/outline.vim " Website: https://github.com/axvr/org.vim -" Last Change: 2019-09-22 +" Last Change: 2020-01-04 " " Reference Specification: GNU Emacs Manual, section 'Outline Mode' " GNU Info: `$ info Emacs Outline Mode` " Web: -function! OutlineFold() - let l:depth = match(getline(v:lnum), '\(^\*\+\)\@<=\( .*$\)\@=') - if l:depth > 0 && synIDattr(synID(v:lnum, 1, 1), 'name') =~# 'outlineHeading' - return ">" . l:depth - endif - return "=" -endfunction - -setlocal foldexpr=OutlineFold() +setlocal foldexpr=org#fold_expr() setlocal foldmethod=expr + +if org#option('org_clean_folds', 0) + setlocal foldtext=org#fold_text() + setlocal fillchars-=fold:- + setlocal fillchars-=fold:\ +endif