From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: "Rehm, Keith" Newsgroups: gmane.emacs.help,gmane.emacs.bugs Subject: RE: .emacs help Date: Wed, 11 Sep 2002 11:19:44 -0500 Sender: help-gnu-emacs-admin@gnu.org Message-ID: NNTP-Posting-Host: localhost.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=_2114cb198587d2a3b43a1330df6aadcd" X-Trace: main.gmane.org 1031761213 8217 127.0.0.1 (11 Sep 2002 16:20:13 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Wed, 11 Sep 2002 16:20:13 +0000 (UTC) Cc: bug-gnu-emacs@gnu.org Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 17pADm-000287-00 for ; Wed, 11 Sep 2002 18:20:07 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10) id 17pADt-0007xk-00; Wed, 11 Sep 2002 12:20:14 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10) id 17pADf-0007wF-00 for help-gnu-emacs@gnu.org; Wed, 11 Sep 2002 12:19:59 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10) id 17pADd-0007vm-00 for help-gnu-emacs@gnu.org; Wed, 11 Sep 2002 12:19:58 -0400 Original-Received: from [65.115.221.98] (helo=ssd.fsi.com) by monty-python.gnu.org with esmtp (Exim 4.10) id 17pADa-0007vA-00; Wed, 11 Sep 2002 12:19:54 -0400 Original-To: Miles Bader , help-gnu-emacs@gnu.org Errors-To: help-gnu-emacs-admin@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.0.11 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: Xref: main.gmane.org gmane.emacs.help:1311 gmane.emacs.bugs:3482 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:1311 This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. --=_2114cb198587d2a3b43a1330df6aadcd Content-Type: text/plain; charset="iso-8859-1" Hi, I am using GNU Emacs and use backup-dir seemingly. I have: (require 'backup-dir) (if (boundp 'bkup-backup-directory-info) (setq bkup-backup-directory-info '((t "c:/documents and settings/keithr/desktop/emacsBackups/" ok-create full-path)))) in my .emacs and am using the backup-dir.el I have attached. (?) Keith -----Original Message----- From: Miles Bader [mailto:miles@lsi.nec.co.jp] Sent: Tuesday, September 10, 2002 8:26 PM To: help-gnu-emacs@gnu.org Cc: bug-gnu-emacs@gnu.org Subject: Re: .emacs help exmixllxer@xattxbi.com writes: > > This is the error I get: > > > File error: "Cannot open load file", "backup-dir" > > > .emacs from xemacs customization: > > (custom-set-variables > > '(bkup-backup-directory-info (quote (("." "~emiller/emacs_bkup" ok-create))) nil (backup-dir))) > > Ugh, I think the parens are unbalanced. Odd since this came > right out of xemacs! No, the parens seem fine. The problem is that the `(backup-dir)' part of the customization entry does what you might expect: it tells emacs that the `backup-dir' feature is required before defining that variable, and emacs will try to load `backup-dir.el' to define it. Since `backup-dir.el' is an xemacs-only thing, it of course fails. This is for bug-gnu-emacs: It would be nice if emacs just ignored customization entries that result in an error (I often ran into the same problem when trying to use older versions of emacs with my emacs21 .emacs file). -Miles -- I'd rather be consing. _______________________________________________ Help-gnu-emacs mailing list Help-gnu-emacs@gnu.org http://mail.gnu.org/mailman/listinfo/help-gnu-emacs --=_2114cb198587d2a3b43a1330df6aadcd Content-Type: application/octet-stream; name="backup-dir.el" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="backup-dir.el" ;;; backup-dir.el --- allow backup files to live in some other = directory(s).=0A= =0A= ;;; Author: Greg Klanderman =0A= ;;; Version: 2.9=0A= ;;; Date: January 8, 1999=0A= ;;; Created: Spring 1992=0A= ;;; Keywords: backup file=0A= =0A= ;;; Copyright (C) 1992-98 Greg Klanderman=0A= ;;;=0A= ;;; This program is free software; you can redistribute it and/or = modify=0A= ;;; it under the terms of the GNU General Public License as published = by=0A= ;;; the Free Software Foundation; either version 2, or (at your = option)=0A= ;;; any later version.=0A= ;;;=0A= ;;; This program is distributed in the hope that it will be useful,=0A= ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of=0A= ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the=0A= ;;; GNU General Public License for more details.=0A= ;;;=0A= ;;; A copy of the GNU General Public License can be obtained from = the=0A= ;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,=0A= ;;; Boston, MA 02111-1307, USA.=0A= ;;;=0A= ;;; Send bug reports, feedback, etc. to = greg.klanderman@alum.mit.edu,=0A= ;;; greg@alphatech.com, or gregk@ai.mit.edu.=0A= =0A= ;;; Commentary:=0A= ;;;=0A= ;;; Allows backup files to be optionally stored in some directories, = based on=0A= ;;; the value of the alist, `bkup-backup-directory-info'. This = variable is a=0A= ;;; list of lists of the form (FILE-REGEXP BACKUP-DIR OPTIONS ...). If = the=0A= ;;; filename to be backed up matches FILE-REGEXP, or FILE-REGEXP is t, = then=0A= ;;; BACKUP-DIR is used as the path for its backups. Directories may = begin=0A= ;;; with "/" to specify an absolute pathname.=0A= ;;;=0A= ;;; If BACKUP-DIR does not exist and OPTIONS contains the symbol = `ok-create',=0A= ;;; then it is created if possible. Otherwise the usual behavior = (backup in=0A= ;;; the same directory as the file) results.=0A= ;;;=0A= ;;; If OPTIONS contains the symbol `full-path', then the full path of = the file=0A= ;;; being backed up is prepended to the backup file name, with each = "/"=0A= ;;; replaced by a "!". This is intended for cases where an absolute = backup=0A= ;;; path is used. If OPTIONS contains `prepend-name' in addition to=0A= ;;; `full-path', then the file name is prepended rather than appended = to the=0A= ;;; path component when forming the backup name.=0A= ;;;=0A= ;;; If OPTIONS contains the symbol `search-upward' and the backup = directory=0A= ;;; BACKUP-DIR is a relative path, then a directory with that name is = searched=0A= ;;; for starting at the current directory and proceeding upward (.., = ../..,=0A= ;;; etc) until one is found of that name or the root is reached, and if = one is=0A= ;;; found it is used as the backup directory.=0A= ;;;=0A= ;;; Finally, if no FILE-REGEXP matches the file name being backed up, = then the=0A= ;;; usual behavior results.=0A= ;;;=0A= ;;; These lines from my .emacs load this file and set the values I = like:=0A= ;;;=0A= ;;; (require 'backup-dir)=0A= ;;; (setq bkup-backup-directory-info=0A= ;;; '(("/home/greg/.*" "/~/.backups/" ok-create full-path = prepend-name)=0A= ;;; ("^/[^/:]+:" ".backups/") ; handle EFS files specially: = don't=0A= ;;; ("^/[^/:]+:" "./") ; search-upward... its very = slow=0A= ;;; (t ".backups/"=0A= ;;; full-path prepend-name search-upward)))=0A= ;;;=0A= ;;;=0A= ;;; The package also provides a new function, `find-file-latest-backup' = to=0A= ;;; find the latest backup file for the current buffer's file.=0A= ;;;=0A= ;;; This package is based on `files.el' from XEmacs 20.3 and = overrides=0A= ;;; functions defined there. The overridden functions are clearly=0A= ;;; marked below and the originals precede the new definitions in=0A= ;;; commented form.=0A= ;;;=0A= ;;; The package is known to work in the latest XEmacs betas. It has=0A= ;;; not been extensively tested on GNU Emacs past 18.58, though I = have=0A= ;;; reports of it working through 20.2. It does not work under = ms-dos.=0A= =0A= ;;; Change Log:=0A= ;;;=0A= ;;; January 8, 1999 Version 2.9=0A= ;;; * Fix bkup-search-upward-for-backup-dir,=0A= ;;; bkup-replace-slashes-with-exclamations, and=0A= ;;; bkup-backup-directory-and-basename for NT.=0A= ;;;=0A= ;;; November 13, 1998 Version 2.8=0A= ;;; * Reformat to fit within 80 columns.=0A= ;;; * Reformat ChangeLog section.=0A= ;;;=0A= ;;; June 10, 1998 Version 2.7=0A= ;;; * Add optional N argument to file-newest-backup and=0A= ;;; find-file-latest-backup.=0A= ;;;=0A= ;;; March 23, 1998 Version 2.6=0A= ;;; * Have to quote the eval-after-load form.=0A= ;;;=0A= ;;; February 22, 1998 Version 2.5=0A= ;;; * Fix infinite loop in bkup-search-upward-for-backup-dir due to = a=0A= ;;; change in expand-file-name. Fix to not rely on = expand-file-name.=0A= ;;;=0A= ;;; February 22, 1998 Version 2.4=0A= ;;; * Add a new option: prepend-name, suggested by Dave Bakhash.=0A= ;;;=0A= ;;; February 2, 1998 Version 2.3=0A= ;;; * Nuke byte-compiler-options.=0A= ;;; * Use eval-when-compile defvars to avoid compiler warnings.=0A= ;;; * Remove unused binding of non-num-bk-name from = find-backup-file-name.=0A= ;;;=0A= ;;; October 27, 1997 Version 2.2=0A= ;;; * Update to adhere to lisp-mnt.el standards.=0A= ;;; * Don't require diff; instead use eval-after-load to patch=0A= ;;; diff-latest-backup-file (patch from Steve Baur).=0A= ;;;=0A= ;;; October 27, 1997 Version 2.1=0A= ;;; * Updated to support GNU Emacs 20.2. The function=0A= ;;; `backup-extract-version' now uses the free variable=0A= ;;; `backup-extract-version-start' rather than `bv-length'.=0A= ;;; Note, we continue to support older GNU Emacs and XEmacs=0A= ;;; by binding both names.=0A= ;;;=0A= ;;; October 22, 1997=0A= ;;; * Customization by Karl M. Hegbloom =0A= ;;;=0A= ;;; December 28, 1996 Version 2.0=0A= ;;; * Updated for XEmacs 19.15b4, much of code reorganized & cleaned = up=0A= ;;;=0A= ;;; December 27, 1996 Version 1.6=0A= ;;; * Explicit loading of dired replaced to use dired-load-hook=0A= ;;; (suggested by Thomas Feuster, = feuster@tp4.physik.uni-giessen.de)=0A= ;;;=0A= ;;; December 2, 1996 Version 1.5=0A= ;;; * Took out obsolete byte compiler options=0A= ;;;=0A= ;;; September 24, 1996 Version 1.4=0A= ;;; * Various bugfixes.=0A= ;;; * Change to OPTIONS alist list (ok-create, full-path..) from=0A= ;;; separate fields for each option variable.=0A= ;;; * Added search-upward option.=0A= ;;; * Added new function `find-file-latest-backup' to find a file's=0A= ;;; latest backup.=0A= ;;;=0A= ;;; January 26, 1996 Version 1.3=0A= ;;; * Name change to backup-dir.el=0A= ;;;=0A= ;;; March 22, 1995 Version 1.2=0A= ;;; * Added new definitions for functions `file-newest-backup',=0A= ;;; `latest-backup-file', and `diff-latest-backup-file' so various = other=0A= ;;; emacs functions will find the right backup files.=0A= ;;;=0A= ;;; April 23, 1993 Version 1.1=0A= ;;; * Reworked to allow different behavior for different files based = on the=0A= ;;; alist `bkup-backup-directory-info'.=0A= ;;;=0A= ;;; Fall 1992 Version 1.0=0A= ;;; * Name change=0A= ;;; * Added ability to make directories absolute.=0A= ;;; * Added the full path stuff to make backup name unique for=0A= ;;; absolute directories.=0A= ;;;=0A= ;;; Spring 1992 Version 0.0=0A= ;;; * The original.=0A= =0A= =0A= ;;; Code:=0A= =0A= (eval-when-compile=0A= ;; avoid compiler warnings: these are dynamically bound by=0A= ;; find-backup-file-name and used by backup extract-versions.=0A= (defvar backup-extract-version-start) ; GNU Emacs 20.2=0A= (defvar bv-length) ; XEmacs, older GNU = Emacs=0A= =0A= ;; this is defined for msdos only=0A= (unless (fboundp 'msdos-long-file-names)=0A= (defun msdos-long-file-names () nil)))=0A= =0A= =0A= ;;; New variables affecting backup file behavior=0A= ;;; This is the only user-customizable variable for this package.=0A= ;;;=0A= (defcustom bkup-backup-directory-info nil=0A= "*Alist of (FILE-REGEXP BACKUP-DIR OPTIONS ...))=0A= If the filename to be backed up matches FILE-REGEXP, or FILE-REGEXP is = t,=0A= then BACKUP-DIR is used as the path for its backups.=0A= =0A= Directories may begin with \"/\" to specify an absolute pathname.=0A= =0A= If BACKUP-DIR does not exist and OPTIONS contains the symbol = `ok-create',=0A= then it is created if possible. Otherwise the usual behavior (backup = in the=0A= same directory as the file) results.=0A= =0A= If OPTIONS contains the symbol `full-path', then the full path of the = file=0A= being backed up is prepended to the backup file name, with each = \"/\"=0A= replaced by a \"!\". This is intended for cases where an absolute = backup=0A= path is used. If OPTIONS contains `prepend-name' in addition to = `full-path',=0A= then the file name is prepended rather than appended to the path = component=0A= when forming the backup name.=0A= =0A= If OPTIONS contains the symbol `search-upward' and the backup = directory=0A= BACKUP-DIR is a relative path, then a directory with that name is = searched=0A= for starting at the current directory and proceeding upward (.., ../.., = etc)=0A= until one is found of that name, or the root is reached, and if one is = found=0A= it is used as the backup directory.=0A= =0A= Finally, if no FILE-REGEXP matches the file name being backed up, then = the=0A= usual behavior results.=0A= =0A= Once you save this variable with `M-x customize-variable',=0A= `backup-dir' will be loaded for you each time you start XEmacs."=0A= :type '(repeat=0A= (list (regexp :tag "File regexp")=0A= (string :tag "Backup Dir")=0A= (set :inline t=0A= (const ok-create)=0A= (const full-path)=0A= (const prepend-name)=0A= (const search-upward))))=0A= :require 'backup-dir=0A= :group 'backup)=0A= =0A= =0A= ;;; New functions=0A= ;;;=0A= (defun bkup-search-upward-for-backup-dir (base bd-name)=0A= "Search upward for a directory named BD-NAME, starting in the=0A= directory BASE and continuing with its parent directories until=0A= one is found or the root is reached."=0A= (let ((prev nil) (curr base) (gotit nil) (tryit nil))=0A= (while (and (not gotit)=0A= (not (equal curr prev))=0A= (not (equal prev "/")))=0A= (setq tryit (expand-file-name bd-name curr))=0A= (if (and (file-directory-p tryit)=0A= (file-exists-p tryit))=0A= (setq gotit tryit)=0A= (setq prev curr=0A= curr (file-name-directory (directory-file-name = curr)))))=0A= (if (and gotit=0A= (eq (aref gotit (1- (length gotit))) ?/))=0A= (setq gotit (substring gotit 0 (1- (length gotit)))))=0A= gotit))=0A= =0A= (defun bkup-replace-slashes-with-exclamations (s)=0A= "Replaces slashes in the string S with exclamations.=0A= A new string is produced and returned."=0A= (let ((ns (copy-sequence s))=0A= (i (1- (length s)))=0A= (mswin (eq system-type 'windows-nt))=0A= (c nil))=0A= (while (>=3D i 0)=0A= (setq c (aref ns i))=0A= (if (or (=3D c ?/)=0A= (and mswin=0A= (or (=3D c ?:) (=3D c ?\\))))=0A= (aset ns i ?!))=0A= (setq i (1- i)))=0A= ns))=0A= =0A= (defun bkup-try-making-directory (dir)=0A= "Try making directory DIR, return non-nil if successful"=0A= (condition-case ()=0A= (progn (make-directory dir t)=0A= t)=0A= (t=0A= nil)))=0A= =0A= (defun bkup-backup-basename (file options)=0A= "Gives the base part of the backup name for FILE, according to = OPTIONS."=0A= (if (memq 'full-path options)=0A= (if (memq 'prepend-name options)=0A= (concat (file-name-nondirectory file)=0A= "!!"=0A= (bkup-replace-slashes-with-exclamations=0A= (file-name-directory file)))=0A= (bkup-replace-slashes-with-exclamations file))=0A= (file-name-nondirectory file)))=0A= =0A= (defun bkup-backup-directory-and-basename (file)=0A= "Return the cons of the backup directory name=0A= and backup file name base for FILE."=0A= (let ((file (expand-file-name file)))=0A= (let ((dir (file-name-directory file))=0A= (alist bkup-backup-directory-info)=0A= (bk-dir nil)=0A= (bk-base nil))=0A= (if (listp alist)=0A= (while (and (not bk-dir) alist)=0A= (if (or (eq (car (car alist)) t)=0A= (eq (string-match (car (car alist)) file) 0))=0A= (let* ((bd (car (cdr (car alist))))=0A= (bd-rel-p (not (file-name-absolute-p = bd)))=0A= (bd-expn (expand-file-name bd dir))=0A= (bd-noslash (directory-file-name bd-expn))=0A= (options (cdr (cdr (car alist))))=0A= (ok-create (and (memq 'ok-create = options) t))=0A= (search-upward (and (memq 'search-upward = options) t)))=0A= (if bd-expn=0A= (cond ((or (file-directory-p bd-expn)=0A= (and ok-create=0A= (not (file-exists-p bd-expn))=0A= (bkup-try-making-directory = bd-noslash)))=0A= (setq bk-dir (file-name-as-directory = bd-noslash)=0A= bk-base (bkup-backup-basename = file=0A= = options)))=0A= ((and bd-rel-p search-upward)=0A= (let ((bd-up = (bkup-search-upward-for-backup-dir=0A= dir bd)))=0A= (if bd-up=0A= (setq bk-dir (file-name-as-directory = bd-up)=0A= bk-base = (bkup-backup-basename=0A= file = options)))))))))=0A= (setq alist (cdr alist))))=0A= (if (and bk-dir bk-base)=0A= (cons bk-dir bk-base)=0A= (cons dir (bkup-backup-basename file nil))))))=0A= =0A= =0A= ;;; This next one is based on the following from `files.el'=0A= ;;; but accepts a second optional argument=0A= =0A= ;;(defun make-backup-file-name (file)=0A= ;; "Create the non-numeric backup file name for FILE.=0A= ;;This is a separate function so you can redefine it for = customization."=0A= ;; (if (and (eq system-type 'ms-dos)=0A= ;; (not (msdos-long-file-names)))=0A= ;; (let ((fn (file-name-nondirectory file)))=0A= ;; (concat (file-name-directory file)=0A= ;; (if (string-match "\\([^.]*\\)\\(\\..*\\)?" fn)=0A= ;; (substring fn 0 (match-end 1)))=0A= ;; ".bak"))=0A= ;; (concat file "~")))=0A= =0A= (defun bkup-make-backup-file-name (file &optional dir-n-base)=0A= "Create the non-numeric backup file name for FILE.=0A= Optionally accept a list containing the backup directory and=0A= backup basename. NB: we don't really handle ms-dos."=0A= (if (and (eq system-type 'ms-dos)=0A= (not (and (fboundp 'msdos-long-file-names)=0A= (msdos-long-file-names))))=0A= (let ((fn (file-name-nondirectory file)))=0A= (concat (file-name-directory file)=0A= (if (string-match "\\([^.]*\\)\\(\\..*\\)?" fn)=0A= (substring fn 0 (match-end 1)))=0A= ".bak"))=0A= (let ((d-n-b (or dir-n-base=0A= (bkup-backup-directory-and-basename file))))=0A= (concat (car d-n-b) (cdr d-n-b) "~"))))=0A= =0A= (defun bkup-existing-backup-files (fn)=0A= "Return list of existing backup files for file"=0A= (let* ((efn (expand-file-name fn))=0A= (dir-n-base (bkup-backup-directory-and-basename efn))=0A= (non-num-bk-name (bkup-make-backup-file-name efn = dir-n-base))=0A= (non-num-bk (file-exists-p non-num-bk-name))=0A= (backup-dir (car dir-n-base))=0A= (base-versions (concat (cdr dir-n-base) ".~"))=0A= (possibilities (file-name-all-completions base-versions = backup-dir))=0A= (poss (mapcar #'(lambda (name) (concat backup-dir name))=0A= possibilities)))=0A= (mapcar #'expand-file-name=0A= (if non-num-bk (cons non-num-bk-name poss) poss))))=0A= =0A= (defun find-file-latest-backup (file &optional n)=0A= "Find the latest backup file for FILE, or the Nth most recent=0A= if optional second argument N is specified. Interactively, N=0A= is specified with the prefix argument."=0A= (interactive=0A= (list=0A= (read-file-name=0A= (format "Find %slatest backup of file (default %s): "=0A= (let* ((arg (prefix-numeric-value=0A= current-prefix-arg))=0A= (mod (% arg 10)))=0A= (if (and (integerp arg) (> arg 1))=0A= (format "%d%s "=0A= arg=0A= (cond ((=3D 1 mod) "st")=0A= ((=3D 2 mod) "nd")=0A= ((=3D 3 mod) "rd")=0A= (t "th")))=0A= ""))=0A= (file-name-nondirectory (buffer-file-name)))=0A= nil (buffer-file-name) t)=0A= (prefix-numeric-value current-prefix-arg)))=0A= (let ((backup (file-newest-backup file n)))=0A= (if backup=0A= (find-file backup)=0A= (message "no %s found for `%s'"=0A= (if (> n 1) "such backup" "backups") file))))=0A= =0A= =0A= ;;; Functions changed from `files.el' and elsewhere -- originals=0A= ;;; precede new versions=0A= =0A= ;;(defun make-backup-file-name (file)=0A= ;; "Create the non-numeric backup file name for FILE.=0A= ;;This is a separate function so you can redefine it for = customization."=0A= ;; (if (and (eq system-type 'ms-dos)=0A= ;; (not (msdos-long-file-names)))=0A= ;; (let ((fn (file-name-nondirectory file)))=0A= ;; (concat (file-name-directory file)=0A= ;; (if (string-match "\\([^.]*\\)\\(\\..*\\)?" fn)=0A= ;; (substring fn 0 (match-end 1)))=0A= ;; ".bak"))=0A= ;; (concat file "~")))=0A= =0A= (defun make-backup-file-name (file)=0A= "Create the non-numeric backup file name for FILE.=0A= This is a separate function so you can redefine it for = customization.=0A= *** Changed by \"backup-dir.el\""=0A= (bkup-make-backup-file-name file))=0A= =0A= =0A= ;;(defun find-backup-file-name (fn)=0A= ;; "Find a file name for a backup file, and suggestions for = deletions.=0A= ;;Value is a list whose car is the name for the backup file=0A= ;; and whose cdr is a list of old versions to consider deleting now.=0A= ;;If the value is nil, don't make a backup."=0A= ;; (let ((handler (find-file-name-handler fn = 'find-backup-file-name)))=0A= ;; ;; Run a handler for this function so that ange-ftp can refuse to = do it.=0A= ;; (if handler=0A= ;; (funcall handler 'find-backup-file-name fn)=0A= ;; (if (eq version-control 'never)=0A= ;; (list (make-backup-file-name fn))=0A= ;; (let* ((base-versions (concat (file-name-nondirectory fn) ".~"))=0A= ;; ;; used by backup-extract-version:=0A= ;; (bv-length (length base-versions))=0A= ;; possibilities=0A= ;; (versions nil)=0A= ;; (high-water-mark 0)=0A= ;; (deserve-versions-p nil)=0A= ;; (number-to-delete 0))=0A= ;; (condition-case ()=0A= ;; (setq possibilities (file-name-all-completions=0A= ;; base-versions=0A= ;; (file-name-directory fn))=0A= ;; versions (sort (mapcar=0A= ;; #'backup-extract-version=0A= ;; possibilities)=0A= ;; '<)=0A= ;; high-water-mark (apply #'max 0 versions)=0A= ;; deserve-versions-p (or version-control=0A= ;; (> high-water-mark 0))=0A= ;; number-to-delete (- (length versions)=0A= ;; kept-old-versions kept-new-versions -1))=0A= ;; (file-error=0A= ;; (setq possibilities nil)))=0A= ;; (if (not deserve-versions-p)=0A= ;; (list (make-backup-file-name fn))=0A= ;; (cons (concat fn ".~" (int-to-string (1+ high-water-mark)) = "~")=0A= ;; (if (and (> number-to-delete 0)=0A= ;; ;; Delete nothing if there is overflow=0A= ;; ;; in the number of versions to keep.=0A= ;; (>=3D (+ kept-new-versions kept-old-versions -1) 0))=0A= ;; (mapcar #'(lambda (n)=0A= ;; (concat fn ".~" (int-to-string n) "~"))=0A= ;; (let ((v (nthcdr kept-old-versions versions)))=0A= ;; (rplacd (nthcdr (1- number-to-delete) v) ())=0A= ;; v))))))))))=0A= =0A= (defun find-backup-file-name (fn)=0A= "Find a file name for a backup file, and suggestions for = deletions.=0A= Value is a list whose car is the name for the backup file=0A= and whose cdr is a list of old versions to consider deleting now.=0A= If the value is nil, don't make a backup.=0A= *** Changed by \"backup-dir.el\""=0A= (let ((handler (find-file-name-handler fn = 'find-backup-file-name)))=0A= ;; Run a handler for this function so that ange-ftp can refuse to = do it.=0A= (if handler=0A= (funcall handler 'find-backup-file-name fn)=0A= (if (eq version-control 'never)=0A= (list (make-backup-file-name fn))=0A= (let* ((dir-n-base (bkup-backup-directory-and-basename fn)) ;add=0A= (bk-dir (car dir-n-base)) = ;add=0A= (bk-base (cdr dir-n-base)) = ;add=0A= (base-versions (concat bk-base ".~")) = ;mod=0A= ;; used by backup-extract-version:=0A= (bv-length (length base-versions)) ;; older GNU and XEmacs=0A= (backup-extract-version-start=0A= (length base-versions)) ;; new GNU Emacs (20.2)=0A= possibilities=0A= (versions nil)=0A= (high-water-mark 0)=0A= (deserve-versions-p nil)=0A= (number-to-delete 0))=0A= (condition-case ()=0A= (setq possibilities (file-name-all-completions=0A= base-versions=0A= bk-dir) ;mod=0A= versions (sort (mapcar=0A= #'backup-extract-version=0A= possibilities)=0A= '<)=0A= high-water-mark (apply #'max 0 versions)=0A= deserve-versions-p (or version-control=0A= (> high-water-mark 0))=0A= number-to-delete (- (length versions)=0A= kept-old-versions=0A= kept-new-versions -1))=0A= (file-error=0A= (setq possibilities nil)))=0A= (if (not deserve-versions-p)=0A= (list (bkup-make-backup-file-name fn dir-n-base)) ;mod=0A= (cons (concat bk-dir base-versions=0A= (int-to-string (1+ high-water-mark)) "~") = ;mod=0A= (if (and (> number-to-delete 0)=0A= ;; Delete nothing if there is overflow=0A= ;; in the number of versions to keep.=0A= (>=3D (+ kept-new-versions kept-old-versions -1) 0))=0A= (mapcar #'(lambda (n)=0A= (concat bk-dir base-versions=0A= (int-to-string n) "~")) = ;mod=0A= (let ((v (nthcdr kept-old-versions versions)))=0A= (rplacd (nthcdr (1- number-to-delete) v) ())=0A= v))))))))))=0A= =0A= =0A= ;;(defun file-newest-backup (filename)=0A= ;; "Return most recent backup file for FILENAME or nil if no backups = exist."=0A= ;; (let* ((filename (expand-file-name filename))=0A= ;; (file (file-name-nondirectory filename))=0A= ;; (dir (file-name-directory filename))=0A= ;; (comp (file-name-all-completions file dir))=0A= ;; newest tem)=0A= ;; (while comp=0A= ;; (setq tem (car comp)=0A= ;; comp (cdr comp))=0A= ;; (cond ((and (backup-file-name-p tem)=0A= ;; (string=3D (file-name-sans-versions tem) file))=0A= ;; (setq tem (concat dir tem))=0A= ;; (if (or (null newest)=0A= ;; (file-newer-than-file-p tem newest))=0A= ;; (setq newest tem)))))=0A= ;; newest))=0A= =0A= (defun file-newest-backup (filename &optional n)=0A= "Return most recent backup file for FILENAME or nil if no backups = exist.=0A= Optional second argument N specifies the Nth newest backup, rather than = the=0A= most recent.=0A= *** Changed by \"backup-dir.el\""=0A= (nth (if (integerp n) (max 0 (1- n)) 0)=0A= (sort (bkup-existing-backup-files filename)=0A= 'file-newer-than-file-p)))=0A= =0A= =0A= ;;; patch `latest-backup-file' from "dired"=0A= ;;;=0A= ;;; we use `dired-load-hook' to avoid loading dired now. This speeds = things=0A= ;;; up considerably according to Thomas Feuster,=0A= ;;; feuster@tp4.physik.uni-giessen.de=0A= ;;;=0A= ;;; one really wonders why there are 3 functions to do the same = thing...=0A= ;;;=0A= (defun bkup-patch-latest-backup-file ()=0A= (fset 'latest-backup-file (symbol-function 'file-newest-backup))=0A= (remove-hook 'dired-load-hook 'bkup-patch-latest-backup-file))=0A= =0A= (if (featurep 'dired)=0A= ;; if loaded, patch it now=0A= (fset 'latest-backup-file (symbol-function 'file-newest-backup))=0A= ;; otherwise do it later=0A= (add-hook 'dired-load-hook 'bkup-patch-latest-backup-file))=0A= =0A= =0A= ;;; patch `diff-latest-backup-file' from "diff"=0A= ;;;=0A= (eval-after-load "diff"=0A= '(fset 'diff-latest-backup-file=0A= (symbol-function 'file-newest-backup)))=0A= =0A= =0A= ;;; finally, add to list of features=0A= ;;;=0A= (provide 'backup-dir)=0A= =0A= ;;; backup-dir.el ends here=0A= --=_2114cb198587d2a3b43a1330df6aadcd--