home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / emacs / 2927 < prev    next >
Encoding:
Text File  |  1992-08-21  |  2.8 KB  |  74 lines

  1. Path: sparky!uunet!airgun!airgun.wg.waii.com!jct
  2. From: jct@se33.wg2.waii.com (Jim Thompson)
  3. Newsgroups: comp.emacs
  4. Subject: Re: How do I send file~ to the wastebasket directory?
  5. Message-ID: <JCT.92Aug21185207@se33.wg2.waii.com>
  6. Date: 21 Aug 92 22:52:07 GMT
  7. References: <1992Aug20.192848.4860@fzi.de>
  8. Sender: news@airgun.wg.waii.com
  9. Followup-To: comp.emacs
  10. Organization: Western Geophysical Exploration Products
  11. Lines: 59
  12. Nntp-Posting-Host: se33.wg2.waii.com
  13. In-reply-to: schreib@fzi.de's message of 20 Aug 92 19:28:48 GMT
  14.  
  15. In article <1992Aug20.192848.4860@fzi.de> schreib@fzi.de (Hartmut Schreiber) writes:
  16.  
  17. > Is there a way to tell emacs, to create all ~-files in a special 
  18. > directory "wastebasket", which I can delete from time to time?
  19.  
  20. Here's some code I wrote to place backup files into "./EmacsBackups",
  21. if it exists, or "." otherwise.  I'm not sure why I overrode
  22. find-backup-file-name instead of make-backup-file-name;  this code is
  23. old and I was quite the Elisp novice when I wrote it (but it still
  24. does the job).
  25.  
  26. (defun backup-name-base (file)
  27.   "Create the non-numeric backup file name for FILE.
  28. This is a separate function so you can redefine it for customization."
  29.   (setq fdir (file-name-directory file))
  30.   (setq fname (file-name-nondirectory file))
  31.   (setq fbackupdir "EmacsBackups/")
  32.  
  33.   (if (file-directory-p (concat fdir fbackupdir))
  34.       (concat fdir fbackupdir fname)
  35.     file))
  36.  
  37. (defun find-backup-file-name (fn)
  38.   "Find a file name for a backup file, and suggestions for deletions.
  39. Value is a list whose car is the name for the backup file
  40. and whose cdr is a list of old versions to consider deleting now.
  41. Mangled from the original version in files.el."
  42.  
  43.   (setq fn (backup-name-base fn))
  44.  
  45.   (if (eq version-control 'never)
  46.       (list (make-backup-file-name fn))
  47.     (let* ((base-versions (concat (file-name-nondirectory fn) ".~"))
  48.        (bv-length (length base-versions))
  49.        (possibilities (file-name-all-completions
  50.                base-versions
  51.                (file-name-directory fn)))
  52.        (versions (sort (mapcar 'backup-extract-version possibilities)
  53.                '<))
  54.        (high-water-mark (apply 'max (cons 0 versions)))
  55.        (deserve-versions-p
  56.         (or version-control
  57.         (> high-water-mark 0)))
  58.        (number-to-delete (- (length versions)
  59.                 kept-old-versions kept-new-versions -1)))
  60.       (if (not deserve-versions-p)
  61.       (list (make-backup-file-name fn))
  62.     (cons (concat fn ".~" (int-to-string (1+ high-water-mark)) "~")
  63.           (if (> number-to-delete 0)
  64.           (mapcar (function (lambda (n)
  65.                       (concat fn ".~" (int-to-string n) "~")))
  66.               (let ((v (nthcdr kept-old-versions versions)))
  67.                 (rplacd (nthcdr (1- number-to-delete) v) ())
  68.                 v))))))))
  69. --
  70.    _    Jim Thompson           |  Wanted:
  71.  _| ~-  thompson@wg2.waii.com  |    Nick Park's "Grand Day Out"
  72.  \,  _} Western Geophysical    |    on VHS-format videotape
  73.    \(   Houston, Texas         |  Email me if you know where I can buy it.
  74.