summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Lenz <Jason@Lenzplace.org>2020-12-17 22:34:26 -0600
committerJason Lenz <Jason@Lenzplace.org>2020-12-17 22:34:26 -0600
commit8d6aa0cecf0a342cf1ac4cf62e784c7b5e5f1044 (patch)
tree3b1295d33efc279131982a3fd23582a9eb2b61de
parent91cc663e8b51e59563272e31e6466b798b0dbb2a (diff)
downloadtodo.txt-vim-8d6aa0cecf0a342cf1ac4cf62e784c7b5e5f1044.zip
Enable user to prevent fold method change after sorting
-rw-r--r--README.markdown9
-rw-r--r--autoload/todo.vim8
-rw-r--r--ftplugin/todo.vim5
3 files changed, 19 insertions, 3 deletions
diff --git a/README.markdown b/README.markdown
index cd57b57..57c4f37 100644
--- a/README.markdown
+++ b/README.markdown
@@ -336,6 +336,13 @@ disable this behavior by setting the following global variable:
## Fold
Todo.txt files can be folded by projects or context (see `:help fold`), by
-default they are foldable by context, to use project fold :
+default they are foldable by context, to use project fold add the following to
+your vimrc:
let g:Todo_fold_char='+'
+
+Note that the fold method by default changes to match the sort order regardless
+of what Todo_fold_char is set to. If you prefer to keep the fold method
+constant even after changing the sort method set the variable below as follows:
+
+ let g:Todo_update_fold_on_sort=0
diff --git a/autoload/todo.vim b/autoload/todo.vim
index e53c941..d8fb172 100644
--- a/autoload/todo.vim
+++ b/autoload/todo.vim
@@ -167,7 +167,9 @@ endfunction
function! todo#Sort(type)
" vim :sort is usually stable
" we sort first on contexts, then on projects and then on priority
- let g:Todo_fold_char='x'
+ if g:Todo_update_fold_on_sort
+ let g:Todo_fold_char=a:type
+ endif
let oldcursor=todo#GetCurpos()
if(a:type != "")
exec ':sort /.\{-}\ze'.a:type.'/'
@@ -297,7 +299,9 @@ function! todo#HierarchicalSort(symbol, symbolsub, dolastsort)
"Empty buffer do nothing
return
endif
- let g:Todo_fold_char=a:symbol
+ if g:Todo_update_fold_on_sort
+ let g:Todo_fold_char=a:symbol
+ endif
"if the sort modes doesn't start by '!' it must start with a space
let l:sortmode=Todo_txt_InsertSpaceIfNeeded(g:Todo_txt_first_level_sort_mode)
let l:sortmodesub=Todo_txt_InsertSpaceIfNeeded(g:Todo_txt_second_level_sort_mode)
diff --git a/ftplugin/todo.vim b/ftplugin/todo.vim
index 4bc3cb9..12133ea 100644
--- a/ftplugin/todo.vim
+++ b/ftplugin/todo.vim
@@ -121,6 +121,11 @@ setlocal foldmethod=expr
setlocal foldexpr=TodoFoldLevel(v:lnum)
setlocal foldtext=TodoFoldText()
+" Update fold method after sort by default
+if ! exists("g:Todo_update_fold_on_sort")
+ let g:Todo_update_fold_on_sort=1
+endif
+
" Go to first completed task
let oldpos=getcurpos()
if(!exists("g:Todo_fold_char"))