home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2 / Openstep-4.2-Intel-User.iso / usr / lib / emacs / lisp / uncompress.el < prev    next >
Lisp/Scheme  |  1990-09-20  |  1KB  |  32 lines

  1. (defun uncompress-while-visiting ()
  2.   "Temporary \"major mode\" used for .Z files, to uncompress the contents.
  3. It then selects a major mode from the uncompressed file name and contents."
  4.   (if (and (not (null buffer-file-name))
  5.        (string-match "\\.Z$" buffer-file-name))
  6.       (set-visited-file-name
  7.        (substring buffer-file-name 0 (match-beginning 0))))
  8.   (message "Uncompressing...")
  9.   (let ((buffer-read-only nil))
  10.     (shell-command-on-region (point-min) (point-max) "uncompress" t))
  11.   (message "Uncompressing...done")
  12.   (set-buffer-modified-p nil)
  13.   (normal-mode))
  14.  
  15. (setq auto-mode-alist
  16.       (cons '("\\.Z$" . uncompress-while-visiting) auto-mode-alist))
  17.  
  18. (defun find-compressed-version ()
  19.   "Hook to read and uncompress the compressed version of a file."
  20.   ;; Just pretend we had visited the compressed file,
  21.   ;; and uncompress-while-visiting will do the rest.
  22.   (if (file-exists-p (concat buffer-file-name ".Z"))
  23.       (progn
  24.     (setq buffer-file-name (concat buffer-file-name ".Z"))
  25.     (insert-file-contents buffer-file-name t)
  26.     (goto-char (point-min))
  27.     (setq error nil)
  28.     t)))
  29.  
  30. (setq find-file-not-found-hooks
  31.       (cons 'find-compressed-version find-file-not-found-hooks))
  32.