comparison lisp/hexl.el @ 90737:95d0cdf160ea

Merge from emacs--devo--0 Patches applied: * emacs--devo--0 (patch 586-614) - Update from CVS - Update from erc--emacs--22 - Merge from gnus--rel--5.10 - Merge from erc--main--0 - Make byte compiler correctly write circular constants * gnus--rel--5.10 (patch 186-196) - Update from CVS - Merge from emacs--devo--0 Revision: emacs@sv.gnu.org/emacs--unicode--0--patch-162
author Miles Bader <miles@gnu.org>
date Fri, 26 Jan 2007 06:16:11 +0000
parents f1d13e615070 efb5e4ca015b
children f55f9811f5d7
comparison
equal deleted inserted replaced
90736:ef1369583937 90737:95d0cdf160ea
1 ;;; hexl.el --- edit a file in a hex dump format using the hexl filter 1 ;;; hexl.el --- edit a file in a hex dump format using the hexl filter
2 2
3 ;; Copyright (C) 1989, 1994, 1998, 2001, 2002, 2003, 2004, 3 ;; Copyright (C) 1989, 1994, 1998, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006 Free Software Foundation, Inc. 4 ;; 2005, 2006, 2007 Free Software Foundation, Inc.
5 5
6 ;; Author: Keith Gabryelski <ag@wheaties.ai.mit.edu> 6 ;; Author: Keith Gabryelski <ag@wheaties.ai.mit.edu>
7 ;; Maintainer: FSF 7 ;; Maintainer: FSF
8 ;; Keywords: data 8 ;; Keywords: data
9 9
281 (setq hexl-mode-old-font-lock-keywords font-lock-defaults) 281 (setq hexl-mode-old-font-lock-keywords font-lock-defaults)
282 (make-local-variable 'font-lock-defaults) 282 (make-local-variable 'font-lock-defaults)
283 (setq font-lock-defaults '(hexl-font-lock-keywords t)) 283 (setq font-lock-defaults '(hexl-font-lock-keywords t))
284 284
285 ;; Add hooks to rehexlify or dehexlify on various events. 285 ;; Add hooks to rehexlify or dehexlify on various events.
286 (add-hook 'before-revert-hook 'hexl-before-revert-hook nil t)
286 (add-hook 'after-revert-hook 'hexl-after-revert-hook nil t) 287 (add-hook 'after-revert-hook 'hexl-after-revert-hook nil t)
287 288
288 (add-hook 'change-major-mode-hook 'hexl-maybe-dehexlify-buffer nil t) 289 (add-hook 'change-major-mode-hook 'hexl-maybe-dehexlify-buffer nil t)
289 290
290 ;; Set a callback function for eldoc. 291 ;; Set a callback function for eldoc.
315 textre)) 316 textre))
316 bound noerror count)) 317 bound noerror count))
317 (let ((isearch-search-fun-function nil)) 318 (let ((isearch-search-fun-function nil))
318 (isearch-search-fun)))) 319 (isearch-search-fun))))
319 320
321 (defun hexl-before-revert-hook ()
322 (remove-hook 'change-major-mode-hook 'hexl-maybe-dehexlify-buffer t))
323
320 (defun hexl-after-revert-hook () 324 (defun hexl-after-revert-hook ()
321 (setq hexl-max-address (1- (buffer-size))) 325 (hexl-mode))
322 (hexlify-buffer)
323 (set-buffer-modified-p nil))
324 326
325 (defvar hexl-in-save-buffer nil) 327 (defvar hexl-in-save-buffer nil)
326 328
327 (defun hexl-save-buffer () 329 (defun hexl-save-buffer ()
328 "Save a hexl format buffer as binary in visited file if modified." 330 "Save a hexl format buffer as binary in visited file if modified."
384 (setq original-point (- original-point 386 (setq original-point (- original-point
385 (count-lines (point-min) (point)))) 387 (count-lines (point-min) (point))))
386 (or (bobp) (setq original-point (1+ original-point)))) 388 (or (bobp) (setq original-point (1+ original-point))))
387 (goto-char original-point))) 389 (goto-char original-point)))
388 390
391 (remove-hook 'before-revert-hook 'hexl-before-revert-hook t)
389 (remove-hook 'after-revert-hook 'hexl-after-revert-hook t) 392 (remove-hook 'after-revert-hook 'hexl-after-revert-hook t)
390 (remove-hook 'change-major-mode-hook 'hexl-maybe-dehexlify-buffer t) 393 (remove-hook 'change-major-mode-hook 'hexl-maybe-dehexlify-buffer t)
391 (remove-hook 'post-command-hook 'hexl-follow-ascii-find t) 394 (remove-hook 'post-command-hook 'hexl-follow-ascii-find t)
392 (setq hexl-ascii-overlay nil) 395 (setq hexl-ascii-overlay nil)
393 396
398 401
399 (if (and (boundp 'hl-line-mode) hl-line-mode (not hexl-mode-old-hl-line-mode)) 402 (if (and (boundp 'hl-line-mode) hl-line-mode (not hexl-mode-old-hl-line-mode))
400 (hl-line-mode 0)) 403 (hl-line-mode 0))
401 (when (boundp 'hexl-mode-old-hl-line-range-function) 404 (when (boundp 'hexl-mode-old-hl-line-range-function)
402 (setq hl-line-range-function hexl-mode-old-hl-line-range-function)) 405 (setq hl-line-range-function hexl-mode-old-hl-line-range-function))
403 (when (boundp hexl-mode-old-hl-line-face) 406 (when (boundp 'hexl-mode-old-hl-line-face)
404 (setq hl-line-face hexl-mode-old-hl-line-face)) 407 (setq hl-line-face hexl-mode-old-hl-line-face))
405 408
406 (setq require-final-newline hexl-mode-old-require-final-newline) 409 (setq require-final-newline hexl-mode-old-require-final-newline)
407 (setq mode-name hexl-mode-old-mode-name) 410 (setq mode-name hexl-mode-old-mode-name)
408 (setq isearch-search-fun-function hexl-mode-old-isearch-search-fun-function) 411 (setq isearch-search-fun-function hexl-mode-old-isearch-search-fun-function)
409 (use-local-map hexl-mode-old-local-map) 412 (use-local-map hexl-mode-old-local-map)
410 (set-syntax-table hexl-mode-old-syntax-table) 413 (set-syntax-table hexl-mode-old-syntax-table)
704 ;;;###autoload 707 ;;;###autoload
705 (defun hexlify-buffer () 708 (defun hexlify-buffer ()
706 "Convert a binary buffer to hexl format. 709 "Convert a binary buffer to hexl format.
707 This discards the buffer's undo information." 710 This discards the buffer's undo information."
708 (interactive) 711 (interactive)
709 (and buffer-undo-list 712 (and (consp buffer-undo-list)
710 (or (y-or-n-p "Converting to hexl format discards undo info; ok? ") 713 (or (y-or-n-p "Converting to hexl format discards undo info; ok? ")
711 (error "Aborted"))) 714 (error "Aborted"))
712 (setq buffer-undo-list nil) 715 (setq buffer-undo-list nil))
713 ;; Don't decode text in the ASCII part of `hexl' program output. 716 ;; Don't decode text in the ASCII part of `hexl' program output.
714 (let ((coding-system-for-read 'raw-text) 717 (let ((coding-system-for-read 'raw-text)
715 (coding-system-for-write buffer-file-coding-system) 718 (coding-system-for-write buffer-file-coding-system)
716 (buffer-undo-list t)) 719 (buffer-undo-list t))
717 (apply 'call-process-region (point-min) (point-max) 720 (apply 'call-process-region (point-min) (point-max)
729 732
730 (defun dehexlify-buffer () 733 (defun dehexlify-buffer ()
731 "Convert a hexl format buffer to binary. 734 "Convert a hexl format buffer to binary.
732 This discards the buffer's undo information." 735 This discards the buffer's undo information."
733 (interactive) 736 (interactive)
734 (and buffer-undo-list 737 (and (consp buffer-undo-list)
735 (or (y-or-n-p "Converting from hexl format discards undo info; ok? ") 738 (or (y-or-n-p "Converting from hexl format discards undo info; ok? ")
736 (error "Aborted"))) 739 (error "Aborted"))
737 (setq buffer-undo-list nil) 740 (setq buffer-undo-list nil))
738 (let ((coding-system-for-write 'raw-text) 741 (let ((coding-system-for-write 'raw-text)
739 (coding-system-for-read buffer-file-coding-system) 742 (coding-system-for-read buffer-file-coding-system)
740 (buffer-undo-list t)) 743 (buffer-undo-list t))
741 (apply 'call-process-region (point-min) (point-max) 744 (apply 'call-process-region (point-min) (point-max)
742 (expand-file-name hexl-program exec-directory) 745 (expand-file-name hexl-program exec-directory)