atomic-chrome icon indicating copy to clipboard operation
atomic-chrome copied to clipboard

Allow recovering from when remote editing session closed unexpectedly (e.g. by backups or saving a history)

Open meliache opened this issue 1 year ago • 2 comments

So it happened a couple of times that my Firefox tab with some text input was accidentally closed and I was surprised that the associated atomic-chrome buffer closed as well. There was no backup as it's not a file-visiting buffer.

Is there a way so set up temporary backups or at least save a history? Today I added a history-saving function myself to atomic-chrome-edit-done-hook and with a defcustom this could be made opt in:

  (defvar atomic-chrome-history-dir
	(file-name-concat no-littering-var-directory "atomic-chrome" "history")
	"Directory where to save atomic chrome buffer contents.")

  (defun my-atomic-chrome-save-to-file ()
	"Save atomic chrome buffer contents to file."
	(let* ((timestamp (format-time-string "%F_%T"))
		   (escaped-buffer-name (file-name-base (make-auto-save-file-name)))
		   (atomic-chrome-save-file-name
			(file-name-concat atomic-chrome-history-dir
							  (format "%s_%s" escaped-buffer-name timestamp))))
	  (make-directory atomic-chrome-history-dir 'parents)
	  (write-region nil nil atomic-chrome-save-file-name nil nil nil 'mustbenew)
	  (message "Wrote backup to %s" atomic-chrome-save-file-name)))

  (add-hook 'atomic-chrome-edit-done-hook #'my-atomic-chrome-save-to-file)

It's not a backup as nothing is saved during editing. For that it would be nice somehow utilize Emacs' built-in backup/auto-save functions, but for most of my use-cases that's good enough.

meliache avatar Nov 24 '23 17:11 meliache

For the history-saving solution, another way compared to the approach above would be to save it in a list or alist and then add this list to desktop-locals-to-save, so that it persists across sessions if the uses uses desktop-save-mode.

meliache avatar Nov 24 '23 18:11 meliache

You might be interested in my branch where I implemented a temporary file association with the atomic buffer. The file can be retained on exit by a variable. https://github.com/eev2/atomic-chrome/blob/file-assoc/atomic-chrome.el

eev2 avatar Feb 04 '24 10:02 eev2