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