annotate lisp/packages/uncompress.el @ 12:bcdc7deadc19 r19-15b7

Import from CVS: tag r19-15b7
author cvs
date Mon, 13 Aug 2007 08:48:16 +0200
parents ac2d302a0011
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1 ;;; uncompress.el --- auto-decompression hook for visiting .Z files
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3 ;; Copyright (C) 1992, 1994 Free Software Foundation, Inc.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
5 ;; Maintainer: FSF
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Keywords: unix extensions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
8 ;; This file is part of XEmacs.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
10 ;; XEmacs is free software; you can redistribute it and/or modify it
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
11 ;; under the terms of the GNU General Public License as published by
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
13 ;; any later version.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
14
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
15 ;; XEmacs is distributed in the hope that it will be useful, but
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
18 ;; General Public License for more details.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
20 ;; You should have received a copy of the GNU General Public License
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
21 ;; along with XEmacs; see the file COPYING. If not, write to the Free
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
22 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
23 ;; 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
25 ;;; Synched up with: 19.34.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
26
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
27 ;;; Commentary:
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
28
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
29 ;; This package can be used to arrange for automatic uncompress of
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
30 ;; files packed with the UNIX compress(1) utility when they are visited.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
31 ;; All that's necessary is to load it. This can conveniently be done from
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
32 ;; your .emacs file.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
33
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
34 ;;; Code:
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;; When we are about to make a backup file,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;; uncompress the file we visited
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;; so that making the backup can work properly.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;; This is used as a write-file-hook.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
41 (defvar uncompress-program "gunzip"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
42 "Program to use for uncompression.")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
43
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 (defun uncompress-backup-file ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 (and buffer-file-name make-backup-files (not buffer-backed-up)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 (not (file-exists-p buffer-file-name))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
47 (call-process uncompress-program nil nil nil buffer-file-name))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (or (assoc "\\.Z$" auto-mode-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (setq auto-mode-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 (cons '("\\.Z$" . uncompress-while-visiting) auto-mode-alist)))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
53 (or (assoc "\\.gz$" auto-mode-alist)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
54 (setq auto-mode-alist
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
55 (cons '("\\.gz$" . uncompress-while-visiting) auto-mode-alist)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 (defun uncompress-while-visiting ()
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
58 "Temporary \"major mode\" used for .Z and .gz files, to uncompress them.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 It then selects a major mode from the uncompressed file name and contents."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (if (and (not (null buffer-file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (string-match "\\.Z$" buffer-file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 (set-visited-file-name
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
63 (substring buffer-file-name 0 (match-beginning 0)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
64 (if (and (not (null buffer-file-name))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
65 (string-match "\\.gz$" buffer-file-name))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
66 (set-visited-file-name
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
67 (substring buffer-file-name 0 (match-beginning 0)))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (message "Uncompressing...")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (let ((buffer-read-only nil))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
70 (shell-command-on-region (point-min) (point-max) uncompress-program t))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (message "Uncompressing...done")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (set-buffer-modified-p nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (make-local-variable 'write-file-hooks)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (or (memq 'uncompress-backup-file write-file-hooks)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (setq write-file-hooks (cons 'uncompress-backup-file write-file-hooks)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (normal-mode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (or (memq 'find-compressed-version find-file-not-found-hooks)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (setq find-file-not-found-hooks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (cons 'find-compressed-version find-file-not-found-hooks)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (defun find-compressed-version ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 "Hook to read and uncompress the compressed version of a file."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 ;; Just pretend we had visited the compressed file,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 ;; and uncompress-while-visiting will do the rest.
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
86 (let (name)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
87 (if (file-exists-p (setq name (concat buffer-file-name ".Z")))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
88 (setq buffer-file-name name)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
89 (if (file-exists-p (setq name (concat buffer-file-name ".gz")))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
90 (setq buffer-file-name name)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
91 (if (eq name buffer-file-name)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
92 (progn
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
93 (insert-file-contents buffer-file-name t)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
94 (goto-char (point-min))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
95 (setq error nil)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
96 t))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
97
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
98 (provide 'uncompress)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
99
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
100 ;;; uncompress.el ends here