diff options
| author | Richard M. Stallman | 1994-04-04 20:48:08 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1994-04-04 20:48:08 +0000 |
| commit | baf90b622677d781227e764d77d22cb4eee649cd (patch) | |
| tree | 65bffa233de84ecc72a9eca4a3c7fed5dd820e9e | |
| parent | 399f8dd64518798f76fbbde4b42e8cc0289a855d (diff) | |
| download | emacs-baf90b622677d781227e764d77d22cb4eee649cd.tar.gz emacs-baf90b622677d781227e764d77d22cb4eee649cd.zip | |
(uncompress-program): New variable.
(uncompress-backup-file): Use it.
(uncompress-while-visiting): Use that var. Handle .gz suffix.
(auto-mode-alist): Handle .gz suffix.
(find-compressed-version): Handle .gz suffix.
| -rw-r--r-- | lisp/uncompress.el | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/lisp/uncompress.el b/lisp/uncompress.el index a44590a3afd..89db52ef56f 100644 --- a/lisp/uncompress.el +++ b/lisp/uncompress.el | |||
| @@ -34,26 +34,36 @@ | |||
| 34 | ;; so that making the backup can work properly. | 34 | ;; so that making the backup can work properly. |
| 35 | ;; This is used as a write-file-hook. | 35 | ;; This is used as a write-file-hook. |
| 36 | 36 | ||
| 37 | (defvar uncompress-program "gunzip" | ||
| 38 | "Program to use for uncompression.") | ||
| 39 | |||
| 37 | (defun uncompress-backup-file () | 40 | (defun uncompress-backup-file () |
| 38 | (and buffer-file-name make-backup-files (not buffer-backed-up) | 41 | (and buffer-file-name make-backup-files (not buffer-backed-up) |
| 39 | (not (file-exists-p buffer-file-name)) | 42 | (not (file-exists-p buffer-file-name)) |
| 40 | (call-process "uncompress" nil nil nil buffer-file-name)) | 43 | (call-process uncompress-program nil nil nil buffer-file-name)) |
| 41 | nil) | 44 | nil) |
| 42 | 45 | ||
| 43 | (or (assoc "\\.Z$" auto-mode-alist) | 46 | (or (assoc "\\.Z$" auto-mode-alist) |
| 44 | (setq auto-mode-alist | 47 | (setq auto-mode-alist |
| 45 | (cons '("\\.Z$" . uncompress-while-visiting) auto-mode-alist))) | 48 | (cons '("\\.Z$" . uncompress-while-visiting) auto-mode-alist))) |
| 49 | (or (assoc "\\.gz$" auto-mode-alist) | ||
| 50 | (setq auto-mode-alist | ||
| 51 | (cons '("\\.gz$" . uncompress-while-visiting) auto-mode-alist))) | ||
| 46 | 52 | ||
| 47 | (defun uncompress-while-visiting () | 53 | (defun uncompress-while-visiting () |
| 48 | "Temporary \"major mode\" used for .Z files, to uncompress the contents. | 54 | "Temporary \"major mode\" used for .Z and .gz files, to uncompress them. |
| 49 | It then selects a major mode from the uncompressed file name and contents." | 55 | It then selects a major mode from the uncompressed file name and contents." |
| 50 | (if (and (not (null buffer-file-name)) | 56 | (if (and (not (null buffer-file-name)) |
| 51 | (string-match "\\.Z$" buffer-file-name)) | 57 | (string-match "\\.Z$" buffer-file-name)) |
| 52 | (set-visited-file-name | 58 | (set-visited-file-name |
| 53 | (substring buffer-file-name 0 (match-beginning 0)))) | 59 | (substring buffer-file-name 0 (match-beginning 0))) |
| 60 | (if (and (not (null buffer-file-name)) | ||
| 61 | (string-match "\\.gz$" buffer-file-name)) | ||
| 62 | (set-visited-file-name | ||
| 63 | (substring buffer-file-name 0 (match-beginning 0))))) | ||
| 54 | (message "Uncompressing...") | 64 | (message "Uncompressing...") |
| 55 | (let ((buffer-read-only nil)) | 65 | (let ((buffer-read-only nil)) |
| 56 | (shell-command-on-region (point-min) (point-max) "uncompress" t)) | 66 | (shell-command-on-region (point-min) (point-max) uncompress-program t)) |
| 57 | (message "Uncompressing...done") | 67 | (message "Uncompressing...done") |
| 58 | (set-buffer-modified-p nil) | 68 | (set-buffer-modified-p nil) |
| 59 | (make-local-variable 'write-file-hooks) | 69 | (make-local-variable 'write-file-hooks) |
| @@ -69,13 +79,17 @@ It then selects a major mode from the uncompressed file name and contents." | |||
| 69 | "Hook to read and uncompress the compressed version of a file." | 79 | "Hook to read and uncompress the compressed version of a file." |
| 70 | ;; Just pretend we had visited the compressed file, | 80 | ;; Just pretend we had visited the compressed file, |
| 71 | ;; and uncompress-while-visiting will do the rest. | 81 | ;; and uncompress-while-visiting will do the rest. |
| 72 | (if (file-exists-p (concat buffer-file-name ".Z")) | 82 | (let (name) |
| 73 | (progn | 83 | (if (file-exists-p (setq name (concat buffer-file-name ".Z"))) |
| 74 | (setq buffer-file-name (concat buffer-file-name ".Z")) | 84 | (setq buffer-file-name name) |
| 75 | (insert-file-contents buffer-file-name t) | 85 | (if (file-exists-p (setq name (concat buffer-file-name ".gz"))) |
| 76 | (goto-char (point-min)) | 86 | (setq buffer-file-name name))) |
| 77 | (setq error nil) | 87 | (if (eq name buffer-file-name) |
| 78 | t))) | 88 | (progn |
| 89 | (insert-file-contents buffer-file-name t) | ||
| 90 | (goto-char (point-min)) | ||
| 91 | (setq error nil) | ||
| 92 | t)))) | ||
| 79 | 93 | ||
| 80 | (provide 'uncompress) | 94 | (provide 'uncompress) |
| 81 | 95 | ||