annotate lisp/uncompress.el @ 612:68ef62058595

*** empty log message ***
author Richard M. Stallman <rms@gnu.org>
date Fri, 17 Apr 1992 12:21:09 +0000
parents 8136d331c964
children fec3f9a1e3e5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
21
8136d331c964 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1 ;; When we are about to make a backup file,
8136d331c964 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2 ;; uncompress the file we visited
8136d331c964 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3 ;; so that making the backup can work properly.
8136d331c964 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4 ;; This is used as a write-file-hook.
8136d331c964 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
5
8136d331c964 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
6 (defun uncompress-backup-file ()
8136d331c964 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
7 (and buffer-file-name make-backup-files (not buffer-backed-up)
8136d331c964 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
8 (not (file-exists-p buffer-file-name))
8136d331c964 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
9 (call-process "uncompress" nil nil nil buffer-file-name))
8136d331c964 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
10 nil)
8136d331c964 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
11
8136d331c964 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
12 (or (assoc "\\.Z$" auto-mode-alist)
8136d331c964 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
13 (setq auto-mode-alist
8136d331c964 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
14 (cons '("\\.Z$" . uncompress-while-visiting) auto-mode-alist)))
8136d331c964 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
15
8136d331c964 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
16 (defun uncompress-while-visiting ()
8136d331c964 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
17 "Temporary \"major mode\" used for .Z files, to uncompress the contents.
8136d331c964 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
18 It then selects a major mode from the uncompressed file name and contents."
8136d331c964 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
19 (if (and (not (null buffer-file-name))
8136d331c964 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
20 (string-match "\\.Z$" buffer-file-name))
8136d331c964 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
21 (set-visited-file-name
8136d331c964 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
22 (substring buffer-file-name 0 (match-beginning 0))))
8136d331c964 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
23 (message "Uncompressing...")
8136d331c964 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
24 (let ((buffer-read-only nil))
8136d331c964 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
25 (shell-command-on-region (point-min) (point-max) "uncompress" t))
8136d331c964 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
26 (message "Uncompressing...done")
8136d331c964 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
27 (set-buffer-modified-p nil)
8136d331c964 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
28 (make-local-variable 'write-file-hooks)
8136d331c964 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
29 (or (memq 'uncompress-backup-file write-file-hooks)
8136d331c964 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
30 (setq write-file-hooks (cons 'uncompress-backup-file write-file-hooks)))
8136d331c964 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
31 (normal-mode))
8136d331c964 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
32
8136d331c964 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
33 (or (memq 'find-compressed-version find-file-not-found-hooks)
8136d331c964 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
34 (setq find-file-not-found-hooks
8136d331c964 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
35 (cons 'find-compressed-version find-file-not-found-hooks)))
8136d331c964 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
36
8136d331c964 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
37 (defun find-compressed-version ()
8136d331c964 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
38 "Hook to read and uncompress the compressed version of a file."
8136d331c964 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
39 ;; Just pretend we had visited the compressed file,
8136d331c964 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
40 ;; and uncompress-while-visiting will do the rest.
8136d331c964 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
41 (if (file-exists-p (concat buffer-file-name ".Z"))
8136d331c964 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
42 (progn
8136d331c964 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
43 (setq buffer-file-name (concat buffer-file-name ".Z"))
8136d331c964 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
44 (insert-file-contents buffer-file-name t)
8136d331c964 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
45 (goto-char (point-min))
8136d331c964 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
46 (setq error nil)
8136d331c964 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
47 t)))