Comments (6)
The latest versions of those functions have a :save-buffer
optional parameter that allows saving the buffer after renaming. They are still not closed automatically though. There are many situations in which Emacs is not deleting buffers automatically (Dired, Magit, Org agenda, etc.). I do not know if there is a good reason for that.
from denote.
That's good, but I'd rarely want to simply unconditionally save the buffer, because
- if I already have unsaved changes, they're unsaved for a reason, and
- all I said above about safety if the file was changed outside of Emacs.
So this only reduces my wrapper like this:
(defun fixed-denote-rewrite-front-matter
(denote-rewrite-front-matter path &rest arguments)
(let* ((buffers (buffer-list))
(buffer (find-file-noselect path))
(_ (refresh-modified-state buffer))
(had-unsaved-changes (buffer-modified-p buffer)))
- (apply denote-rewrite-front-matter path arguments)
+ (apply denote-rewrite-front-matter path :save-buffer (not had-unsaved-changes) arguments)
(unless had-unsaved-changes
- (with-current-buffer buffer
- (basic-save-buffer))
(unless (memq buffer buffers)
(kill-buffer buffer)))))
from denote.
Re:
There are many situations in which Emacs is not deleting buffers automatically (Dired, Magit, Org agenda, etc.). I do not know if there is a good reason for that.
I think there's several good reasons, most not applicable here (but it's not like I would be against a parameter to keep the buffers open unconditionally if someone wanted that):
-
Those things leave around buffers that you opened. They don't create and leave a bunch of persistent buffers that you never even saw. My wrapper above only automatically closes buffers if they weren't even open when you ran the rename - in other words, situations where you never even see the buffer open, because you just did the rename on the file under point in Dired or whatever.
-
Navigation. You can quickly find buffers you already opened.
-
I suspect this is part of why Dired does this: so you don't have to just navigate by Dired links and new calls to
dired
. -
This is why I advise the help functions in my config to make a new help buffer for each topic (when I run
describe-function
ondenote
, I get a help buffer called*Help (function: denote)*
and the main benefit is that I can then very quickly go to or search for any help page I've visited.
-
-
Persistence. You might have state you don't want to lose in the buffer, so you bury by default rather than killing.
-
Dired might have marks/etc. (Of course if this was the sole reason, they could kill by default and bury if there's marks.)
-
Magit might have some partially finished procedure. Similarly, my own Git interface has my quitting keys bound to quit-window without killing because if I still have a git command running in it, I don't want to kill it or lose it.
-
-
(historical reason) Efficiency. Creating buffers is cheap, but "expensive" relative to just reusing the buffer you already have. (Doesn't really matter with modern machines unless you're recreating buffers in a hot loop or something, but something like Dired hails from the 1970s/1980s when needlessly allocating a few thousand bytes, running an
ls
, and parsing+coloringls
output, all while the old almost identical buffer was being garbage collected, could actually be noticably expensive). -
Invariants. Complex stateful packages might benefit from the simplicity or guarantees of having the same buffer persist in the background.
-
Review. Sometimes you want to review what you did or what happened.
- In my Git interface, old commands are left in the buffer scrollback. So if you staged a hunk at some point, if you haven't yet killed the
git add -p
buffer for that repo or file, you can go back and find that you staged it, and when you did so. If a push had an error hours ago and you want to show it to someone, if you haven't killed the buffer that day you can go back in the git push buffer and see it again.
- In my Git interface, old commands are left in the buffer scrollback. So if you staged a hunk at some point, if you haven't yet killed the
There's probably other reasons, but I think that covers almost all of them. And I don't think any of that applies to buffers of files only opened automatically in the background to do the front matter part of the rename, if they're also automatically saved.
from denote.
Actually, you could just add a :kill-buffer
parameter!
Then I can simplify my wrapper down to
(let* ((buffer (find-buffer-visiting path))
(unsaved-changes (when buffer
(refresh-modified-state buffer)
(buffer-modified-p buffer))))
(denote-whatever
...
:save-buffer (not unsaved-changes)
:kill-buffer (not buffer)))
- Simpler for you, no coupling to my code to refresh buffer's modified state. I think I even like that orthogonality better.
- Still an improvement on my end too.
- Kinda sucks that other users don't benefit like I do though... but I guess
they should've thought about that before deciding to be someone other than memaybe we could toss a note in the docs about how to put these two pieces together.
from denote.
Closing now that we have the new user option denote-kill-buffers
by @jeanphilippegg.
from denote.
Nice! That code looks like it does exactly what I wanted/needed. Thank you @jeanphilippegg and @protesilaos !
from denote.
Related Issues (20)
- When ~denote-org-capture-specifiers~ don't include a format specificer for a link don't call ~org-get-id-create~ HOT 5
- Suggestion a denote-keyword-append function. HOT 12
- error with denote-files-matching-regexp-prompt HOT 5
- Nested silo interferes with `denote-directory-files` (was: "dblock enhancement add a silo target") HOT 10
- denote-rename-file-title ==> Destination file xxx already exists HOT 13
- Make default file permission configurable HOT 2
- How to make heading with custom_id properties searchable? HOT 3
- Backlinks buffer links not working with nested dirs HOT 1
- `denote-create-note` silently HOT 3
- "No links found" when using `denote-find-link` in denote files inside a silo HOT 10
- When exporting all my notes to Markdown, `denote:` links point to `.org` files HOT 7
- Cannot insert links in org indirect buffer HOT 3
- Only use ASCII in file names HOT 7
- A general way to exclude files matching regexp from dblocks and maybe more (was: Exclude keywords while using dblocks) HOT 2
- Lisp error: (void-function denote-link-buttonize-buffer) HOT 1
- Feature request : adding an option to list empty or non-empty notes with denote-sort-dired HOT 1
- denote-rename-file and real-auto-save HOT 5
- Dynamic block backlinks to this-heading-only doesn't work? HOT 4
- [Feature Request] Add indicator of current silo in the prompt when running denote commands HOT 4
- Prettification of links to Denote attachments HOT 3
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 denote.