Skip to content

Commit 0f50e89

Browse files
authored
feat: Add ability to clear notification history (#248)
1 parent fcb7cc6 commit 0f50e89

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,18 @@ You can get a list of past notifications with the history function
165165
require("notify").history()
166166
```
167167

168+
There is another command to clear the history.
169+
170+
```vim
171+
:NotificationsClear
172+
```
173+
174+
You can clear the notifications with the clear history function
175+
176+
```lua
177+
require("notify").clear_history()
178+
```
179+
168180
## Configuration
169181

170182
### Setup

lua/notify/init.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ function notify.setup(user_config)
2323
require("telescope").load_extension("notify")
2424
end
2525
vim.cmd([[command! Notifications :lua require("notify")._print_history()<CR>]])
26+
vim.cmd([[command! NotificationsClear :lua require("notify").clear_history()<CR>]])
2627
end
2728

2829
function notify._config()
@@ -110,6 +111,16 @@ end
110111
---@class notify.HistoryOpts
111112
---@field include_hidden boolean Include notifications hidden from history
112113

114+
--- Clear records of all previous notifications
115+
---
116+
--- You can use the `:NotificationsClear` command to clear the log of previous notifications
117+
function notify.clear_history()
118+
if not global_instance then
119+
notify.setup()
120+
end
121+
return global_instance.clear_history()
122+
end
123+
113124
--- Dismiss all notification windows currently displayed
114125
---@param opts notify.DismissOpts
115126
function notify.dismiss(opts)

lua/notify/instance.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,10 @@ return function(user_config, inherit, global_config)
209209
return service and service:pending() or {}
210210
end
211211

212+
function instance.clear_history()
213+
notifications = {}
214+
end
215+
212216
setmetatable(instance, {
213217
__call = function(_, m, l, o)
214218
if vim.in_fast_event() then

0 commit comments

Comments
 (0)