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

write-as or "clone file" #62

Open
anarcat opened this Issue Sep 28, 2018 · 0 comments

Comments

Projects
None yet
1 participant
@anarcat

anarcat commented Sep 28, 2018

One thing I'm frequently fighting with in Emacs (because it allows me to do crazy things like that) is how to synchronize file copies sent through TRAMP and local copies.

As a concrete example, I was doing a small hotfix on a Python library today, in /usr/lib/python3/dist-pacakges/npm2deb/mapper.py. The git source is in ~/src/npm2deb/npm2deb/mapper.py so I naturally started writing there. But then to test my changes, instead of rebuilding and reinstalling the whole thing, I cheat and write directly to the system lib with TRAMP (/:sudo:/usr/lib/python3/dist-pacakges/npm2deb/mapper.py or whatever that magic sauce is). Then I can tweak things there ("we'll do it live!") but what often happens is I forget to sync the file back into ~/src.

If there was a quick way to write a copy of the file without changing the buffer association, this would be much easier and intuitive. This SO thread has a few implementations, for example:

(defun my-clone-and-open-file (filename)
  "Clone the current buffer writing it into FILENAME and open it"
  (interactive "FClone to file: ")
  (save-restriction
    (widen)
    (write-region (point-min) (point-max) filename nil nil nil 'confirm))
  (find-file filename))

I would personally prefer that approach of keeping the other buffer in the background:

(defun crux-clone-file (filename)
  "Clone the current buffer writing it into FILENAME and open it in another buffer"
  (interactive "FClone to file: ")
  (save-restriction
    (widen)
    (write-region (point-min) (point-max) filename nil nil nil 'confirm))
  (find-file-no-select filename))

Obviously, for my use case, this would need to be added in a after-save-hook.

Would that make sense? would this be accepted as a PR?

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment