comparison lisp/tar-mode.el @ 11450:aee30032f324

(tar-mode): Locally bind next-line-add-newlines to nil. (tar-subfile-mode): Doc fix. (tar-expunge): Make questions and messages start with upper case letter. (tar-summarize-buffer): Ditto. (tar-subfile-save-buffer): Make message like others. (tar-mode): Locally bind local-write-file-hooks. (tar-mode-write-file): Renamed from tar-mode-maybe-write-tar-file. (tar-mode-write-file): Simplify to only work for tar file buffers. (write-file-hooks): Don't modify this.
author Richard M. Stallman <rms@gnu.org>
date Fri, 14 Apr 1995 20:46:11 +0000
parents 6e6385618bb4
children c5cf8807738b
comparison
equal deleted inserted replaced
11449:fca5a32f7806 11450:aee30032f324
412 (defun tar-summarize-buffer () 412 (defun tar-summarize-buffer ()
413 "Parse the contents of the tar file in the current buffer. 413 "Parse the contents of the tar file in the current buffer.
414 Place a dired-like listing on the front; 414 Place a dired-like listing on the front;
415 then narrow to it, so that only that listing 415 then narrow to it, so that only that listing
416 is visible (and the real data of the buffer is hidden)." 416 is visible (and the real data of the buffer is hidden)."
417 (message "parsing tar file...") 417 (message "Parsing tar file...")
418 (let* ((result '()) 418 (let* ((result '())
419 (pos 1) 419 (pos 1)
420 (bs (max 1 (- (buffer-size) 1024))) ; always 2+ empty blocks at end. 420 (bs (max 1 (- (buffer-size) 1024))) ; always 2+ empty blocks at end.
421 (bs100 (max 1 (/ bs 100))) 421 (bs100 (max 1 (/ bs 100)))
422 tokens) 422 tokens)
576 (setq require-final-newline nil) ; binary data, dude... 576 (setq require-final-newline nil) ; binary data, dude...
577 (make-local-variable 'revert-buffer-function) 577 (make-local-variable 'revert-buffer-function)
578 (setq revert-buffer-function 'tar-mode-revert) 578 (setq revert-buffer-function 'tar-mode-revert)
579 (make-local-variable 'enable-local-variables) 579 (make-local-variable 'enable-local-variables)
580 (setq enable-local-variables nil) 580 (setq enable-local-variables nil)
581 (make-local-variable 'next-line-add-newlines)
582 (setq next-line-add-newlines nil)
581 (setq major-mode 'tar-mode) 583 (setq major-mode 'tar-mode)
582 (setq mode-name "Tar") 584 (setq mode-name "Tar")
583 (use-local-map tar-mode-map) 585 (use-local-map tar-mode-map)
584 (auto-save-mode 0) 586 (auto-save-mode 0)
587 (make-local-variable 'local-write-file-hooks)
588 (setq local-write-file-hooks '(tar-mode-write-file))
585 (widen) 589 (widen)
586 (if (and (boundp 'tar-header-offset) tar-header-offset) 590 (if (and (boundp 'tar-header-offset) tar-header-offset)
587 (narrow-to-region 1 tar-header-offset) 591 (narrow-to-region 1 tar-header-offset)
588 (tar-summarize-buffer)) 592 (tar-summarize-buffer))
589 (run-hooks 'tar-mode-hook) 593 (run-hooks 'tar-mode-hook)
590 ) 594 )
591 595
592 596
593 ;; This should be converted to use a minor mode keymap.
594
595 (defun tar-subfile-mode (p) 597 (defun tar-subfile-mode (p)
596 "Minor mode for editing an element of a tar-file. 598 "Minor mode for editing an element of a tar-file.
597 This mode redefines C-x C-s to save the current buffer back into its 599 This mode redefines the save-buffer command to save the current buffer back
598 associated tar-file buffer. You must save that buffer to actually 600 into its associated tar-file buffer. You must save that buffer to actually
599 save your changes to disk." 601 save your changes to disk."
600 (interactive "P") 602 (interactive "P")
601 (or (and (boundp 'tar-superior-buffer) tar-superior-buffer) 603 (or (and (boundp 'tar-superior-buffer) tar-superior-buffer)
602 (error "This buffer is not an element of a tar file")) 604 (error "This buffer is not an element of a tar file"))
603 ;;; Don't do this, because it is redundant and wastes mode line space. 605 ;;; Don't do this, because it is redundant and wastes mode line space.
730 (narrow-to-region 1 tar-header-offset))) 732 (narrow-to-region 1 tar-header-offset)))
731 (if view-p 733 (if view-p
732 (progn 734 (progn
733 (view-buffer buffer) 735 (view-buffer buffer)
734 (and just-created 736 (and just-created
737 ;; This will be created by view.el
735 (setq view-exit-action 'kill-buffer))) 738 (setq view-exit-action 'kill-buffer)))
736 (if (eq other-window-p 'display) 739 (if (eq other-window-p 'display)
737 (display-buffer buffer) 740 (display-buffer buffer)
738 (if other-window-p 741 (if other-window-p
739 (switch-to-buffer-other-window buffer) 742 (switch-to-buffer-other-window buffer)
866 "*In Tar mode, delete all the archived files flagged for deletion. 869 "*In Tar mode, delete all the archived files flagged for deletion.
867 This does not modify the disk image; you must save the tar file itself 870 This does not modify the disk image; you must save the tar file itself
868 for this to be permanent." 871 for this to be permanent."
869 (interactive) 872 (interactive)
870 (if (or noconfirm 873 (if (or noconfirm
871 (y-or-n-p "expunge files marked for deletion? ")) 874 (y-or-n-p "Expunge files marked for deletion? "))
872 (let ((n 0)) 875 (let ((n 0))
873 (save-excursion 876 (save-excursion
874 (goto-char 0) 877 (goto-char 0)
875 (while (not (eobp)) 878 (while (not (eobp))
876 (if (looking-at "D") 879 (if (looking-at "D")
880 ;; after doing the deletions, add any padding that may be necessary. 883 ;; after doing the deletions, add any padding that may be necessary.
881 (tar-pad-to-blocksize) 884 (tar-pad-to-blocksize)
882 (narrow-to-region 1 tar-header-offset) 885 (narrow-to-region 1 tar-header-offset)
883 ) 886 )
884 (if (zerop n) 887 (if (zerop n)
885 (message "nothing to expunge.") 888 (message "Nothing to expunge.")
886 (message "%s expunged. Be sure to save this buffer." n))))) 889 (message "%s files expunged. Be sure to save this buffer." n)))))
887 890
888 891
889 (defun tar-clear-modification-flags () 892 (defun tar-clear-modification-flags ()
890 "Remove the stars at the beginning of each line." 893 "Remove the stars at the beginning of each line."
891 (interactive) 894 (interactive)
1121 (tar-pad-to-blocksize)) 1124 (tar-pad-to-blocksize))
1122 (narrow-to-region 1 tar-header-offset))) 1125 (narrow-to-region 1 tar-header-offset)))
1123 (set-buffer-modified-p t) ; mark the tar file as modified 1126 (set-buffer-modified-p t) ; mark the tar file as modified
1124 (set-buffer subfile) 1127 (set-buffer subfile)
1125 (set-buffer-modified-p nil) ; mark the tar subfile as unmodified 1128 (set-buffer-modified-p nil) ; mark the tar subfile as unmodified
1126 (message "saved into tar-buffer `%s' -- remember to save that buffer!" 1129 (message "Saved into tar-buffer `%s'. Be sure to save that buffer!"
1127 (buffer-name tar-superior-buffer)) 1130 (buffer-name tar-superior-buffer))
1128 ;; Prevent ordinary saving from happening. 1131 ;; Prevent ordinary saving from happening.
1129 t))) 1132 t)))
1130 1133
1131 1134
1156 0))) 1159 0)))
1157 ))) 1160 )))
1158 1161
1159 1162
1160 ;; Used in write-file-hook to write tar-files out correctly. 1163 ;; Used in write-file-hook to write tar-files out correctly.
1161 (defun tar-mode-maybe-write-tar-file () 1164 (defun tar-mode-write-file ()
1162 ;; 1165 (unwind-protect
1163 ;; If the current buffer is in Tar mode and has its header-offset set, 1166 (save-excursion
1164 ;; only write out the part of the file after the header-offset. 1167 (widen)
1165 ;; 1168 ;; Doing this here confuses things - the region gets left too wide!
1166 (if (and (eq major-mode 'tar-mode) 1169 ;; I suppose this is run in a context where changing the buffer is bad.
1167 (and (boundp 'tar-header-offset) tar-header-offset)) 1170 ;; (tar-pad-to-blocksize)
1168 (unwind-protect 1171 (write-region tar-header-offset (point-max) buffer-file-name nil t)
1169 (save-excursion 1172 (tar-clear-modification-flags))
1170 (tar-clear-modification-flags) 1173 (narrow-to-region 1 tar-header-offset))
1171 (widen) 1174 ;; return T because we've written the file.
1172 ;; Doing this here confuses things - the region gets left too wide! 1175 t)
1173 ;; I suppose this is run in a context where changing the buffer is bad.
1174 ;; (tar-pad-to-blocksize)
1175 (write-region tar-header-offset (1+ (buffer-size)) buffer-file-name nil t)
1176 ;; return T because we've written the file.
1177 t)
1178 (narrow-to-region 1 tar-header-offset)
1179 t)
1180 ;; return NIL because we haven't.
1181 nil))
1182
1183 1176
1184 ;;; Patch it in.
1185
1186 (or (memq 'tar-mode-maybe-write-tar-file write-file-hooks)
1187 (setq write-file-hooks
1188 (cons 'tar-mode-maybe-write-tar-file write-file-hooks)))
1189
1190 (provide 'tar-mode) 1177 (provide 'tar-mode)
1191 1178
1192 ;;; tar-mode.el ends here 1179 ;;; tar-mode.el ends here