🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.emacs.bug
Article #100001

Superseding a deleted file

#100001
From: Dale Worley
Date: Tue, 20 Feb 1990 19:07
149 lines
6015 bytes
A while back I noted that I wanted Emacs to warn when a deleted file
was superseded.  Someone responded that this wasn't what *he* wanted.
However, in our environment, this is very desirable.  (I won't go into
the details.)  So I added code to Emacs (18.53) to make this a
user-selectable option controlled by the variable
'warn-if-superseding-deleted-file'.  I have been running this code
(except for a misspelling of 'supersede') for a while and it seems to
work fine.  You might want to consider it for inclusion into future
versions of Emacs.

As a point of design, you might note that the test "are we superseding
the file in this buffer?" is coded in three places -- filelock.c,
insdel.c, and files.el.  You might want to consolidate these in some
way.

Thanks,

Dale Worley		Compass, Inc.			worley@compass.com
--
Vietnam was only a police action so why do we have a War on Drugs?!?
-- P.B. Horton
----------------------------------------------------------------------
*** emacs.c.orig	Wed Feb  7 12:41:48 1990
--- emacs.c	Wed Feb  7 12:46:15 1990
***************
*** 402,407 ****
--- 402,408 ----
        syms_of_filelock ();
  #endif /* CLASH_DETECTION */
        syms_of_indent ();
+       syms_of_insdel ();
        syms_of_keyboard ();
        syms_of_keymap ();
        syms_of_macros ();
*** filelock.c.orig	Wed Feb  7 12:41:56 1990
--- filelock.c	Mon Feb 12 10:34:35 1990
***************
*** 35,40 ****
--- 35,46 ----
  
  #ifdef CLASH_DETECTION
    
+ /* Nonzero means warn if user tries to supersede a buffer visiting a file
+    that has been deleted.
+    Defined in insdel.c */
+ 
+ extern int warn_if_superseding_deleted_file;
+ 
  /* If system does not have symbolic links, it does not have lstat.
     In that case, use ordinary stat instead.  */
  
***************
*** 92,98 ****
      register Lisp_Object subject_buf = Fget_file_buffer (fn);
      if (!NULL (subject_buf)
  	&& NULL (Fverify_visited_file_modtime (subject_buf))
! 	&& !NULL (Ffile_exists_p (fn)))
        call1 (intern ("ask-user-about-supersession-threat"), fn);
    }
  
--- 98,105 ----
      register Lisp_Object subject_buf = Fget_file_buffer (fn);
      if (!NULL (subject_buf)
  	&& NULL (Fverify_visited_file_modtime (subject_buf))
! 	&& (warn_if_superseding_deleted_file ||
! 	    !NULL (Ffile_exists_p (fn))))
        call1 (intern ("ask-user-about-supersession-threat"), fn);
    }
  
*** insdel.c.orig	Wed Feb  7 12:42:05 1990
--- insdel.c	Mon Feb 12 10:33:34 1990
***************
*** 24,29 ****
--- 24,34 ----
  #include "buffer.h"
  #include "window.h"
  
+ /* Nonzero means warn if user tries to supersede a buffer visiting a file
+    that has been deleted. */
+ 
+ int warn_if_superseding_deleted_file;
+ 
  /* Move gap to position `pos'.
     Note that this can quit!  */
  
***************
*** 366,373 ****
    if (!NULL (bf_cur->filename)
        && bf_cur->save_modified >= bf_modified
        && NULL (Fverify_visited_file_modtime (Fcurrent_buffer ()))
!       && !NULL (Ffile_exists_p (bf_cur->filename)))
      call1 (intern ("ask-user-about-supersession-threat"),
  	   bf_cur->filename);
  #endif /* not CLASH_DETECTION */
  }
--- 371,389 ----
    if (!NULL (bf_cur->filename)
        && bf_cur->save_modified >= bf_modified
        && NULL (Fverify_visited_file_modtime (Fcurrent_buffer ()))
!       && (warn_if_superseding_deleted_file ||
! 	  !NULL (Ffile_exists_p (bf_cur->filename))))
      call1 (intern ("ask-user-about-supersession-threat"),
  	   bf_cur->filename);
  #endif /* not CLASH_DETECTION */
+ }
+ 
+ syms_of_insdel ()
+ {
+   DEFVAR_BOOL ("warn-if-superseding-deleted-file", 
+ 	       &warn_if_superseding_deleted_file,
+     "*Non-nil means to query the user if he attempts to modify a buffer\n\
+ visiting a file that has been deleted since it was visited.\n\
+ The query is done via  ask-user-about-supersession-threat .");
+   warn_if_superseding_deleted_file = 0;
  }
*** files.el.orig	Wed Feb 14 11:12:31 1990
--- files.el	Wed Feb 14 11:32:49 1990
***************
*** 679,685 ****
  	      (error
     "Attempt to save to a file which you aren't allowed to write")))
  	(or (verify-visited-file-modtime (current-buffer))
! 	    (not (file-exists-p buffer-file-name))
  	    (yes-or-no-p
  	      "Disk file has changed since visited or saved.  Save anyway? ")
  	    (error "Save not confirmed"))
--- 679,686 ----
  	      (error
     "Attempt to save to a file which you aren't allowed to write")))
  	(or (verify-visited-file-modtime (current-buffer))
! 	    (and (not warn-if-superseding-deleted-file)
! 		 (not (file-exists-p buffer-file-name)))
  	    (yes-or-no-p
  	      "Disk file has changed since visited or saved.  Save anyway? ")
  	    (error "Save not confirmed"))
***************
*** 737,742 ****
--- 738,748 ----
  			    ;; Change the mode back, after writing.
  			    (setq setmodes (file-modes buffer-file-name))
  			    (set-file-modes buffer-file-name 511)))
+ 		     ;; Make sure we don't get a complaint about a modtime
+ 		     ;; discrepancy, since backing up the file may have
+ 		     ;; deleted it.  We have checked for a discrepancy above,
+ 		     ;; anyway.
+ 		     (clear-visited-file-modtime)
  		     (write-region (point-min) (point-max) 
  				   buffer-file-name nil t)))))
  	  (if setmodes
Technical Details
Message-ID: <9002201907.AA02638@sn1987a.compass.com>
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!bu.edu!snorkelwacker!tut.cis.ohio-state.edu!compass.com!worley

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: fb2f1,6d0286890379aa18,start
X-Google-Attributes: gidfb2f1,public
X-Google-ArrivalTime: 1990-02-20 14:16:45 PST
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!bu.edu!snorkelwacker!tut.cis.ohio-state.edu!compass.com!worley
From: worley@compass.com (Dale Worley)
Newsgroups: gnu.emacs.bug
Subject: Superseding a deleted file
Message-ID: <9002201907.AA02638@sn1987a.compass.com>
Date: 20 Feb 90 19:07:59 GMT
Sender: daemon@tut.cis.ohio-state.edu
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 149
Posted: Tue Feb 20 20:07:59 1990