From: CSBVAX::MRGATE!aks%nowhere@hub.ucsb.edu@SMTP 20-JUL-1988 18:49 To: ARISIA::EVERHART Subj: z-mode.el Received: from hub.ucsb.edu by prep.ai.mit.edu; Tue, 19 Jul 88 20:29:45 EST Message-Id: <8807200129.AA04959@prep.ai.mit.edu> Received: from nowhere.ucsb.edu by hub.ucsb.edu (5.59) id AA16642; Tue, 19 Jul 88 18:52:36 PDT Received: from by nowhere (3.2) id AA14505; Tue, 19 Jul 88 16:15:30 PDT Posted-Date: Tue, 19 Jul 88 16:15:28 PDT To: info-gnu-emacs@prep.ai.mit.edu Subject: z-mode.el Date: Tue, 19 Jul 88 16:15:28 PDT From: Alan Stebbens Speaking of auto-uncompressing ".Z" files when visiting them, here is my little Emacs hack to do this. It is invoked automatically by including the function in the auto-mode-alist in my .emacs startup file. My original idea was to auto-compress it upon saving, but there are good reasons not to do this. Generally, compressing a file is a way of archiving it for later (usually much later) retrieval. However, if you visit a file and make changes to it, more often than not, you are entering a modification cycle, and will make subsequent changes to the same file. So, compressing a file automatically is usually counter-productive and wastes time, since it will likely be accessed again until the modification cycle is complete. Once the changes are done, though, it is easy enough to compress the file, and you need not visit the file to do this: "M-! compress FILE". Thus, auto-compressing the visited file was not considered useful. Alan Stebbens ========================= z-mode.el ========================= (defun z-mode () "\ Temporary major mode triggered by the \".Z\" suffix on a file, used to automatically uncompress the file when visiting. After running the buffer contents through \"uncompress\", the buffer name is changed by truncating the \".Z\" (as well as the visited file name). Also, the buffer is marked as read-only. Finally, normal-mode is invoked to process the buffer for its normal mode." (if (and (not (null buffer-file-name)) (string-match "^\\(.*\\)\\.Z$" buffer-file-name)) (let ((new (substring buffer-file-name (match-beginning 1) (match-end 1)))) (setq buffer-read-only nil) (message "Uncompressing text...") (shell-command-on-region (point-min) (point-max) "uncompress" t) (message "Uncompressing text...done") (goto-char (point-min)) (set-visited-file-name new) (set-buffer-modified-p nil) (setq buffer-read-only t))) (normal-mode)) ============================================================ To use it, place the following (or equivalent) in your ~/.emacs startup. ========================== .emacs ========================== ;; Define z-mode to auto-load when visiting a ".Z" file (autoload 'z-mode "z-mode" "\ Mode triggered by \".Z\" suffixed files, which then get automatically uncompressed with appropriate buffer and visited file name changes. The buffer containing the uncompressed source is set to read-only." t) ;; Establish '.Z' as a valid mode (setq auto-mode-alist (nconc '(("\\.Z$" . z-mode)) auto-mode-alist))