emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: suggestion: reverting/notifying of files that no longer exist


From: Juri Linkov
Subject: Re: suggestion: reverting/notifying of files that no longer exist
Date: Mon, 12 Jul 2004 19:18:33 +0300
User-agent: Gnus/5.110002 (No Gnus v0.2) Emacs/21.3.50 (gnu/linux)

Karl Chen <address@hidden> writes:
> I think Emacs (maybe as part of auto-revert-mode) should notify
> you when you edit files that no longer exist.  Sometimes I rename
> or move a file in shell, but still have the old file open and
> accidentally edit buffer for the old file.
>
> It would be very useful if Emacs tells you when a file that used
> to exist vanishes:
>     (1) when you edit its buffer
>     (2) if (global-)auto-revert-mode or some customizable variable
>         is enabled, as soon as the file vanishes

This is the kind of situation Emacs should warn the user about.
It's no fun having an unintentionally forked version which needs
to be merged later with the original version when the fact of forking
is discovered by the user.

One place where the warning could be added is `basic-save-buffer'.  It
could ask if the user tries to save the buffer which was at least once
saved to the file and was renamed or moved afterwards.  The complete
condition to check this situation is:

(and (not (verify-visited-file-modtime (current-buffer)))
     (not (file-exists-p buffer-file-name))
     (> buffer-saved-size 0))

It works in all cases with the exception of the case when a
0-sized file is moved or renamed.  However, this case is not
noteworthy.

Index: lisp/files.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/files.el,v
retrieving revision 1.707
diff -c -r1.707 files.el
*** lisp/files.el       26 Jun 2004 14:41:13 -0000      1.707
--- lisp/files.el       12 Jul 2004 14:05:51 -0000
***************
*** 3082,3090 ****
                (set-visited-file-name filename)))
          (or (verify-visited-file-modtime (current-buffer))
!             (not (file-exists-p buffer-file-name))
              (yes-or-no-p
!              (format "%s has changed since visited or saved.  Save anyway? "
!                      (file-name-nondirectory buffer-file-name)))
              (error "Save not confirmed"))
          (save-restriction
            (widen)
--- 3082,3093 ----
                (set-visited-file-name filename)))
          (or (verify-visited-file-modtime (current-buffer))
!             (not (or (file-exists-p buffer-file-name)
!                      (> buffer-saved-size 0)))
              (yes-or-no-p
!              (format "%s was %s since visited or saved.  Save anyway? "
!                      (file-name-nondirectory buffer-file-name)
!                      (if (file-exists-p buffer-file-name)
!                          "changed" "renamed or deleted")))
              (error "Save not confirmed"))
          (save-restriction
            (widen)

-- 
Juri Linkov
http://www.jurta.org/emacs/





reply via email to

[Prev in Thread] Current Thread [Next in Thread]