RFC auto-save of WIP/drafts
- Instead of keeping the buffer entirely in memory and exclusively pushing it into the websocket, allow normal Emacs auto-save to function correctly.
- The big question is "where should these files go"? This can be set in buffer-auto-save-file-name.
- I'm guessing ~/.emacs.d/atomic-chrome/buffer-name/foo would be reasonable.
- Are there any multiplatform considerations? IIRC Windows file systems support a much-restricted character set for file names. Is there already a library that will do character substitutions? For example, replacing colons ":" with double underscores "__"?
- Whenever the user manually saves, using C-x s or C-x C-s, the buffer should be saved to disk [edit: in addition to the existing behaviour of being pushed into the websocket]. This is analogous to saving a draft.
- A nice to have extension to this behaviour would be to ask the browser for the URL of the page that is being edited, and save this such that it won't appear in the text-area edited of the form that is being edited in the browser, nor in the buffer that is being edited in atomic-chrome. I imagine that injecting a file-local variable will do the trick.
- Are there any pitfalls involving buffer-revert or recover-session?
- Is there a future follow-up issue for an enhanced recover-session for atomic-chrome?
Did I miss anything?
Just putting this here for anyone hacking at this, I was able to accomplish this in my configs.
You have to stop atomic chrome from setting buffer-modified-p to nil, Otherwise even if you give the buffer a name, and have it visit a file with set-visited-file-name the buffers aren't saved normally. Emacs will continuously think there are no modifications, which makes sense, since the changes were sent to chrome.
It does this in in atomic-chrome-send-buffer-text. So lets grab that buffer-modified-p before the call, and reset it after.
(advice-add 'atomic-chrome-send-buffer-text :around (lambda (orig-fun &rest args)
(let ((flag (buffer-modified-p)))
(apply orig-fun args)
(set-buffer-modified-p flag)
)
))
)
After you do this if you try to save the buffer you'll be prompted for a filename. I like this personally because then I can choose the project location and file extention at that point. Keep in mind atomic chrome binds some keys, so you may have to deal with that if they collide with yours
(define-key map (kbd "C-c C-s") 'atomic-chrome-send-buffer-text)
(define-key map (kbd "C-c C-c") 'atomic-chrome-close-current-buffer)
My atomic chrome is configured to auto update, so for quick edits I just don't "save", and it works all the same (besides, my modeline reporting modifications). For something more I save the file and choose where and what extenstion.
There might be a better way to achieve this but it works great for me, I feel like this should be the default (or at least configurable)
If you really want to have a configured directory where your files go, you'd just have to set the visited file name yourself, maybe replacing chars or whatever. atomic-chrome-edit-mode-hook would work.
(let
((name (s-replace-all '((" " . "_") ("(" . "") (")" . "") ("<" . "") (">" . "")) (buffer-name))))
(set-visited-file-name (f-join "~/some/directory" name))
)
however I'd rather just be prompted