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