(forms--mode-menu-edit,forms--mode-menu-ro):
[bpt/emacs.git] / lisp / hexl.el
index 130a257..5fc0817 100644 (file)
@@ -77,6 +77,10 @@ and \"-de\" when dehexlfying a buffer.")
 
 (defvar hexl-mode-map nil)
 
+(defvar hexl-mode-old-local-map)
+(defvar hexl-mode-old-mode-name)
+(defvar hexl-mode-old-major-mode)
+
 ;; routines
 
 ;;;###autoload
@@ -170,8 +174,14 @@ You can use \\[hexl-find-file] to visit a file in hexl-mode.
     (make-local-variable 'write-contents-hooks)
     (add-hook 'write-contents-hooks 'hexl-save-buffer)
 
+    (make-local-hook 'after-revert-hook)
+    (add-hook 'after-revert-hook 'hexl-after-revert-hook nil t)
+
     (make-local-variable 'hexl-max-address)
 
+    (make-local-variable 'change-major-mode-hook)
+    (add-hook 'change-major-mode-hook 'hexl-maybe-dehexlify-buffer)
+
     (let ((modified (buffer-modified-p))
          (inhibit-read-only t)
          (original-point (1- (point))))
@@ -183,6 +193,10 @@ You can use \\[hexl-find-file] to visit a file in hexl-mode.
         (set-buffer-modified-p modified)
         (hexl-goto-address original-point)))))
 
+(defun hexl-after-revert-hook ()
+  (hexlify-buffer)
+  (set-buffer-modified-p nil))
+
 (defvar hexl-in-save-buffer nil)
 
 (defun hexl-save-buffer ()
@@ -220,7 +234,7 @@ You can use \\[hexl-find-file] to visit a file in hexl-mode.
   "Edit file FILENAME in hexl-mode.
 Switch to a buffer visiting file FILENAME, creating one in none exists."
   (interactive "fFilename: ")
-  (if (eq system-type 'ms-dos)
+  (if (or (eq system-type 'ms-dos) (eq system-type 'windows-nt))
       (find-file-binary filename)
     (find-file filename))
   (if (not (eq major-mode 'hexl-mode))
@@ -241,9 +255,19 @@ With arg, don't unhexlify buffer."
   (setq mode-name hexl-mode-old-mode-name)
   (use-local-map hexl-mode-old-local-map)
   (setq major-mode hexl-mode-old-major-mode)
-;; Kludge to update mode-line
-  (switch-to-buffer (current-buffer))
-)
+  (force-mode-line-update))
+
+(defun hexl-maybe-dehexlify-buffer ()
+  "Convert a hexl format buffer to binary.
+Ask the user for confirmation."
+  (if (y-or-n-p "Convert contents back to binary format? ")
+      (let ((modified (buffer-modified-p))
+           (inhibit-read-only t)
+           (original-point (1+ (hexl-current-address))))
+       (dehexlify-buffer)
+       (remove-hook 'write-contents-hook 'hexl-save-buffer)
+       (set-buffer-modified-p modified)
+       (goto-char original-point))))
 
 (defun hexl-current-address ()
   "Return current hexl-address."
@@ -498,7 +522,7 @@ You may also type up to 3 octal digits, to insert a character with that code"
 
 ;;;###autoload
 (defun hexlify-buffer ()
-  "Convert a binary buffer to hexl format"
+  "Convert a binary buffer to hexl format."
   (interactive)
   (let ((binary-process-output nil) ; for Ms-Dos
        (binary-process-input t))
@@ -614,7 +638,7 @@ You may also type up to 3 octal digits, to insert a character with that code"
     (define-key hexl-mode-map "\C-f" 'hexl-forward-char)
 
     (if (not (eq (key-binding (char-to-string help-char)) 'help-command))
-       (define-key hexl-mode-map help-char 'undefined))
+       (define-key hexl-mode-map (char-to-string help-char) 'undefined))
 
     (define-key hexl-mode-map "\C-i" 'hexl-self-insert-command)
     (define-key hexl-mode-map "\C-j" 'hexl-self-insert-command)