home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / lucid / lemacs-19.6 / lisp / packages / uncompress.el < prev    next >
Encoding:
Text File  |  1993-01-16  |  2.0 KB  |  57 lines

  1.  
  2.  
  3.  
  4. ;; ============================================================
  5. ;; NOTE: crypt.el is a much more complete version of this hack.
  6. ;; ============================================================
  7.  
  8.  
  9.  
  10. ;; When we are about to make a backup file,
  11. ;; uncompress the file we visited
  12. ;; so that making the backup can work properly.
  13. ;; This is used as a write-file-hook.
  14.  
  15. (defun uncompress-backup-file ()
  16.   (and buffer-file-name make-backup-files (not buffer-backed-up)
  17.        (not (file-exists-p buffer-file-name))
  18.        (call-process "uncompress" nil nil nil buffer-file-name))
  19.   nil)
  20.  
  21. (or (assoc "\\.Z$" auto-mode-alist)
  22.     (setq auto-mode-alist
  23.       (cons '("\\.Z$" . uncompress-while-visiting) auto-mode-alist)))
  24.  
  25. (defun uncompress-while-visiting ()
  26.   "Temporary \"major mode\" used for .Z files, to uncompress the contents.
  27. It then selects a major mode from the uncompressed file name and contents."
  28.   (if (and (not (null buffer-file-name))
  29.        (string-match "\\.Z$" buffer-file-name))
  30.       (set-visited-file-name
  31.        (substring buffer-file-name 0 (match-beginning 0))))
  32.   (message "Uncompressing...")
  33.   (let ((buffer-read-only nil))
  34.     (shell-command-on-region (point-min) (point-max) "uncompress" t))
  35.   (message "Uncompressing...done")
  36.   (set-buffer-modified-p nil)
  37.   (make-local-variable 'write-file-hooks)
  38.   (or (memq 'uncompress-backup-file write-file-hooks)
  39.       (setq write-file-hooks (cons 'uncompress-backup-file write-file-hooks)))
  40.   (normal-mode))
  41.  
  42. (or (memq 'find-compressed-version find-file-not-found-hooks)
  43.     (setq find-file-not-found-hooks
  44.       (cons 'find-compressed-version find-file-not-found-hooks)))
  45.  
  46. (defun find-compressed-version ()
  47.   "Hook to read and uncompress the compressed version of a file."
  48.   ;; Just pretend we had visited the compressed file,
  49.   ;; and uncompress-while-visiting will do the rest.
  50.   (if (file-exists-p (concat buffer-file-name ".Z"))
  51.       (progn
  52.     (setq buffer-file-name (concat buffer-file-name ".Z"))
  53.     (insert-file-contents buffer-file-name t)
  54.     (goto-char (point-min))
  55.     (setq error nil)
  56.     t)))
  57.