diff options
| author | Daiki Ueno | 2010-10-21 11:38:46 +0900 |
|---|---|---|
| committer | Daiki Ueno | 2010-10-21 11:38:46 +0900 |
| commit | 08ffb131098cb044f501cceacdd11651f9b7621d (patch) | |
| tree | 6cdc018d12778f9506d0a2a2669d22a63ca4eea1 | |
| parent | d5798f68ccc1fa853437af6398cf43b399688c4d (diff) | |
| download | emacs-08ffb131098cb044f501cceacdd11651f9b7621d.tar.gz emacs-08ffb131098cb044f501cceacdd11651f9b7621d.zip | |
Tweak revert-buffer-function to inhibit auto-mode-alist.
* hexl.el (hexl-mode, hexl-mode-exit): Tweak
revert-buffer-function to inhibit auto-mode-alist (Bug#7252).
(hexl-revert-buffer-function): New function.
(hexl-before-revert-hook, hexl-after-revert-hook): Abolish.
| -rw-r--r-- | lisp/ChangeLog | 7 | ||||
| -rw-r--r-- | lisp/hexl.el | 34 |
2 files changed, 29 insertions, 12 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 58d7841dfd8..5d7457dd010 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,10 @@ | |||
| 1 | 2010-10-21 Daiki Ueno <ueno@unixuser.org> | ||
| 2 | |||
| 3 | * hexl.el (hexl-mode, hexl-mode-exit): Tweak | ||
| 4 | revert-buffer-function to inhibit auto-mode-alist (Bug#7252). | ||
| 5 | (hexl-revert-buffer-function): New function. | ||
| 6 | (hexl-before-revert-hook, hexl-after-revert-hook): Abolish. | ||
| 7 | |||
| 1 | 2010-10-19 Alan Mackenzie <acm@muc.de> | 8 | 2010-10-19 Alan Mackenzie <acm@muc.de> |
| 2 | 9 | ||
| 3 | * progmodes/cc-langs.el (c-type-decl-prefix-key): C++ bit: move | 10 | * progmodes/cc-langs.el (c-type-decl-prefix-key): C++ bit: move |
diff --git a/lisp/hexl.el b/lisp/hexl.el index ebc43e43d25..8e000e72ecd 100644 --- a/lisp/hexl.el +++ b/lisp/hexl.el | |||
| @@ -212,6 +212,7 @@ Quoting cannot be used, so the arguments cannot themselves contain spaces." | |||
| 212 | (defvar hexl-mode-old-syntax-table) | 212 | (defvar hexl-mode-old-syntax-table) |
| 213 | (defvar hexl-mode-old-font-lock-keywords) | 213 | (defvar hexl-mode-old-font-lock-keywords) |
| 214 | (defvar hexl-mode-old-eldoc-documentation-function) | 214 | (defvar hexl-mode-old-eldoc-documentation-function) |
| 215 | (defvar hexl-mode-old-revert-buffer-function) | ||
| 215 | 216 | ||
| 216 | (defvar hexl-ascii-overlay nil | 217 | (defvar hexl-ascii-overlay nil |
| 217 | "Overlay used to highlight ASCII element corresponding to current point.") | 218 | "Overlay used to highlight ASCII element corresponding to current point.") |
| @@ -373,10 +374,9 @@ You can use \\[hexl-find-file] to visit a file in Hexl mode. | |||
| 373 | (setq hexl-mode-old-font-lock-keywords font-lock-defaults) | 374 | (setq hexl-mode-old-font-lock-keywords font-lock-defaults) |
| 374 | (setq font-lock-defaults '(hexl-font-lock-keywords t)) | 375 | (setq font-lock-defaults '(hexl-font-lock-keywords t)) |
| 375 | 376 | ||
| 376 | ;; Add hooks to rehexlify or dehexlify on various events. | 377 | (make-local-variable 'hexl-mode-old-revert-buffer-function) |
| 377 | (add-hook 'before-revert-hook 'hexl-before-revert-hook nil t) | 378 | (setq hexl-mode-old-revert-buffer-function revert-buffer-function) |
| 378 | (add-hook 'after-revert-hook 'hexl-after-revert-hook nil t) | 379 | (setq revert-buffer-function 'hexl-revert-buffer-function) |
| 379 | |||
| 380 | (add-hook 'change-major-mode-hook 'hexl-maybe-dehexlify-buffer nil t) | 380 | (add-hook 'change-major-mode-hook 'hexl-maybe-dehexlify-buffer nil t) |
| 381 | 381 | ||
| 382 | ;; Set a callback function for eldoc. | 382 | ;; Set a callback function for eldoc. |
| @@ -413,12 +413,6 @@ You can use \\[hexl-find-file] to visit a file in Hexl mode. | |||
| 413 | (let ((isearch-search-fun-function nil)) | 413 | (let ((isearch-search-fun-function nil)) |
| 414 | (isearch-search-fun)))) | 414 | (isearch-search-fun)))) |
| 415 | 415 | ||
| 416 | (defun hexl-before-revert-hook () | ||
| 417 | (remove-hook 'change-major-mode-hook 'hexl-maybe-dehexlify-buffer t)) | ||
| 418 | |||
| 419 | (defun hexl-after-revert-hook () | ||
| 420 | (hexl-mode)) | ||
| 421 | |||
| 422 | (defvar hexl-in-save-buffer nil) | 416 | (defvar hexl-in-save-buffer nil) |
| 423 | 417 | ||
| 424 | (defun hexl-save-buffer () | 418 | (defun hexl-save-buffer () |
| @@ -464,6 +458,23 @@ and edit the file in `hexl-mode'." | |||
| 464 | (if (not (eq major-mode 'hexl-mode)) | 458 | (if (not (eq major-mode 'hexl-mode)) |
| 465 | (hexl-mode))) | 459 | (hexl-mode))) |
| 466 | 460 | ||
| 461 | (defun hexl-revert-buffer-function (ignore-auto noconfirm) | ||
| 462 | (let ((coding-system-for-read 'no-conversion) | ||
| 463 | revert-buffer-function) | ||
| 464 | ;; Call the original `revert-buffer' without code conversion; also | ||
| 465 | ;; prevent it from changing the major mode to normal-mode, which | ||
| 466 | ;; calls `set-auto-mode'. | ||
| 467 | (revert-buffer nil nil t) | ||
| 468 | ;; A couple of hacks are necessary here: | ||
| 469 | ;; 1. change the major-mode to one other than hexl-mode since the | ||
| 470 | ;; function `hexl-mode' does nothing if the current major-mode is | ||
| 471 | ;; already hexl-mode. | ||
| 472 | ;; 2. reset change-major-mode-hook in case that `hexl-mode' | ||
| 473 | ;; previously added hexl-maybe-dehexlify-buffer to it. | ||
| 474 | (remove-hook 'change-major-mode-hook 'hexl-maybe-dehexlify-buffer t) | ||
| 475 | (setq major-mode 'fundamental-mode) | ||
| 476 | (hexl-mode))) | ||
| 477 | |||
| 467 | (defun hexl-mode-exit (&optional arg) | 478 | (defun hexl-mode-exit (&optional arg) |
| 468 | "Exit Hexl mode, returning to previous mode. | 479 | "Exit Hexl mode, returning to previous mode. |
| 469 | With arg, don't unhexlify buffer." | 480 | With arg, don't unhexlify buffer." |
| @@ -483,8 +494,6 @@ With arg, don't unhexlify buffer." | |||
| 483 | (or (bobp) (setq original-point (1+ original-point)))) | 494 | (or (bobp) (setq original-point (1+ original-point)))) |
| 484 | (goto-char original-point))) | 495 | (goto-char original-point))) |
| 485 | 496 | ||
| 486 | (remove-hook 'before-revert-hook 'hexl-before-revert-hook t) | ||
| 487 | (remove-hook 'after-revert-hook 'hexl-after-revert-hook t) | ||
| 488 | (remove-hook 'change-major-mode-hook 'hexl-maybe-dehexlify-buffer t) | 497 | (remove-hook 'change-major-mode-hook 'hexl-maybe-dehexlify-buffer t) |
| 489 | (remove-hook 'post-command-hook 'hexl-follow-ascii-find t) | 498 | (remove-hook 'post-command-hook 'hexl-follow-ascii-find t) |
| 490 | (setq hexl-ascii-overlay nil) | 499 | (setq hexl-ascii-overlay nil) |
| @@ -512,6 +521,7 @@ With arg, don't unhexlify buffer." | |||
| 512 | (set-syntax-table hexl-mode-old-syntax-table) | 521 | (set-syntax-table hexl-mode-old-syntax-table) |
| 513 | (setq font-lock-defaults hexl-mode-old-font-lock-keywords) | 522 | (setq font-lock-defaults hexl-mode-old-font-lock-keywords) |
| 514 | (setq major-mode hexl-mode-old-major-mode) | 523 | (setq major-mode hexl-mode-old-major-mode) |
| 524 | (setq revert-buffer-function hexl-mode-old-revert-buffer-function) | ||
| 515 | (force-mode-line-update)) | 525 | (force-mode-line-update)) |
| 516 | 526 | ||
| 517 | (defun hexl-maybe-dehexlify-buffer () | 527 | (defun hexl-maybe-dehexlify-buffer () |