aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1992-07-28 19:38:08 +0000
committerRichard M. Stallman1992-07-28 19:38:08 +0000
commit2d051399770c312b514081780e514fdabee2183d (patch)
treecc107d6ba710dab3e9155cbc36df457e1aa46b5b
parentb6df3e11b27d4aad739d89001d1d8d18b82528b6 (diff)
downloademacs-2d051399770c312b514081780e514fdabee2183d.tar.gz
emacs-2d051399770c312b514081780e514fdabee2183d.zip
*** empty log message ***
-rw-r--r--lisp/dired-aux.el88
-rw-r--r--lisp/dired.el95
-rw-r--r--lisp/files.el20
3 files changed, 110 insertions, 93 deletions
diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el
index d81d0641ec4..be93d71d70e 100644
--- a/lisp/dired-aux.el
+++ b/lisp/dired-aux.el
@@ -1,9 +1,8 @@
1;; dired-aux.el --- directory browsing command support 1;; dired-aux.el --- all of dired except what people usually use
2 2
3;; Copyright (C) 1985, 1986, 1992 Free Software Foundation, Inc. 3;; Copyright (C) 1985, 1986, 1992 Free Software Foundation, Inc.
4 4
5;; Author: Sebastian Kremer <sk@thp.uni-koeln.de>. 5;; Author: Sebastian Kremer <sk@thp.uni-koeln.de>.
6;; Version: 5.234
7 6
8;; This file is part of GNU Emacs. 7;; This file is part of GNU Emacs.
9 8
@@ -171,6 +170,91 @@ Uses the shell command coming from variables `lpr-command' and
171 (function read-string) 170 (function read-string)
172 (format prompt (dired-mark-prompt arg files)) initial)) 171 (format prompt (dired-mark-prompt arg files)) initial))
173 172
173;;; Cleaning a directory: flagging some backups for deletion.
174
175(defun dired-clean-directory (keep)
176 "Flag numerical backups for deletion.
177Spares `dired-kept-versions' latest versions, and `kept-old-versions' oldest.
178Positive prefix arg KEEP overrides `dired-kept-versions';
179Negative prefix arg KEEP overrides `kept-old-versions' with KEEP made positive.
180
181To clear the flags on these files, you can use \\[dired-flag-backup-files]
182with a prefix argument."
183 (interactive "P")
184 (setq keep (if keep (prefix-numeric-value keep) dired-kept-versions))
185 (let ((early-retention (if (< keep 0) (- keep) kept-old-versions))
186 (late-retention (if (<= keep 0) dired-kept-versions keep))
187 (dired-file-version-alist ()))
188 (message "Cleaning numerical backups (keeping %d late, %d old)..."
189 late-retention early-retention)
190 ;; Look at each file.
191 ;; If the file has numeric backup versions,
192 ;; put on dired-file-version-alist an element of the form
193 ;; (FILENAME . VERSION-NUMBER-LIST)
194 (dired-map-dired-file-lines (function dired-collect-file-versions))
195 ;; Sort each VERSION-NUMBER-LIST,
196 ;; and remove the versions not to be deleted.
197 (let ((fval dired-file-version-alist))
198 (while fval
199 (let* ((sorted-v-list (cons 'q (sort (cdr (car fval)) '<)))
200 (v-count (length sorted-v-list)))
201 (if (> v-count (+ early-retention late-retention))
202 (rplacd (nthcdr early-retention sorted-v-list)
203 (nthcdr (- v-count late-retention)
204 sorted-v-list)))
205 (rplacd (car fval)
206 (cdr sorted-v-list)))
207 (setq fval (cdr fval))))
208 ;; Look at each file. If it is a numeric backup file,
209 ;; find it in a VERSION-NUMBER-LIST and maybe flag it for deletion.
210 (dired-map-dired-file-lines (function dired-trample-file-versions))
211 (message "Cleaning numerical backups...done")))
212
213;;; Subroutines of dired-clean-directory.
214
215(defun dired-map-dired-file-lines (fun)
216 ;; Perform FUN with point at the end of each non-directory line.
217 ;; FUN takes one argument, the filename (complete pathname).
218 (save-excursion
219 (let (file buffer-read-only)
220 (goto-char (point-min))
221 (while (not (eobp))
222 (save-excursion
223 (and (not (looking-at dired-re-dir))
224 (not (eolp))
225 (setq file (dired-get-filename nil t)) ; nil on non-file
226 (progn (end-of-line)
227 (funcall fun file))))
228 (forward-line 1)))))
229
230(defun dired-collect-file-versions (fn)
231 ;; "If it looks like file FN has versions, return a list of the versions.
232 ;;That is a list of strings which are file names.
233 ;;The caller may want to flag some of these files for deletion."
234 (let* ((base-versions
235 (concat (file-name-nondirectory fn) ".~"))
236 (bv-length (length base-versions))
237 (possibilities (file-name-all-completions
238 base-versions
239 (file-name-directory fn)))
240 (versions (mapcar 'backup-extract-version possibilities)))
241 (if versions
242 (setq dired-file-version-alist (cons (cons fn versions)
243 dired-file-version-alist)))))
244
245(defun dired-trample-file-versions (fn)
246 (let* ((start-vn (string-match "\\.~[0-9]+~$" fn))
247 base-version-list)
248 (and start-vn
249 (setq base-version-list ; there was a base version to which
250 (assoc (substring fn 0 start-vn) ; this looks like a
251 dired-file-version-alist)) ; subversion
252 (not (memq (string-to-int (substring fn (+ 2 start-vn)))
253 base-version-list)) ; this one doesn't make the cut
254 (progn (beginning-of-line)
255 (delete-char 1)
256 (insert dired-del-marker)))))
257
174;;; Shell commands 258;;; Shell commands
175;;>>> install (move this function into simple.el) 259;;>>> install (move this function into simple.el)
176(defun dired-shell-quote (filename) 260(defun dired-shell-quote (filename)
diff --git a/lisp/dired.el b/lisp/dired.el
index 0f2d205afa5..be4595fa28b 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -1700,91 +1700,6 @@ Type SPC or `y' to unflag one file, DEL or `n' to skip to next,
1700 (forward-line 1)))) 1700 (forward-line 1))))
1701 (message "%s" (format "Flags removed: %d %s" count flag) ))) 1701 (message "%s" (format "Flags removed: %d %s" count flag) )))
1702 1702
1703;;; Cleaning a directory: flagging some backups for deletion.
1704
1705(defun dired-clean-directory (keep)
1706 "Flag numerical backups for deletion.
1707Spares `dired-kept-versions' latest versions, and `kept-old-versions' oldest.
1708Positive prefix arg KEEP overrides `dired-kept-versions';
1709Negative prefix arg KEEP overrides `kept-old-versions' with KEEP made positive.
1710
1711To clear the flags on these files, you can use \\[dired-flag-backup-files]
1712with a prefix argument."
1713 (interactive "P")
1714 (setq keep (if keep (prefix-numeric-value keep) dired-kept-versions))
1715 (let ((early-retention (if (< keep 0) (- keep) kept-old-versions))
1716 (late-retention (if (<= keep 0) dired-kept-versions keep))
1717 (dired-file-version-alist ()))
1718 (message "Cleaning numerical backups (keeping %d late, %d old)..."
1719 late-retention early-retention)
1720 ;; Look at each file.
1721 ;; If the file has numeric backup versions,
1722 ;; put on dired-file-version-alist an element of the form
1723 ;; (FILENAME . VERSION-NUMBER-LIST)
1724 (dired-map-dired-file-lines (function dired-collect-file-versions))
1725 ;; Sort each VERSION-NUMBER-LIST,
1726 ;; and remove the versions not to be deleted.
1727 (let ((fval dired-file-version-alist))
1728 (while fval
1729 (let* ((sorted-v-list (cons 'q (sort (cdr (car fval)) '<)))
1730 (v-count (length sorted-v-list)))
1731 (if (> v-count (+ early-retention late-retention))
1732 (rplacd (nthcdr early-retention sorted-v-list)
1733 (nthcdr (- v-count late-retention)
1734 sorted-v-list)))
1735 (rplacd (car fval)
1736 (cdr sorted-v-list)))
1737 (setq fval (cdr fval))))
1738 ;; Look at each file. If it is a numeric backup file,
1739 ;; find it in a VERSION-NUMBER-LIST and maybe flag it for deletion.
1740 (dired-map-dired-file-lines (function dired-trample-file-versions))
1741 (message "Cleaning numerical backups...done")))
1742
1743;;; Subroutines of dired-clean-directory.
1744
1745(defun dired-map-dired-file-lines (fun)
1746 ;; Perform FUN with point at the end of each non-directory line.
1747 ;; FUN takes one argument, the filename (complete pathname).
1748 (save-excursion
1749 (let (file buffer-read-only)
1750 (goto-char (point-min))
1751 (while (not (eobp))
1752 (save-excursion
1753 (and (not (looking-at dired-re-dir))
1754 (not (eolp))
1755 (setq file (dired-get-filename nil t)) ; nil on non-file
1756 (progn (end-of-line)
1757 (funcall fun file))))
1758 (forward-line 1)))))
1759
1760(defun dired-collect-file-versions (fn)
1761 ;; "If it looks like file FN has versions, return a list of the versions.
1762 ;;That is a list of strings which are file names.
1763 ;;The caller may want to flag some of these files for deletion."
1764 (let* ((base-versions
1765 (concat (file-name-nondirectory fn) ".~"))
1766 (bv-length (length base-versions))
1767 (possibilities (file-name-all-completions
1768 base-versions
1769 (file-name-directory fn)))
1770 (versions (mapcar 'backup-extract-version possibilities)))
1771 (if versions
1772 (setq dired-file-version-alist (cons (cons fn versions)
1773 dired-file-version-alist)))))
1774
1775(defun dired-trample-file-versions (fn)
1776 (let* ((start-vn (string-match "\\.~[0-9]+~$" fn))
1777 base-version-list)
1778 (and start-vn
1779 (setq base-version-list ; there was a base version to which
1780 (assoc (substring fn 0 start-vn) ; this looks like a
1781 dired-file-version-alist)) ; subversion
1782 (not (memq (string-to-int (substring fn (+ 2 start-vn)))
1783 base-version-list)) ; this one doesn't make the cut
1784 (progn (beginning-of-line)
1785 (delete-char 1)
1786 (insert dired-del-marker)))))
1787
1788;; Logging failures operating on files, and showing the results. 1703;; Logging failures operating on files, and showing the results.
1789 1704
1790(defvar dired-log-buffer "*Dired log*") 1705(defvar dired-log-buffer "*Dired log*")
@@ -1936,6 +1851,16 @@ If this file is a backup, diff it with its original.
1936The backup file is the first file given to `diff'." 1851The backup file is the first file given to `diff'."
1937 t) 1852 t)
1938 1853
1854(autoload 'dired-clean-directory "dired-aux"
1855 "Flag numerical backups for deletion.
1856Spares `dired-kept-versions' latest versions, and `kept-old-versions' oldest.
1857Positive prefix arg KEEP overrides `dired-kept-versions';
1858Negative prefix arg KEEP overrides `kept-old-versions' with KEEP made positive.
1859
1860To clear the flags on these files, you can use \\[dired-flag-backup-files]
1861with a prefix argument."
1862 t)
1863
1939(autoload 'dired-do-chmod "dired-aux" 1864(autoload 'dired-do-chmod "dired-aux"
1940 "Change the mode of the marked (or next ARG) files. 1865 "Change the mode of the marked (or next ARG) files.
1941This calls chmod, thus symbolic modes like `g+w' are allowed." 1866This calls chmod, thus symbolic modes like `g+w' are allowed."
diff --git a/lisp/files.el b/lisp/files.el
index f1fde0575e0..c16581f60b4 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -836,6 +836,19 @@ This is a separate function so you can redefine it for customization.
836You may need to redefine `file-name-sans-versions' as well." 836You may need to redefine `file-name-sans-versions' as well."
837 (string-match "~$" file)) 837 (string-match "~$" file))
838 838
839;; This is used in various files.
840;; The usage of bv-length is not very clean,
841;; but I can't see a good alternative,
842;; so as of now I am leaving it alone.
843(defun backup-extract-version (fn)
844 "Given the name of a numeric backup file, return the backup number.
845Uses the free variable `bv-length', whose value should be
846the index in the name where the version number begins."
847 (if (and (string-match "[0-9]+~$" fn bv-length)
848 (= (match-beginning 0) bv-length))
849 (string-to-int (substring fn bv-length -1))
850 0))
851
839;; I believe there is no need to alter this behavior for VMS; 852;; I believe there is no need to alter this behavior for VMS;
840;; since backup files are not made on VMS, it should not get called. 853;; since backup files are not made on VMS, it should not get called.
841(defun find-backup-file-name (fn) 854(defun find-backup-file-name (fn)
@@ -850,12 +863,7 @@ Value is a list whose car is the name for the backup file
850 base-versions 863 base-versions
851 (file-name-directory fn))) 864 (file-name-directory fn)))
852 (versions (sort (mapcar 865 (versions (sort (mapcar
853 (function 866 (function backup-extract-version)
854 (lambda (fn)
855 (if (and (string-match "[0-9]+~$" fn bv-length)
856 (= (match-beginning 0) bv-length))
857 (string-to-int (substring fn bv-length -1))
858 0)))
859 possibilities) 867 possibilities)
860 '<)) 868 '<))
861 (high-water-mark (apply 'max 0 versions)) 869 (high-water-mark (apply 'max 0 versions))