annotate lisp/obsolete/uncompress.el @ 48360:033719ff91f1

(w32_get_glyph_string_clip_rect): Clip cursor tightly.
author Jason Rumney <jasonr@gnu.org>
date Sat, 16 Nov 2002 01:21:22 +0000
parents cd6477e9b6dc
children 03a8f1957f3e
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
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
3 ;; Copyright (C) 1992, 1994, 2001 Free Software Foundation, Inc.
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
4
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
5 ;; Maintainer: FSF
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
6 ;; Keywords: files
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
7
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
9
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
11 ;; 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
12 ;; the Free Software Foundation; either version 2, or (at your option)
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
13 ;; any later version.
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
14
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
18 ;; GNU General Public License for more details.
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
19
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
23 ;; Boston, MA 02111-1307, USA.
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
24
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
25 ;;; Commentary:
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
26
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
27 ;; This package can be used to arrange for automatic uncompress of
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
28 ;; compressed files when they are visited.
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
29 ;; 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
30 ;; your .emacs file.
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
31
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
32 ;; 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
33
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
34 ;;; Code:
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
35
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
36 ;; When we are about to make a backup file,
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
37 ;; uncompress the file we visited
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
38 ;; so that making the backup can work properly.
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
39 ;; This is used as a write-file-hook.
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
40
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
41 (defvar uncompress-program "gunzip"
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
42 "Program to use for uncompression.")
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
43
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
44 (defun uncompress-backup-file ()
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
45 (and buffer-file-name make-backup-files (not buffer-backed-up)
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
46 (not (file-exists-p buffer-file-name))
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
47 (call-process uncompress-program nil nil nil buffer-file-name))
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
48 nil)
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
49
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
50 (or (assoc "\\.Z$" auto-mode-alist)
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
51 (setq auto-mode-alist
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
52 (cons '("\\.Z$" . uncompress-while-visiting) auto-mode-alist)))
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
53 (or (assoc "\\.gz$" auto-mode-alist)
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
54 (setq auto-mode-alist
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
55 (cons '("\\.gz$" . uncompress-while-visiting) auto-mode-alist)))
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
56 (or (assoc "\\.tgz$" auto-mode-alist)
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
57 (setq auto-mode-alist
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
58 (cons '("\\.tgz$" . uncompress-while-visiting) auto-mode-alist)))
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
59
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
60 (defun uncompress-while-visiting ()
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
61 "Temporary \"major mode\" used for .Z and .gz files, to uncompress them.
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
62 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
63 (if (and (not (null buffer-file-name))
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
64 (string-match "\\.Z$" buffer-file-name))
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
65 (set-visited-file-name
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
66 (substring buffer-file-name 0 (match-beginning 0)))
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
67 (if (and (not (null buffer-file-name))
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
68 (string-match "\\.gz$" buffer-file-name))
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
69 (set-visited-file-name
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
70 (substring buffer-file-name 0 (match-beginning 0)))
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
71 (if (and (not (null buffer-file-name))
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
72 (string-match "\\.tgz$" buffer-file-name))
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
73 (set-visited-file-name
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
74 (concat (substring buffer-file-name 0 (match-beginning 0)) ".tar")))))
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
75 (message "Uncompressing...")
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
76 (let ((buffer-read-only nil)
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
77 (coding-system-for-write 'no-conversion)
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
78 (coding-system-for-read
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
79 (car (find-operation-coding-system
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
80 'insert-file-contents
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
81 buffer-file-name t))))
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
82 (shell-command-on-region (point-min) (point-max) uncompress-program t))
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
83 (goto-char (point-min))
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
84 (message "Uncompressing...done")
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
85 (set-buffer-modified-p nil)
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
86 (make-local-variable 'write-file-hooks)
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
87 (or (memq 'uncompress-backup-file write-file-hooks)
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
88 (setq write-file-hooks (cons 'uncompress-backup-file write-file-hooks)))
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
89 (normal-mode))
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
90
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
91 (or (memq 'find-compressed-version find-file-not-found-hooks)
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
92 (setq find-file-not-found-hooks
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
93 (cons 'find-compressed-version find-file-not-found-hooks)))
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
94
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
95 (defun find-compressed-version ()
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
96 "Hook to read and uncompress the compressed version of a file."
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
97 ;; Just pretend we had visited the compressed file,
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
98 ;; and uncompress-while-visiting will do the rest.
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
99 (let (name)
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
100 (if (file-exists-p (setq name (concat buffer-file-name ".Z")))
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
101 (setq buffer-file-name name)
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
102 (if (file-exists-p (setq name (concat buffer-file-name ".gz")))
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
103 (setq buffer-file-name name)))
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
104 (if (eq name buffer-file-name)
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
105 (progn
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
106 (insert-file-contents buffer-file-name t)
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
107 (goto-char (point-min))
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
108 ;; No need for this, because error won't be set to t
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
109 ;; if this function returns t.
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
110 ;; (setq error nil)
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
111 t))))
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
112
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
113 (provide 'uncompress)
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
114
cd6477e9b6dc *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
115 ;;; uncompress.el ends here