Repository navigation
feat(capture): Finalize on :w and show the destination - #1197
Conversation
|
How does "kill" behave in this scenario? Even after writing the file, you should be able to kill (cancel) the capture. |
|
That is actually the question. My intuition is: |
53441bf to
b22030d
Compare
|
Isn't org-roam creating a capture buffer with a path to a proper, non-temporary file? nvim-orgmode capture creates a temp file, so when the capture is finished, headline is refiled from the temp file to a destination. |
|
I'm working on a solution that is closer to what Emacs does. The biggest difference here is that Neovim cannot maintain (narrowed) views of the same buffer (where the write actually goes to the buffer). |
|
Sounds good to me, as long as it is only used for org-roam stuff. Plain nvim-orgmode capture should stay as it is, because it uses temp files. |
b22030d to
2699ad1
Compare
|
I reworked the branch into two commits. The second one implements what I described above, but only for The first commit only changes Escape on the |
f53d153 to
2699ad1
Compare
Closing a capture with unsaved changes asks whether to refile it. Escape counted as No and discarded the capture, so dismissing the prompt lost the text. Escape now reopens the capture with its content, since an autocmd cannot stop the buffer from being wiped. While Neovim exits, Escape refiles instead. Only an explicit No still discards. The prompt now comes before the refile target is resolved, so dismissing it does not run on_pre_refile or create the target. AI-assisted: Claude Code
:w in a capture buffer wrote a temp file nobody reads. For a whole_file template into a new file, which is how org-roam creates nodes, :w should create the file and keep the capture open, as C-x C-s does in Emacs. Such a capture now edits the target file's own buffer. Finishing hands the buffer over as a normal one. Kill removes the text and, when the file exists on disk, asks "Delete file for aborted capture?" like org-roam. On No the buffer stays loaded, so undo brings the text back. on_pre_refile runs when the capture opens, since only the hook knows the final path. Captures into existing files and all other templates keep the temp buffer. AI-assisted: Claude Code
2699ad1 to
2b8ae96
Compare
Today
:win a capture buffer writes a temporary file that nothing reads. Only the finalize mapping refiles the capture, and it also closes the window.With this change,
:wrefiles the capture and opens the destination in the same window, with the cursor where it was.:wqrefiles and closes the window. The finalize mapping works as before. For org-roam this means:wcreates the new node and leaves you in it, without a prompt since #1196.refile()takes a newdispositionoption:'close'(default, used by the mapping) or'show'(used by:w).Three details that are not obvious from the diff:
BufWriteCmdisnested. The refile adds the destination withbufadd, and the buffer cache drops its cached miss only onBufAdd, which a non-nested autocmd suppresses. Without it the write fails with an invalid buffer id.show()detaches the capture window's autocmds before swapping the buffer. The capture buffer isbufhidden=wipe, and itsBufWipeouthandler would start the refile again.show()runsfiletype detect, becausebufloadskips detection and:editreuses the loaded buffer.