-
-
Notifications
You must be signed in to change notification settings - Fork 171
Open
Labels
enhancementEnhancement, not necessarily available in emacsEnhancement, not necessarily available in emacs
Description
Does this feature exist in Emacs orgmode core?
Yes
Orgmode link
org-after-note-stored-hook and org-clock-out-hook are mentioned here.
Feature value
The user would be able hook into events like these for any arbitrary action they may take.
The use case in particular I'm thinking of is hooking into these events to talk to an external API like Jira.
Would be interested to hear any thoughts on this.
Additional context
Here is a PoC:
diff --git a/lua/orgmode/events/types/init.lua b/lua/orgmode/events/types/init.lua
index 73afa80..2558280 100644
--- a/lua/orgmode/events/types/init.lua
+++ b/lua/orgmode/events/types/init.lua
@@ -6,4 +6,5 @@ return {
HeadlinePromoted = require('orgmode.events.types.headline_promoted_event'),
HeadlineDemoted = require('orgmode.events.types.headline_demoted_event'),
HeadingToggled = require('orgmode.events.types.heading_toggled'),
+ NoteAdded = require('orgmode.events.types.note_added_event'),
}
diff --git a/lua/orgmode/events/types/note_added_event.lua b/lua/orgmode/events/types/note_added_event.lua
new file mode 100644
index 0000000..a9a7bee
--- /dev/null
+++ b/lua/orgmode/events/types/note_added_event.lua
@@ -0,0 +1,19 @@
+---@class OrgNoteAddedEvent: OrgEvent
+---@field type string
+---@field headline OrgHeadline
+---@field note string[]
+local NoteAddedEvent = {
+ type = 'orgmode.note_added',
+}
+
+---@param headline OrgHeadline
+---@param note string[]
+function NoteAddedEvent:new(headline, note)
+ local obj = setmetatable({}, self)
+ self.__index = self
+ obj.headline = headline
+ obj.note = note
+ return obj
+end
+
+return NoteAddedEvent
diff --git a/lua/orgmode/files/headline.lua b/lua/orgmode/files/headline.lua
index f494b14..9fe61e9 100644
--- a/lua/orgmode/files/headline.lua
+++ b/lua/orgmode/files/headline.lua
@@ -8,6 +8,8 @@ local indent = require('orgmode.org.indent')
local Logbook = require('orgmode.files.elements.logbook')
local OrgId = require('orgmode.org.id')
local Memoize = require('orgmode.utils.memoize')
+local EventManager = require('orgmode.events')
+local events = EventManager.event
---@alias OrgPlanDateTypes 'DEADLINE' | 'SCHEDULED' | 'CLOSED'
@@ -527,6 +529,7 @@ function Headline:add_note(note)
append_line = self:get_append_line()
end
vim.api.nvim_buf_set_lines(self.file:get_valid_bufnr(), append_line, append_line, false, note)
+ EventManager.dispatch(events.NoteAdded:new(self, note))
return self:refresh()
end
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementEnhancement, not necessarily available in emacsEnhancement, not necessarily available in emacs