1 (defun uncompress-while-visiting ()
2 "Temporary \"major mode\" used for .Z files, to uncompress the contents.
3 It then selects a major mode from the uncompressed file name and contents."
4 (if (and (not (null buffer-file-name
))
5 (string-match "\\.Z$" buffer-file-name
))
7 (substring buffer-file-name
0 (match-beginning 0))))
8 (message "Uncompressing...")
9 (let ((buffer-read-only nil
))
10 (shell-command-on-region (point-min) (point-max) "uncompress" t
))
11 (message "Uncompressing...done")
12 (set-buffer-modified-p nil
)
16 (cons '("\\.Z$" . uncompress-while-visiting
) auto-mode-alist
))
18 (defun find-compressed-version ()
19 "Hook to read and uncompress the compressed version of a file."
20 ;; Just pretend we had visited the compressed file,
21 ;; and uncompress-while-visiting will do the rest.
22 (if (file-exists-p (concat buffer-file-name
".Z"))
24 (setq buffer-file-name
(concat buffer-file-name
".Z"))
25 (insert-file-contents buffer-file-name t
)
26 (goto-char (point-min))
30 (setq find-file-not-found-hooks
31 (cons 'find-compressed-version find-file-not-found-hooks
))