Fix up comment convention on the arch-tag lines.
[bpt/emacs.git] / lisp / obsolete / uncompress.el
1 ;;; uncompress.el --- auto-decompression hook for visiting .Z files
2
3 ;; Copyright (C) 1992, 1994, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
5
6 ;; Maintainer: FSF
7 ;; Keywords: files
8
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 3, 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., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
25
26 ;;; Commentary:
27
28 ;; This package can be used to arrange for automatic uncompress of
29 ;; compressed files when they are visited.
30 ;; All that's necessary is to load it. This can conveniently be done from
31 ;; your .emacs file.
32
33 ;; M-x auto-compression-mode is a more modern replacement for this package.
34
35 ;;; Code:
36
37 ;; When we are about to make a backup file,
38 ;; uncompress the file we visited
39 ;; so that making the backup can work properly.
40 ;; This is used as a write-file-hook.
41
42 (defvar uncompress-program "gunzip"
43 "Program to use for uncompression.")
44
45 (defun uncompress-backup-file ()
46 (and buffer-file-name make-backup-files (not buffer-backed-up)
47 (not (file-exists-p buffer-file-name))
48 (call-process uncompress-program nil nil nil buffer-file-name))
49 nil)
50
51 (or (assoc "\\.Z$" auto-mode-alist)
52 (setq auto-mode-alist
53 (cons '("\\.Z$" . uncompress-while-visiting) auto-mode-alist)))
54 (or (assoc "\\.gz$" auto-mode-alist)
55 (setq auto-mode-alist
56 (cons '("\\.gz$" . uncompress-while-visiting) auto-mode-alist)))
57 (or (assoc "\\.tgz$" auto-mode-alist)
58 (setq auto-mode-alist
59 (cons '("\\.tgz$" . uncompress-while-visiting) auto-mode-alist)))
60
61 (defun uncompress-while-visiting ()
62 "Temporary \"major mode\" used for .Z and .gz files, to uncompress them.
63 It then selects a major mode from the uncompressed file name and contents."
64 (if (and (not (null buffer-file-name))
65 (string-match "\\.Z$" buffer-file-name))
66 (set-visited-file-name
67 (substring buffer-file-name 0 (match-beginning 0)))
68 (if (and (not (null buffer-file-name))
69 (string-match "\\.gz$" buffer-file-name))
70 (set-visited-file-name
71 (substring buffer-file-name 0 (match-beginning 0)))
72 (if (and (not (null buffer-file-name))
73 (string-match "\\.tgz$" buffer-file-name))
74 (set-visited-file-name
75 (concat (substring buffer-file-name 0 (match-beginning 0)) ".tar")))))
76 (message "Uncompressing...")
77 (let ((buffer-read-only nil)
78 (coding-system-for-write 'no-conversion)
79 (coding-system-for-read
80 (car (find-operation-coding-system
81 'insert-file-contents
82 buffer-file-name t))))
83 (shell-command-on-region (point-min) (point-max) uncompress-program t))
84 (goto-char (point-min))
85 (message "Uncompressing...done")
86 (set-buffer-modified-p nil)
87 (add-hook 'write-file-functions 'uncompress-backup-file nil t)
88 (normal-mode))
89
90 (add-hook 'find-file-not-found-functions 'find-compressed-version)
91
92 (defun find-compressed-version ()
93 "Hook to read and uncompress the compressed version of a file."
94 ;; Just pretend we had visited the compressed file,
95 ;; and uncompress-while-visiting will do the rest.
96 (let (name)
97 (if (file-exists-p (setq name (concat buffer-file-name ".Z")))
98 (setq buffer-file-name name)
99 (if (file-exists-p (setq name (concat buffer-file-name ".gz")))
100 (setq buffer-file-name name)))
101 (if (eq name buffer-file-name)
102 (progn
103 (insert-file-contents buffer-file-name t)
104 (goto-char (point-min))
105 ;; No need for this, because error won't be set to t
106 ;; if this function returns t.
107 ;; (setq error nil)
108 t))))
109
110 (message "The uncompress package is obsolete; use M-x auto-compression-mode")
111
112 (provide 'uncompress)
113
114 ;; arch-tag: 626658d4-fcce-499a-990d-d165f2ed7da3
115 ;;; uncompress.el ends here