nvim-orgmode/orgmode

[Help Needed] Notifications testing

kristijanhusak opened this issue ยท 29 comments

Experimental support for notifications was added.

Any help with testing this, especially on MacOS and Windows, is highly appreciated. If you have any questions, feel free to post them on this issue.

image
I just try notification and get this error message

below is my setting:

notifications = {
        enabled = true,
        cron_enabled = false,
        repeater_reminder_time = {1, 5, 10},
        deadline_warning_reminder_time = {1, 5, 10},
        reminder_time = {1, 5, 10},
        deadline_reminder = true,
        scheduled_reminder = true,
        notifier = function(tasks)
          local result = {}
          for _, task in ipairs(tasks) do
            utils.concat(result, {
              string.format('# %s (%s)', task.category, task.humanized_duration),
              string.format('%s %s %s', string.rep('*', task.level), task.todo, task.title),
              string.format('%s: <%s>', task.type, task.time:to_string())
            })
          end
    
          if not vim.tbl_isempty(result) then
            require('orgmode.notifications.notification_popup'):new({ content = result })
          end
        end,
}

@hongphong177 I missed one spot that's not using proper function. I updated the docs, but only change is that utils on line 12 becomes require('orgmode.utils').

it's worked thanks a lot @kristijanhusak

I use these every day (rather than cron I've setup a systemd timer) and they work flawlessly.

I've been using this with just the neovim notification and it works well! Especially with nvim-notify

I tried it using the optimal way the service returned an error (I used systemd timer)
image

image
if I used my config it'll return this
image

this is my config:

  notifications = {
    enabled = true,
    cron_enabled = true,
    repeater_reminder_time = {0, 1, 5},
    deadline_warning_reminder_time = {0, 1, 5, 15, 30, 60},
    reminder_time = 10,
    deadline_reminder = true,
    scheduled_reminder = true,
    notifier = function(tasks)
      local result = {}
      for _, task in ipairs(tasks) do
        require('orgmode.utils').concat(result, {
          string.format('# %s (%s)', task.category, task.humanized_duration),
          string.format('%s %s %s', string.rep('*', task.level), task.todo, task.title),
          string.format('%s: <%s>', task.type, task.time:to_string())
        })
      end

      if not vim.tbl_isempty(result) then
        require('orgmode.notifications.notification_popup'):new({ content = result })
      end
    end,
    cron_notifier = function(tasks)
      for _, task in ipairs(tasks) do
        local title = string.format('%s (%s)', task.category, task.humanized_duration)
        local subtitle = string.format('%s %s %s', string.rep('*', task.level), task.todo, task.title)
        local date = string.format('%s: %s', task.type, task.time:to_string())

        if vim.fn.executable('notify-send') == 1 then
          vim.loop.spawn('notify-send', { args = { string.format('%s\n%s\n%s', title, subtitle, date) }})
        end
      end
    end
  },

@excalios seems like you generally have something loaded incorrectly, because I see some indent line errors.
what does it happen if you do this:

ni --noplugin --headless -c "echo 'test' | qa"

@kristijanhusak Thanks for the reply I ran the command and got this result:
image

@excalios is your config working properly when you run it through regular neovim session?

@kristijanhusak Seems to be working fine except the notifications? I'm unsure on how to test it

@excalios set up a TODO that will happen in a bit more than 10 minutes. Open up Neovim and wait until exactly 10 minutes before the task deadline time, and it should show you a notification inside Neovim in top right corner.

I managed to get it working-ish.
I upgraded my neovim apparently it was quite old version. Managed to run it with no error on this command
/usr/bin/nvim --headless --noplugin -c 'lua require("orgmode").cron(require("excalios.orgconf"))'
I moved the systemd timer from system dir to user dir. Apparently when it's on system it couldn't find the orgmode but on user it was able to find it. I didn't change the config from there.
But, the notification doesn't always popup sometimes it does more time it doesn't. I checked the handle and the pid it was able to create the process no problem. But, the notification just doesn't popup somehow. I tried adding another empty spawn it popped up more often but not always. Adding a spawn with a command in it made it to always popup but I don't like this approach. Might just be my setup thanks for the help though

If we just add a SCHEDULED entry, do we need to do something to make it in effect?

@Tokubara you should be getting both scheduled and deadline notifications.

I'm only getting notifications for SCHEDULED (and possibly DEADLINE, didn't test), but not for plain timestamps. Is this on purpose?
In general I'm wondering whether I'm using plain timestamps properly, since there were a few other bugs with this in the past (and some issues I'll file soon). I'm using orgmode also as a calendar, and when I have a meeting scheduled, I make a headline entry with the meeting name and a plain timestamp to indicate the time. Is this not how org should be used?

I'd say orgmode should be used how it fits your needs. I also use plain timestamps on things I just want on my agenda, like you do. This is what orgmode says about it. The difference, as far as the agenda is concerned (and I am aware of), is that scheduled items will continue to show up on the current day, until you set them to DONE archive them.

All right, thanks for clarifying! :)
So I suppose it should be a bug then that headlines with just a plain timestamp don't shop up in the notifications. Should I file an issue?

Not sure if bug or missing feature. Emacs orgmode also does not seem to have notifications built in. Feel free to open an issue ๐Ÿ‘

I can't make this feature to function at all i have a scheduled entry in a org file like this:

* Events
** Send notification now
   SCHEDULED: <2023-12-02 Sat 21:45>

running following command manually from command line I'm not getting any notification

/usr/bin/nvim --headless --noplugin -c 'lua require("orgmode").cron()'

notify-send is installed anything am i missing?

@mortezadadgar what are your reminder settings? If you set reminder time to 10 it will show you the notification only if you run it exactly 10 minutes before the scheduled datetime. So for given todo, to see a notification, you need to run it at 2023-12-02 Sat 21:35, considering you are using correct configuration for corn, and a default reminder time which is 10.

@kristijanhusak yes indeed it does work sorry for noise

I've had cron notifications set up since a long time by now, and I haven't changed anything. However, the notifications recently stopped working. What's more, I have tons of stuck nvim processes that fill up my RAM.
I suspect that there's an error in one of my org files, which trips up the treesitter parser and leads to an error in the orgmode plugin. When I run the command in crontab manually, I get

$ DISPLAY=:0 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus /home/maltimore/programs/nvim --headless --noplugin -c 'lua require("orgmode").cron()'
Error executing vim.schedule lua callback: ...er/start/orgmode.nvim.git/lua/orgmode/files/headline.lua:307: attempt to index a nil value
stack traceback:
        ...er/start/orgmode.nvim.git/lua/orgmode/files/headline.lua:307: in function 'method'
        ...packer/start/orgmode.nvim.git/lua/orgmode/utils/init.lua:570: in function 'get_todo'
        ...er/start/orgmode.nvim.git/lua/orgmode/files/headline.lua:328: in function 'is_done'
        ...packer/start/orgmode.nvim.git/lua/orgmode/files/file.lua:455: in function <...packer/start/orgmode.nvim.git/lua/orgmode/files/file.lua:453>
        vim/shared.lua: in function 'method'
        ...packer/start/orgmode.nvim.git/lua/orgmode/utils/init.lua:570: in function 'get_opened_unfinished_headlines'
        ...tart/orgmode.nvim.git/lua/orgmode/notifications/init.lua:95: in function 'get_tasks'
        ...tart/orgmode.nvim.git/lua/orgmode/notifications/init.lua:65: in function 'cron'
        .../pack/packer/start/orgmode.nvim.git/lua/orgmode/init.lua:221: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>

If my suspicion that there's an error in one of my orgfiles is correct, it would be great if orgmode could report the org file and line where the error occurs. And, ideally, report this as a notification.

@Maltimore Removing --noplugin should make it work. This would load all the plugins though, but it should work.
I use a separate file where I load everything that's necessary for a cron and use it like this:

* * * * * DISPLAY=:0 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus /home/kristijan/.local/share/bob/nvim-bin/nvim -u NONE --headless --noplugin -c 'lua require("partials.orgmode_cron")'

I can't recall how this managed to work with --noplugin since there is a dependency on nvim-treesitter.

Let me know if removing --noplugin works for you.

Unfortunately, removing --noplugin does not work, I get the same error as before.

Can you try using my file I provided and see if that helps? What package manager are you using?

I'm using packer for now. I wanted to migrate to lazy anyways, so I guess I'll do that now/soon and then use your partial lazy-based config and report back!

it would be great if orgmode could report the org file and line where the error occurs. And, ideally, report this as a notification.

I had these issues myself so I'll see to add some way to notify the user that something is failing

@Maltimore I pushed some changes (4c7b539) that should properly exit and report errors via system notifier.
Also the error you got is something that can really happen (even though I didn't manage to reproduce it), so I also addressed that. Let me know if it works now.

I moved to lazy.nvim and use your partial orgmode cron file now. I can confirm that with your latest changes, everything works perfectly:

  • if an error occurs, I get notified of this now
  • the error itself doesn't occur anymore because you fixed the source of that

Furthermore, I also tested it with my previous approach and can confirm that even then (i.e. not using the partial config), it works. Thanks a lot!! :)