annotate lisp/obsolete/uncompress.el @ 74897:3dd44b8cf2b9

** Report that datagrams don't work on Windows. Done by KFS.
author Chong Yidong <cyd@stupidchicken.com>
date Mon, 25 Dec 2006 18:09:08 +0000
parents e8a3fb527b77
children e3694f1cb928 c5406394f567
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
39125
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1 ;;; uncompress.el --- auto-decompression hook for visiting .Z files
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
2
64751
5b1a238fcbb4 Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 64085
diff changeset
3 ;; Copyright (C) 1992, 1994, 2001, 2002, 2003, 2004,
68640
e8a3fb527b77 Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 64751
diff changeset
4 ;; 2005, 2006 Free Software Foundation, Inc.
39125
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
5
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
6 ;; Maintainer: FSF
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
7 ;; Keywords: files
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
8
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
10
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
14 ;; any later version.
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
15
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
19 ;; GNU General Public License for more details.
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
20
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
64085
18a818a2ee7c Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 62189
diff changeset
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18a818a2ee7c Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 62189
diff changeset
24 ;; Boston, MA 02110-1301, USA.
39125
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
25
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
26 ;;; Commentary:
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
27
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
28 ;; This package can be used to arrange for automatic uncompress of
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
29 ;; compressed files when they are visited.
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
30 ;; All that's necessary is to load it. This can conveniently be done from
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
31 ;; your .emacs file.
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
32
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
33 ;; M-x auto-compression-mode is a more modern replacement for this package.
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
34
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
35 ;;; Code:
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
36
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
37 ;; When we are about to make a backup file,
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
38 ;; uncompress the file we visited
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
39 ;; so that making the backup can work properly.
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
40 ;; This is used as a write-file-hook.
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
41
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
42 (defvar uncompress-program "gunzip"
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
43 "Program to use for uncompression.")
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
44
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
45 (defun uncompress-backup-file ()
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
46 (and buffer-file-name make-backup-files (not buffer-backed-up)
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
47 (not (file-exists-p buffer-file-name))
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
48 (call-process uncompress-program nil nil nil buffer-file-name))
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
49 nil)
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
50
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
51 (or (assoc "\\.Z$" auto-mode-alist)
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
52 (setq auto-mode-alist
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
53 (cons '("\\.Z$" . uncompress-while-visiting) auto-mode-alist)))
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
54 (or (assoc "\\.gz$" auto-mode-alist)
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
55 (setq auto-mode-alist
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
56 (cons '("\\.gz$" . uncompress-while-visiting) auto-mode-alist)))
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
57 (or (assoc "\\.tgz$" auto-mode-alist)
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
58 (setq auto-mode-alist
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
59 (cons '("\\.tgz$" . uncompress-while-visiting) auto-mode-alist)))
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
60
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
61 (defun uncompress-while-visiting ()
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
62 "Temporary \"major mode\" used for .Z and .gz files, to uncompress them.
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
63 It then selects a major mode from the uncompressed file name and contents."
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
64 (if (and (not (null buffer-file-name))
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
65 (string-match "\\.Z$" buffer-file-name))
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
66 (set-visited-file-name
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
67 (substring buffer-file-name 0 (match-beginning 0)))
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
68 (if (and (not (null buffer-file-name))
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
69 (string-match "\\.gz$" buffer-file-name))
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
70 (set-visited-file-name
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
71 (substring buffer-file-name 0 (match-beginning 0)))
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
72 (if (and (not (null buffer-file-name))
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
73 (string-match "\\.tgz$" buffer-file-name))
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
74 (set-visited-file-name
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
75 (concat (substring buffer-file-name 0 (match-beginning 0)) ".tar")))))
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
76 (message "Uncompressing...")
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
77 (let ((buffer-read-only nil)
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
78 (coding-system-for-write 'no-conversion)
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
79 (coding-system-for-read
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
80 (car (find-operation-coding-system
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
81 'insert-file-contents
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
82 buffer-file-name t))))
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
83 (shell-command-on-region (point-min) (point-max) uncompress-program t))
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
84 (goto-char (point-min))
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
85 (message "Uncompressing...done")
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
86 (set-buffer-modified-p nil)
62189
0cbd8db584f6 Set `find-file-not-found-functions', not `find-file-not-found-hooks'; use
Juanma Barranquero <lekktu@gmail.com>
parents: 52401
diff changeset
87 (add-hook 'write-file-functions 'uncompress-backup-file nil t)
39125
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
88 (normal-mode))
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
89
62189
0cbd8db584f6 Set `find-file-not-found-functions', not `find-file-not-found-hooks'; use
Juanma Barranquero <lekktu@gmail.com>
parents: 52401
diff changeset
90 (add-hook 'find-file-not-found-functions 'find-compressed-version)
39125
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
91
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
92 (defun find-compressed-version ()
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
93 "Hook to read and uncompress the compressed version of a file."
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
94 ;; Just pretend we had visited the compressed file,
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
95 ;; and uncompress-while-visiting will do the rest.
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
96 (let (name)
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
97 (if (file-exists-p (setq name (concat buffer-file-name ".Z")))
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
98 (setq buffer-file-name name)
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
99 (if (file-exists-p (setq name (concat buffer-file-name ".gz")))
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
100 (setq buffer-file-name name)))
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
101 (if (eq name buffer-file-name)
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
102 (progn
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
103 (insert-file-contents buffer-file-name t)
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
104 (goto-char (point-min))
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
105 ;; No need for this, because error won't be set to t
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
106 ;; if this function returns t.
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
107 ;; (setq error nil)
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
108 t))))
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
109
49072
03a8f1957f3e Display message that this package is obsolete.
Richard M. Stallman <rms@gnu.org>
parents: 39125
diff changeset
110 (message "The uncompress package is obsolete; use M-x auto-compression-mode")
03a8f1957f3e Display message that this package is obsolete.
Richard M. Stallman <rms@gnu.org>
parents: 39125
diff changeset
111
39125
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
112 (provide 'uncompress)
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
113
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 49072
diff changeset
114 ;;; arch-tag: 626658d4-fcce-499a-990d-d165f2ed7da3
39125
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
115 ;;; uncompress.el ends here