Mercurial > emacs
annotate lisp/obsolete/uncompress.el @ 94000:ee22366f2a68
Add a comment giving version of obsolescence.
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Fri, 11 Apr 2008 07:44:49 +0000 |
parents | 1e3a407766b9 |
children | 43d30a1ea764 |
rev | line source |
---|---|
39125 | 1 ;;; uncompress.el --- auto-decompression hook for visiting .Z files |
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, |
79715 | 4 ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc. |
39125 | 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 | |
78228
1e016d63f292
Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents:
75347
diff
changeset
|
13 ;; the Free Software Foundation; either version 3, or (at your option) |
39125 | 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 | |
64085 | 23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
24 ;; Boston, MA 02110-1301, USA. | |
39125 | 25 |
26 ;;; Commentary: | |
27 | |
94000
ee22366f2a68
Add a comment giving version of obsolescence.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
28 ;; This file has been obsolete since Emacs 21.1. |
ee22366f2a68
Add a comment giving version of obsolescence.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
29 |
39125 | 30 ;; This package can be used to arrange for automatic uncompress of |
31 ;; compressed files when they are visited. | |
32 ;; All that's necessary is to load it. This can conveniently be done from | |
33 ;; your .emacs file. | |
34 | |
35 ;; M-x auto-compression-mode is a more modern replacement for this package. | |
36 | |
37 ;;; Code: | |
38 | |
39 ;; When we are about to make a backup file, | |
40 ;; uncompress the file we visited | |
41 ;; so that making the backup can work properly. | |
42 ;; This is used as a write-file-hook. | |
43 | |
44 (defvar uncompress-program "gunzip" | |
45 "Program to use for uncompression.") | |
46 | |
47 (defun uncompress-backup-file () | |
48 (and buffer-file-name make-backup-files (not buffer-backed-up) | |
49 (not (file-exists-p buffer-file-name)) | |
50 (call-process uncompress-program nil nil nil buffer-file-name)) | |
51 nil) | |
52 | |
53 (or (assoc "\\.Z$" auto-mode-alist) | |
54 (setq auto-mode-alist | |
55 (cons '("\\.Z$" . uncompress-while-visiting) auto-mode-alist))) | |
56 (or (assoc "\\.gz$" auto-mode-alist) | |
57 (setq auto-mode-alist | |
58 (cons '("\\.gz$" . uncompress-while-visiting) auto-mode-alist))) | |
59 (or (assoc "\\.tgz$" auto-mode-alist) | |
60 (setq auto-mode-alist | |
61 (cons '("\\.tgz$" . uncompress-while-visiting) auto-mode-alist))) | |
62 | |
63 (defun uncompress-while-visiting () | |
64 "Temporary \"major mode\" used for .Z and .gz files, to uncompress them. | |
65 It then selects a major mode from the uncompressed file name and contents." | |
66 (if (and (not (null buffer-file-name)) | |
67 (string-match "\\.Z$" buffer-file-name)) | |
68 (set-visited-file-name | |
69 (substring buffer-file-name 0 (match-beginning 0))) | |
70 (if (and (not (null buffer-file-name)) | |
71 (string-match "\\.gz$" buffer-file-name)) | |
72 (set-visited-file-name | |
73 (substring buffer-file-name 0 (match-beginning 0))) | |
74 (if (and (not (null buffer-file-name)) | |
75 (string-match "\\.tgz$" buffer-file-name)) | |
76 (set-visited-file-name | |
77 (concat (substring buffer-file-name 0 (match-beginning 0)) ".tar"))))) | |
78 (message "Uncompressing...") | |
79 (let ((buffer-read-only nil) | |
80 (coding-system-for-write 'no-conversion) | |
81 (coding-system-for-read | |
82 (car (find-operation-coding-system | |
83 'insert-file-contents | |
84 buffer-file-name t)))) | |
85 (shell-command-on-region (point-min) (point-max) uncompress-program t)) | |
86 (goto-char (point-min)) | |
87 (message "Uncompressing...done") | |
88 (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
|
89 (add-hook 'write-file-functions 'uncompress-backup-file nil t) |
39125 | 90 (normal-mode)) |
91 | |
62189
0cbd8db584f6
Set `find-file-not-found-functions', not `find-file-not-found-hooks'; use
Juanma Barranquero <lekktu@gmail.com>
parents:
52401
diff
changeset
|
92 (add-hook 'find-file-not-found-functions 'find-compressed-version) |
39125 | 93 |
94 (defun find-compressed-version () | |
95 "Hook to read and uncompress the compressed version of a file." | |
96 ;; Just pretend we had visited the compressed file, | |
97 ;; and uncompress-while-visiting will do the rest. | |
98 (let (name) | |
99 (if (file-exists-p (setq name (concat buffer-file-name ".Z"))) | |
100 (setq buffer-file-name name) | |
101 (if (file-exists-p (setq name (concat buffer-file-name ".gz"))) | |
102 (setq buffer-file-name name))) | |
103 (if (eq name buffer-file-name) | |
104 (progn | |
105 (insert-file-contents buffer-file-name t) | |
106 (goto-char (point-min)) | |
107 ;; No need for this, because error won't be set to t | |
108 ;; if this function returns t. | |
109 ;; (setq error nil) | |
110 t)))) | |
111 | |
49072
03a8f1957f3e
Display message that this package is obsolete.
Richard M. Stallman <rms@gnu.org>
parents:
39125
diff
changeset
|
112 (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
|
113 |
39125 | 114 (provide 'uncompress) |
115 | |
93975
1e3a407766b9
Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
79715
diff
changeset
|
116 ;; arch-tag: 626658d4-fcce-499a-990d-d165f2ed7da3 |
39125 | 117 ;;; uncompress.el ends here |