Skip to content

Instantly share code, notes, and snippets.

@mikejakobsen
Created May 20, 2017 08:56
Show Gist options
  • Select an option

  • Save mikejakobsen/4a847eb3daf561f2f1a9f51d620c194b to your computer and use it in GitHub Desktop.

Select an option

Save mikejakobsen/4a847eb3daf561f2f1a9f51d620c194b to your computer and use it in GitHub Desktop.
command! -nargs=? -bang Husk call <SID>Husk(<bang>0, "<args>")
function! s:Husk(bang, comment)
if a:comment != "" || a:bang
call <SID>WriteHusk(a:comment)
else
call <SID>ViewHusk()
endif
endfunction
function! s:WriteHusk(comment)
let file_exists = filereadable(".todo")
if a:comment == ""
let comment = "(no comment)"
else
let comment = a:comment
end
let time = strftime("%F %H:%M:%S")
let path_and_line = @% . ":" . line(".")
let prev_lines = file_exists ? readfile(".todo") : []
call writefile([time, path_and_line, comment, ""] + prev_lines, ".todo")
echo "Jeg husker " . comment
endfunction
function! s:ViewHusk()
let file_exists = filereadable(".todo")
if file_exists
tabe .todo
noremap <buffer> gf gF
else
echo "Ingen .todo fil fundet."
end
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment