Mercurial > emacs
annotate lisp/arc-mode.el @ 18092:8428d56cd207
(smtpmail-via-smtp): Recognize XVRB as a synonym for
VERB and XONE as a synonym for ONEX.
(smtpmail-read-response): Add "%s" to `message' calls to avoid
problems with percent signs in strings.
(smtpmail-read-response): Return all lines of the
response text as a list of strings. Formerly only the first line
was returned. This is insufficient when one wants to parse
e.g. an EHLO response.
Ignore responses starting with "0". This is necessary to support
the VERB SMTP extension.
(smtpmail-via-smtp): Try EHLO and find out which SMTP service
extensions the receiving mailer supports.
Issue the ONEX and XUSR commands if the corresponding extensions
are supported.
Issue VERB if supported and `smtpmail-debug-info' is non-nil.
Add SIZE attribute to MAIL FROM: command if SIZE extension is
supported.
Add code that could set the BODY= attribute to MAIL FROM: if the
receiving mailer supports 8BITMIME. This is currently disabled,
since doing it right might involve adding MIME headers to, and in
some cases reencoding, the message.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sun, 01 Jun 1997 22:24:22 +0000 |
parents | 727cf56647a4 |
children | e526918bbae8 |
rev | line source |
---|---|
11880 | 1 ;;; arc-mode.el --- simple editing of archives |
2 | |
14169 | 3 ;; Copyright (C) 1995 Free Software Foundation, Inc. |
11880 | 4 |
17977 | 5 ;; Author: Morten Welinder <terra@diku.dk> |
11880 | 6 ;; Keywords: archives msdog editing major-mode |
7 ;; Favourite-brand-of-beer: None, I hate beer. | |
8 | |
14169 | 9 ;; This file is part of GNU Emacs. |
10 | |
11 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
12 ;; it under the terms of the GNU General Public License as published by | |
13 ;; the Free Software Foundation; either version 2, or (at your option) | |
14 ;; any later version. | |
15 | |
16 ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
24 ;; Boston, MA 02111-1307, USA. | |
11880 | 25 |
26 ;;; Commentary: | |
14169 | 27 |
11880 | 28 ;; NAMING: "arc" is short for "archive" and does not refer specifically |
29 ;; to files whose name end in ".arc" | |
30 ;; | |
31 ;; This code does not decode any files internally, although it does | |
32 ;; understand the directory level of the archives. For this reason, | |
33 ;; you should expect this code to need more fiddling than tar-mode.el | |
34 ;; (although it at present has fewer bugs :-) In particular, I have | |
35 ;; not tested this under Ms-Dog myself. | |
36 ;; ------------------------------------- | |
37 ;; INTERACTION: arc-mode.el should play together with | |
38 ;; | |
39 ;; * ange-ftp.el: Remote archives (i.e., ones that ange-ftp has brought | |
40 ;; to you) are handled by doing all updates on a local | |
41 ;; copy. When you make changes to a remote file the | |
42 ;; changes will first take effect when the archive buffer | |
43 ;; is saved. You will be warned about this. | |
44 ;; | |
45 ;; * dos-fns.el: (Part of Emacs 19). You get automatic ^M^J <--> ^J | |
46 ;; conversion. | |
47 ;; | |
48 ;; arc-mode.el does not work well with crypt++.el; for the archives as | |
49 ;; such this could be fixed (but wouldn't be useful) by declaring such | |
50 ;; archives to be "remote". For the members this is a general Emacs | |
51 ;; problem that 19.29's file formats may fix. | |
52 ;; ------------------------------------- | |
53 ;; ARCHIVE TYPES: Currently only the archives below are handled, but the | |
54 ;; structure for handling just about anything is in place. | |
55 ;; | |
56 ;; Arc Lzh Zip Zoo | |
57 ;; -------------------------------- | |
58 ;; View listing Intern Intern Intern Intern | |
59 ;; Extract member Y Y Y Y | |
60 ;; Save changed member Y Y Y Y | |
61 ;; Add new member N N N N | |
62 ;; Delete member Y Y Y Y | |
63 ;; Rename member Y Y N N | |
64 ;; Chmod - Y Y - | |
65 ;; Chown - Y - - | |
66 ;; Chgrp - Y - - | |
67 ;; | |
68 ;; Special thanks to Bill Brodie <wbrodie@panix.com> for very useful tips | |
69 ;; on the first released version of this package. | |
70 ;; | |
71 ;; This code is partly based on tar-mode.el from Emacs. | |
72 ;; ------------------------------------- | |
73 ;; ARCHIVE STRUCTURES: | |
74 ;; (This is mostly for myself.) | |
75 ;; | |
76 ;; ARC A series of (header,file). No interactions among members. | |
77 ;; | |
78 ;; LZH A series of (header,file). Headers are checksummed. No | |
79 ;; interaction among members. | |
80 ;; | |
81 ;; ZIP A series of (lheader,fil) followed by a "central directory" | |
82 ;; which is a series of (cheader) followed by an end-of- | |
83 ;; central-dir record possibly followed by junk. The e-o-c-d | |
84 ;; links to c-d. cheaders link to lheaders which are basically | |
85 ;; cut-down versions of the cheaders. | |
86 ;; | |
87 ;; ZOO An archive header followed by a series of (header,file). | |
88 ;; Each member header points to the next. The archive is | |
89 ;; terminated by a bogus header with a zero next link. | |
90 ;; ------------------------------------- | |
91 ;; HOOKS: `foo' means one the the supported archive types. | |
92 ;; | |
93 ;; archive-mode-hook | |
94 ;; archive-foo-mode-hook | |
95 ;; archive-extract-hooks | |
96 | |
97 ;;; Code: | |
98 | |
99 ;; ------------------------------------------------------------------------- | |
100 ;; Section: Configuration. | |
101 | |
102 (defvar archive-dos-members t | |
12791
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
103 "*If non-nil then recognize member files using ^M^J as line terminator.") |
11880 | 104 |
105 (defvar archive-tmpdir | |
106 (expand-file-name | |
107 (make-temp-name (if (eq system-type 'ms-dos) "ar" "archive.tmp")) | |
108 (or (getenv "TMPDIR") (getenv "TMP") "/tmp")) | |
109 "*Directory for temporary files made by arc-mode.el") | |
110 | |
12756
0a2d094db7d8
(archive-remote-regexp): Don't accept hostnames
Richard M. Stallman <rms@gnu.org>
parents:
12437
diff
changeset
|
111 (defvar archive-remote-regexp "^/[^/:]*[^/:.]:" |
12791
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
112 "*Regexp recognizing archive files names that are not local. |
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
113 A non-local file is one whose file name is not proper outside Emacs. |
13539
4b42b497a96d
(archive-remote-regexp): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
13339
diff
changeset
|
114 A local copy of the archive will be used when updating.") |
11880 | 115 |
116 (defvar archive-extract-hooks nil | |
117 "*Hooks to run when an archive member has been extracted.") | |
118 ;; ------------------------------ | |
119 ;; Arc archive configuration | |
120 | |
121 ;; We always go via a local file since there seems to be no reliable way | |
122 ;; to extract to stdout without junk getting added. | |
123 (defvar archive-arc-extract | |
124 '("arc" "x") | |
12791
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
125 "*Program and its options to run in order to extract an arc file member. |
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
126 Extraction should happen to the current directory. Archive and member |
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
127 name will be added.") |
11880 | 128 |
129 (defvar archive-arc-expunge | |
130 '("arc" "d") | |
131 "*Program and its options to run in order to delete arc file members. | |
132 Archive and member names will be added.") | |
133 | |
134 (defvar archive-arc-write-file-member | |
135 '("arc" "u") | |
136 "*Program and its options to run in order to update an arc file member. | |
137 Archive and member name will be added.") | |
138 ;; ------------------------------ | |
139 ;; Lzh archive configuration | |
140 | |
141 (defvar archive-lzh-extract | |
142 '("lha" "pq") | |
12791
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
143 "*Program and its options to run in order to extract an lzh file member. |
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
144 Extraction should happen to standard output. Archive and member name will |
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
145 be added.") |
11880 | 146 |
147 (defvar archive-lzh-expunge | |
148 '("lha" "d") | |
149 "*Program and its options to run in order to delete lzh file members. | |
150 Archive and member names will be added.") | |
151 | |
152 (defvar archive-lzh-write-file-member | |
153 '("lha" "a") | |
154 "*Program and its options to run in order to update an lzh file member. | |
155 Archive and member name will be added.") | |
156 ;; ------------------------------ | |
157 ;; Zip archive configuration | |
158 | |
159 (defvar archive-zip-use-pkzip (memq system-type '(ms-dos windows-nt)) | |
12791
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
160 "*If non-nil then pkzip option are used instead of zip options. |
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
161 Only set to true for msdog systems!") |
11880 | 162 |
163 (defvar archive-zip-extract | |
164 (if archive-zip-use-pkzip '("pkunzip" "-e") '("unzip" "-qq" "-c")) | |
12791
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
165 "*Program and its options to run in order to extract a zip file member. |
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
166 Extraction should happen to standard output. Archive and member name will |
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
167 be added. If `archive-zip-use-pkzip' is non-nil then this program is |
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
168 expected to extract to a file junking the directory part of the name.") |
11880 | 169 |
13966
82eeef849f8b
(archive-summarize-files): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
13539
diff
changeset
|
170 ;; For several reasons the latter behaviour is not desirable in general. |
11880 | 171 ;; (1) It uses more disk space. (2) Error checking is worse or non- |
172 ;; existent. (3) It tends to do funny things with other systems' file | |
173 ;; names. | |
174 | |
175 (defvar archive-zip-expunge | |
176 (if archive-zip-use-pkzip '("pkzip" "-d") '("zip" "-d" "-q")) | |
177 "*Program and its options to run in order to delete zip file members. | |
178 Archive and member names will be added.") | |
179 | |
180 (defvar archive-zip-update | |
181 (if archive-zip-use-pkzip '("pkzip" "-u") '("zip" "-q")) | |
182 "*Program and its options to run in order to update a zip file member. | |
183 Options should ensure that specified directory will be put into the zip | |
184 file. Archive and member name will be added.") | |
185 | |
186 (defvar archive-zip-update-case | |
187 (if archive-zip-use-pkzip archive-zip-update '("zip" "-q" "-k")) | |
12791
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
188 "*Program and its options to run in order to update a case fiddled zip member. |
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
189 Options should ensure that specified directory will be put into the zip file. |
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
190 Archive and member name will be added.") |
11880 | 191 |
192 (defvar archive-zip-case-fiddle t | |
12791
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
193 "*If non-nil then zip file members are case fiddled. |
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
194 Case fiddling will only happen for members created by a system that |
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
195 uses caseless file names.") |
11880 | 196 ;; ------------------------------ |
197 ;; Zoo archive configuration | |
198 | |
199 (defvar archive-zoo-extract | |
200 '("zoo" "xpq") | |
12791
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
201 "*Program and its options to run in order to extract a zoo file member. |
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
202 Extraction should happen to standard output. Archive and member name will |
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
203 be added.") |
11880 | 204 |
205 (defvar archive-zoo-expunge | |
206 '("zoo" "DqPP") | |
207 "*Program and its options to run in order to delete zoo file members. | |
208 Archive and member names will be added.") | |
209 | |
210 (defvar archive-zoo-write-file-member | |
211 '("zoo" "a") | |
212 "*Program and its options to run in order to update a zoo file member. | |
213 Archive and member name will be added.") | |
214 ;; ------------------------------------------------------------------------- | |
215 ;; Section: Variables | |
216 | |
217 (defvar archive-subtype nil "*Symbol describing archive type.") | |
218 (defvar archive-file-list-start nil "*Position of first contents line.") | |
219 (defvar archive-file-list-end nil "*Position just after last contents line.") | |
220 (defvar archive-proper-file-start nil "*Position of real archive's start.") | |
221 (defvar archive-read-only nil "*Non-nil if the archive is read-only on disk.") | |
222 (defvar archive-remote nil "*Non-nil if the archive is outside file system.") | |
223 (defvar archive-local-name nil "*Name of local copy of remote archive.") | |
224 (defvar archive-mode-map nil "*Local keymap for archive mode listings.") | |
225 (defvar archive-file-name-indent nil "*Column where file names start.") | |
226 | |
227 (defvar archive-alternate-display nil | |
228 "*Non-nil when alternate information is shown.") | |
229 (make-variable-buffer-local 'archive-alternate-display) | |
230 (put 'archive-alternate-display 'permanent-local t) | |
231 | |
232 (defvar archive-superior-buffer nil "*In archive members, points to archive.") | |
233 (put 'archive-superior-buffer 'permanent-local t) | |
234 | |
235 (defvar archive-subfile-mode nil "*Non-nil in archive member buffers.") | |
236 (make-variable-buffer-local 'archive-subfile-mode) | |
237 (put 'archive-subfile-mode 'permanent-local t) | |
238 | |
239 (defvar archive-subfile-dos nil | |
16290
583e730756ef
(archive-mode, archive-extract, archive-check-dos)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
240 "Negation of `buffer-file-type', which see.") |
11880 | 241 (make-variable-buffer-local 'archive-subfile-dos) |
242 (put 'archive-subfile-dos 'permanent-local t) | |
243 | |
16291 | 244 (defvar archive-files nil |
245 "Vector of file descriptors. | |
246 Each descriptor is a vector of the form | |
247 [EXT-FILE-NAME INT-FILE-NAME CASE-FIDDLED MODE ...]") | |
11880 | 248 (make-variable-buffer-local 'archive-files) |
12024
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
249 |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
250 (defvar archive-lemacs |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
251 (string-match "\\(Lucid\\|Xemacs\\)" emacs-version) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
252 "*Non-nil when running under under Lucid Emacs or Xemacs.") |
11880 | 253 ;; ------------------------------------------------------------------------- |
254 ;; Section: Support functions. | |
255 | |
256 (defsubst archive-name (suffix) | |
257 (intern (concat "archive-" (symbol-name archive-subtype) "-" suffix))) | |
258 | |
259 (defun archive-l-e (str &optional len) | |
12791
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
260 "Convert little endian string/vector to integer. |
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
261 Alternatively, first argument may be a buffer position in the current buffer |
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
262 in which case a second argument, length, should be supplied." |
11880 | 263 (if (stringp str) |
264 (setq len (length str)) | |
265 (setq str (buffer-substring str (+ str len)))) | |
266 (let ((result 0) | |
267 (i 0)) | |
268 (while (< i len) | |
269 (setq i (1+ i) | |
270 result (+ (ash result 8) (aref str (- len i))))) | |
271 result)) | |
272 | |
273 (defun archive-int-to-mode (mode) | |
274 "Turn an integer like 0700 (i.e., 448) into a mode string like -rwx------" | |
275 (let ((str (make-string 10 ?-))) | |
276 (or (zerop (logand 16384 mode)) (aset str 0 ?d)) | |
277 (or (zerop (logand 8192 mode)) (aset str 0 ?c)) ; completeness | |
278 (or (zerop (logand 256 mode)) (aset str 1 ?r)) | |
279 (or (zerop (logand 128 mode)) (aset str 2 ?w)) | |
280 (or (zerop (logand 64 mode)) (aset str 3 ?x)) | |
281 (or (zerop (logand 32 mode)) (aset str 4 ?r)) | |
282 (or (zerop (logand 16 mode)) (aset str 5 ?w)) | |
283 (or (zerop (logand 8 mode)) (aset str 6 ?x)) | |
284 (or (zerop (logand 4 mode)) (aset str 7 ?r)) | |
285 (or (zerop (logand 2 mode)) (aset str 8 ?w)) | |
286 (or (zerop (logand 1 mode)) (aset str 9 ?x)) | |
287 (or (zerop (logand 1024 mode)) (aset str 3 (if (zerop (logand 64 mode)) | |
288 ?S ?s))) | |
289 (or (zerop (logand 2048 mode)) (aset str 6 (if (zerop (logand 8 mode)) | |
290 ?S ?s))) | |
291 str)) | |
292 | |
293 (defun archive-calc-mode (oldmode newmode &optional error) | |
12791
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
294 "From the integer OLDMODE and the string NEWMODE calculate a new file mode. |
11880 | 295 NEWMODE may be an octal number including a leading zero in which case it |
296 will become the new mode.\n | |
297 NEWMODE may also be a relative specification like \"og-rwx\" in which case | |
298 OLDMODE will be modified accordingly just like chmod(2) would have done.\n | |
299 If optional third argument ERROR is non-nil an error will be signaled if | |
300 the mode is invalid. If ERROR is nil then nil will be returned." | |
301 (cond ((string-match "^0[0-7]*$" newmode) | |
302 (let ((result 0) | |
303 (len (length newmode)) | |
304 (i 1)) | |
305 (while (< i len) | |
306 (setq result (+ (lsh result 3) (aref newmode i) (- ?0)) | |
307 i (1+ i))) | |
308 (logior (logand oldmode 65024) result))) | |
309 ((string-match "^\\([agou]+\\)\\([---+=]\\)\\([rwxst]+\\)$" newmode) | |
310 (let ((who 0) | |
311 (result oldmode) | |
312 (op (aref newmode (match-beginning 2))) | |
313 (bits 0) | |
314 (i (match-beginning 3))) | |
315 (while (< i (match-end 3)) | |
316 (let ((rwx (aref newmode i))) | |
317 (setq bits (logior bits (cond ((= rwx ?r) 292) | |
318 ((= rwx ?w) 146) | |
319 ((= rwx ?x) 73) | |
320 ((= rwx ?s) 3072) | |
321 ((= rwx ?t) 512))) | |
322 i (1+ i)))) | |
323 (while (< who (match-end 1)) | |
324 (let* ((whoc (aref newmode who)) | |
325 (whomask (cond ((= whoc ?a) 4095) | |
326 ((= whoc ?u) 1472) | |
327 ((= whoc ?g) 2104) | |
328 ((= whoc ?o) 7)))) | |
329 (if (= op ?=) | |
330 (setq result (logand result (lognot whomask)))) | |
331 (if (= op ?-) | |
332 (setq result (logand result (lognot (logand whomask bits)))) | |
333 (setq result (logior result (logand whomask bits))))) | |
334 (setq who (1+ who))) | |
335 result)) | |
336 (t | |
337 (if error | |
338 (error "Invalid mode specification: %s" newmode))))) | |
339 | |
340 (defun archive-dosdate (date) | |
341 "Stringify dos packed DATE record." | |
342 (let ((year (+ 1980 (logand (ash date -9) 127))) | |
343 (month (logand (ash date -5) 15)) | |
344 (day (logand date 31))) | |
345 (if (or (> month 12) (< month 1)) | |
346 "" | |
347 (format "%2d-%s-%d" | |
348 day | |
349 (aref ["Jan" "Feb" "Mar" "Apr" "May" "Jun" | |
350 "Jul" "Aug" "Sep" "Oct" "Nov" "Dec"] (1- month)) | |
351 year)))) | |
352 | |
353 (defun archive-dostime (time) | |
354 "Stringify dos packed TIME record." | |
355 (let ((hour (logand (ash time -11) 31)) | |
356 (minute (logand (ash time -5) 53)) | |
357 (second (* 2 (logand time 31)))) ; 2 seconds resolution | |
358 (format "%02d:%02d:%02d" hour minute second))) | |
359 | |
360 ;;(defun archive-unixdate (low high) | |
361 ;; "Stringify unix (LOW HIGH) date." | |
362 ;; (let ((str (current-time-string (cons high low)))) | |
363 ;; (format "%s-%s-%s" | |
364 ;; (substring str 8 9) | |
365 ;; (substring str 4 7) | |
366 ;; (substring str 20 24)))) | |
367 | |
368 ;;(defun archive-unixtime (low high) | |
369 ;; "Stringify unix (LOW HIGH) time." | |
370 ;; (let ((str (current-time-string (cons high low)))) | |
371 ;; (substring str 11 19))) | |
372 | |
373 (defun archive-get-lineno () | |
374 (if (>= (point) archive-file-list-start) | |
375 (count-lines archive-file-list-start | |
376 (save-excursion (beginning-of-line) (point))) | |
377 0)) | |
378 | |
379 (defun archive-get-descr (&optional noerror) | |
12791
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
380 "Return the descriptor vector for file at point. |
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
381 Does not signal an error if optional second argument NOERROR is non-nil." |
11880 | 382 (let ((no (archive-get-lineno))) |
383 (if (and (>= (point) archive-file-list-start) | |
384 (< no (length archive-files))) | |
385 (let ((item (aref archive-files no))) | |
386 (if (vectorp item) | |
387 item | |
388 (if (not noerror) | |
389 (error "Entry is not a regular member of the archive")))) | |
390 (if (not noerror) | |
391 (error "Line does not describe a member of the archive"))))) | |
392 ;; ------------------------------------------------------------------------- | |
393 ;; Section: the mode definition | |
394 | |
12437
c3597b66e4bf
(archive-mode): Add autoload cookie.
Richard M. Stallman <rms@gnu.org>
parents:
12304
diff
changeset
|
395 ;;;###autoload |
11880 | 396 (defun archive-mode (&optional force) |
12791
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
397 "Major mode for viewing an archive file in a dired-like way. |
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
398 You can move around using the usual cursor motion commands. |
11880 | 399 Letters no longer insert themselves. |
400 Type `e' to pull a file out of the archive and into its own buffer; | |
401 or click mouse-2 on the file's line in the archive mode buffer. | |
402 | |
403 If you edit a sub-file of this archive (as with the `e' command) and | |
404 save it, the contents of that buffer will be saved back into the | |
405 archive. | |
406 | |
407 \\{archive-mode-map}" | |
408 ;; This is not interactive because you shouldn't be turning this | |
409 ;; mode on and off. You can corrupt things that way. | |
410 (if (zerop (buffer-size)) | |
411 ;; At present we cannot create archives from scratch | |
412 (funcall default-major-mode) | |
413 (if (and (not force) archive-files) nil | |
414 (let* ((type (archive-find-type)) | |
415 (typename (copy-sequence (symbol-name type)))) | |
416 (aset typename 0 (upcase (aref typename 0))) | |
417 (kill-all-local-variables) | |
418 (make-local-variable 'archive-subtype) | |
419 (setq archive-subtype type) | |
420 | |
421 ;; Buffer contains treated image of file before the file contents | |
422 (make-local-variable 'revert-buffer-function) | |
423 (setq revert-buffer-function 'archive-mode-revert) | |
424 (auto-save-mode 0) | |
425 (make-local-variable 'local-write-file-hooks) | |
426 (add-hook 'local-write-file-hooks 'archive-write-file) | |
427 | |
428 ;; Real file contents is binary | |
429 (make-local-variable 'require-final-newline) | |
430 (setq require-final-newline nil) | |
431 (make-local-variable 'enable-local-variables) | |
432 (setq enable-local-variables nil) | |
16290
583e730756ef
(archive-mode, archive-extract, archive-check-dos)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
433 (if (boundp 'default-buffer-file-type) |
583e730756ef
(archive-mode, archive-extract, archive-check-dos)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
434 (setq buffer-file-type t)) |
11880 | 435 |
436 (make-local-variable 'archive-read-only) | |
437 (setq archive-read-only (not (file-writable-p (buffer-file-name)))) | |
438 | |
439 ;; Should we use a local copy when accessing from outside Emacs? | |
440 (make-local-variable 'archive-local-name) | |
441 (make-local-variable 'archive-remote) | |
442 (setq archive-remote (string-match archive-remote-regexp | |
443 (buffer-file-name))) | |
444 | |
445 (setq major-mode 'archive-mode) | |
446 (setq mode-name (concat typename "-Archive")) | |
447 ;; Run archive-foo-mode-hook and archive-mode-hook | |
448 (run-hooks (archive-name "mode-hook") 'archive-mode-hook) | |
449 (use-local-map archive-mode-map)) | |
450 | |
451 (make-local-variable 'archive-proper-file-start) | |
452 (make-local-variable 'archive-file-list-start) | |
453 (make-local-variable 'archive-file-list-end) | |
454 (make-local-variable 'archive-file-name-indent) | |
455 (archive-summarize) | |
456 (setq buffer-read-only t)))) | |
457 | |
458 ;; Archive mode is suitable only for specially formatted data. | |
459 (put 'archive-mode 'mode-class 'special) | |
460 ;; ------------------------------------------------------------------------- | |
461 ;; Section: Key maps | |
462 | |
463 (if archive-mode-map nil | |
464 (setq archive-mode-map (make-keymap)) | |
465 (suppress-keymap archive-mode-map) | |
466 (define-key archive-mode-map " " 'archive-next-line) | |
467 (define-key archive-mode-map "a" 'archive-alternate-display) | |
468 ;;(define-key archive-mode-map "c" 'archive-copy) | |
469 (define-key archive-mode-map "d" 'archive-flag-deleted) | |
470 (define-key archive-mode-map "\C-d" 'archive-flag-deleted) | |
471 (define-key archive-mode-map "e" 'archive-extract) | |
472 (define-key archive-mode-map "f" 'archive-extract) | |
473 (define-key archive-mode-map "\C-m" 'archive-extract) | |
474 (define-key archive-mode-map "g" 'revert-buffer) | |
475 (define-key archive-mode-map "h" 'describe-mode) | |
476 (define-key archive-mode-map "m" 'archive-mark) | |
477 (define-key archive-mode-map "n" 'archive-next-line) | |
478 (define-key archive-mode-map "\C-n" 'archive-next-line) | |
479 (define-key archive-mode-map [down] 'archive-next-line) | |
480 (define-key archive-mode-map "o" 'archive-extract-other-window) | |
481 (define-key archive-mode-map "p" 'archive-previous-line) | |
482 (define-key archive-mode-map "\C-p" 'archive-previous-line) | |
483 (define-key archive-mode-map [up] 'archive-previous-line) | |
484 (define-key archive-mode-map "r" 'archive-rename-entry) | |
485 (define-key archive-mode-map "u" 'archive-unflag) | |
486 (define-key archive-mode-map "\M-\C-?" 'archive-unmark-all-files) | |
487 (define-key archive-mode-map "v" 'archive-view) | |
488 (define-key archive-mode-map "x" 'archive-expunge) | |
489 (define-key archive-mode-map "\177" 'archive-unflag-backwards) | |
490 (define-key archive-mode-map "E" 'archive-extract-other-window) | |
491 (define-key archive-mode-map "M" 'archive-chmod-entry) | |
492 (define-key archive-mode-map "G" 'archive-chgrp-entry) | |
493 (define-key archive-mode-map "O" 'archive-chown-entry) | |
494 | |
12024
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
495 (if archive-lemacs |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
496 (progn |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
497 ;; Not a nice "solution" but it'll have to do |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
498 (define-key archive-mode-map "\C-xu" 'archive-undo) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
499 (define-key archive-mode-map "\C-_" 'archive-undo)) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
500 (substitute-key-definition 'undo 'archive-undo |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
501 archive-mode-map global-map)) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
502 |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
503 (define-key archive-mode-map |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
504 (if archive-lemacs 'button2 [mouse-2]) 'archive-mouse-extract) |
11880 | 505 |
12024
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
506 (if archive-lemacs |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
507 () ; out of luck |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
508 ;; Get rid of the Edit menu bar item to save space. |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
509 (define-key archive-mode-map [menu-bar edit] 'undefined) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
510 |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
511 (define-key archive-mode-map [menu-bar immediate] |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
512 (cons "Immediate" (make-sparse-keymap "Immediate"))) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
513 (define-key archive-mode-map [menu-bar immediate alternate] |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
514 '("Alternate Display" . archive-alternate-display)) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
515 (put 'archive-alternate-display 'menu-enable |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
516 '(boundp (archive-name "alternate-display"))) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
517 (define-key archive-mode-map [menu-bar immediate view] |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
518 '("View This File" . archive-view)) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
519 (define-key archive-mode-map [menu-bar immediate display] |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
520 '("Display in Other Window" . archive-display-other-window)) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
521 (define-key archive-mode-map [menu-bar immediate find-file-other-window] |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
522 '("Find in Other Window" . archive-extract-other-window)) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
523 (define-key archive-mode-map [menu-bar immediate find-file] |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
524 '("Find This File" . archive-extract)) |
11880 | 525 |
12024
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
526 (define-key archive-mode-map [menu-bar mark] |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
527 (cons "Mark" (make-sparse-keymap "Mark"))) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
528 (define-key archive-mode-map [menu-bar mark unmark-all] |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
529 '("Unmark All" . archive-unmark-all-files)) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
530 (define-key archive-mode-map [menu-bar mark deletion] |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
531 '("Flag" . archive-flag-deleted)) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
532 (define-key archive-mode-map [menu-bar mark unmark] |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
533 '("Unflag" . archive-unflag)) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
534 (define-key archive-mode-map [menu-bar mark mark] |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
535 '("Mark" . archive-mark)) |
11880 | 536 |
12024
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
537 (define-key archive-mode-map [menu-bar operate] |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
538 (cons "Operate" (make-sparse-keymap "Operate"))) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
539 (define-key archive-mode-map [menu-bar operate chown] |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
540 '("Change Owner..." . archive-chown-entry)) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
541 (put 'archive-chown-entry 'menu-enable |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
542 '(fboundp (archive-name "chown-entry"))) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
543 (define-key archive-mode-map [menu-bar operate chgrp] |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
544 '("Change Group..." . archive-chgrp-entry)) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
545 (put 'archive-chgrp-entry 'menu-enable |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
546 '(fboundp (archive-name "chgrp-entry"))) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
547 (define-key archive-mode-map [menu-bar operate chmod] |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
548 '("Change Mode..." . archive-chmod-entry)) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
549 (put 'archive-chmod-entry 'menu-enable |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
550 '(fboundp (archive-name "chmod-entry"))) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
551 (define-key archive-mode-map [menu-bar operate rename] |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
552 '("Rename to..." . archive-rename-entry)) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
553 (put 'archive-rename-entry 'menu-enable |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
554 '(fboundp (archive-name "rename-entry"))) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
555 ;;(define-key archive-mode-map [menu-bar operate copy] |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
556 ;; '("Copy to..." . archive-copy)) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
557 (define-key archive-mode-map [menu-bar operate expunge] |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
558 '("Expunge Marked Files" . archive-expunge)) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
559 )) |
11880 | 560 |
561 (let* ((item1 '(archive-subfile-mode " Archive")) | |
562 (item2 '(archive-subfile-dos " Dos")) | |
563 (items (if (memq system-type '(ms-dos windows-nt)) | |
564 (list item1) ; msdog has its own indicator | |
565 (list item1 item2)))) | |
566 (or (member item1 minor-mode-alist) | |
567 (setq minor-mode-alist (append items minor-mode-alist)))) | |
568 ;; ------------------------------------------------------------------------- | |
569 (defun archive-find-type () | |
570 (widen) | |
571 (goto-char (point-min)) | |
572 ;; The funny [] here make it unlikely that the .elc file will be treated | |
573 ;; as an archive by other software. | |
574 (let (case-fold-search) | |
575 (cond ((looking-at "[P]K\003\004") 'zip) | |
576 ((looking-at "..-l[hz][0-9]-") 'lzh) | |
577 ((looking-at "....................[\334]\247\304\375") 'zoo) | |
578 ((and (looking-at "\C-z") ; signature too simple, IMHO | |
579 (string-match "\\.[aA][rR][cC]$" | |
580 (or buffer-file-name (buffer-name)))) | |
581 'arc) | |
582 (t (error "Buffer format not recognized."))))) | |
583 ;; ------------------------------------------------------------------------- | |
584 (defun archive-summarize () | |
585 "Parse the contents of the archive file in the current buffer. | |
586 Place a dired-like listing on the front; | |
587 then narrow to it, so that only that listing | |
588 is visible (and the real data of the buffer is hidden)." | |
589 (widen) | |
590 (let (buffer-read-only) | |
591 (message "Parsing archive file...") | |
592 (buffer-disable-undo (current-buffer)) | |
593 (setq archive-files (funcall (archive-name "summarize"))) | |
594 (message "Parsing archive file...done.") | |
595 (setq archive-proper-file-start (point-marker)) | |
596 (narrow-to-region (point-min) (point)) | |
597 (set-buffer-modified-p nil) | |
598 (buffer-enable-undo)) | |
599 (goto-char archive-file-list-start) | |
600 (archive-next-line 0)) | |
601 | |
602 (defun archive-resummarize () | |
603 "Recreate the contents listing of an archive." | |
604 (let ((modified (buffer-modified-p)) | |
605 (no (archive-get-lineno)) | |
606 buffer-read-only) | |
607 (widen) | |
608 (delete-region (point-min) archive-proper-file-start) | |
609 (archive-summarize) | |
610 (set-buffer-modified-p modified) | |
611 (goto-char archive-file-list-start) | |
612 (archive-next-line no))) | |
613 | |
614 (defun archive-summarize-files (files) | |
16291 | 615 "Insert a description of a list of files annotated with proper mouse face." |
11880 | 616 (setq archive-file-list-start (point-marker)) |
617 (setq archive-file-name-indent (if files (aref (car files) 1) 0)) | |
618 ;; We don't want to do an insert for each element since that takes too | |
619 ;; long when the archive -- which has to be moved in memory -- is large. | |
620 (insert | |
621 (apply | |
622 (function concat) | |
623 (mapcar | |
12024
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
624 (function |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
625 (lambda (fil) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
626 ;; Using `concat' here copies the text also, so we can add |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
627 ;; properties without problems. |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
628 (let ((text (concat (aref fil 0) "\n"))) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
629 (if archive-lemacs |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
630 () ; out of luck |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
631 (put-text-property (aref fil 1) (aref fil 2) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
632 'mouse-face 'highlight |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
633 text)) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
634 text))) |
11880 | 635 files))) |
636 (setq archive-file-list-end (point-marker))) | |
637 | |
638 (defun archive-alternate-display () | |
12791
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
639 "Toggle alternative display. |
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
640 To avoid very long lines some archive mode don't show all information. |
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
641 This function changes the set of information shown for each files." |
11880 | 642 (interactive) |
643 (setq archive-alternate-display (not archive-alternate-display)) | |
644 (archive-resummarize)) | |
645 ;; ------------------------------------------------------------------------- | |
646 ;; Section: Local archive copy handling | |
647 | |
648 (defun archive-maybe-copy (archive) | |
649 (if archive-remote | |
650 (let ((start (point-max))) | |
651 (setq archive-local-name (expand-file-name | |
652 (file-name-nondirectory archive) | |
653 archive-tmpdir)) | |
654 (make-directory archive-tmpdir t) | |
655 (save-restriction | |
656 (widen) | |
657 (write-region start (point-max) archive-local-name nil 'nomessage)) | |
658 archive-local-name) | |
659 (if (buffer-modified-p) (save-buffer)) | |
660 archive)) | |
661 | |
662 (defun archive-maybe-update (unchanged) | |
663 (if archive-remote | |
664 (let ((name archive-local-name) | |
665 (modified (buffer-modified-p)) | |
666 buffer-read-only) | |
667 (if unchanged nil | |
668 (erase-buffer) | |
669 (insert-file-contents name) | |
670 (archive-mode t)) | |
671 (archive-delete-local name) | |
672 (if (not unchanged) | |
673 (message "Archive file must be saved for changes to take effect")) | |
674 (set-buffer-modified-p (or modified (not unchanged)))))) | |
675 | |
676 (defun archive-delete-local (name) | |
12791
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
677 "Delete file NAME and its parents up to and including `archive-tmpdir'." |
11880 | 678 (let ((again t) |
679 (top (directory-file-name (file-name-as-directory archive-tmpdir)))) | |
680 (condition-case nil | |
681 (delete-file name) | |
682 (error nil)) | |
683 (while again | |
684 (setq name (directory-file-name (file-name-directory name))) | |
685 (condition-case nil | |
686 (delete-directory name) | |
687 (error nil)) | |
688 (if (string= name top) (setq again nil))))) | |
689 ;; ------------------------------------------------------------------------- | |
690 ;; Section: Member extraction | |
691 | |
692 (defun archive-mouse-extract (event) | |
693 "Extract a file whose name you click on." | |
694 (interactive "e") | |
12024
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
695 (mouse-set-point event) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
696 (switch-to-buffer |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
697 (save-excursion |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
698 (archive-extract) |
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
699 (current-buffer)))) |
11880 | 700 |
701 (defun archive-extract (&optional other-window-p) | |
702 "In archive mode, extract this entry of the archive into its own buffer." | |
703 (interactive) | |
704 (let* ((view-p (eq other-window-p 'view)) | |
705 (descr (archive-get-descr)) | |
706 (ename (aref descr 0)) | |
707 (iname (aref descr 1)) | |
708 (archive-buffer (current-buffer)) | |
709 (arcdir default-directory) | |
710 (archive (buffer-file-name)) | |
711 (arcname (file-name-nondirectory archive)) | |
712 (bufname (concat (file-name-nondirectory iname) " (" arcname ")")) | |
713 (extractor (archive-name "extract")) | |
714 (read-only-p (or archive-read-only view-p)) | |
715 (buffer (get-buffer bufname)) | |
716 (just-created nil)) | |
717 (if buffer | |
718 nil | |
719 (setq archive (archive-maybe-copy archive)) | |
720 (setq buffer (get-buffer-create bufname)) | |
721 (setq just-created t) | |
722 (save-excursion | |
723 (set-buffer buffer) | |
724 (setq buffer-file-name | |
725 (expand-file-name (concat arcname ":" iname))) | |
726 (setq buffer-file-truename | |
727 (abbreviate-file-name buffer-file-name)) | |
728 ;; Set the default-directory to the dir of the superior buffer. | |
729 (setq default-directory arcdir) | |
730 (make-local-variable 'archive-superior-buffer) | |
731 (setq archive-superior-buffer archive-buffer) | |
732 (make-local-variable 'local-write-file-hooks) | |
733 (add-hook 'local-write-file-hooks 'archive-write-file-member) | |
734 (setq archive-subfile-mode descr) | |
16290
583e730756ef
(archive-mode, archive-extract, archive-check-dos)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
735 (setq archive-subfile-dos nil) |
583e730756ef
(archive-mode, archive-extract, archive-check-dos)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
736 (if (boundp 'default-buffer-file-type) |
583e730756ef
(archive-mode, archive-extract, archive-check-dos)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
737 (setq buffer-file-type t)) |
11880 | 738 (if (fboundp extractor) |
739 (funcall extractor archive ename) | |
740 (archive-*-extract archive ename (symbol-value extractor))) | |
741 (if archive-dos-members (archive-check-dos)) | |
742 (goto-char (point-min)) | |
743 (rename-buffer bufname) | |
744 (setq buffer-read-only read-only-p) | |
745 (setq buffer-undo-list nil) | |
746 (set-buffer-modified-p nil) | |
747 (setq buffer-saved-size (buffer-size)) | |
748 (normal-mode) | |
749 ;; Just in case an archive occurs inside another archive. | |
750 (if (eq major-mode 'archive-mode) | |
751 (setq archive-remote t)) | |
752 (run-hooks 'archive-extract-hooks)) | |
753 (archive-maybe-update t)) | |
754 (if view-p | |
755 (progn | |
756 (view-buffer buffer) | |
757 (and just-created (setq view-exit-action 'kill-buffer))) | |
758 (if (eq other-window-p 'display) | |
759 (display-buffer buffer) | |
760 (if other-window-p | |
761 (switch-to-buffer-other-window buffer) | |
762 (switch-to-buffer buffer)))))) | |
763 | |
764 (defun archive-*-extract (archive name command) | |
765 (let* ((default-directory (file-name-as-directory archive-tmpdir)) | |
766 (tmpfile (expand-file-name (file-name-nondirectory name) | |
767 default-directory))) | |
768 (make-directory (directory-file-name default-directory) t) | |
769 (apply 'call-process | |
770 (car command) | |
771 nil | |
772 nil | |
773 nil | |
774 (append (cdr command) (list archive name))) | |
775 (insert-file-contents tmpfile) | |
776 (archive-delete-local tmpfile))) | |
777 | |
778 (defun archive-extract-by-stdout (archive name command) | |
779 (let ((binary-process-output t)) ; for Ms-Dos | |
780 (apply 'call-process | |
781 (car command) | |
782 nil | |
783 t | |
784 nil | |
785 (append (cdr command) (list archive name))))) | |
786 | |
787 (defun archive-extract-other-window () | |
788 "In archive mode, find this member in another window." | |
789 (interactive) | |
790 (archive-extract t)) | |
791 | |
792 (defun archive-display-other-window () | |
793 "In archive mode, display this member in another window." | |
794 (interactive) | |
795 (archive-extract 'display)) | |
796 | |
797 (defun archive-view () | |
798 "In archive mode, view the member on this line." | |
799 (interactive) | |
800 (archive-extract 'view)) | |
801 | |
802 (defun archive-add-new-member (arcbuf name) | |
12791
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
803 "Add current buffer to the archive in ARCBUF naming it NAME." |
11880 | 804 (interactive |
805 (list (get-buffer | |
806 (read-buffer "Buffer containing archive: " | |
807 ;; Find first archive buffer and suggest that | |
808 (let ((bufs (buffer-list))) | |
809 (while (and bufs (not (eq (save-excursion | |
810 (set-buffer (car bufs)) | |
811 major-mode) | |
812 'archive-mode))) | |
813 (setq bufs (cdr bufs))) | |
814 (if bufs | |
815 (car bufs) | |
816 (error "There are no archive buffers"))) | |
817 t)) | |
818 (read-string "File name in archive: " | |
819 (if buffer-file-name | |
820 (file-name-nondirectory buffer-file-name) | |
821 "")))) | |
822 (save-excursion | |
823 (set-buffer arcbuf) | |
824 (or (eq major-mode 'archive-mode) | |
825 (error "Buffer is not an archive buffer")) | |
826 (if archive-read-only | |
827 (error "Archive is read-only"))) | |
828 (if (eq arcbuf (current-buffer)) | |
829 (error "An archive buffer cannot be added to itself")) | |
830 (if (string= name "") | |
831 (error "Archive members may not be given empty names")) | |
832 (let ((func (save-excursion (set-buffer arcbuf) | |
833 (archive-name "add-new-member"))) | |
834 (membuf (current-buffer))) | |
835 (if (fboundp func) | |
836 (save-excursion | |
837 (set-buffer arcbuf) | |
838 (funcall func buffer-file-name membuf name)) | |
839 (error "Adding a new member is not supported for this archive type")))) | |
840 ;; ------------------------------------------------------------------------- | |
841 ;; Section: IO stuff | |
842 | |
843 (defun archive-check-dos (&optional force) | |
12791
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
844 "*Possibly handle a buffer with ^M^J terminated lines." |
11880 | 845 (save-restriction |
846 (widen) | |
847 (save-excursion | |
848 (goto-char (point-min)) | |
849 (setq archive-subfile-dos | |
850 (or force (not (search-forward-regexp "[^\r]\n" nil t)))) | |
16290
583e730756ef
(archive-mode, archive-extract, archive-check-dos)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
851 (if (boundp 'default-buffer-file-type) |
583e730756ef
(archive-mode, archive-extract, archive-check-dos)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
852 (setq buffer-file-type (not archive-subfile-dos))) |
11880 | 853 (if archive-subfile-dos |
854 (let ((modified (buffer-modified-p))) | |
855 (buffer-disable-undo (current-buffer)) | |
856 (goto-char (point-min)) | |
857 (while (search-forward "\r\n" nil t) | |
858 (replace-match "\n")) | |
859 (buffer-enable-undo) | |
860 (set-buffer-modified-p modified)))))) | |
861 | |
862 (defun archive-write-file-member () | |
863 (if archive-subfile-dos | |
864 (save-restriction | |
865 (widen) | |
866 (save-excursion | |
867 (goto-char (point-min)) | |
868 ;; We don't want our ^M^J <--> ^J changes to show in the undo list | |
869 (let ((undo-list buffer-undo-list)) | |
870 (unwind-protect | |
871 (progn | |
872 (setq buffer-undo-list t) | |
873 (while (search-forward "\n" nil t) | |
874 (replace-match "\r\n")) | |
875 (setq archive-subfile-dos nil) | |
16290
583e730756ef
(archive-mode, archive-extract, archive-check-dos)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
876 (if (boundp 'default-buffer-file-type) |
583e730756ef
(archive-mode, archive-extract, archive-check-dos)
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
877 (setq buffer-file-type t)) |
11880 | 878 ;; OK, we're now have explicit ^M^Js -- save and re-unixfy |
879 (archive-write-file-member)) | |
880 (progn | |
881 (archive-check-dos t) | |
882 (setq buffer-undo-list undo-list)))) | |
883 t)) | |
884 (save-excursion | |
885 (save-restriction | |
886 (message "Updating archive...") | |
887 (widen) | |
888 (let ((writer (save-excursion (set-buffer archive-superior-buffer) | |
889 (archive-name "write-file-member"))) | |
890 (archive (save-excursion (set-buffer archive-superior-buffer) | |
891 (buffer-file-name)))) | |
892 (if (fboundp writer) | |
893 (funcall writer archive archive-subfile-mode) | |
894 (archive-*-write-file-member archive | |
895 archive-subfile-mode | |
896 (symbol-value writer)))) | |
897 (set-buffer-modified-p nil) | |
898 (message "Updating archive...done") | |
899 (set-buffer archive-superior-buffer) | |
900 (revert-buffer) | |
901 t)))) | |
902 | |
903 (defun archive-*-write-file-member (archive descr command) | |
904 (let* ((ename (aref descr 0)) | |
905 (tmpfile (expand-file-name ename archive-tmpdir)) | |
906 (top (directory-file-name (file-name-as-directory archive-tmpdir))) | |
907 (default-directory (file-name-as-directory top))) | |
908 (unwind-protect | |
909 (progn | |
910 (make-directory (file-name-directory tmpfile) t) | |
911 (write-region (point-min) (point-max) tmpfile nil 'nomessage) | |
912 (if (aref descr 3) | |
913 ;; Set the file modes, but make sure we can read it. | |
914 (set-file-modes tmpfile (logior ?\400 (aref descr 3)))) | |
915 (let ((exitcode (apply 'call-process | |
916 (car command) | |
917 nil | |
918 nil | |
919 nil | |
920 (append (cdr command) (list archive ename))))) | |
921 (if (equal exitcode 0) | |
922 nil | |
923 (error "Updating was unsuccessful (%S)" exitcode)))) | |
924 (archive-delete-local tmpfile)))) | |
925 | |
926 (defun archive-write-file () | |
927 (save-excursion | |
928 (write-region archive-proper-file-start (point-max) buffer-file-name nil t) | |
929 (set-buffer-modified-p nil) | |
930 t)) | |
931 ;; ------------------------------------------------------------------------- | |
932 ;; Section: Marking and unmarking. | |
933 | |
934 (defun archive-flag-deleted (p &optional type) | |
935 "In archive mode, mark this member to be deleted from the archive. | |
936 With a prefix argument, mark that many files." | |
937 (interactive "p") | |
938 (or type (setq type ?D)) | |
939 (beginning-of-line) | |
940 (let ((sign (if (>= p 0) +1 -1)) | |
941 (modified (buffer-modified-p)) | |
942 buffer-read-only) | |
943 (while (not (zerop p)) | |
944 (if (archive-get-descr t) | |
945 (progn | |
946 (delete-char 1) | |
947 (insert type))) | |
948 (forward-line sign) | |
949 (setq p (- p sign))) | |
950 (set-buffer-modified-p modified)) | |
951 (archive-next-line 0)) | |
952 | |
953 (defun archive-unflag (p) | |
954 "In archive mode, un-mark this member if it is marked to be deleted. | |
955 With a prefix argument, un-mark that many files forward." | |
956 (interactive "p") | |
957 (archive-flag-deleted p ? )) | |
958 | |
959 (defun archive-unflag-backwards (p) | |
960 "In archive mode, un-mark this member if it is marked to be deleted. | |
961 With a prefix argument, un-mark that many members backward." | |
962 (interactive "p") | |
963 (archive-flag-deleted (- p) ? )) | |
964 | |
965 (defun archive-unmark-all-files () | |
966 "Remove all marks." | |
967 (interactive) | |
968 (let ((modified (buffer-modified-p)) | |
969 buffer-read-only) | |
970 (save-excursion | |
971 (goto-char archive-file-list-start) | |
972 (while (< (point) archive-file-list-end) | |
973 (or (= (following-char) ? ) | |
974 (progn (delete-char 1) (insert ? ))) | |
975 (forward-line 1))) | |
976 (set-buffer-modified-p modified))) | |
977 | |
978 (defun archive-mark (p) | |
979 "In archive mode, mark this member for group operations. | |
980 With a prefix argument, mark that many members. | |
981 Use \\[archive-unmark-all-files] to remove all marks." | |
982 (interactive "p") | |
983 (archive-flag-deleted p ?*)) | |
984 | |
985 (defun archive-get-marked (mark &optional default) | |
986 (let (files) | |
987 (save-excursion | |
988 (goto-char archive-file-list-start) | |
989 (while (< (point) archive-file-list-end) | |
990 (if (= (following-char) mark) | |
991 (setq files (cons (archive-get-descr) files))) | |
992 (forward-line 1))) | |
993 (or (nreverse files) | |
994 (and default | |
995 (list (archive-get-descr)))))) | |
996 ;; ------------------------------------------------------------------------- | |
997 ;; Section: Operate | |
998 | |
999 (defun archive-next-line (p) | |
1000 (interactive "p") | |
1001 (forward-line p) | |
1002 (or (eobp) | |
1003 (forward-char archive-file-name-indent))) | |
1004 | |
1005 (defun archive-previous-line (p) | |
1006 (interactive "p") | |
1007 (archive-next-line (- p))) | |
1008 | |
1009 (defun archive-chmod-entry (new-mode) | |
12791
61bbb487bf2c
Standardize layout of doc strings.
Richard M. Stallman <rms@gnu.org>
parents:
12756
diff
changeset
|
1010 "Change the protection bits associated with all marked or this member. |
11880 | 1011 The new protection bits can either be specified as an octal number or |
1012 as a relative change like \"g+rw\" as for chmod(2)" | |
1013 (interactive "sNew mode (octal or relative): ") | |
1014 (if archive-read-only (error "Archive is read-only")) | |
1015 (let ((func (archive-name "chmod-entry"))) | |
1016 (if (fboundp func) | |
1017 (progn | |
1018 (funcall func new-mode (archive-get-marked ?* t)) | |
1019 (archive-resummarize)) | |
1020 (error "Setting mode bits is not supported for this archive type")))) | |
1021 | |
1022 (defun archive-chown-entry (new-uid) | |
1023 "Change the owner of all marked or this member." | |
1024 (interactive "nNew uid: ") | |
1025 (if archive-read-only (error "Archive is read-only")) | |
1026 (let ((func (archive-name "chown-entry"))) | |
1027 (if (fboundp func) | |
1028 (progn | |
1029 (funcall func new-uid (archive-get-marked ?* t)) | |
1030 (archive-resummarize)) | |
1031 (error "Setting owner is not supported for this archive type")))) | |
1032 | |
1033 (defun archive-chgrp-entry (new-gid) | |
1034 "Change the group of all marked or this member." | |
1035 (interactive "nNew gid: ") | |
1036 (if archive-read-only (error "Archive is read-only")) | |
1037 (let ((func (archive-name "chgrp-entry"))) | |
1038 (if (fboundp func) | |
1039 (progn | |
1040 (funcall func new-gid (archive-get-marked ?* t)) | |
1041 (archive-resummarize)) | |
1042 (error "Setting group is not supported for this archive type")))) | |
1043 | |
1044 (defun archive-expunge () | |
1045 "Do the flagged deletions." | |
1046 (interactive) | |
1047 (let (files) | |
1048 (save-excursion | |
1049 (goto-char archive-file-list-start) | |
1050 (while (< (point) archive-file-list-end) | |
1051 (if (= (following-char) ?D) | |
1052 (setq files (cons (aref (archive-get-descr) 0) files))) | |
1053 (forward-line 1))) | |
1054 (setq files (nreverse files)) | |
1055 (and files | |
1056 (or (not archive-read-only) | |
1057 (error "Archive is read-only")) | |
1058 (or (yes-or-no-p (format "Really delete %d member%s? " | |
1059 (length files) | |
1060 (if (null (cdr files)) "" "s"))) | |
1061 (error "Operation aborted")) | |
1062 (let ((archive (archive-maybe-copy (buffer-file-name))) | |
1063 (expunger (archive-name "expunge"))) | |
1064 (if (fboundp expunger) | |
1065 (funcall expunger archive files) | |
1066 (archive-*-expunge archive files (symbol-value expunger))) | |
1067 (archive-maybe-update nil) | |
1068 (if archive-remote | |
1069 (archive-resummarize) | |
1070 (revert-buffer)))))) | |
1071 | |
1072 (defun archive-*-expunge (archive files command) | |
1073 (apply 'call-process | |
1074 (car command) | |
1075 nil | |
1076 nil | |
1077 nil | |
1078 (append (cdr command) (cons archive files)))) | |
1079 | |
1080 (defun archive-rename-entry (newname) | |
1081 "Change the name associated with this entry in the tar file." | |
1082 (interactive "sNew name: ") | |
1083 (if archive-read-only (error "Archive is read-only")) | |
1084 (if (string= newname "") | |
1085 (error "Archive members may not be given empty names")) | |
1086 (let ((func (archive-name "rename-entry")) | |
1087 (descr (archive-get-descr))) | |
1088 (if (fboundp func) | |
1089 (progn | |
1090 (funcall func (buffer-file-name) newname descr) | |
1091 (archive-resummarize)) | |
1092 (error "Renaming is not supported for this archive type")))) | |
1093 | |
1094 ;; Revert the buffer and recompute the dired-like listing. | |
1095 (defun archive-mode-revert (&optional no-autosave no-confirm) | |
1096 (let ((no (archive-get-lineno))) | |
1097 (setq archive-files nil) | |
1098 (let ((revert-buffer-function nil)) | |
1099 (revert-buffer t t)) | |
1100 (archive-mode) | |
1101 (goto-char archive-file-list-start) | |
1102 (archive-next-line no))) | |
1103 | |
1104 (defun archive-undo () | |
1105 "Undo in an archive buffer. | |
1106 This doesn't recover lost files, it just undoes changes in the buffer itself." | |
1107 (interactive) | |
1108 (let (buffer-read-only) | |
1109 (undo))) | |
1110 ;; ------------------------------------------------------------------------- | |
1111 ;; Section: Arc Archives | |
1112 | |
1113 (defun archive-arc-summarize () | |
1114 (let ((p 1) | |
1115 (totalsize 0) | |
1116 (maxlen 8) | |
1117 files | |
1118 visual) | |
1119 (while (and (< (+ p 29) (point-max)) | |
1120 (= (char-after p) ?\C-z) | |
1121 (> (char-after (1+ p)) 0)) | |
1122 (let* ((namefld (buffer-substring (+ p 2) (+ p 2 13))) | |
1123 (fnlen (or (string-match "\0" namefld) 13)) | |
1124 (efnname (substring namefld 0 fnlen)) | |
1125 (csize (archive-l-e (+ p 15) 4)) | |
1126 (moddate (archive-l-e (+ p 19) 2)) | |
1127 (modtime (archive-l-e (+ p 21) 2)) | |
1128 (ucsize (archive-l-e (+ p 25) 4)) | |
1129 (fiddle (string= efnname (upcase efnname))) | |
1130 (ifnname (if fiddle (downcase efnname) efnname)) | |
1131 (text (format " %8d %-11s %-8s %s" | |
1132 ucsize | |
1133 (archive-dosdate moddate) | |
1134 (archive-dostime modtime) | |
1135 ifnname))) | |
1136 (setq maxlen (max maxlen fnlen) | |
1137 totalsize (+ totalsize ucsize) | |
1138 visual (cons (vector text | |
1139 (- (length text) (length ifnname)) | |
1140 (length text)) | |
1141 visual) | |
1142 files (cons (vector efnname ifnname fiddle nil (1- p)) | |
1143 files) | |
1144 p (+ p 29 csize)))) | |
1145 (goto-char (point-min)) | |
1146 (let ((dash (concat "- -------- ----------- -------- " | |
1147 (make-string maxlen ?-) | |
1148 "\n"))) | |
1149 (insert "M Length Date Time File\n" | |
1150 dash) | |
1151 (archive-summarize-files (nreverse visual)) | |
1152 (insert dash | |
1153 (format " %8d %d file%s" | |
1154 totalsize | |
1155 (length files) | |
1156 (if (= 1 (length files)) "" "s")) | |
1157 "\n")) | |
1158 (apply 'vector (nreverse files)))) | |
1159 | |
1160 (defun archive-arc-rename-entry (archive newname descr) | |
1161 (if (string-match "[:\\\\/]" newname) | |
1162 (error "File names in arc files may not contain a path")) | |
1163 (if (> (length newname) 12) | |
1164 (error "File names in arc files are limited to 12 characters")) | |
1165 (let ((name (concat newname (substring "\0\0\0\0\0\0\0\0\0\0\0\0\0" | |
1166 (length newname)))) | |
1167 buffer-read-only) | |
1168 (save-restriction | |
1169 (save-excursion | |
1170 (widen) | |
1171 (goto-char (+ archive-proper-file-start (aref descr 4) 2)) | |
1172 (delete-char 13) | |
1173 (insert name))))) | |
1174 ;; ------------------------------------------------------------------------- | |
1175 ;; Section: Lzh Archives | |
1176 | |
1177 (defun archive-lzh-summarize () | |
1178 (let ((p 1) | |
1179 (totalsize 0) | |
1180 (maxlen 8) | |
1181 files | |
1182 visual) | |
1183 (while (progn (goto-char p) (looking-at "..-l[hz][0-9]-")) | |
1184 (let* ((hsize (char-after p)) | |
1185 (csize (archive-l-e (+ p 7) 4)) | |
1186 (ucsize (archive-l-e (+ p 11) 4)) | |
1187 (modtime (archive-l-e (+ p 15) 2)) | |
1188 (moddate (archive-l-e (+ p 17) 2)) | |
1189 (fnlen (char-after (+ p 21))) | |
1190 (efnname (buffer-substring (+ p 22) (+ p 22 fnlen))) | |
1191 (fiddle (string= efnname (upcase efnname))) | |
1192 (ifnname (if fiddle (downcase efnname) efnname)) | |
1193 (p2 (+ p 22 fnlen)) | |
1194 (creator (if (>= (- hsize fnlen) 24) (char-after (+ p2 2)) 0)) | |
1195 (mode (if (= creator ?U) (archive-l-e (+ p2 8) 2) ?\666)) | |
1196 (modestr (if mode (archive-int-to-mode mode) "??????????")) | |
1197 (uid (if (= creator ?U) (archive-l-e (+ p2 10) 2))) | |
1198 (gid (if (= creator ?U) (archive-l-e (+ p2 12) 2))) | |
1199 (text (if archive-alternate-display | |
1200 (format " %8d %5S %5S %s" | |
1201 ucsize | |
1202 (or uid "?") | |
1203 (or gid "?") | |
1204 ifnname) | |
1205 (format " %10s %8d %-11s %-8s %s" | |
1206 modestr | |
1207 ucsize | |
1208 (archive-dosdate moddate) | |
1209 (archive-dostime modtime) | |
1210 ifnname)))) | |
1211 (setq maxlen (max maxlen fnlen) | |
1212 totalsize (+ totalsize ucsize) | |
1213 visual (cons (vector text | |
1214 (- (length text) (length ifnname)) | |
1215 (length text)) | |
1216 visual) | |
1217 files (cons (vector efnname ifnname fiddle mode (1- p)) | |
1218 files) | |
1219 p (+ p hsize 2 csize)))) | |
1220 (goto-char (point-min)) | |
1221 (let ((dash (concat (if archive-alternate-display | |
1222 "- -------- ----- ----- " | |
1223 "- ---------- -------- ----------- -------- ") | |
1224 (make-string maxlen ?-) | |
1225 "\n")) | |
1226 (header (if archive-alternate-display | |
1227 "M Length Uid Gid File\n" | |
1228 "M Filemode Length Date Time File\n")) | |
1229 (sumline (if archive-alternate-display | |
1230 " %8d %d file%s" | |
1231 " %8d %d file%s"))) | |
1232 (insert header dash) | |
1233 (archive-summarize-files (nreverse visual)) | |
1234 (insert dash | |
1235 (format sumline | |
1236 totalsize | |
1237 (length files) | |
1238 (if (= 1 (length files)) "" "s")) | |
1239 "\n")) | |
1240 (apply 'vector (nreverse files)))) | |
1241 | |
1242 (defconst archive-lzh-alternate-display t) | |
1243 | |
1244 (defun archive-lzh-extract (archive name) | |
1245 (archive-extract-by-stdout archive name archive-lzh-extract)) | |
1246 | |
1247 (defun archive-lzh-resum (p count) | |
1248 (let ((sum 0)) | |
1249 (while (> count 0) | |
1250 (setq count (1- count) | |
1251 sum (+ sum (char-after p)) | |
1252 p (1+ p))) | |
1253 (logand sum 255))) | |
1254 | |
1255 (defun archive-lzh-rename-entry (archive newname descr) | |
1256 (save-restriction | |
1257 (save-excursion | |
1258 (widen) | |
1259 (let* ((p (+ archive-proper-file-start (aref descr 4))) | |
1260 (oldhsize (char-after p)) | |
1261 (oldfnlen (char-after (+ p 21))) | |
1262 (newfnlen (length newname)) | |
1263 (newhsize (+ oldhsize newfnlen (- oldfnlen))) | |
1264 buffer-read-only) | |
1265 (if (> newhsize 255) | |
1266 (error "The file name is too long")) | |
1267 (goto-char (+ p 21)) | |
1268 (delete-char (1+ oldfnlen)) | |
1269 (insert newfnlen newname) | |
1270 (goto-char p) | |
1271 (delete-char 2) | |
1272 (insert newhsize (archive-lzh-resum p newhsize)))))) | |
1273 | |
1274 (defun archive-lzh-ogm (newval files errtxt ofs) | |
1275 (save-restriction | |
1276 (save-excursion | |
1277 (widen) | |
1278 (while files | |
1279 (let* ((fil (car files)) | |
1280 (p (+ archive-proper-file-start (aref fil 4))) | |
1281 (hsize (char-after p)) | |
1282 (fnlen (char-after (+ p 21))) | |
1283 (p2 (+ p 22 fnlen)) | |
1284 (creator (if (>= (- hsize fnlen) 24) (char-after (+ p2 2)) 0)) | |
1285 buffer-read-only) | |
1286 (if (= creator ?U) | |
1287 (progn | |
1288 (or (numberp newval) | |
1289 (setq newval (funcall newval (archive-l-e (+ p2 ofs) 2)))) | |
1290 (goto-char (+ p2 ofs)) | |
1291 (delete-char 2) | |
1292 (insert (logand newval 255) (lsh newval -8)) | |
1293 (goto-char (1+ p)) | |
1294 (delete-char 1) | |
1295 (insert (archive-lzh-resum (1+ p) hsize))) | |
1296 (message "Member %s does not have %s field" | |
1297 (aref fil 1) errtxt))) | |
1298 (setq files (cdr files)))))) | |
1299 | |
1300 (defun archive-lzh-chown-entry (newuid files) | |
1301 (archive-lzh-ogm newuid files "an uid" 10)) | |
1302 | |
1303 (defun archive-lzh-chgrp-entry (newgid files) | |
1304 (archive-lzh-ogm newgid files "a gid" 12)) | |
1305 | |
1306 (defun archive-lzh-chmod-entry (newmode files) | |
1307 (archive-lzh-ogm | |
1308 ;; This should work even though newmode will be dynamically accessed. | |
12024
8e31a35ac027
(archive-lemacs): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
11887
diff
changeset
|
1309 (function (lambda (old) (archive-calc-mode old newmode t))) |
11880 | 1310 files "a unix-style mode" 8)) |
1311 ;; ------------------------------------------------------------------------- | |
1312 ;; Section: Zip Archives | |
1313 | |
1314 (defun archive-zip-summarize () | |
1315 (goto-char (- (point-max) (- 22 18))) | |
1316 (search-backward-regexp "[P]K\005\006") | |
1317 (let ((p (1+ (archive-l-e (+ (point) 16) 4))) | |
1318 (maxlen 8) | |
1319 (totalsize 0) | |
1320 files | |
1321 visual) | |
1322 (while (string= "PK\001\002" (buffer-substring p (+ p 4))) | |
1323 (let* ((creator (char-after (+ p 5))) | |
1324 (method (archive-l-e (+ p 10) 2)) | |
1325 (modtime (archive-l-e (+ p 12) 2)) | |
1326 (moddate (archive-l-e (+ p 14) 2)) | |
1327 (ucsize (archive-l-e (+ p 24) 4)) | |
1328 (fnlen (archive-l-e (+ p 28) 2)) | |
1329 (exlen (archive-l-e (+ p 30) 2)) | |
12304
3cf4df625c3b
(archive-zip-summarize): Handle per-file comments in central directory.
Richard M. Stallman <rms@gnu.org>
parents:
12024
diff
changeset
|
1330 (fclen (archive-l-e (+ p 32) 2)) |
11880 | 1331 (lheader (archive-l-e (+ p 42) 4)) |
1332 (efnname (buffer-substring (+ p 46) (+ p 46 fnlen))) | |
1333 (isdir (and (= ucsize 0) | |
1334 (string= (file-name-nondirectory efnname) ""))) | |
1335 (mode (cond ((memq creator '(2 3)) ; Unix + VMS | |
1336 (archive-l-e (+ p 40) 2)) | |
1337 ((memq creator '(0 5 6 7 10 11)) ; Dos etc. | |
1338 (logior ?\444 | |
1339 (if isdir (logior 16384 ?\111) 0) | |
1340 (if (zerop | |
1341 (logand 1 (char-after (+ p 38)))) | |
1342 ?\222 0))) | |
1343 (t nil))) | |
1344 (modestr (if mode (archive-int-to-mode mode) "??????????")) | |
1345 (fiddle (and archive-zip-case-fiddle | |
1346 (not (not (memq creator '(0 2 4 5 9)))))) | |
1347 (ifnname (if fiddle (downcase efnname) efnname)) | |
1348 (text (format " %10s %8d %-11s %-8s %s" | |
1349 modestr | |
1350 ucsize | |
1351 (archive-dosdate moddate) | |
1352 (archive-dostime modtime) | |
1353 ifnname))) | |
1354 (setq maxlen (max maxlen fnlen) | |
1355 totalsize (+ totalsize ucsize) | |
1356 visual (cons (vector text | |
1357 (- (length text) (length ifnname)) | |
1358 (length text)) | |
1359 visual) | |
1360 files (cons (if isdir | |
1361 nil | |
1362 (vector efnname ifnname fiddle mode | |
1363 (list (1- p) lheader))) | |
1364 files) | |
12304
3cf4df625c3b
(archive-zip-summarize): Handle per-file comments in central directory.
Richard M. Stallman <rms@gnu.org>
parents:
12024
diff
changeset
|
1365 p (+ p 46 fnlen exlen fclen)))) |
11880 | 1366 (goto-char (point-min)) |
1367 (let ((dash (concat "- ---------- -------- ----------- -------- " | |
1368 (make-string maxlen ?-) | |
1369 "\n"))) | |
1370 (insert "M Filemode Length Date Time File\n" | |
1371 dash) | |
1372 (archive-summarize-files (nreverse visual)) | |
1373 (insert dash | |
1374 (format " %8d %d file%s" | |
1375 totalsize | |
1376 (length files) | |
1377 (if (= 1 (length files)) "" "s")) | |
1378 "\n")) | |
1379 (apply 'vector (nreverse files)))) | |
1380 | |
1381 (defun archive-zip-extract (archive name) | |
1382 (if archive-zip-use-pkzip | |
1383 (archive-*-extract archive name archive-zip-extract) | |
1384 (archive-extract-by-stdout archive name archive-zip-extract))) | |
1385 | |
1386 (defun archive-zip-write-file-member (archive descr) | |
1387 (archive-*-write-file-member | |
1388 archive | |
1389 descr | |
1390 (if (aref descr 2) archive-zip-update-case archive-zip-update))) | |
1391 | |
1392 (defun archive-zip-chmod-entry (newmode files) | |
1393 (save-restriction | |
1394 (save-excursion | |
1395 (widen) | |
1396 (while files | |
1397 (let* ((fil (car files)) | |
1398 (p (+ archive-proper-file-start (car (aref fil 4)))) | |
1399 (creator (char-after (+ p 5))) | |
1400 (oldmode (aref fil 3)) | |
1401 (newval (archive-calc-mode oldmode newmode t)) | |
1402 buffer-read-only) | |
1403 (cond ((memq creator '(2 3)) ; Unix + VMS | |
1404 (goto-char (+ p 40)) | |
1405 (delete-char 2) | |
1406 (insert (logand newval 255) (lsh newval -8))) | |
1407 ((memq creator '(0 5 6 7 10 11)) ; Dos etc. | |
1408 (goto-char (+ p 38)) | |
1409 (insert (logior (logand (char-after (point)) 254) | |
1410 (logand (logxor 1 (lsh newval -7)) 1))) | |
1411 (delete-char 1)) | |
1412 (t (message "Don't know how to change mode for this member")))) | |
1413 (setq files (cdr files)))))) | |
1414 ;; ------------------------------------------------------------------------- | |
1415 ;; Section: Zoo Archives | |
1416 | |
1417 (defun archive-zoo-summarize () | |
1418 (let ((p (1+ (archive-l-e 25 4))) | |
1419 (maxlen 8) | |
1420 (totalsize 0) | |
1421 files | |
1422 visual) | |
1423 (while (and (string= "\334\247\304\375" (buffer-substring p (+ p 4))) | |
1424 (> (archive-l-e (+ p 6) 4) 0)) | |
1425 (let* ((next (1+ (archive-l-e (+ p 6) 4))) | |
1426 (moddate (archive-l-e (+ p 14) 2)) | |
1427 (modtime (archive-l-e (+ p 16) 2)) | |
1428 (ucsize (archive-l-e (+ p 20) 4)) | |
1429 (namefld (buffer-substring (+ p 38) (+ p 38 13))) | |
13339
13b7b667b18f
(archive-zoo-summarize): Handle archives with long file names.
Richard M. Stallman <rms@gnu.org>
parents:
12791
diff
changeset
|
1430 (dirtype (char-after (+ p 4))) |
13b7b667b18f
(archive-zoo-summarize): Handle archives with long file names.
Richard M. Stallman <rms@gnu.org>
parents:
12791
diff
changeset
|
1431 (lfnlen (if (= dirtype 2) (char-after (+ p 56)) 0)) |
13b7b667b18f
(archive-zoo-summarize): Handle archives with long file names.
Richard M. Stallman <rms@gnu.org>
parents:
12791
diff
changeset
|
1432 (ldirlen (if (= dirtype 2) (char-after (+ p 57)) 0)) |
13b7b667b18f
(archive-zoo-summarize): Handle archives with long file names.
Richard M. Stallman <rms@gnu.org>
parents:
12791
diff
changeset
|
1433 (fnlen (+ ldirlen |
13b7b667b18f
(archive-zoo-summarize): Handle archives with long file names.
Richard M. Stallman <rms@gnu.org>
parents:
12791
diff
changeset
|
1434 (if (> lfnlen 0) |
13b7b667b18f
(archive-zoo-summarize): Handle archives with long file names.
Richard M. Stallman <rms@gnu.org>
parents:
12791
diff
changeset
|
1435 (1- lfnlen) |
13b7b667b18f
(archive-zoo-summarize): Handle archives with long file names.
Richard M. Stallman <rms@gnu.org>
parents:
12791
diff
changeset
|
1436 (or (string-match "\0" namefld) 13)))) |
13b7b667b18f
(archive-zoo-summarize): Handle archives with long file names.
Richard M. Stallman <rms@gnu.org>
parents:
12791
diff
changeset
|
1437 (efnname (concat |
13b7b667b18f
(archive-zoo-summarize): Handle archives with long file names.
Richard M. Stallman <rms@gnu.org>
parents:
12791
diff
changeset
|
1438 (if (> ldirlen 0) |
13b7b667b18f
(archive-zoo-summarize): Handle archives with long file names.
Richard M. Stallman <rms@gnu.org>
parents:
12791
diff
changeset
|
1439 (concat (buffer-substring |
13b7b667b18f
(archive-zoo-summarize): Handle archives with long file names.
Richard M. Stallman <rms@gnu.org>
parents:
12791
diff
changeset
|
1440 (+ p 58 lfnlen) (+ p 58 lfnlen ldirlen -1)) |
13b7b667b18f
(archive-zoo-summarize): Handle archives with long file names.
Richard M. Stallman <rms@gnu.org>
parents:
12791
diff
changeset
|
1441 "/") |
13b7b667b18f
(archive-zoo-summarize): Handle archives with long file names.
Richard M. Stallman <rms@gnu.org>
parents:
12791
diff
changeset
|
1442 "") |
13b7b667b18f
(archive-zoo-summarize): Handle archives with long file names.
Richard M. Stallman <rms@gnu.org>
parents:
12791
diff
changeset
|
1443 (if (> lfnlen 0) |
13b7b667b18f
(archive-zoo-summarize): Handle archives with long file names.
Richard M. Stallman <rms@gnu.org>
parents:
12791
diff
changeset
|
1444 (buffer-substring (+ p 58) (+ p 58 lfnlen -1)) |
13b7b667b18f
(archive-zoo-summarize): Handle archives with long file names.
Richard M. Stallman <rms@gnu.org>
parents:
12791
diff
changeset
|
1445 (substring namefld 0 fnlen)))) |
13b7b667b18f
(archive-zoo-summarize): Handle archives with long file names.
Richard M. Stallman <rms@gnu.org>
parents:
12791
diff
changeset
|
1446 (fiddle (and (= lfnlen 0) (string= efnname (upcase efnname)))) |
11880 | 1447 (ifnname (if fiddle (downcase efnname) efnname)) |
1448 (text (format " %8d %-11s %-8s %s" | |
1449 ucsize | |
1450 (archive-dosdate moddate) | |
1451 (archive-dostime modtime) | |
1452 ifnname))) | |
1453 (setq maxlen (max maxlen fnlen) | |
1454 totalsize (+ totalsize ucsize) | |
1455 visual (cons (vector text | |
1456 (- (length text) (length ifnname)) | |
1457 (length text)) | |
1458 visual) | |
1459 files (cons (vector efnname ifnname fiddle nil (1- p)) | |
1460 files) | |
1461 p next))) | |
1462 (goto-char (point-min)) | |
1463 (let ((dash (concat "- -------- ----------- -------- " | |
1464 (make-string maxlen ?-) | |
1465 "\n"))) | |
1466 (insert "M Length Date Time File\n" | |
1467 dash) | |
1468 (archive-summarize-files (nreverse visual)) | |
1469 (insert dash | |
1470 (format " %8d %d file%s" | |
1471 totalsize | |
1472 (length files) | |
1473 (if (= 1 (length files)) "" "s")) | |
1474 "\n")) | |
1475 (apply 'vector (nreverse files)))) | |
1476 | |
1477 (defun archive-zoo-extract (archive name) | |
1478 (archive-extract-by-stdout archive name archive-zoo-extract)) | |
1479 ;; ------------------------------------------------------------------------- | |
1480 (provide 'archive-mode) | |
1481 | |
1482 ;; arc-mode.el ends here. |