diff options
| -rw-r--r-- | lisp/ChangeLog | 12 | ||||
| -rw-r--r-- | lisp/tar-mode.el | 57 |
2 files changed, 36 insertions, 33 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 3a025d5bac9..34b98c6589e 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,15 @@ | |||
| 1 | 2008-12-26 Andreas Schwab <schwab@suse.de> | ||
| 2 | |||
| 3 | * tar-mode.el (tar-swap-data): New function. | ||
| 4 | (tar-change-major-mode-hook): Use it instead of buffer-swap-text. | ||
| 5 | (tar-mode-revert): Likewise. | ||
| 6 | (tar-mode): Likewise. Don't set write-region-annotate-functions. | ||
| 7 | (tar-data-swapped-p): Test buffer-swapped-with. | ||
| 8 | (tar-write-region-annotate): Remove. | ||
| 9 | (tar-header-block-tokenize): Add argument `coding' and use it | ||
| 10 | instead of tar-file-name-coding-system. | ||
| 11 | (tar-summarize-buffer): Pass tar-file-name-coding-system here. | ||
| 12 | |||
| 1 | 2008-12-26 Eli Zaretskii <eliz@gnu.org> | 13 | 2008-12-26 Eli Zaretskii <eliz@gnu.org> |
| 2 | 14 | ||
| 3 | * dos-fns.el (dosified-file-name): New function. | 15 | * dos-fns.el (dosified-file-name): New function. |
diff --git a/lisp/tar-mode.el b/lisp/tar-mode.el index 4d05746a347..ba4ded36a83 100644 --- a/lisp/tar-mode.el +++ b/lisp/tar-mode.el | |||
| @@ -161,14 +161,19 @@ This information is useful, but it takes screen space away from file names." | |||
| 161 | 161 | ||
| 162 | (defun tar-data-swapped-p () | 162 | (defun tar-data-swapped-p () |
| 163 | "Return non-nil if the tar-data is in `tar-data-buffer'." | 163 | "Return non-nil if the tar-data is in `tar-data-buffer'." |
| 164 | ;; We need to be careful to keep track of which buffer holds the tar-data, | 164 | (buffer-live-p buffer-swapped-with)) |
| 165 | ;; since we swap them back and forth. Since the user may make the summary | 165 | |
| 166 | ;; buffer unibyte, we can't rely on the multibyteness of the buffers. | 166 | (defun tar-swap-data () |
| 167 | ;; We could try and recognize the tar-format signature, but instead | 167 | "Swap buffer contents between current buffer and `tar-data-buffer'. |
| 168 | ;; I decided to go for something simpler. | 168 | Preserve the modified states of the buffers and set `buffer-swapped-with'." |
| 169 | (and (buffer-live-p tar-data-buffer) | 169 | (let ((data-buffer-modified-p (buffer-modified-p tar-data-buffer)) |
| 170 | (> (buffer-size tar-data-buffer) (buffer-size)))) | 170 | (current-buffer-modified-p (buffer-modified-p))) |
| 171 | 171 | (buffer-swap-text tar-data-buffer) | |
| 172 | (setq buffer-swapped-with | ||
| 173 | (if buffer-swapped-with nil tar-data-buffer)) | ||
| 174 | (set-buffer-modified-p data-buffer-modified-p) | ||
| 175 | (with-current-buffer tar-data-buffer | ||
| 176 | (set-buffer-modified-p current-buffer-modified-p)))) | ||
| 172 | 177 | ||
| 173 | ;;; down to business. | 178 | ;;; down to business. |
| 174 | 179 | ||
| @@ -207,7 +212,7 @@ This information is useful, but it takes screen space away from file names." | |||
| 207 | "Round S up to the next multiple of 512." | 212 | "Round S up to the next multiple of 512." |
| 208 | (ash (ash (+ s 511) -9) 9)) | 213 | (ash (ash (+ s 511) -9) 9)) |
| 209 | 214 | ||
| 210 | (defun tar-header-block-tokenize (pos) | 215 | (defun tar-header-block-tokenize (pos coding) |
| 211 | "Return a `tar-header' structure. | 216 | "Return a `tar-header' structure. |
| 212 | This is a list of name, mode, uid, gid, size, | 217 | This is a list of name, mode, uid, gid, size, |
| 213 | write-date, checksum, link-type, and link-name." | 218 | write-date, checksum, link-type, and link-name." |
| @@ -249,10 +254,9 @@ write-date, checksum, link-type, and link-name." | |||
| 249 | "/" name))) | 254 | "/" name))) |
| 250 | (if default-enable-multibyte-characters | 255 | (if default-enable-multibyte-characters |
| 251 | (setq name | 256 | (setq name |
| 252 | (decode-coding-string name tar-file-name-coding-system) | 257 | (decode-coding-string name coding) |
| 253 | linkname | 258 | linkname |
| 254 | (decode-coding-string linkname | 259 | (decode-coding-string linkname coding))) |
| 255 | tar-file-name-coding-system))) | ||
| 256 | (if (and (null link-p) (string-match "/\\'" name)) | 260 | (if (and (null link-p) (string-match "/\\'" name)) |
| 257 | (setq link-p 5)) ; directory | 261 | (setq link-p 5)) ; directory |
| 258 | 262 | ||
| @@ -264,7 +268,7 @@ write-date, checksum, link-type, and link-name." | |||
| 264 | ;; -1 so as to strip the terminating 0 byte. | 268 | ;; -1 so as to strip the terminating 0 byte. |
| 265 | (name (buffer-substring pos (+ pos size -1))) | 269 | (name (buffer-substring pos (+ pos size -1))) |
| 266 | (descriptor (tar-header-block-tokenize | 270 | (descriptor (tar-header-block-tokenize |
| 267 | (+ pos (tar-roundup-512 size))))) | 271 | (+ pos (tar-roundup-512 size)) coding))) |
| 268 | (cond | 272 | (cond |
| 269 | ((eq link-p (- ?L ?0)) ;GNUTYPE_LONGNAME. | 273 | ((eq link-p (- ?L ?0)) ;GNUTYPE_LONGNAME. |
| 270 | (setf (tar-header-name descriptor) name)) | 274 | (setf (tar-header-name descriptor) name)) |
| @@ -456,6 +460,7 @@ MODE should be an integer which is a file mode value." | |||
| 456 | (let* ((modified (buffer-modified-p)) | 460 | (let* ((modified (buffer-modified-p)) |
| 457 | (result '()) | 461 | (result '()) |
| 458 | (pos (point-min)) | 462 | (pos (point-min)) |
| 463 | (coding tar-file-name-coding-system) | ||
| 459 | (progress-reporter | 464 | (progress-reporter |
| 460 | (with-current-buffer tar-data-buffer | 465 | (with-current-buffer tar-data-buffer |
| 461 | (make-progress-reporter "Parsing tar file..." | 466 | (make-progress-reporter "Parsing tar file..." |
| @@ -463,7 +468,7 @@ MODE should be an integer which is a file mode value." | |||
| 463 | descriptor) | 468 | descriptor) |
| 464 | (with-current-buffer tar-data-buffer | 469 | (with-current-buffer tar-data-buffer |
| 465 | (while (and (<= (+ pos 512) (point-max)) | 470 | (while (and (<= (+ pos 512) (point-max)) |
| 466 | (setq descriptor (tar-header-block-tokenize pos))) | 471 | (setq descriptor (tar-header-block-tokenize pos coding))) |
| 467 | (let ((size (tar-header-size descriptor))) | 472 | (let ((size (tar-header-size descriptor))) |
| 468 | (if (< size 0) | 473 | (if (< size 0) |
| 469 | (error "%s has size %s - corrupted" | 474 | (error "%s has size %s - corrupted" |
| @@ -578,7 +583,7 @@ MODE should be an integer which is a file mode value." | |||
| 578 | 583 | ||
| 579 | (defun tar-change-major-mode-hook () | 584 | (defun tar-change-major-mode-hook () |
| 580 | ;; Bring the actual Tar data back into the main buffer. | 585 | ;; Bring the actual Tar data back into the main buffer. |
| 581 | (when (tar-data-swapped-p) (buffer-swap-text tar-data-buffer)) | 586 | (when (tar-data-swapped-p) (tar-swap-data)) |
| 582 | ;; Throw away the summary. | 587 | ;; Throw away the summary. |
| 583 | (when (buffer-live-p tar-data-buffer) (kill-buffer tar-data-buffer))) | 588 | (when (buffer-live-p tar-data-buffer) (kill-buffer tar-data-buffer))) |
| 584 | 589 | ||
| @@ -621,7 +626,6 @@ See also: variables `tar-update-datestamp' and `tar-anal-blocksize'. | |||
| 621 | ;; buffer for the summary. | 626 | ;; buffer for the summary. |
| 622 | (assert (not (tar-data-swapped-p))) | 627 | (assert (not (tar-data-swapped-p))) |
| 623 | (set (make-local-variable 'revert-buffer-function) 'tar-mode-revert) | 628 | (set (make-local-variable 'revert-buffer-function) 'tar-mode-revert) |
| 624 | (add-hook 'write-region-annotate-functions 'tar-write-region-annotate nil t) | ||
| 625 | (add-hook 'kill-buffer-hook 'tar-mode-kill-buffer-hook nil t) | 629 | (add-hook 'kill-buffer-hook 'tar-mode-kill-buffer-hook nil t) |
| 626 | (add-hook 'change-major-mode-hook 'tar-change-major-mode-hook nil t) | 630 | (add-hook 'change-major-mode-hook 'tar-change-major-mode-hook nil t) |
| 627 | ;; Tar data is made of bytes, not chars. | 631 | ;; Tar data is made of bytes, not chars. |
| @@ -630,7 +634,7 @@ See also: variables `tar-update-datestamp' and `tar-anal-blocksize'. | |||
| 630 | (generate-new-buffer (format " *tar-data %s*" | 634 | (generate-new-buffer (format " *tar-data %s*" |
| 631 | (file-name-nondirectory | 635 | (file-name-nondirectory |
| 632 | (or buffer-file-name (buffer-name)))))) | 636 | (or buffer-file-name (buffer-name)))))) |
| 633 | (buffer-swap-text tar-data-buffer) | 637 | (tar-swap-data) |
| 634 | (tar-summarize-buffer) | 638 | (tar-summarize-buffer) |
| 635 | (tar-next-line 0)) | 639 | (tar-next-line 0)) |
| 636 | 640 | ||
| @@ -666,16 +670,14 @@ appear on disk when you save the tar-file's buffer." | |||
| 666 | (defun tar-mode-revert (&optional no-auto-save no-confirm) | 670 | (defun tar-mode-revert (&optional no-auto-save no-confirm) |
| 667 | (unwind-protect | 671 | (unwind-protect |
| 668 | (let ((revert-buffer-function nil)) | 672 | (let ((revert-buffer-function nil)) |
| 669 | (if (tar-data-swapped-p) (buffer-swap-text tar-data-buffer)) | 673 | (if (tar-data-swapped-p) (tar-swap-data)) |
| 670 | ;; FIXME: If we ask for confirmation, the user will be temporarily | 674 | ;; FIXME: If we ask for confirmation, the user will be temporarily |
| 671 | ;; looking at the raw data. | 675 | ;; looking at the raw data. |
| 672 | (revert-buffer no-auto-save no-confirm 'preserve-modes) | 676 | (revert-buffer no-auto-save no-confirm 'preserve-modes) |
| 673 | ;; The new raw data may be smaller than the old summary, so let's | ||
| 674 | ;; make sure tar-data-swapped-p doesn't get confused. | ||
| 675 | (if (buffer-live-p tar-data-buffer) (kill-buffer tar-data-buffer)) | ||
| 676 | ;; Recompute the summary. | 677 | ;; Recompute the summary. |
| 678 | (if (buffer-live-p tar-data-buffer) (kill-buffer tar-data-buffer)) | ||
| 677 | (tar-mode)) | 679 | (tar-mode)) |
| 678 | (unless (tar-data-swapped-p) (buffer-swap-text tar-data-buffer)))) | 680 | (unless (tar-data-swapped-p) (tar-swap-data)))) |
| 679 | 681 | ||
| 680 | 682 | ||
| 681 | (defun tar-next-line (arg) | 683 | (defun tar-next-line (arg) |
| @@ -1197,17 +1199,6 @@ Leaves the region wide." | |||
| 1197 | (delete-region goal-end (point-max)) | 1199 | (delete-region goal-end (point-max)) |
| 1198 | (goto-char (point-max)) | 1200 | (goto-char (point-max)) |
| 1199 | (insert (make-string (- goal-end (point-max)) ?\0)))))))) | 1201 | (insert (make-string (- goal-end (point-max)) ?\0)))))))) |
| 1200 | |||
| 1201 | |||
| 1202 | ;; Used in write-region-annotate-functions to write tar-files out correctly. | ||
| 1203 | (defun tar-write-region-annotate (start end) | ||
| 1204 | ;; When called from write-file (and auto-save), `start' is nil. | ||
| 1205 | ;; When called from M-x write-region, we assume the user wants to save | ||
| 1206 | ;; (part of) the summary, not the tar data. | ||
| 1207 | (unless (or start (not (tar-data-swapped-p))) | ||
| 1208 | (tar-clear-modification-flags) | ||
| 1209 | (set-buffer tar-data-buffer) | ||
| 1210 | nil)) | ||
| 1211 | 1202 | ||
| 1212 | (provide 'tar-mode) | 1203 | (provide 'tar-mode) |
| 1213 | 1204 | ||