Function: tar-subfile-save-buffer
tar-subfile-save-buffer is an interactive and byte-compiled function
defined in tar-mode.el.gz.
Signature
(tar-subfile-save-buffer)
Documentation
In tar subfile mode, save this buffer into its parent tar-file buffer.
This doesn't write anything to disk; you must save the parent tar-file buffer to make your changes permanent.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/tar-mode.el.gz
(defun tar-subfile-save-buffer ()
"In tar subfile mode, save this buffer into its parent tar-file buffer.
This doesn't write anything to disk; you must save the parent tar-file buffer
to make your changes permanent."
(interactive)
(if (not (and (boundp 'tar-superior-buffer) tar-superior-buffer))
(error "This buffer has no superior tar file buffer"))
(if (not (and (boundp 'tar-superior-descriptor) tar-superior-descriptor))
(error "This buffer doesn't have an index into its superior tar file!"))
(unless (buffer-live-p tar-superior-buffer)
(error "The tar buffer no longer exists; can't save"))
(let ((subfile (current-buffer))
(coding buffer-file-coding-system)
(descriptor tar-superior-descriptor)
subfile-size)
(with-current-buffer tar-superior-buffer
(let* ((start (tar-header-data-start descriptor))
(size (tar-header-size descriptor))
(head (memq descriptor tar-parse-info)))
(if (not head)
(error "Can't find this tar file entry in its parent tar file!"))
(with-current-buffer tar-data-buffer
;; delete the old data...
(let* ((data-start start)
(data-end (+ data-start (tar-roundup-512 size))))
(narrow-to-region data-start data-end)
(delete-region (point-min) (point-max))
;; insert the new data...
(goto-char data-start)
(let ((dest (current-buffer)))
(with-current-buffer subfile
(save-restriction
(widen)
(encode-coding-region (point-min) (point-max) coding dest))))
(setq subfile-size (- (point-max) (point-min)))
;;
;; pad the new data out to a multiple of 512...
(let ((subfile-size-pad (tar-roundup-512 subfile-size)))
(goto-char (point-max))
(insert (make-string (- subfile-size-pad subfile-size) 0))
;;
;; update the data of this files...
(setf (tar-header-size descriptor) subfile-size)
;;
;; Update the size field in the header block.
(widen))))
;;
;; alter the descriptor-line and header
;;
(let ((position (- (length tar-parse-info) (length head))))
(goto-char (point-min))
(forward-line position)
(tar-alter-one-field tar-size-offset (format "%11o " subfile-size))
;;
;; Maybe update the datestamp.
(when tar-update-datestamp
(tar-alter-one-field tar-time-offset
(concat (tar-octal-time nil) " "))))
;; After doing the insertion, add any necessary final padding.
(tar-pad-to-blocksize))
(set-buffer-modified-p t) ; mark the tar file as modified
(tar-next-line 0))
(set-buffer-modified-p nil) ; mark the tar subfile as unmodified
(message "Saved into tar-buffer `%s'. Be sure to save that buffer!"
(buffer-name tar-superior-buffer))
;; Prevent basic-save-buffer from changing our coding-system.
(setq last-coding-system-used buffer-file-coding-system)
;; Prevent ordinary saving from happening.
t))