emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] emacs/lisp ChangeLog tar-mode.el


From: Andreas Schwab
Subject: [Emacs-diffs] emacs/lisp ChangeLog tar-mode.el
Date: Fri, 26 Dec 2008 16:38:05 +0000

CVSROOT:        /sources/emacs
Module name:    emacs
Changes by:     Andreas Schwab <schwab> 08/12/26 16:38:05

Modified files:
        lisp           : ChangeLog tar-mode.el 

Log message:
        (tar-swap-data): New function.
        (tar-change-major-mode-hook): Use it instead of buffer-swap-text.
        (tar-mode-revert): Likewise.
        (tar-mode): Likewise.  Don't set write-region-annotate-functions.
        (tar-data-swapped-p): Test buffer-swapped-with.
        (tar-write-region-annotate): Remove.
        (tar-header-block-tokenize): Add argument `coding' and use it
        instead of tar-file-name-coding-system.
        (tar-summarize-buffer): Pass tar-file-name-coding-system here.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/emacs/lisp/ChangeLog?cvsroot=emacs&r1=1.14991&r2=1.14992
http://cvs.savannah.gnu.org/viewcvs/emacs/lisp/tar-mode.el?cvsroot=emacs&r1=1.130&r2=1.131

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/emacs/emacs/lisp/ChangeLog,v
retrieving revision 1.14991
retrieving revision 1.14992
diff -u -b -r1.14991 -r1.14992
--- ChangeLog   26 Dec 2008 15:02:47 -0000      1.14991
+++ ChangeLog   26 Dec 2008 16:38:00 -0000      1.14992
@@ -1,3 +1,15 @@
+2008-12-26  Andreas Schwab  <address@hidden>
+
+       * tar-mode.el (tar-swap-data): New function.
+       (tar-change-major-mode-hook): Use it instead of buffer-swap-text.
+       (tar-mode-revert): Likewise.
+       (tar-mode): Likewise.  Don't set write-region-annotate-functions.
+       (tar-data-swapped-p): Test buffer-swapped-with.
+       (tar-write-region-annotate): Remove.
+       (tar-header-block-tokenize): Add argument `coding' and use it
+       instead of tar-file-name-coding-system.
+       (tar-summarize-buffer): Pass tar-file-name-coding-system here.
+
 2008-12-26  Eli Zaretskii  <address@hidden>
 
        * dos-fns.el (dosified-file-name): New function.

Index: tar-mode.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/tar-mode.el,v
retrieving revision 1.130
retrieving revision 1.131
diff -u -b -r1.130 -r1.131
--- tar-mode.el 1 Jun 2008 02:35:03 -0000       1.130
+++ tar-mode.el 26 Dec 2008 16:38:04 -0000      1.131
@@ -161,14 +161,19 @@
 
 (defun tar-data-swapped-p ()
   "Return non-nil if the tar-data is in `tar-data-buffer'."
-  ;; We need to be careful to keep track of which buffer holds the tar-data,
-  ;; since we swap them back and forth.  Since the user may make the summary
-  ;; buffer unibyte, we can't rely on the multibyteness of the buffers.
-  ;; We could try and recognize the tar-format signature, but instead
-  ;; I decided to go for something simpler.
-  (and (buffer-live-p tar-data-buffer)
-       (> (buffer-size tar-data-buffer) (buffer-size))))
+  (buffer-live-p buffer-swapped-with))
 
+(defun tar-swap-data ()
+  "Swap buffer contents between current buffer and `tar-data-buffer'.
+Preserve the modified states of the buffers and set `buffer-swapped-with'."
+  (let ((data-buffer-modified-p (buffer-modified-p tar-data-buffer))
+       (current-buffer-modified-p (buffer-modified-p)))
+    (buffer-swap-text tar-data-buffer)
+    (setq buffer-swapped-with
+         (if buffer-swapped-with nil tar-data-buffer))
+    (set-buffer-modified-p data-buffer-modified-p)
+    (with-current-buffer tar-data-buffer
+      (set-buffer-modified-p current-buffer-modified-p))))
 
 ;;; down to business.
 
@@ -207,7 +212,7 @@
   "Round S up to the next multiple of 512."
   (ash (ash (+ s 511) -9) 9))
  
-(defun tar-header-block-tokenize (pos)
+(defun tar-header-block-tokenize (pos coding)
   "Return a `tar-header' structure.
 This is a list of name, mode, uid, gid, size,
 write-date, checksum, link-type, and link-name."
@@ -249,10 +254,9 @@
                              "/" name)))
         (if default-enable-multibyte-characters
             (setq name
-                  (decode-coding-string name tar-file-name-coding-system)
+                  (decode-coding-string name coding)
                   linkname
-                  (decode-coding-string linkname
-                                        tar-file-name-coding-system)))
+                  (decode-coding-string linkname coding)))
         (if (and (null link-p) (string-match "/\\'" name))
             (setq link-p 5))            ; directory
 
@@ -264,7 +268,7 @@
                    ;; -1 so as to strip the terminating 0 byte.
                    (name (buffer-substring pos (+ pos size -1)))
                    (descriptor (tar-header-block-tokenize
-                                (+ pos (tar-roundup-512 size)))))
+                                (+ pos (tar-roundup-512 size)) coding)))
               (cond
                ((eq link-p (- ?L ?0))      ;GNUTYPE_LONGNAME.
                 (setf (tar-header-name descriptor) name))
@@ -456,6 +460,7 @@
   (let* ((modified (buffer-modified-p))
          (result '())
          (pos (point-min))
+        (coding tar-file-name-coding-system)
          (progress-reporter
           (with-current-buffer tar-data-buffer
             (make-progress-reporter "Parsing tar file..."
@@ -463,7 +468,7 @@
          descriptor)
     (with-current-buffer tar-data-buffer
       (while (and (<= (+ pos 512) (point-max))
-                  (setq descriptor (tar-header-block-tokenize pos)))
+                  (setq descriptor (tar-header-block-tokenize pos coding)))
         (let ((size (tar-header-size descriptor)))
           (if (< size 0)
               (error "%s has size %s - corrupted"
@@ -578,7 +583,7 @@
 
 (defun tar-change-major-mode-hook ()
   ;; Bring the actual Tar data back into the main buffer.
-  (when (tar-data-swapped-p) (buffer-swap-text tar-data-buffer))
+  (when (tar-data-swapped-p) (tar-swap-data))
   ;; Throw away the summary.
   (when (buffer-live-p tar-data-buffer) (kill-buffer tar-data-buffer)))
 
@@ -621,7 +626,6 @@
   ;; buffer for the summary.
   (assert (not (tar-data-swapped-p)))
   (set (make-local-variable 'revert-buffer-function) 'tar-mode-revert)
-  (add-hook 'write-region-annotate-functions 'tar-write-region-annotate nil t)
   (add-hook 'kill-buffer-hook 'tar-mode-kill-buffer-hook nil t)
   (add-hook 'change-major-mode-hook 'tar-change-major-mode-hook nil t)
   ;; Tar data is made of bytes, not chars.
@@ -630,7 +634,7 @@
        (generate-new-buffer (format " *tar-data %s*"
                                     (file-name-nondirectory
                                      (or buffer-file-name (buffer-name))))))
-  (buffer-swap-text tar-data-buffer)
+  (tar-swap-data)
   (tar-summarize-buffer)
   (tar-next-line 0))
 
@@ -666,16 +670,14 @@
 (defun tar-mode-revert (&optional no-auto-save no-confirm)
   (unwind-protect
       (let ((revert-buffer-function nil))
-        (if (tar-data-swapped-p) (buffer-swap-text tar-data-buffer))
+        (if (tar-data-swapped-p) (tar-swap-data))
         ;; FIXME: If we ask for confirmation, the user will be temporarily
         ;; looking at the raw data.
         (revert-buffer no-auto-save no-confirm 'preserve-modes)
-        ;; The new raw data may be smaller than the old summary, so let's
-        ;; make sure tar-data-swapped-p doesn't get confused.
-        (if (buffer-live-p tar-data-buffer) (kill-buffer tar-data-buffer))
         ;; Recompute the summary.
+        (if (buffer-live-p tar-data-buffer) (kill-buffer tar-data-buffer))
         (tar-mode))
-    (unless (tar-data-swapped-p) (buffer-swap-text tar-data-buffer))))
+    (unless (tar-data-swapped-p) (tar-swap-data))))
 
 
 (defun tar-next-line (arg)
@@ -1198,17 +1200,6 @@
             (goto-char (point-max))
             (insert (make-string (- goal-end (point-max)) ?\0))))))))
 
-
-;; Used in write-region-annotate-functions to write tar-files out correctly.
-(defun tar-write-region-annotate (start end)
-  ;; When called from write-file (and auto-save), `start' is nil.
-  ;; When called from M-x write-region, we assume the user wants to save
-  ;; (part of) the summary, not the tar data.
-  (unless (or start (not (tar-data-swapped-p)))
-    (tar-clear-modification-flags)
-    (set-buffer tar-data-buffer)
-    nil))
-
 (provide 'tar-mode)
 
 ;; arch-tag: 8a585a4a-340e-42c2-89e7-d3b1013a4b78




reply via email to

[Prev in Thread] Current Thread [Next in Thread]