Comments (13)
If you for example mark another element of the agenda as done or as archived, the actions are going to be done on the wrong item
This should not happen unless the change to the agenda item adds some content to it's subtree. For example if you have a headline with a deadline that repeats, each time you mark it as done it adds entry to the logbook, and shifts all headlines below. This caused wrong item to be updated in the agenda.
I solved that in 1425b36, so now agenda will automatically reload if there is a need for it.
It will not reload if you archive a headline by adding ARCHIVE tag, or marking a nonrepeater task as done, but that should not cause any issues with the wrong item being updated. The idea is to be able to undo these changes easily in the agenda in case you made a mistake.
I also just pushed 66591ca that should allow reloading agenda window remotely.
So to achieve what you want here you can add this to your configuration:
vim.api.nvim_create_autocmd('BufWritePost', {
pattern = '*.org',
callback = function()
local bufnr = vim.fn.bufnr('orgagenda') or -1
if bufnr > -1 then
require('orgmode').agenda:redo()
end
end
})
This will reload agenda window if it's open each time you write any org file.
I think this should solve both this issue and #596. @Maltimore can yo check?
from orgmode.
It works beautifully @kristijanhusak thank you so much as always, you don't know how happy you make me xD.
I'm fine closing the issue as is, but just one more question. The autocmd works only if I save the file where I archived the element. But there are cases where I just archive an element without saving so the agenda is not refreshed. To solve this I'm thinking of two solutions:
- That nvim-orgmode has this functionality
- To create a keybinding that saves the file when archiving an element. I suppose this solution is the cleanest for this (I guess) corner case. I have no idea though on how to do this. I'll search online the code to save a file from a lua function, but can you help me with the archiving lua code for the function? Only if it's trivial for you and don't have to search in the code (I can do that myself)
Thanks as always <3
from orgmode.
Hi both of you,
I have tested the new code and can confirm that the issue described here is fixed, thanks @kristijanhusak!
There's still one case that doesn't work though, and that is simply if I have the agenda open in one nvim
instance, and in another nvim
instance I change a .org
file. I do this quite frequently to be honest. I wonder, now that we have the require('orgmode').agenda:redo()
function, could we have a loop that just refreshes the agenda every x minutes (with x configurable)?
from orgmode.
@Maltimore you can probably do that with timers :h vim.loop
, but i haven't tested.
from orgmode.
Yes, that sounds quite straightforward, thanks!
from orgmode.
@Maltimore If you finally go in the vim.loop
direction could you please post here the solution? It's also the last feature I'm missing on this issue
from orgmode.
Will do! :)
from orgmode.
@lyz-code This should do the trick:
local timer = vim.loop.new_timer()
timer:start(
0,
10000,
vim.schedule_wrap(function()
local bufnr = vim.fn.bufnr('orgagenda') or -1
if bufnr > -1 then
require('orgmode').agenda:redo()
end
end)
)
This will reload the agenda if it's opened every 10 sec.
Note that you need to pull latest master. I found some bugs around reloading that I fixed in the meantime.
from orgmode.
Damn @kristijanhusak each morning a new gift (âĨīšâĨ)
. It works like a charm.
For those of you that doubt where to put that snippet, I've added it to a FileType
autocommand
vim.api.nvim_create_autocmd("FileType", {
pattern = "org",
group = vim.api.nvim_create_augroup("orgmode", { clear = true }),
callback = function()
-- Reload the agenda each second if its opened so that unsaved changes
-- in the files are shown
local timer = vim.loop.new_timer()
timer:start(
0,
10000,
vim.schedule_wrap(function()
local bufnr = vim.fn.bufnr("orgagenda") or -1
if bufnr > -1 then
require("orgmode").agenda:redo(true)
end
end)
)
end,
})
from orgmode.
I've detected a little bug when using the timer. Each time the agenda reloads the cursor is moved to the top of the day. Imagine that we have this agenda:
Tuesday 05 March 2024
inbox: 18:00...... Do X
inbox: 19:30...... Do Y <-- cursor is here
When the agenda is reloaded, the cursor is moved to the top of the day
Tuesday 05 March 2024 <-- cursor is moved here
inbox: 18:00...... Do X
inbox: 19:30...... Do Y
10 seconds was too much for me, so I set the agenda reload each second. If I have 10 elements in a day agenda I don't have time to reach the bottom before I'm moved back up xD.
Would it be possible to remember the position where the cursor was so that it's stable after the agenda refresh?
I don't know if that is one of the fixes you made. I'm at 779a568
.
from orgmode.
@lyz-code Just note that your example will work only after some org
file was opened.
Regarding the cursor position, try passing true
to redo
, that should keep the cursor position.
from orgmode.
I feel that's fine because if no org file is opened then there is no need to reload the agenda as there will be no changes. I guess the other place to add the snippet is in the setup
of the plugin.
Setting true
to redo
fixes it indeed ^^
from orgmode.
Another solution to avoid using the timer is to use the auto-save plugin I found it really elegant
from orgmode.
Related Issues (20)
- Actions on text objects are not performed if the cursor is positioned before the text object HOT 2
- "Add new headline" moves cursor one line too much HOT 2
- Make refile heading finder case insensitive
- Clipboard expansion fails when URL encoding is contained HOT 1
- [plugin] org-roam.nvim progress & discussion HOT 158
- Add a note to the entry (org-agenda-add-note)
- Date/Time prompts in Capture Templates HOT 1
- Loading org file causes expected string, got table error HOT 5
- Orgmode mappings for increment/decrement date part under cursor are inverted HOT 2
- Huge performance drop after tree-sitter drop HOT 9
- Keep empty line between folded headlines
- No agenda entries found HOT 6
- Orgmode as filetype plugin throws error HOT 9
- Add support for citations
- Application of colorscheme breaks todo keyword highlighting HOT 3
- uuidgen does not exist on Windows HOT 2
- Windwos path with Colon (:) (ex: E:\repoes\README.md) can't open
- Error (freezes nvim) when opening file with code block name in different case (e.g. "Python", "JSON", "R"): `no such language: R` HOT 1
- Context is lost when archiving headline with level >1 HOT 2
- Make Virtual Indentation (indent mode) support `set wrap` HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
đ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. đđđ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google â¤ī¸ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from orgmode.