mirror of
https://github.com/freitass/todo.txt-vim.git
synced 2025-11-16 22:03:38 -05:00
Folding completed tasks
This commit is contained in:
6
Todo.txt
6
Todo.txt
@@ -1,13 +1,13 @@
|
||||
(A) 2011-06-03 Accept variable space length between fields @syntax
|
||||
(A) 2011-06-03 Implement foldings @ftplugin
|
||||
(A) 2011-06-06 Easier date input @ftplugin
|
||||
(B) 2011-05-31 Start documentation @doc
|
||||
(C) 2011-05-30 Create README.markdown to be published in github @doc
|
||||
(C) 2011-06-01 Improve syntax file @syntax
|
||||
2011-05-30 Contact main project for reference
|
||||
2011-05-30 Map commands to add, rm, ls, pri, depri etc @ftplugin
|
||||
2011-06-06 Check file syntax @syntax
|
||||
X 2011-05-30 Implement colorized priorities @syntax
|
||||
X 2011-05-30 Implement filetype detection @ftdetect
|
||||
X 2011-05-30 Sort lines per priority @ftplugin
|
||||
X 2011-05-31 Highlight date, project and context of tasks with no priority @syntax
|
||||
X 2011-05-31 Stop breaking lines automatically @ftplugin
|
||||
X 2011-05-31 Stop breaking lines automatically @ftplugin
|
||||
X 2011-06-06 Implement foldings @ftplugin
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
" Author: Leandro Freitas <freitass@gmail.com>
|
||||
" Licence: Vim licence
|
||||
" Website: http://github.com/freitass/todo.txt.vim
|
||||
" Version: 0.2
|
||||
" Version: 0.3
|
||||
|
||||
if exists("g:loaded_todo")
|
||||
finish
|
||||
@@ -16,4 +16,28 @@ set cpo&vim
|
||||
setlocal textwidth=0
|
||||
setlocal wrapmargin=0
|
||||
|
||||
setlocal foldmethod=expr
|
||||
setlocal foldexpr=TodoFoldLevel(v:lnum)
|
||||
setlocal foldtext=TodoFoldText()
|
||||
|
||||
function! TodoFoldLevel(lnum)
|
||||
" The match function returns the index of the matching pattern or -1 if
|
||||
" the pattern doesn't match. In this case, we always try to match a
|
||||
" completed task from the beginning of the line so that the matching
|
||||
" function will always return -1 if the pattern doesn't match or 0 if the
|
||||
" pattern matches. Incrementing by one the value returned by the matching
|
||||
" function we will return 1 for the completed tasks (they will be at the
|
||||
" first folding level) while for the other lines 0 will be returned,
|
||||
" indicating that they do not fold.
|
||||
return match(getline(a:lnum),'^[xX]\s.\+$') + 1
|
||||
endfunction
|
||||
|
||||
function! TodoFoldText()
|
||||
" The text displayed at the fold is formatted as '+- N Completed tasks'
|
||||
" where N is the number of lines folded.
|
||||
return '+' . v:folddashes . ' '
|
||||
\ . (v:foldend - v:foldstart + 1)
|
||||
\ . ' Completed tasks'
|
||||
endfunction
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
|
||||
Reference in New Issue
Block a user