nvim-telekasten / telekasten.nvim

A Neovim (lua) plugin for working with a markdown zettelkasten / wiki and mixing it with a journal, based on telescope.nvim
MIT License
1.42k stars 91 forks source link

[FR] Add some useful goto options - tomorrow & yesterday #296

Open TC72 opened 10 months ago

TC72 commented 10 months ago

Add more goto options like goto_today. I now live in telekasten for everything I'm working on and it would be nice to have a simple way to go to tomorrow's journal and write myself notes to get that workday started on a roll. Being able to go back to yesterday to find all the todos I failed to complete would also be nice. I can add this myself but wanted to raise it as an issue before submitting a PR.

I'd thought about suggesting this before but I see that Obsidian.nvim goes a step further and goto tomorrow and yesterday can figure out which work day to go to. I don't need that feature myself but would be good to cover all bases.

lambtho12 commented 10 months ago

I agree with the proposal. And I am happy that you are willing to make it happen! Thank you very much for getting involved! If you are motivated, feel free to tackle other stuff as well :smile:


Now, let's be smart (and lazy) about that implementation.. Rather than defining a new function, we could just add an offset option to GotoToday (or ultimately GotoDate) that would let user define their mappings or functions as they want (yesterday offset=-1, same day last week offset=-7, tomorrow offset=1, same day next week offset=7, in three days offset=3, whatever).

E.g.

  vim.keymap.set(
    "n",
    "<leader>zY",
    ":lua require('telekasten').goto_today({offset=-1})<CR>",
    { desc = "Go to [Y]esterday" }
  )

If you want to really go over board, we could also have a parser so we could say (GotoDate("next sunday")) or something, but that is probably much complex.

TC72 commented 10 months ago

This works and handles no offset being provided.

My only experience with Lua is writing a simple telescope extension so any feedback on whether this is the right way to do things would be great. I've just added an extra parameter into the os.date() call instead of it defaulting to using os.time() to get now.

local function GotoToday(opts)
    opts = opts or {}
    opts.offset = opts.offset or 0

    global_dir_check(function(dir_check)
        if not dir_check then
            return
        end

        local today = os.date(dateutils.dateformats.date,(os.time()+(86400*opts.offset)))
        opts.date_table = os.date("*t")
        opts.date = today
        opts.dailies_create_nonexisting = true -- Always use template for GotoToday
        GotoDate(opts)
    end)
end
lambtho12 commented 10 months ago

(Sorry for the delay)

Looks good for me. No need to reinvent the wheel. We should maybe call it day_offset rather than simply offset to be clearer tho.

Do not forget to document this new option properly in the doc/telekasten.tex as well in your PR.