home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / unix / emacs / lisp / uncompre.el < prev    next >
Encoding:
Text File  |  1992-04-29  |  1.4 KB  |  38 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 "\\.[zZ]$" buffer-file-name)) ; OS/2
  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. ; OS/2
  19. (setq auto-mode-alist
  20.       (cons '("\\.z$" . uncompress-while-visiting) auto-mode-alist))
  21. (setq file-type-alist (append file-type-alist
  22.       '(("\\.[Zz]$" . "b"))))
  23.  
  24. (defun find-compressed-version ()
  25.   "Hook to read and uncompress the compressed version of a file."
  26.   ;; Just pretend we had visited the compressed file,
  27.   ;; and uncompress-while-visiting will do the rest.
  28.   (if (file-exists-p (concat buffer-file-name ".Z"))
  29.       (progn
  30.     (setq buffer-file-name (concat buffer-file-name ".Z"))
  31.     (insert-file-contents buffer-file-name t)
  32.     (goto-char (point-min))
  33.     (setq error nil)
  34.     t)))
  35.  
  36. (setq find-file-not-found-hooks
  37.       (cons 'find-compressed-version find-file-not-found-hooks))
  38.