Commit 47414bc1 authored by Richard M. Stallman's avatar Richard M. Stallman
Browse files

(tar-mode): Position point on the name of the first file.

(tar-extract): Detect coding-system of the archive member and
decode it like insert-file-contents does.
(tar-alter-one-field): Reposition point on the file name of the
current tar entry.
(tar-subfile-save-buffer): Encode the file when updating it in the
archive, and use the size of encoded text to update the header
block.  Set last-coding-system-used to coding-system of the file.
Restore point of tar-superior-buffer after updating the descriptor line.
parent f0d527fc
......@@ -610,7 +610,8 @@ See also: variables `tar-update-datestamp' and `tar-anal-blocksize'.
(if (and (boundp 'tar-header-offset) tar-header-offset)
(narrow-to-region 1 tar-header-offset)
(tar-next-line 0))
(run-hooks 'tar-mode-hook)
......@@ -743,6 +744,43 @@ appear on disk when you save the tar-file's buffer."
(expand-file-name (concat tarname "!" name)))
(setq buffer-file-truename
(abbreviate-file-name buffer-file-name))
;; We need to mimic the parts of insert-file-contents
;; which determine the coding-system and decode the text.
(let ((coding
(and set-auto-coding-function
(if (< (point-max) 4096)
(buffer-substring-no-properties 1 (point-max))
(buffer-substring-no-properties 1 1025)
(- (point-max) 3072) (point-max)))))))
(multibyte enable-multibyte-characters)
(detected (detect-coding-region
1 (min 16384 (point-max)))))
(if coding
(or (numberp (coding-system-eol-type coding))
(setq coding (coding-system-change-eol-conversion
(coding-system-eol-type detected))))
(setq coding
(or (find-new-buffer-file-coding-system detected)
(let ((file-coding
'insert-file-contents buffer-file-name)))
(if (consp file-coding)
(setq file-coding (car file-coding))
(if (or (eq coding 'no-conversion)
(eq (coding-system-type coding) 5))
(setq multibyte (set-buffer-multibyte nil)))
(or multibyte
(setq coding
coding 'raw-text)))
(decode-coding-region 1 (point-max) coding)
(set-buffer-file-coding-system coding))
;; Set the default-directory to the dir of the
;; superior buffer.
(setq default-directory
......@@ -1057,7 +1095,8 @@ for this to be permanent."
(buffer-substring start (+ start 512))
chk (tar-header-name tokens))
(narrow-to-region 1 tar-header-offset))))
(narrow-to-region 1 tar-header-offset)
(tar-next-line 0))))
(defun tar-octal-time (timeval)
......@@ -1081,6 +1120,7 @@ to make your changes permanent."
(let ((subfile (current-buffer))
(subfile-size (buffer-size))
(coding buffer-file-coding-system)
(descriptor tar-superior-descriptor))
(set-buffer tar-superior-buffer)
(let* ((tokens (tar-desc-tokens descriptor))
......@@ -1102,6 +1142,9 @@ to make your changes permanent."
;; insert the new data...
(goto-char data-start)
(insert-buffer subfile)
(setq subfile-size
data-start (+ data-start subfile-size) coding))
;; pad the new data out to a multiple of 512...
(let ((subfile-size-pad (ash (ash (+ subfile-size 511) -9) 9)))
......@@ -1161,10 +1204,13 @@ to make your changes permanent."
(narrow-to-region 1 tar-header-offset)))
(set-buffer-modified-p t) ; mark the tar file as modified
(tar-next-line 0)
(set-buffer subfile)
(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.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment