GNU bug report logs - #7252
hexl-revert-buffer

Previous Next

Package: emacs;

Reported by: Daiki Ueno <ueno <at> unixuser.org>

Date: Wed, 20 Oct 2010 06:01:02 UTC

Severity: normal

Done: Daiki Ueno <ueno <at> unixuser.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 7252 in the body.
You can then email your comments to 7252 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#7252; Package emacs. (Wed, 20 Oct 2010 06:01:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Daiki Ueno <ueno <at> unixuser.org>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Wed, 20 Oct 2010 06:01:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Daiki Ueno <ueno <at> unixuser.org>
To: bug-gnu-emacs <at> gnu.org
Subject: hexl-revert-buffer
Date: Wed, 20 Oct 2010 14:57:13 +0900
[Message part 1 (text/plain, inline)]
If I open a ZIP file with M-x hexl-find-file and then M-x revert-buffer,
I see hexified file list generated by arc-mode, instead of raw ZIP data.

This behavior is surprising for me and it is cumbersome to do M-x
kill-buffer and M-x hexl-find-file each time.

How about adding M-x hexl-revert-buffer?

[hexl-revert-buffer.diff (text/x-patch, inline)]
=== modified file 'lisp/hexl.el'
--- lisp/hexl.el	2010-10-10 23:12:30 +0000
+++ lisp/hexl.el	2010-10-20 05:46:47 +0000
@@ -189,6 +189,7 @@
     (define-key map "\C-x\C-p" 'undefined)
     (define-key map "\C-x\C-s" 'hexl-save-buffer)
     (define-key map "\C-x\C-t" 'undefined)
+    (define-key map "\C-xg" 'hexl-revert-buffer)
     map))
 
 ;; Variable declarations for suppressing warnings from the byte-compiler.
@@ -464,6 +465,16 @@
   (if (not (eq major-mode 'hexl-mode))
       (hexl-mode)))
 
+(defun hexl-revert-buffer ()
+  "Revert the buffer previously opened with `hexl-find-file'."
+  (interactive)
+  (if (eq major-mode 'hexl-mode)
+      (let ((coding-system-for-read 'no-conversion))
+	(revert-buffer nil nil t)
+	(setq major-mode 'fundamental-mode)
+	(hexl-mode))
+    (call-interactively #'revert-buffer)))
+
 (defun hexl-mode-exit (&optional arg)
   "Exit Hexl mode, returning to previous mode.
 With arg, don't unhexlify buffer."

[Message part 3 (text/plain, inline)]
Regards,
-- 
Daiki Ueno

Information forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#7252; Package emacs. (Wed, 20 Oct 2010 16:16:01 GMT) Full text and rfc822 format available.

Message #8 received at 7252 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Daiki Ueno <ueno <at> unixuser.org>
Cc: 7252 <at> debbugs.gnu.org
Subject: Re: bug#7252: hexl-revert-buffer
Date: Wed, 20 Oct 2010 12:18:53 -0400
> If I open a ZIP file with M-x hexl-find-file and then M-x revert-buffer,
> I see hexified file list generated by arc-mode, instead of raw ZIP data.

> This behavior is surprising for me and it is cumbersome to do M-x
> kill-buffer and M-x hexl-find-file each time.

> How about adding M-x hexl-revert-buffer?

No, we should tweak revert-buffer-function instead.

> +  (if (eq major-mode 'hexl-mode)

Use derived-mode-p rather than looking at major-mode.

> +      (let ((coding-system-for-read 'no-conversion))
> +	(revert-buffer nil nil t)
> +	(setq major-mode 'fundamental-mode)

Why is this setq needed (IOW please add a comment explaining why it's
needed).


        Stefan




Information forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#7252; Package emacs. (Thu, 21 Oct 2010 01:53:03 GMT) Full text and rfc822 format available.

Message #11 received at 7252 <at> debbugs.gnu.org (full text, mbox):

From: Daiki Ueno <ueno <at> unixuser.org>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 7252 <at> debbugs.gnu.org
Subject: Re: bug#7252: hexl-revert-buffer
Date: Thu, 21 Oct 2010 11:00:23 +0900
[Message part 1 (text/plain, inline)]
Stefan Monnier <monnier <at> iro.umontreal.ca> writes:

>> If I open a ZIP file with M-x hexl-find-file and then M-x revert-buffer,
>> I see hexified file list generated by arc-mode, instead of raw ZIP data.
>
>> This behavior is surprising for me and it is cumbersome to do M-x
>> kill-buffer and M-x hexl-find-file each time.
>
>> How about adding M-x hexl-revert-buffer?
>
> No, we should tweak revert-buffer-function instead.

Ok, how about this?

[hexl-revert-buffer.diff (text/x-patch, inline)]
=== modified file 'lisp/hexl.el'
--- lisp/hexl.el	2010-10-10 23:12:30 +0000
+++ lisp/hexl.el	2010-10-21 01:51:54 +0000
@@ -212,6 +212,7 @@
 (defvar hexl-mode-old-syntax-table)
 (defvar hexl-mode-old-font-lock-keywords)
 (defvar hexl-mode-old-eldoc-documentation-function)
+(defvar hexl-mode-old-revert-buffer-function)
 
 (defvar hexl-ascii-overlay nil
   "Overlay used to highlight ASCII element corresponding to current point.")
@@ -373,10 +374,9 @@
     (setq hexl-mode-old-font-lock-keywords font-lock-defaults)
     (setq font-lock-defaults '(hexl-font-lock-keywords t))
 
-    ;; Add hooks to rehexlify or dehexlify on various events.
-    (add-hook 'before-revert-hook 'hexl-before-revert-hook nil t)
-    (add-hook 'after-revert-hook 'hexl-after-revert-hook nil t)
-
+    (make-local-variable 'hexl-mode-old-revert-buffer-function)
+    (setq hexl-mode-old-revert-buffer-function revert-buffer-function)
+    (setq revert-buffer-function 'hexl-revert-buffer-function)
     (add-hook 'change-major-mode-hook 'hexl-maybe-dehexlify-buffer nil t)
 
     ;; Set a callback function for eldoc.
@@ -413,12 +413,6 @@
     (let ((isearch-search-fun-function nil))
       (isearch-search-fun))))
 
-(defun hexl-before-revert-hook ()
-  (remove-hook 'change-major-mode-hook 'hexl-maybe-dehexlify-buffer t))
-
-(defun hexl-after-revert-hook ()
-  (hexl-mode))
-
 (defvar hexl-in-save-buffer nil)
 
 (defun hexl-save-buffer ()
@@ -464,6 +458,23 @@
   (if (not (eq major-mode 'hexl-mode))
       (hexl-mode)))
 
+(defun hexl-revert-buffer-function (ignore-auto noconfirm)
+  (let ((coding-system-for-read 'no-conversion)
+	revert-buffer-function)
+    ;; Call the original `revert-buffer' without code conversion; also
+    ;; prevent it changes the major mode to normal-mode, which calls
+    ;; `set-auto-mode'.
+    (revert-buffer nil nil t)
+    ;; A couple of hacks are necessary here:
+    ;; 1. change the major-mode to one other than hexl-mode since the
+    ;; function `hexl-mode' does nothing if the current major-mode is
+    ;; already hexl-mode.
+    ;; 2. reset change-major-mode-hook in case that `hexl-mode'
+    ;; previously add `hexl-maybe-dehexlify-buffer' to it.
+    (remove-hook 'change-major-mode-hook 'hexl-maybe-dehexlify-buffer t)
+    (setq major-mode 'fundamental-mode)
+    (hexl-mode)))
+
 (defun hexl-mode-exit (&optional arg)
   "Exit Hexl mode, returning to previous mode.
 With arg, don't unhexlify buffer."
@@ -483,8 +494,6 @@
 	  (or (bobp) (setq original-point (1+ original-point))))
 	(goto-char original-point)))
 
-  (remove-hook 'before-revert-hook 'hexl-before-revert-hook t)
-  (remove-hook 'after-revert-hook 'hexl-after-revert-hook t)
   (remove-hook 'change-major-mode-hook 'hexl-maybe-dehexlify-buffer t)
   (remove-hook 'post-command-hook 'hexl-follow-ascii-find t)
   (setq hexl-ascii-overlay nil)
@@ -512,6 +521,7 @@
   (set-syntax-table hexl-mode-old-syntax-table)
   (setq font-lock-defaults hexl-mode-old-font-lock-keywords)
   (setq major-mode hexl-mode-old-major-mode)
+  (setq revert-buffer-function hexl-mode-old-revert-buffer-function)
   (force-mode-line-update))
 
 (defun hexl-maybe-dehexlify-buffer ()

[Message part 3 (text/plain, inline)]
Regards,
-- 
Daiki Ueno

Information forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#7252; Package emacs. (Thu, 21 Oct 2010 02:17:02 GMT) Full text and rfc822 format available.

Message #14 received at 7252 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Daiki Ueno <ueno <at> unixuser.org>
Cc: 7252 <at> debbugs.gnu.org
Subject: Re: bug#7252: hexl-revert-buffer
Date: Wed, 20 Oct 2010 22:20:02 -0400
>> No, we should tweak revert-buffer-function instead.
> Ok, how about this?

Looks good (even better than I thought since I hadn't noticed the
*-revert-hooks).  Assuming you've tested it, please install it.


        Stefan




Reply sent to Daiki Ueno <ueno <at> unixuser.org>:
You have taken responsibility. (Thu, 21 Oct 2010 02:35:01 GMT) Full text and rfc822 format available.

Notification sent to Daiki Ueno <ueno <at> unixuser.org>:
bug acknowledged by developer. (Thu, 21 Oct 2010 02:35:02 GMT) Full text and rfc822 format available.

Message #19 received at 7252-done <at> debbugs.gnu.org (full text, mbox):

From: Daiki Ueno <ueno <at> unixuser.org>
To: 7252-done <at> debbugs.gnu.org
Subject: Re: bug#7252: hexl-revert-buffer
Date: Thu, 21 Oct 2010 11:42:14 +0900
Done as r102027.

Regards,
-- 
Daiki Ueno




Information forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#7252; Package emacs. (Thu, 21 Oct 2010 17:50:03 GMT) Full text and rfc822 format available.

Message #22 received at 7252 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
To: 7252 <at> debbugs.gnu.org
Cc: ueno <at> unixuser.org
Subject: Re: bug#7252: hexl-revert-buffer
Date: Thu, 21 Oct 2010 13:53:08 -0400
> Done as r102027.

Thank you.

Actually, I see now that, while your patch is going in the right
direction, the problem is deeper.  E.g. M-x find-file-literally RET
foo.tar.gz RET does the right thing but M-x revert-buffer RET in it
ignores the "literally" part and gives you a tar-mode view of the file.
I.e. revert-buffer should probably pay attention to the
`find-file-literally' variable, and hexl-mode should then make use of it
as well.


        Stefan




Information forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#7252; Package emacs. (Fri, 22 Oct 2010 01:08:02 GMT) Full text and rfc822 format available.

Message #25 received at 7252 <at> debbugs.gnu.org (full text, mbox):

From: Daiki Ueno <ueno <at> unixuser.org>
To: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
Cc: 7252 <at> debbugs.gnu.org
Subject: Re: bug#7252: hexl-revert-buffer
Date: Fri, 22 Oct 2010 10:15:16 +0900
Stefan Monnier <monnier <at> IRO.UMontreal.CA> writes:

> Actually, I see now that, while your patch is going in the right
> direction, the problem is deeper.  E.g. M-x find-file-literally RET
> foo.tar.gz RET does the right thing but M-x revert-buffer RET in it
> ignores the "literally" part and gives you a tar-mode view of the file.

Right, but my personal feeling is that typical users would not expect
such a "literally"-ness of revert-buffer when the file is opened with
M-x find-file-literally, unlike with M-x hexl-find-file.

With M-x find-file-literally user's intension would be to quick look at
the raw content.  In that case he might do M-x revert-buffer to "go back
to the normal view of that file" and expect auto-mode conversion.

However, with M-x hexl-find-file user's intension would be to analyze
the file format or edit the raw content.  In that case auto-mode
conversion is definitely unwanted.

Perhaps it might be better to bring this up in emacs-devel.

Regards,
-- 
Daiki Ueno




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Fri, 19 Nov 2010 12:24:03 GMT) Full text and rfc822 format available.

This bug report was last modified 14 years and 274 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.