Code Monkey home page Code Monkey logo

Comments (13)

kristijanhusak avatar kristijanhusak commented on June 3, 2024 1

If you for example mark another element of the agenda as done or as archived, the actions are going to be done on the wrong item

This should not happen unless the change to the agenda item adds some content to it's subtree. For example if you have a headline with a deadline that repeats, each time you mark it as done it adds entry to the logbook, and shifts all headlines below. This caused wrong item to be updated in the agenda.

I solved that in 1425b36, so now agenda will automatically reload if there is a need for it.

It will not reload if you archive a headline by adding ARCHIVE tag, or marking a nonrepeater task as done, but that should not cause any issues with the wrong item being updated. The idea is to be able to undo these changes easily in the agenda in case you made a mistake.

I also just pushed 66591ca that should allow reloading agenda window remotely.

So to achieve what you want here you can add this to your configuration:

vim.api.nvim_create_autocmd('BufWritePost', {
  pattern = '*.org',
  callback = function()
    local bufnr = vim.fn.bufnr('orgagenda') or -1
    if bufnr > -1 then
      require('orgmode').agenda:redo()
    end
  end
})

This will reload agenda window if it's open each time you write any org file.

I think this should solve both this issue and #596. @Maltimore can yo check?

from orgmode.

lyz-code avatar lyz-code commented on June 3, 2024

It works beautifully @kristijanhusak thank you so much as always, you don't know how happy you make me xD.

I'm fine closing the issue as is, but just one more question. The autocmd works only if I save the file where I archived the element. But there are cases where I just archive an element without saving so the agenda is not refreshed. To solve this I'm thinking of two solutions:

  • That nvim-orgmode has this functionality
  • To create a keybinding that saves the file when archiving an element. I suppose this solution is the cleanest for this (I guess) corner case. I have no idea though on how to do this. I'll search online the code to save a file from a lua function, but can you help me with the archiving lua code for the function? Only if it's trivial for you and don't have to search in the code (I can do that myself)

Thanks as always <3

from orgmode.

Maltimore avatar Maltimore commented on June 3, 2024

Hi both of you,
I have tested the new code and can confirm that the issue described here is fixed, thanks @kristijanhusak!
There's still one case that doesn't work though, and that is simply if I have the agenda open in one nvim instance, and in another nvim instance I change a .org file. I do this quite frequently to be honest. I wonder, now that we have the require('orgmode').agenda:redo() function, could we have a loop that just refreshes the agenda every x minutes (with x configurable)?

from orgmode.

kristijanhusak avatar kristijanhusak commented on June 3, 2024

@Maltimore you can probably do that with timers :h vim.loop, but i haven't tested.

from orgmode.

Maltimore avatar Maltimore commented on June 3, 2024

Yes, that sounds quite straightforward, thanks!

from orgmode.

lyz-code avatar lyz-code commented on June 3, 2024

@Maltimore If you finally go in the vim.loop direction could you please post here the solution? It's also the last feature I'm missing on this issue

from orgmode.

Maltimore avatar Maltimore commented on June 3, 2024

Will do! :)

from orgmode.

kristijanhusak avatar kristijanhusak commented on June 3, 2024

@lyz-code This should do the trick:

local timer = vim.loop.new_timer()
timer:start(
  0,
  10000,
  vim.schedule_wrap(function()
    local bufnr = vim.fn.bufnr('orgagenda') or -1
    if bufnr > -1 then
      require('orgmode').agenda:redo()
    end
  end)
)

This will reload the agenda if it's opened every 10 sec.
Note that you need to pull latest master. I found some bugs around reloading that I fixed in the meantime.

from orgmode.

lyz-code avatar lyz-code commented on June 3, 2024

Damn @kristijanhusak each morning a new gift (â•Ĩīšâ•Ĩ). It works like a charm.

For those of you that doubt where to put that snippet, I've added it to a FileType autocommand

vim.api.nvim_create_autocmd("FileType", {
  pattern = "org",
  group = vim.api.nvim_create_augroup("orgmode", { clear = true }),
  callback = function()
    -- Reload the agenda each second if its opened so that unsaved changes 
    -- in the files are shown
    local timer = vim.loop.new_timer()
    timer:start(
      0,
      10000,
      vim.schedule_wrap(function()
        local bufnr = vim.fn.bufnr("orgagenda") or -1
        if bufnr > -1 then
          require("orgmode").agenda:redo(true)
        end
      end)
    )
  end,
})

from orgmode.

lyz-code avatar lyz-code commented on June 3, 2024

I've detected a little bug when using the timer. Each time the agenda reloads the cursor is moved to the top of the day. Imagine that we have this agenda:

Tuesday    05 March 2024
  inbox:           18:00......  Do X
  inbox:           19:30...... Do Y  <-- cursor is here

When the agenda is reloaded, the cursor is moved to the top of the day

Tuesday    05 March 2024  <-- cursor is moved here
  inbox:           18:00......  Do X
  inbox:           19:30...... Do Y  

10 seconds was too much for me, so I set the agenda reload each second. If I have 10 elements in a day agenda I don't have time to reach the bottom before I'm moved back up xD.

Would it be possible to remember the position where the cursor was so that it's stable after the agenda refresh?

I don't know if that is one of the fixes you made. I'm at 779a568.

from orgmode.

kristijanhusak avatar kristijanhusak commented on June 3, 2024

@lyz-code Just note that your example will work only after some org file was opened.
Regarding the cursor position, try passing true to redo, that should keep the cursor position.

from orgmode.

lyz-code avatar lyz-code commented on June 3, 2024

I feel that's fine because if no org file is opened then there is no need to reload the agenda as there will be no changes. I guess the other place to add the snippet is in the setup of the plugin.

Setting true to redo fixes it indeed ^^

from orgmode.

lyz-code avatar lyz-code commented on June 3, 2024

Another solution to avoid using the timer is to use the auto-save plugin I found it really elegant

from orgmode.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤ī¸ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.