dhruvasagar / vim-dotoo

Org-mode like task logging & time tracking in Vim
554 stars 27 forks source link

[Feature request] Journal frequency config #141

Open cherryramatisdev opened 1 year ago

cherryramatisdev commented 1 year ago

Hi! I'd like to propose a new feature that would enhance the journal functionality by allowing users to maintain entries in weekly, monthly, and yearly formats instead of being limited to daily entries only.

Vimwiki has already implemented a similar feature with their diary option. You can check it out here: Vimwiki Diary PR. Additionally, org-journal provides a (setq org-journal-file-type 'weekly) option to achieve similar behavior.

Currently, I have a custom extension in my configuration that mimics this functionality. It works as follows:

fun! GetStartOfTheWeek(timestamp) abort
  return system('start-of-week ' . a:timestamp)->trim()
endfun

fun! GetJournalHeader() abort
  let l:day_of_the_week = strftime("%A")

  let l:has_header = system('grep ' . l:day_of_the_week . ' ' . expand('~/dotoo/journal/' . GetStartOfTheWeek(localtime()) . '.dotoo')) != ""

  if l:has_header
    return ''
  else
    return '* ' . l:day_of_the_week
  endif
endfun

let g:dotoo#capture#templates = {
  \ 'j': {
  \ 'description': 'Journal Entry',
  \ 'lines': [GetJournalHeader(), '** ' . strftime('%H:%m') . ' %?'],
  \ 'target': 'journal/' . GetStartOfTheWeek(localtime()) . '.dotoo',
  \ 'append': 1,
  \ },
}

With this extension, whenever I create a new journal entry, it opens the file for the beginning of the week (Monday) and automatically adds an interactive first heading with the current week's name if it's not already present.

For a clearer understanding of this feature, I've created a demo for you: Asciinema Demo.

I believe this functionality could be a valuable addition to the plugin. If something similar already exists or if you have any suggestions or feedback, please feel free to let me know! I would be more than happy to contribute in any way I can.

dhruvasagar commented 1 year ago

@cherryramatisdev This looks quite nice. Thanks, i'll try to add this to dotoo itself. If you think you're up to raising a PR, go for it!

cherryramatisdev commented 1 year ago

i'll look into the codebase and try to open a PR for sure! thanks for the feedback