I sometimes would like to make changes to my emacs files but without changing the date of the modified file. For instance, I would like to write up a brief evaluation of a lecture I might have given. Ideally, I would not like to change the file's date under these circumstances. Is there any way to do this? I run emacs on Windows 7. I have noted too that changing a file's name also changes its date. It would be nice to change the name but without effecting the date.

  • Are you talking about the date you see in Windows Explorer? It's not possible to change the contents of a file and not have its modified date updated. Also, renaming a file should not change the date. How are you renaming the file?
    – nanny
    Jun 29 '15 at 14:23
  • You are right. I am not sure why I drew that inference about renaming.
    – rari
    Jun 29 '15 at 14:42

I don't think you can avoid changing the timestamp when saving, but you could write a function that resets it back to the original pre-save timestamp:

(defun save-buffer-preserving-modtime ()
  "Call `save-buffer', but keep the visited file's modtime the same."
  (let ((original-time (visited-file-modtime)))
    (set-file-times buffer-file-name original-time)
    (set-visited-file-modtime original-time)))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.