Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Help Needed] Notifications testing #49

Open
kristijanhusak opened this issue Jul 15, 2021 · 29 comments
Open

[Help Needed] Notifications testing #49

kristijanhusak opened this issue Jul 15, 2021 · 29 comments
Labels
help wanted Extra attention is needed

Comments

@kristijanhusak
Copy link
Member

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.

@kristijanhusak kristijanhusak added the help wanted Extra attention is needed label Jul 15, 2021
@kristijanhusak kristijanhusak pinned this issue Jul 15, 2021
@kristijanhusak kristijanhusak changed the title [Help Needed] Notifications [Help Needed] Notifications testing Jul 16, 2021
@hongphong177
Copy link

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,
}

@kristijanhusak
Copy link
Member Author

@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').

@hongphong177
Copy link

it's worked thanks a lot @kristijanhusak

@levouh
Copy link
Contributor

levouh commented Nov 17, 2021

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

@joshpetit
Copy link
Contributor

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

@kristijanhusak kristijanhusak unpinned this issue Feb 6, 2022
@excalios
Copy link

excalios commented Mar 4, 2022

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
  },

@kristijanhusak
Copy link
Member Author

@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"

@excalios
Copy link

excalios commented Mar 4, 2022

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

@kristijanhusak
Copy link
Member Author

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

@excalios
Copy link

excalios commented Mar 4, 2022

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

@kristijanhusak
Copy link
Member Author

@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.

@excalios
Copy link

excalios commented Mar 8, 2022

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

@Tokubara
Copy link

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

@kristijanhusak
Copy link
Member Author

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

@Maltimore
Copy link
Contributor

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?

@jgollenz
Copy link
Contributor

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.

@Maltimore
Copy link
Contributor

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?

@jgollenz
Copy link
Contributor

jgollenz commented Jul 25, 2022

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

@mortezadadgar
Copy link

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?

@kristijanhusak
Copy link
Member Author

@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.

@mortezadadgar
Copy link

@kristijanhusak yes indeed it does work sorry for noise

@Maltimore
Copy link
Contributor

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.

@kristijanhusak
Copy link
Member Author

@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.

@Maltimore
Copy link
Contributor

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

@kristijanhusak
Copy link
Member Author

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

@Maltimore
Copy link
Contributor

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!

@kristijanhusak
Copy link
Member Author

kristijanhusak commented Feb 25, 2024

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

@kristijanhusak
Copy link
Member Author

@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.

@Maltimore
Copy link
Contributor

Maltimore commented Feb 25, 2024

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!! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

9 participants