annotate lisp/packages/uncompress.el @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children ac2d302a0011
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; Synched up with: Not synched with FSF. Close though.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;;; #### This loser doesn't even provide .gz support here!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;;; FSF's version does.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;;; uncompress.el --- auto-decompression hook for visiting .Z files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Keywords: unix extensions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; ============================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; NOTE: crypt.el is a much more complete version of this hack.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; ============================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; When we are about to make a backup file,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; uncompress the file we visited
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; so that making the backup can work properly.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; This is used as a write-file-hook.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 (defun uncompress-backup-file ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 (and buffer-file-name make-backup-files (not buffer-backed-up)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 (not (file-exists-p buffer-file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 (call-process "uncompress" nil nil nil buffer-file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 (or (assoc "\\.Z$" auto-mode-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 (setq auto-mode-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 (cons '("\\.Z$" . uncompress-while-visiting) auto-mode-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 (defun uncompress-while-visiting ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 "Temporary \"major mode\" used for .Z files, to uncompress the contents.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 It then selects a major mode from the uncompressed file name and contents."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 (if (and (not (null buffer-file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 (string-match "\\.Z$" buffer-file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 (set-visited-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 (substring buffer-file-name 0 (match-beginning 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 (message "Uncompressing...")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 (let ((buffer-read-only nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 (shell-command-on-region (point-min) (point-max) "uncompress" t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 (message "Uncompressing...done")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 (set-buffer-modified-p nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 (make-local-variable 'write-file-hooks)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 (or (memq 'uncompress-backup-file write-file-hooks)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 (setq write-file-hooks (cons 'uncompress-backup-file write-file-hooks)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 (normal-mode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (or (memq 'find-compressed-version find-file-not-found-hooks)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 (setq find-file-not-found-hooks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 (cons 'find-compressed-version find-file-not-found-hooks)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (defun find-compressed-version ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 "Hook to read and uncompress the compressed version of a file."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ;; Just pretend we had visited the compressed file,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ;; and uncompress-while-visiting will do the rest.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 (if (file-exists-p (concat buffer-file-name ".Z"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 (setq buffer-file-name (concat buffer-file-name ".Z"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 (insert-file-contents buffer-file-name t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (setq error nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 t)))