[gnu.emacs.bug] uncompress-while-visiting dies on read only files

brachman@cs.ubc.ca (Barry Brachman) (11/03/88)

--text follows this line--

In GNU Emacs 18.52.1 of Thu Sep 15 1988 on grads.cs.ubc.ca (berkeley-unix)

Index: uncompress.el

If you visit a compressed file that you can't write, the compressed file
is placed in a read-only buffer.  Subsequent execution of
shell-command-on-region to uncompress the contents of the buffer fails
because the buffer has been marked read-only.

Suggested fix:

(defun uncompress-while-visiting ()
  "Temporary \"major mode\" used for .Z files, to uncompress the contents.
It then selects a major mode from the uncompressed file name and contents."
  (if buffer-read-only			;; Allow uncompress on the buffer - bjb
	  (toggle-read-only))		;;
  (if (and (not (null buffer-file-name))
		   (string-match "\\.Z$" buffer-file-name))
      (set-visited-file-name
       (substring buffer-file-name 0 (match-beginning 0))))
  (message "Uncompressing...")
  (shell-command-on-region (point-min) (point-max) "uncompress" t)
  (message "Uncompressing...done")
  (set-buffer-modified-p nil)
  (normal-mode))

-----
Barry Brachman           | {alberta,uw-beaver,uunet}!
Dept. of Computer Science|  ubc-vision!ubc-csgrads!brachman
Univ. of British Columbia| brachman@grads.cs.ubc.cdn
Vancouver, B.C. V6T 1W5  | brachman%ubc.csnet@csnet-relay.arpa
(604) 228-4327           | brachman@ubc.csnet (ubc-csgrads=128.189.97.20)