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

fix: run Org init as part of setup #664

Merged
merged 1 commit into from
Feb 14, 2024

Conversation

PriceHiller
Copy link
Contributor

@PriceHiller PriceHiller commented Feb 14, 2024

Copied from the commit message:

This ensures that notifications do not error on startup. Prior to this commit the OrgFiles object wasn't loaded in time for notifications to work.

Currently Orgmode throws an error on startup on the nightly branch when notifications are enabled because the Org instance isn't ready in time for when the notifications are actually initialized.

This was the simplest way I saw to ensure the notifications have files available on the Org instance at startup.

Perhaps it would be better to move the notifications setup into the Org:init function and make the config object available across that module after setup? I didn't undertake that move as I'm not 100% sure as to the nuances involved with setting up the notifications and why they're setup where they are.

Here's a patch I can apply for moving the notifications setup:
diff --git a/lua/orgmode/init.lua b/lua/orgmode/init.lua
index 2f13e8e..f04ce6c 100644
--- a/lua/orgmode/init.lua
+++ b/lua/orgmode/init.lua
@@ -13,6 +13,8 @@ local auto_instance_keys = {
   notifications = true,
 }
 
+local config = require('orgmode.config')
+
 ---@class Org
 ---@field initialized boolean
 ---@field files OrgFiles
@@ -60,6 +62,15 @@ function Org:init()
   self.clock = require('orgmode.clock'):new({
     files = self.files,
   })
+  if config.notifications.enabled and #vim.api.nvim_list_uis() > 0 then
+    Org.files:load():next(vim.schedule_wrap(function()
+      instance.notifications = require('orgmode.notifications')
+        :new({
+          files = Org.files,
+        })
+        :start_timer()
+    end))
+  end
   require('orgmode.org.autocompletion').register()
   self.statusline_debounced = require('orgmode.utils').debounce('statusline', self.clock.get_statusline, 300)
   self.initialized = true
@@ -134,20 +145,10 @@ end
 function Org.setup(opts)
   opts = opts or {}
   Org._check_ts_grammar()
-  local config = require('orgmode.config'):extend(opts)
+  config:extend(opts)
   instance = Org:new()
   config:setup_ts_predicates()
   vim.defer_fn(function()
-    if config.notifications.enabled and #vim.api.nvim_list_uis() > 0 then
-      Org:init()
-      Org.files:load():next(vim.schedule_wrap(function()
-        instance.notifications = require('orgmode.notifications')
-          :new({
-            files = Org.files,
-          })
-          :start_timer()
-      end))
-    end
     config:setup_mappings('global')
   end, 1)
   return instance

@PriceHiller PriceHiller marked this pull request as draft February 14, 2024 18:50
@PriceHiller PriceHiller marked this pull request as ready for review February 14, 2024 18:54
@kristijanhusak
Copy link
Member

This ensures that notifications do not error on startup. Prior to this
commit the `OrgFiles` object wasn't loaded in time for notifications to
work.
@PriceHiller
Copy link
Contributor Author

We can call use Org.instance() as we do for cron here https://github.com/nvim-orgmode/orgmode/pull/664/files#diff-83b45fa03268fbaf07c250824cf10ba2471882c14bdb7ad6e3d36355cdbd906cR210

Yes. Done on the latest force push.

@kristijanhusak kristijanhusak merged commit cb16c03 into nvim-orgmode:nightly Feb 14, 2024
2 checks passed
@PriceHiller PriceHiller deleted the org-init-on-setup branch February 14, 2024 19:49
kristijanhusak added a commit that referenced this pull request Feb 14, 2024
* refactor!: Rewrite file management to use tree-sitter

* feat!: Deprecate org_mappings.handle_return in favor of org_mappings.meta_return

If you did not use this mapping directly everything is ok. This is just for users that mapped it directly

* feat: Add org_return_uses_meta_return option

* fix: Allow modifications of plan date range end date

* fix: Properly show plan date ranges in agenda

* feat(api): Add get_closest_headline and refile to api

* fix: Update minimal init to work with Windows

* tests: Add tests for file and fix edge case with set text

* fix(cron): Instantiate orgmode before running cron

* refactor: Stars highlighter

* refactor: Todo faces highlighter

* refactor: Markup highlighter

* fix: Do not rely on node:has_changes()

* feat: make VirtualIndent dynamically attach/detach based on `vim.b.org_indent_mode` (#658)

* feat: make VirtualIndent react to changes in `vim.b.org_indent_mode`

* test: add test to validate VirtualIndent dynamic attach functionality

* docs: update docs to reflect dynamic virtual indent attach

* refactor: make VirtualIndent `start_watch_org_indent` idempotent

This ensures we can call `start_watch_org_indent` as much as we want
without starting a bunch of timers in the background.

This enforces the use of `start_watch_org_indent` and `stop_watch_org_indent` for managing the timer.

* feat: add dict_watcher utility

* refactor: use `dict_watcher` to monitor `vim.b.org_indent_mode`

* ci: Run tests when creating PR to nightly

* chore: Reformat files

* refactor: remove sync call to set indent for virtual indents (#663)

On the current version of nightly (at the time of writing this is NVIM
v0.10.0-dev-2361+ga376d979b) the synchronous call doesn't seem to have
any value.

Using only a scheduled call is seemingly smooth now -- perhaps when I
made the original commit I had something wrong with my configuration or
perhaps upstream Neovim fixed whatever was causing some choppiness?

Another note is that `on_lines` in `nvim_buf_attach` can have `textlock`
restrictions and more applied, thus we really should just use
`vim.schedule` only anyhow.

* feat: add `org-indent-mode-turns-on-hiding-stars` equivalent (#659)

* feat: add equivalent of `org-indent-mode-turns-on-hiding-stars`

* docs: add documentation for `org_indent_mode_turns_on_hiding_stars`

* docs: add reference to `org_indent_mode`  for hiding stars

Co-authored-by: Kristijan Husak <husakkristijan@gmail.com>

* fix: ensure hl group for hiding stars is applied

See
#659 (review)

Co-authored-by: Kristijan Husak <husakkristijan@gmail.com>

---------

Co-authored-by: Kristijan Husak <husakkristijan@gmail.com>

* fix: Hide leading stars on foldtext

* ci: Run tests only on nightly

* fix: run Org init as part of setup (#664)

This ensures that notifications do not error on startup. Prior to this
commit the `OrgFiles` object wasn't loaded in time for notifications to
work.

* fix: Statusline function for clock

* ci: Remove nightly branch from CI triggers

---------

Co-authored-by: Price Hiller <price@orion-technologies.io>
SlayerOfTheBad pushed a commit to SlayerOfTheBad/orgmode that referenced this pull request Aug 16, 2024
* refactor!: Rewrite file management to use tree-sitter

* feat!: Deprecate org_mappings.handle_return in favor of org_mappings.meta_return

If you did not use this mapping directly everything is ok. This is just for users that mapped it directly

* feat: Add org_return_uses_meta_return option

* fix: Allow modifications of plan date range end date

* fix: Properly show plan date ranges in agenda

* feat(api): Add get_closest_headline and refile to api

* fix: Update minimal init to work with Windows

* tests: Add tests for file and fix edge case with set text

* fix(cron): Instantiate orgmode before running cron

* refactor: Stars highlighter

* refactor: Todo faces highlighter

* refactor: Markup highlighter

* fix: Do not rely on node:has_changes()

* feat: make VirtualIndent dynamically attach/detach based on `vim.b.org_indent_mode` (nvim-orgmode#658)

* feat: make VirtualIndent react to changes in `vim.b.org_indent_mode`

* test: add test to validate VirtualIndent dynamic attach functionality

* docs: update docs to reflect dynamic virtual indent attach

* refactor: make VirtualIndent `start_watch_org_indent` idempotent

This ensures we can call `start_watch_org_indent` as much as we want
without starting a bunch of timers in the background.

This enforces the use of `start_watch_org_indent` and `stop_watch_org_indent` for managing the timer.

* feat: add dict_watcher utility

* refactor: use `dict_watcher` to monitor `vim.b.org_indent_mode`

* ci: Run tests when creating PR to nightly

* chore: Reformat files

* refactor: remove sync call to set indent for virtual indents (nvim-orgmode#663)

On the current version of nightly (at the time of writing this is NVIM
v0.10.0-dev-2361+ga376d979b) the synchronous call doesn't seem to have
any value.

Using only a scheduled call is seemingly smooth now -- perhaps when I
made the original commit I had something wrong with my configuration or
perhaps upstream Neovim fixed whatever was causing some choppiness?

Another note is that `on_lines` in `nvim_buf_attach` can have `textlock`
restrictions and more applied, thus we really should just use
`vim.schedule` only anyhow.

* feat: add `org-indent-mode-turns-on-hiding-stars` equivalent (nvim-orgmode#659)

* feat: add equivalent of `org-indent-mode-turns-on-hiding-stars`

* docs: add documentation for `org_indent_mode_turns_on_hiding_stars`

* docs: add reference to `org_indent_mode`  for hiding stars

Co-authored-by: Kristijan Husak <husakkristijan@gmail.com>

* fix: ensure hl group for hiding stars is applied

See
nvim-orgmode#659 (review)

Co-authored-by: Kristijan Husak <husakkristijan@gmail.com>

---------

Co-authored-by: Kristijan Husak <husakkristijan@gmail.com>

* fix: Hide leading stars on foldtext

* ci: Run tests only on nightly

* fix: run Org init as part of setup (nvim-orgmode#664)

This ensures that notifications do not error on startup. Prior to this
commit the `OrgFiles` object wasn't loaded in time for notifications to
work.

* fix: Statusline function for clock

* ci: Remove nightly branch from CI triggers

---------

Co-authored-by: Price Hiller <price@orion-technologies.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants