Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC auto-save of WIP/drafts #58

Open
sten0 opened this issue Jan 25, 2021 · 1 comment
Open

RFC auto-save of WIP/drafts #58

sten0 opened this issue Jan 25, 2021 · 1 comment

Comments

@sten0
Copy link

sten0 commented Jan 25, 2021

  1. Instead of keeping the buffer entirely in memory and exclusively pushing it into the websocket, allow normal Emacs auto-save to function correctly.
  2. 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.
  3. 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 "__"?
  4. 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.
  5. 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?

@mikedmcfarland
Copy link

mikedmcfarland commented Jul 22, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants