changeset 90283:9970a9645ad9

Revision: emacs@sv.gnu.org/emacs--unicode--0--patch-4 Creator: Stefan Monnier <monnier@iro.umontreal.ca> Merge tar-mode changes from the trunk. * tar-mode.el: Merge changes from the trunk: (tar-header-block-tokenize): Tighten regexp. (tar-summarize-buffer): Don't clear the modified-p bit if it wasn't cleared before. Obey default-enable-multibyte-characters. Use mapconcat. (tar-mode-map): Move initialization inside delcaration. (tar-alter-one-field): Don't hardcode point-min==1.
author Miles Bader <miles@gnu.org>
date Sat, 21 Jan 2006 06:45:38 +0000
parents 065f97626ec7
children f12f7e75abbe
files lisp/ChangeLog.unicode lisp/tar-mode.el
diffstat 2 files changed, 172 insertions(+), 169 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog.unicode	Fri Jan 20 07:38:27 2006 +0000
+++ b/lisp/ChangeLog.unicode	Sat Jan 21 06:45:38 2006 +0000
@@ -1,3 +1,13 @@
+2006-01-19  Stefan Monnier  <monnier@iro.umontreal.ca>
+
+	* tar-mode.el: Merge changes from the trunk:
+	(tar-header-block-tokenize): Tighten regexp.
+	(tar-summarize-buffer): Don't clear the modified-p bit if it wasn't
+	cleared before.  Obey default-enable-multibyte-characters.
+	Use mapconcat.
+	(tar-mode-map): Move initialization inside delcaration.
+	(tar-alter-one-field): Don't hardcode point-min==1.
+
 2006-01-20  Naoto Takahashi  <ntakahas@m17n.org>
 
 	* language/ethiopic.el: Copyright fixed.
@@ -24,14 +34,13 @@
 
 	* international/mule-cmds.el (locale-language-names): Add entries
 	for zh_CN.GB2312, zh_CN.GBK, and zh_CN.GB18030.
-	(locale-preferred-coding-systems): Fix entries for Chinese
-	locales.
+	(locale-preferred-coding-systems): Fix entries for Chinese locales.
 
 2005-10-24  Kenichi Handa  <handa@etlken>
 
 	* international/utf-7.el: Delete the definition of utf-7.
-	(utf-7-post-read-conversion, utf-7-pre-write-conversion): Add
-	autoload cookies.
+	(utf-7-post-read-conversion, utf-7-pre-write-conversion):
+	Add autoload cookies.
 
 2005-10-18  YAMAMOTO Mitsuharu  <mituharu@math.s.chiba-u.ac.jp>
 
@@ -53,15 +62,15 @@
 
 	* descr-text.el (describe-char): Sync with the main trunk.
 
-	* international/mule.el (coding-system-get): Check
-	`ascii-incompatible' for backward compatiblity.
+	* international/mule.el (coding-system-get):
+	Check `ascii-incompatible' for backward compatiblity.
 	(set-file-name-coding-system): Signal an error for a coding system
 	not suitable for file name.
 	(set-keyboard-coding-system): Signal an error for a coding system
 	not suitable for keyboard.
 
-	* language/chinese.el (iso-2022-cn, iso-2022-cn-ext): Set
-	:suitable-for-keyboard property to 1.
+	* language/chinese.el (iso-2022-cn, iso-2022-cn-ext):
+	Set :suitable-for-keyboard property to 1.
 
 	* language/japanese.el (iso-2022-jp, iso-2022-jp-2)
 	(iso-2022-jp-2004): Set :suitable-for-keyboard property to 1.
@@ -71,8 +80,7 @@
 
 2005-07-26  Naoto Takahashi  <ntakahas@m17n.org>
 
-	* international/robin.el (robin-define-package): Delete redundant
-	code.
+	* international/robin.el (robin-define-package): Delete redundant code.
 	(robin-add-rule): Allow N-1 reverse conversion.
 
 2005-07-26  Naoto Takahashi  <ntakahas@m17n.org>
@@ -1242,24 +1250,23 @@
 2002-09-08  Dave Love  <fx@gnu.org>
 
 	* language/ind-util.el (ucs-devanagari-to-is13194-alist)
-	(indian-glyph-char, indian-char-glyph): Deleted.
-	(is13194-default-repertory): Renamed from
-	is13194-default-repartory,
+	(indian-glyph-char, indian-char-glyph): Delete.
+	(is13194-default-repertory): Rename from is13194-default-repartory.
 	(iscii-to-ucs-region): Hoist evals from loop.
 
 	* language/devan-util.el (dev-charseq): Avoid indian-glyph-char.
 
 	* language/indian.el (indian-script-table)
-	(ccl-encode-indian-glyph-font): Deleted.
-
-	* international/mule-conf.el (emacs-mule, iso-2022-7bit) 
-	(iso-2022-7bit-ss2, iso-2022-7bit-lock, iso-2022-8bit-ss2) 
+	(ccl-encode-indian-glyph-font): Delete.
+
+	* international/mule-conf.el (emacs-mule, iso-2022-7bit)
+	(iso-2022-7bit-ss2, iso-2022-7bit-lock, iso-2022-8bit-ss2)
 	(compound-text, ctext-no-compositions): Remove :charset-list.
 
 	* international/mule-cmds.el (language-info-custom-alist): New.
-	(input-method-activate-hook, input-method-inactivate-hook) 
-	(input-method-after-insert-chunk-hook) 
-	(input-method-use-echo-area, set-language-environment-hook) 
+	(input-method-activate-hook, input-method-inactivate-hook)
+	(input-method-after-insert-chunk-hook)
+	(input-method-use-echo-area, set-language-environment-hook)
 	(exit-language-environment-hook): Customize.
 	(find-coding-systems-for-charsets): Rewritten.
 	(default-input-method): Add :link.
@@ -1271,8 +1278,7 @@
 	(cp851): Doc fix.
 	(unicode-bmp): New.
 
-	* case-table.el (set-case-syntax-pair): Remove check on byte
-	lengths.
+	* case-table.el (set-case-syntax-pair): Remove check on byte lengths.
 
 	* language/european.el (cp858): New.
 	("Turkish"): Add special case rules.
@@ -1300,8 +1306,8 @@
 
 2002-08-19  Kenichi Handa  <handa@etl.go.jp>
 
-	* international/characters.el: Fix categories ?A and ?C.  Treat
-	ASCII characters as `latin' script.
+	* international/characters.el: Fix categories ?A and ?C.
+	Treat ASCII characters as `latin' script.
 
 2002-08-18  Kenichi Handa  <handa@etl.go.jp>
 
@@ -1320,24 +1326,23 @@
 
 	* wid-edit.el (character): Use characterp.
 
-	* international/mule-diag.el (describe-coding-system): Add utf-16
-	case.
+	* international/mule-diag.el (describe-coding-system): Add utf-16 case.
 
 	* language/viet-util.el (viet-encode-viscii-char): Use encode-char.
 
-	* language/cyrillic.el ("Tajik", "Bulgarian", "Belarusian"): Add
-	charset.
+	* language/cyrillic.el ("Tajik", "Bulgarian", "Belarusian"):
+	Add charset.
 	("Ukrainian"): New.
 
 	* language/georgian.el (georgian-ps): New coding system.
 
 2002-08-15  Kenichi Handa  <handa@etl.go.jp>
 
-	* international/mule-cmds.el (reset-language-environment): Don't
-	set nonascii-translation-table and nonascii-insert-offset.  Call
-	set-unibyte-charset, not set-primary-charset.
-	(nonascii-translation-table, nonascii-insert-offset): Declare
-	these variable as obsolete ones.
+	* international/mule-cmds.el (reset-language-environment):
+	Don't set nonascii-translation-table and nonascii-insert-offset.
+	Call set-unibyte-charset, not set-primary-charset.
+	(nonascii-translation-table, nonascii-insert-offset):
+	Declare these variable as obsolete ones.
 	(set-language-environment): Call set-unibyte-charset, not
 	set-primary-charset.  Call set-charset-priority with `charset'
 	info of the language environment.
@@ -1348,8 +1353,8 @@
 
 2002-08-02  Kenichi Handa  <handa@etl.go.jp>
 
-	* international/characters.el (next-word-boundary-han): Don't
-	treat katakana following han characters as a part of a word.
+	* international/characters.el (next-word-boundary-han):
+	Don't treat katakana following han characters as a part of a word.
 
 2002-08-01  Kenichi Handa  <handa@etl.go.jp>
 
@@ -1376,14 +1381,14 @@
 	(archive-rename-entry): Encode the filename by
 	archive-file-name-coding-system.
 	(archive-mode-revert): Don't change the buffer's multibyteness.
-	(archive-arc-summarize, archive-lzh-summarize,
-	archive-zoo-summarize): Don't change the buffer's multibyteness.
+	(archive-arc-summarize, archive-lzh-summarize)
+	(archive-zoo-summarize): Don't change the buffer's multibyteness.
 	Decode filenames by archive-file-name-coding-system.
 	(archive-arc-rename-entry, archive-zip-chmod-entry): Don't change
 	the buffer's multibyteness.
 
-	* tar-mode.el (tar-file-name-coding-system): New variable.  Make
-	it permanent-local.p
+	* tar-mode.el (tar-file-name-coding-system): New variable.
+	Make it permanent-local.
 	(tar-header-block-tokenize): Decode filename and linkname by
 	tar-file-name-coding-system.
 	(tar-header-block-checksum): Call multibyte-char-to-unibyte to get
@@ -1392,27 +1397,23 @@
 	`to'.  Delete unnecessary call of position-bytes.
 	(tar-mode): Set tar-file-name-coding-system.  Delete unnecessary
 	call of position-bytes.
-	(tar-extract): Simplified by calling decode-coding-region with
+	(tar-extract): Simplify by calling decode-coding-region with
 	DESTINATION argument.  Don't toggle multibyteness of tar buffer.
 	(tar-copy): Don't toggle multibyteness of tar buffer.
 	(tar-expunge): Likewise.
 	(tar-clear-modification-flags): Delete unnecessary call of
 	position-bytes.
-	(tar-rename-entry): Call tar-alter-one-field with encoded new
-	name.
+	(tar-rename-entry): Call tar-alter-one-field with encoded new name.
 	(tar-alter-one-field): Don't toggle multibyteness of tar buffer.
-	Convert new-data-string by string-to-multibyte before inserting
-	it.
+	Convert new-data-string by string-to-multibyte before inserting it.
 	(tar-subfile-save-buffer): Don't toggle multibyteness of tar
-	buffer.  Simplified by calling encoding-coding-region with
+	buffer.  Simplify by calling encoding-coding-region with
 	DESTINATION argument.
-	(tar-mode-write-file): Delete unnecessary call of
-	byte-to-position.
+	(tar-mode-write-file): Delete unnecessary call of byte-to-position.
 
 2002-07-30  Dave Love  <fx@gnu.org>
 
-	* international/titdic-cnv.el (quail-cxterm-package-ext-info): Doc
-	fix.
+	* international/titdic-cnv.el (quail-cxterm-package-ext-info): Doc fix.
 
 	* emacs-lisp/copyright.el (copyright-regexp): Remove redundancy.
 
@@ -1448,13 +1449,12 @@
 
 2002-07-17  Kenichi Handa  <handa@etl.go.jp>
 
-	* international/mule-util.el (detect-coding-with-priority): Fix
-	the place of using `,' marker in backguote form.
+	* international/mule-util.el (detect-coding-with-priority):
+	Fix the place of using `,' marker in backguote form.
 
 2002-07-12  Dave Love  <fx@gnu.org>
 
-	* international/mule-conf.el (mule-unicode-e000-ffff): Set
-	:max-code.
+	* international/mule-conf.el (mule-unicode-e000-ffff): Set :max-code.
 
 	* international/mule-util.el (with-coding-priority): Fix.
 
@@ -2203,9 +2203,9 @@
 	(coding-spec-XXX-idx): Variables deleted.
 	(coding-system-iso-2022-flags): New variable.
 	(define-coding-system): New function.
-	(transform-make-coding-system-args, make-coding-system): Deleted.
+	(transform-make-coding-system-args, make-coding-system): Delete.
 	(set-coding-priority): Make it obsolete.
-	(after-insert-file-set-buffer-file-coding-system): Adjusted for
+	(after-insert-file-set-buffer-file-coding-system): Adjust for
 	the new coding system structure.
 	(find-new-buffer-file-coding-system): Likewise.
 
@@ -2221,7 +2221,7 @@
 	(sgml-char-names-table): Iteration limit fixed.
 
 	* term/mac-win.el: Deleted unnecessary calls of set-fontset-font.
-	(ccl-encode-mac-roman-font): Deleted.
+	(ccl-encode-mac-roman-font): Delete.
 
 	* Makefile.in (DONTCOMPILE): Add latin1-disp.el, ucs-tables.el,
 	utf-8.el, and utf-8-subst.el as they can't be bytecompiled
--- a/lisp/tar-mode.el	Fri Jan 20 07:38:27 2006 +0000
+++ b/lisp/tar-mode.el	Sat Jan 21 06:45:38 2006 +0000
@@ -237,7 +237,7 @@
 		     linkname
 		     (decode-coding-string linkname
 					   tar-file-name-coding-system)))
-	   (if (and (null link-p) (string-match "/$" name)) (setq link-p 5)) ; directory
+	   (if (and (null link-p) (string-match "/\\'" name)) (setq link-p 5)) ; directory
 	   (make-tar-header
 	     name
 	     (tar-parse-octal-integer string tar-mode-offset tar-uid-offset)
@@ -404,144 +404,145 @@
 Place a dired-like listing on the front;
 then narrow to it, so that only that listing
 is visible (and the real data of the buffer is hidden)."
-  (set-buffer-multibyte nil)
-  (let* ((result '())
-	 (pos (point-min))
-	 (progress-reporter
-	  (make-progress-reporter "Parsing tar file..."
-				  (point-min) (max 1 (- (buffer-size) 1024))))
-	 tokens)
-    (while (and (<= (+ pos 512) (point-max))
-		(not (eq 'empty-tar-block
-			 (setq tokens
-			       (tar-header-block-tokenize
-				(buffer-substring pos (+ pos 512)))))))
-      (setq pos (+ pos 512))
-      (progress-reporter-update progress-reporter pos)
-      (if (eq (tar-header-link-type tokens) 20)
-	  ;; Foo.  There's an extra empty block after these.
-	  (setq pos (+ pos 512)))
-      (let ((size (tar-header-size tokens)))
-	(if (< size 0)
-	    (error "%s has size %s - corrupted"
-		   (tar-header-name tokens) size))
-	;
-	; This is just too slow.  Don't really need it anyway....
-	;(tar-header-block-check-checksum
-	;  hblock (tar-header-block-checksum hblock)
-	;  (tar-header-name tokens))
+  (let ((modified (buffer-modified-p)))
+    (set-buffer-multibyte nil)
+    (let* ((result '())
+           (pos (point-min))
+           (progress-reporter
+            (make-progress-reporter "Parsing tar file..."
+                                    (point-min) (max 1 (- (buffer-size) 1024))))
+           tokens)
+      (while (and (<= (+ pos 512) (point-max))
+                  (not (eq 'empty-tar-block
+                           (setq tokens
+                                 (tar-header-block-tokenize
+                                  (buffer-substring pos (+ pos 512)))))))
+        (setq pos (+ pos 512))
+        (progress-reporter-update progress-reporter pos)
+        (if (eq (tar-header-link-type tokens) 20)
+            ;; Foo.  There's an extra empty block after these.
+            (setq pos (+ pos 512)))
+        (let ((size (tar-header-size tokens)))
+          (if (< size 0)
+              (error "%s has size %s - corrupted"
+                     (tar-header-name tokens) size))
+          ;;
+          ;; This is just too slow.  Don't really need it anyway....
+          ;;(tar-header-block-check-checksum
+          ;;  hblock (tar-header-block-checksum hblock)
+          ;;  (tar-header-name tokens))
 
-	(setq result (cons (make-tar-desc pos tokens) result))
+          (push (make-tar-desc pos tokens) result)
 
-	(and (null (tar-header-link-type tokens))
-	     (> size 0)
-	     (setq pos
-		   (+ pos 512 (ash (ash (1- size) -9) 9))        ; this works
-		   ;(+ pos (+ size (- 512 (rem (1- size) 512)))) ; this doesn't
-		   ))))
-    (make-local-variable 'tar-parse-info)
-    (setq tar-parse-info (nreverse result))
-    ;; A tar file should end with a block or two of nulls,
-    ;; but let's not get a fatal error if it doesn't.
-    (if (eq tokens 'empty-tar-block)
-	(progress-reporter-done progress-reporter)
-      (message "Warning: premature EOF parsing tar file")))
-  (save-excursion
+          (and (null (tar-header-link-type tokens))
+               (> size 0)
+               (setq pos
+                     (+ pos 512 (ash (ash (1- size) -9) 9)) ; this works
+                     ;;(+ pos (+ size (- 512 (rem (1- size) 512)))) ; this doesn't
+                     ))))
+      (make-local-variable 'tar-parse-info)
+      (setq tar-parse-info (nreverse result))
+      ;; A tar file should end with a block or two of nulls,
+      ;; but let's not get a fatal error if it doesn't.
+      (if (eq tokens 'empty-tar-block)
+          (progress-reporter-done progress-reporter)
+        (message "Warning: premature EOF parsing tar file")))
+    ;; Obey the user's preference for the use of uni/multibytes.
+    (set-buffer-multibyte default-enable-multibyte-characters)
     (goto-char (point-min))
-    (let ((buffer-read-only nil)
-	  (summaries nil))
-      ;; Collect summary lines and insert them all at once since tar files
-      ;; can be pretty big.
-      (dolist (tar-desc (reverse tar-parse-info))
-	(setq summaries
-	      (cons (tar-header-block-summarize (tar-desc-tokens tar-desc))
-		    (cons "\n"
-			  summaries))))
-      (let ((total-summaries (apply 'concat summaries)))
-	(insert total-summaries))
-      (make-local-variable 'tar-header-offset)
-      (setq tar-header-offset (point))
-      (narrow-to-region (point-min) tar-header-offset)
-      (set-buffer-modified-p nil))))
+    (let ((inhibit-read-only t)
+          ;; Collect summary lines and insert them all at once since tar files
+          ;; can be pretty big.
+          (total-summaries
+           (mapconcat
+            (lambda (tar-desc)
+              (tar-header-block-summarize (tar-desc-tokens tar-desc)))
+            tar-parse-info
+            "\n")))
+      (insert total-summaries "\n"))
+    (narrow-to-region (point-min) (point))
+    (set (make-local-variable 'tar-header-offset) (position-bytes (point)))
+    (goto-char (point-min))
+    (restore-buffer-modified-p modified)))
 
-(defvar tar-mode-map nil "*Local keymap for Tar mode listings.")
+(defvar tar-mode-map
+  (let ((map (make-keymap)))
+    (suppress-keymap map)
+    (define-key map " " 'tar-next-line)
+    (define-key map "C" 'tar-copy)
+    (define-key map "d" 'tar-flag-deleted)
+    (define-key map "\^D" 'tar-flag-deleted)
+    (define-key map "e" 'tar-extract)
+    (define-key map "f" 'tar-extract)
+    (define-key map "\C-m" 'tar-extract)
+    (define-key map [mouse-2] 'tar-mouse-extract)
+    (define-key map "g" 'revert-buffer)
+    (define-key map "h" 'describe-mode)
+    (define-key map "n" 'tar-next-line)
+    (define-key map "\^N" 'tar-next-line)
+    (define-key map [down] 'tar-next-line)
+    (define-key map "o" 'tar-extract-other-window)
+    (define-key map "p" 'tar-previous-line)
+    (define-key map "q" 'quit-window)
+    (define-key map "\^P" 'tar-previous-line)
+    (define-key map [up] 'tar-previous-line)
+    (define-key map "R" 'tar-rename-entry)
+    (define-key map "u" 'tar-unflag)
+    (define-key map "v" 'tar-view)
+    (define-key map "x" 'tar-expunge)
+    (define-key map "\177" 'tar-unflag-backwards)
+    (define-key map "E" 'tar-extract-other-window)
+    (define-key map "M" 'tar-chmod-entry)
+    (define-key map "G" 'tar-chgrp-entry)
+    (define-key map "O" 'tar-chown-entry)
+
+    ;; Make menu bar items.
 
-(if tar-mode-map
-    nil
-  (setq tar-mode-map (make-keymap))
-  (suppress-keymap tar-mode-map)
-  (define-key tar-mode-map " " 'tar-next-line)
-  (define-key tar-mode-map "C" 'tar-copy)
-  (define-key tar-mode-map "d" 'tar-flag-deleted)
-  (define-key tar-mode-map "\^D" 'tar-flag-deleted)
-  (define-key tar-mode-map "e" 'tar-extract)
-  (define-key tar-mode-map "f" 'tar-extract)
-  (define-key tar-mode-map "\C-m" 'tar-extract)
-  (define-key tar-mode-map [mouse-2] 'tar-mouse-extract)
-  (define-key tar-mode-map "g" 'revert-buffer)
-  (define-key tar-mode-map "h" 'describe-mode)
-  (define-key tar-mode-map "n" 'tar-next-line)
-  (define-key tar-mode-map "\^N" 'tar-next-line)
-  (define-key tar-mode-map [down] 'tar-next-line)
-  (define-key tar-mode-map "o" 'tar-extract-other-window)
-  (define-key tar-mode-map "p" 'tar-previous-line)
-  (define-key tar-mode-map "q" 'quit-window)
-  (define-key tar-mode-map "\^P" 'tar-previous-line)
-  (define-key tar-mode-map [up] 'tar-previous-line)
-  (define-key tar-mode-map "R" 'tar-rename-entry)
-  (define-key tar-mode-map "u" 'tar-unflag)
-  (define-key tar-mode-map "v" 'tar-view)
-  (define-key tar-mode-map "x" 'tar-expunge)
-  (define-key tar-mode-map "\177" 'tar-unflag-backwards)
-  (define-key tar-mode-map "E" 'tar-extract-other-window)
-  (define-key tar-mode-map "M" 'tar-chmod-entry)
-  (define-key tar-mode-map "G" 'tar-chgrp-entry)
-  (define-key tar-mode-map "O" 'tar-chown-entry)
-  )
-
-;; Make menu bar items.
+    ;; Get rid of the Edit menu bar item to save space.
+    (define-key map [menu-bar edit] 'undefined)
 
-;; Get rid of the Edit menu bar item to save space.
-(define-key tar-mode-map [menu-bar edit] 'undefined)
-
-(define-key tar-mode-map [menu-bar immediate]
+    (define-key map [menu-bar immediate]
   (cons "Immediate" (make-sparse-keymap "Immediate")))
 
-(define-key tar-mode-map [menu-bar immediate view]
+    (define-key map [menu-bar immediate view]
   '("View This File" . tar-view))
-(define-key tar-mode-map [menu-bar immediate display]
+    (define-key map [menu-bar immediate display]
   '("Display in Other Window" . tar-display-other-window))
-(define-key tar-mode-map [menu-bar immediate find-file-other-window]
+    (define-key map [menu-bar immediate find-file-other-window]
   '("Find in Other Window" . tar-extract-other-window))
-(define-key tar-mode-map [menu-bar immediate find-file]
+    (define-key map [menu-bar immediate find-file]
   '("Find This File" . tar-extract))
 
-(define-key tar-mode-map [menu-bar mark]
+    (define-key map [menu-bar mark]
   (cons "Mark" (make-sparse-keymap "Mark")))
 
-(define-key tar-mode-map [menu-bar mark unmark-all]
+    (define-key map [menu-bar mark unmark-all]
   '("Unmark All" . tar-clear-modification-flags))
-(define-key tar-mode-map [menu-bar mark deletion]
+    (define-key map [menu-bar mark deletion]
   '("Flag" . tar-flag-deleted))
-(define-key tar-mode-map [menu-bar mark unmark]
+    (define-key map [menu-bar mark unmark]
   '("Unflag" . tar-unflag))
 
-(define-key tar-mode-map [menu-bar operate]
+    (define-key map [menu-bar operate]
   (cons "Operate" (make-sparse-keymap "Operate")))
 
-(define-key tar-mode-map [menu-bar operate chown]
+    (define-key map [menu-bar operate chown]
   '("Change Owner..." . tar-chown-entry))
-(define-key tar-mode-map [menu-bar operate chgrp]
+    (define-key map [menu-bar operate chgrp]
   '("Change Group..." . tar-chgrp-entry))
-(define-key tar-mode-map [menu-bar operate chmod]
+    (define-key map [menu-bar operate chmod]
   '("Change Mode..." . tar-chmod-entry))
-(define-key tar-mode-map [menu-bar operate rename]
+    (define-key map [menu-bar operate rename]
   '("Rename to..." . tar-rename-entry))
-(define-key tar-mode-map [menu-bar operate copy]
+    (define-key map [menu-bar operate copy]
   '("Copy to..." . tar-copy))
-(define-key tar-mode-map [menu-bar operate expunge]
+    (define-key map [menu-bar operate expunge]
   '("Expunge Marked Files" . tar-expunge))
 
+    map)
+  "Local keymap for Tar mode listings.")
+
+
 ;; tar mode is suitable only for specially formatted data.
 (put 'tar-mode 'mode-class 'special)
 (put 'tar-subfile-mode 'mode-class 'special)
@@ -1010,7 +1011,7 @@
 
 
 (defun tar-chmod-entry (new-mode)
-  "*Change the protection bits associated with this entry in the tar file.
+  "Change the protection bits associated with this entry in the tar file.
 This does not modify the disk image; you must save the tar file itself
 for this to be permanent."
   (interactive (list (tar-parse-octal-integer-safe
@@ -1036,7 +1037,9 @@
 	    (setq tar-header-offset (point-max)))
 
 	  (widen)
-	  (let* ((start (+ (tar-desc-data-start descriptor) tar-header-offset -513)))
+	  (let* ((start (+ (tar-desc-data-start descriptor)
+			   (- tar-header-offset (point-min))
+                           -512)))
 	    ;;
 	    ;; delete the old field and insert a new one.
 	    (goto-char (+ start data-position))