annotate lisp/efs/dired-cmpr.el @ 118:7d55a9ba150c r20-1b11

Import from CVS: tag r20-1b11
author cvs
date Mon, 13 Aug 2007 09:24:17 +0200
parents 9f59509498e1
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2 ;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3 ;; File: dired-cmpr.el
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 22
diff changeset
4 ;; Dired Version: #Revision: 7.9 $
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5 ;; RCS:
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6 ;; Description: Commands for compressing marked files.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
7 ;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
8 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
9
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
10 ;;; Requirements and provisions
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
11 (provide 'dired-cmpr)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
12 (require 'dired)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
13
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
14 ;;; Entry points.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
15
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
16 (defun dired-do-compress (&optional arg files)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
17 "Compress or uncompress marked (or next ARG) files.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
18 With a zero prefix, prompts for a new value of `dired-compression-method'."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
19 (interactive
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
20 (let ((arg (prefix-numeric-value current-prefix-arg))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
21 files)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
22 (if (zerop arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
23 (let ((new (completing-read
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
24 (format "Set compression method (currently %s): "
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
25 dired-compression-method)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
26 (mapcar
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
27 (function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
28 (lambda (x)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
29 (cons (symbol-name (car x)) nil)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
30 dired-compression-method-alist)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
31 nil t)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
32 (or (string-equal new "")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
33 (setq dired-compression-method (intern new))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
34 (setq files (dired-get-marked-files nil current-prefix-arg))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
35 (or (memq 'compress dired-no-confirm)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
36 (let* ((dir (dired-current-directory))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
37 (rfiles (mapcar (function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
38 (lambda (fn)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
39 (dired-make-relative fn dir t)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
40 files))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
41 (prompt "")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
42 (comp 0)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
43 (uncomp nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
44 (total (length files))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
45 elt)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
46 (mapcar (function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
47 (lambda (fn)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
48 (if (listp (setq elt
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
49 (dired-make-compressed-filename fn)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
50 (let* ((method (car (nth 3 elt)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
51 (count (assoc method uncomp)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
52 (if count
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
53 (setcdr count (1+ (cdr count)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
54 (setq uncomp (cons (cons method 1) uncomp))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
55 (setq comp (1+ comp)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
56 files)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
57 (if (/= comp 0)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
58 (setq prompt
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
59 (format "%s %d"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
60 (car
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
61 (nth 2
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
62 (assq dired-compression-method
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
63 dired-compression-method-alist)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
64 comp)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
65 (if uncomp
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
66 (let ((case-fold-search t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
67 method)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
68 (or (string-equal prompt "")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
69 (setq prompt (concat prompt "; ")))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
70 (setq uncomp
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
71 (sort
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
72 (mapcar
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
73 (function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
74 (lambda (elt)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
75 (setq method (car elt))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
76 (if (string-equal method "gzip")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
77 (setq method "gunzip")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
78 (or (string-match "^un" method)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
79 (setq method (concat "un" method))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
80 (setcar elt method)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
81 elt))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
82 uncomp)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
83 (function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
84 (lambda (x y)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
85 (string< (car x) (car y))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
86 (setq prompt
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
87 (concat prompt
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
88 (mapconcat
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
89 (function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
90 (lambda (elt)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
91 (format "%s %d" (car elt) (cdr elt))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
92 uncomp ", ")))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
93 (cond
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
94 ((= (length rfiles) 1)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
95 (setq prompt (format "%s %s? "
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
96 ;; Don't need the number 1
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
97 (substring prompt 0 -2)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
98 (car rfiles))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
99 ((or (> (length uncomp) 1) (and (/= 0 comp) uncomp))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
100 (setq prompt (format "%s? Total: %d file%s " prompt total
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
101 (dired-plural-s total))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
102 ((setq prompt (format "%s file%s? " prompt
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
103 (dired-plural-s total)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
104 (or (dired-mark-pop-up nil 'compress rfiles 'y-or-n-p prompt)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
105 (setq arg 0)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
106 (list arg files)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
107
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
108 (if (not (zerop arg))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
109 (dired-create-files
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
110 'dired-compress-file
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
111 "Compress or Uncompress"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
112 files
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
113 (function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
114 (lambda (fn)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
115 (let ((cfn (dired-make-compressed-filename fn)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
116 (if (stringp cfn)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
117 cfn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
118 (substring fn 0 (- (length (nth 1 cfn))))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
119 dired-keep-marker-compress nil t)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
120
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
121 (defun dired-compress-subdir-files (&optional uncompress)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
122 "Compress all uncompressed files in the current subdirectory.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
123 With a prefix argument uncompresses all compressed files."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
124 (interactive "P")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
125 (let ((dir (dired-current-directory))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
126 files methods uncomp elt)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
127 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
128 (save-restriction
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
129 (narrow-to-region (dired-subdir-min) (dired-subdir-max))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
130 (dired-map-dired-file-lines
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
131 (function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
132 (lambda (f)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
133 (if uncompress
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
134 (and (listp (setq uncomp (dired-make-compressed-filename f)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
135 (let ((program (car (nth 3 uncomp))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
136 (setq files (cons f files))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
137 (if (setq elt (assoc program methods))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
138 (setcdr elt (1+ (cdr elt)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
139 (setq methods (cons (cons program 1) methods)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
140 (and (stringp (dired-make-compressed-filename f))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
141 (setq files (cons f files)))))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
142 (if files
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
143 (let ((total (length files))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
144 (rfiles (mapcar
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
145 (function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
146 (lambda (fn)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
147 (dired-make-relative fn dir t)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
148 files))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
149 prompt)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
150 (if uncompress
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
151 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
152 (setq prompt (mapconcat
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
153 (function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
154 (lambda (x)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
155 (format "%s %d"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
156 (if (string-equal (car x) "gzip")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
157 "gunzip"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
158 (if (string-match "^un" (car x))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
159 (car x)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
160 (concat "un" (car x))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
161 (cdr x))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
162 methods ", "))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
163 (cond
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
164 ((= total 1)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
165 (setq prompt
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
166 (concat (substring prompt 0 -1) (car rfiles) "? ")))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
167 ((= (length methods) 1)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
168 (setq prompt
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
169 (format "%s file%s? " prompt (dired-plural-s total))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
170 (t
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
171 (setq prompt (format "%s? Total: %d file%s " prompt total
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
172 (dired-plural-s total))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
173 (setq prompt
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
174 (if (= total 1)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
175 (format "%s %s? " dired-compression-method (car rfiles))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
176 (format "%s %d file%s? "
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
177 dired-compression-method total
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
178 (dired-plural-s total)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
179 (if (dired-mark-pop-up nil 'compress rfiles 'y-or-n-p prompt)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
180 (dired-create-files
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
181 'dired-compress-file
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
182 "Compress or Uncompress"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
183 files
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
184 (function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
185 (lambda (fn)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
186 (let ((cfn (dired-make-compressed-filename fn)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
187 (if (stringp cfn)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
188 cfn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
189 (substring fn 0 (- (length (nth 1 cfn))))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
190 dired-keep-marker-compress nil t)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
191 (message "No files need %scompressing in %s."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
192 (if uncompress "un" "")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
193 (dired-abbreviate-file-name dir)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
194
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
195 (defun dired-compress-file (file ok-flag)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
196 ;; Compress or uncompress FILE.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
197 ;; If ok-flag is non-nil, it is OK to overwrite an existing
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
198 ;; file. How well this actually works may depend on the compression
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
199 ;; program.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
200 ;; Return the name of the compressed or uncompressed file.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
201 (let ((handler (find-file-name-handler file 'dired-compress-file)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
202 (if handler
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
203 (funcall handler 'dired-compress-file file ok-flag)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
204 (let ((compressed-fn (dired-make-compressed-filename file))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
205 (err-buff (get-buffer-create " *dired-check-process output*")))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
206 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
207 (set-buffer err-buff)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
208 (erase-buffer)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
209 (cond ((file-symlink-p file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
210 (signal 'file-error (list "Error compressing file"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
211 file "a symbolic link")))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
212 ((listp compressed-fn)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
213 (message "Uncompressing %s..." file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
214 (let* ((data (nth 3 compressed-fn))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
215 (ret
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
216 (apply 'call-process
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
217 (car data) file t nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
218 (append (cdr data)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
219 (and ok-flag
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
220 (list (nth 4 compressed-fn)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
221 (list file)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
222 (if (or (and (integerp ret) (/= ret 0))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
223 (not (bobp)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
224 (signal 'file-error
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
225 (nconc
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
226 (list "Error uncompressing file"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
227 file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
228 (and (not (bobp))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
229 (list
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
230 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
231 (goto-char (point-min))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
232 (buffer-substring
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
233 (point) (progn (end-of-line)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
234 (point))))))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
235 (message "Uncompressing %s...done" file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
236 (dired-remove-file file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
237 (let ((to (substring file 0
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
238 (- (length (nth 1 compressed-fn))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
239 ;; rename any buffers
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
240 (and (get-file-buffer file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
241 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
242 (set-buffer (get-file-buffer file))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
243 (let ((modflag (buffer-modified-p)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
244 ;; kills write-file-hooks
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
245 (set-visited-file-name to)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
246 (set-buffer-modified-p modflag))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
247 to))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
248 ((stringp compressed-fn)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
249 (message "Compressing %s..." file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
250 (let* ((data (assq dired-compression-method
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
251 dired-compression-method-alist))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
252 (compr-args (nth 2 data))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
253 (ret
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
254 (apply 'call-process
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
255 (car compr-args) file t nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
256 (append (cdr compr-args)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
257 (and ok-flag
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
258 (list (nth 4 data)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
259 (list file)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
260 (if (or (and (integerp ret) (/= ret 0))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
261 (not (bobp)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
262 (signal 'file-error
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
263 (nconc
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
264 (list "Error compressing file"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
265 file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
266 (and (not (bobp))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
267 (list
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
268 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
269 (goto-char (point-min))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
270 (buffer-substring
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
271 (point) (progn (end-of-line)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
272 (point))))))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
273 (message "Compressing %s...done" file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
274 (dired-remove-file file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
275 ;; rename any buffers
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
276 (and (get-file-buffer file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
277 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
278 (set-buffer (get-file-buffer file))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
279 (let ((modflag (buffer-modified-p)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
280 ;; kills write-file-hooks
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
281 (set-visited-file-name compressed-fn)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
282 (set-buffer-modified-p modflag))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
283 compressed-fn)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
284 (t (error "Strange error in dired-compress-file."))))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
285
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
286 (defun dired-make-compressed-filename (name &optional method)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
287 ;; If NAME is in the syntax of a compressed file (according to
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
288 ;; dired-compression-method-alist), return the data (a list) from this
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
289 ;; alist on how to uncompress it. Otherwise, return a string, the
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
290 ;; compressed form of this file name. This is computed using the optional
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
291 ;; argument METHOD (a symbol). If METHOD is nil, the ambient value of
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
292 ;; dired-compression-method is used.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
293 (let ((handler (find-file-name-handler
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
294 name 'dired-make-compressed-filename)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
295 (if handler
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
296 (funcall handler 'dired-make-compressed-filename name method)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
297 (let ((alist dired-compression-method-alist)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
298 (len (length name))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
299 ext ext-len result)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
300 (while alist
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
301 (if (and (> len
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
302 (setq ext-len (length (setq ext (nth 1 (car alist))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
303 (string-equal ext (substring name (- ext-len))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
304 (setq result (car alist)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
305 alist nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
306 (setq alist (cdr alist))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
307 (or result
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
308 (concat name
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
309 (nth 1 (or (assq (or method dired-compression-method)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
310 dired-compression-method-alist)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
311 (error "Unknown compression method: %s"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
312 (or method dired-compression-method))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
313 ))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
314
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
315 ;;; end of dired-cmpr.el