;;; hexl.el --- edit a file in a hex dump format using the hexl filter
;; Copyright (C) 1989, 1994, 1998, 2001, 2002, 2003, 2004,
-;; 2005, 2006 Free Software Foundation, Inc.
+;; 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
;; Author: Keith Gabryelski <ag@wheaties.ai.mit.edu>
;; Maintainer: FSF
;; This file is part of GNU Emacs.
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 2, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING. If not, write to the
-;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;;; Code:
(require 'eldoc)
+(eval-when-compile (require 'cl))
;;
;; vars here
(defface hexl-address-region
'((t (:inherit header-line)))
- "Face used in address are of hexl-mode buffer."
+ "Face used in address area of hexl-mode buffer."
:group 'hexl)
(defface hexl-ascii-region
'((t (:inherit header-line)))
- "Face used in ascii are of hexl-mode buffer."
+ "Face used in ascii area of hexl-mode buffer."
:group 'hexl)
(defvar hexl-max-address 0
(defvar hexl-mode-old-require-final-newline)
(defvar hexl-mode-old-syntax-table)
(defvar hexl-mode-old-font-lock-keywords)
+(defvar hexl-mode-old-eldoc-documentation-function)
(defvar hexl-ascii-overlay nil
"Overlay used to highlight ASCII element corresponding to current point.")
(make-local-variable 'hexl-mode-old-font-lock-keywords)
(setq hexl-mode-old-font-lock-keywords font-lock-defaults)
- (make-local-variable '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)
(add-hook 'change-major-mode-hook 'hexl-maybe-dehexlify-buffer nil t)
;; Set a callback function for eldoc.
+ (make-local-variable 'hexl-mode-old-eldoc-documentation-function)
+ (setq hexl-mode-old-eldoc-documentation-function
+ (bound-and-true-p eldoc-documentation-function))
+
(set (make-local-variable 'eldoc-documentation-function)
'hexl-print-current-point-info)
(eldoc-add-command-completions "hexl-")
(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 ()
- (setq hexl-max-address (1- (buffer-size)))
- (hexlify-buffer)
- (set-buffer-modified-p nil))
+ (hexl-mode))
(defvar hexl-in-save-buffer nil)
(list
(let ((completion-ignored-extensions nil))
(read-file-name "Filename: " nil nil 'ret-must-match))))
- ;; Ignore the user's setting of default-major-mode.
- (let ((default-major-mode 'fundamental-mode))
+ ;; Ignore the user's setting of default major-mode.
+ (letf (((default-value 'major-mode) 'fundamental-mode))
(find-file-literally filename))
(if (not (eq major-mode 'hexl-mode))
(hexl-mode)))
(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)
(hl-line-mode 0))
(when (boundp 'hexl-mode-old-hl-line-range-function)
(setq hl-line-range-function hexl-mode-old-hl-line-range-function))
- (when (boundp hexl-mode-old-hl-line-face)
+ (when (boundp 'hexl-mode-old-hl-line-face)
(setq hl-line-face hexl-mode-old-hl-line-face))
-
+
+ (when (boundp 'hexl-mode-old-eldoc-documentation-function)
+ (setq eldoc-documentation-function
+ hexl-mode-old-eldoc-documentation-function))
+
(setq require-final-newline hexl-mode-old-require-final-newline)
(setq mode-name hexl-mode-old-mode-name)
(setq isearch-search-fun-function hexl-mode-old-isearch-search-fun-function)
(if (>= current-column 41)
(- current-column 41)
(/ (- current-column (/ current-column 5)) 2))))
- (when (interactive-p)
+ (when (called-interactively-p 'interactive)
(message "Current address is %d/0x%08x" hexl-address hexl-address))
hexl-address))
(+ (* (/ address 16) 68) 10 (point-min) (/ (* (% address 16) 5) 2)))
(defun hexl-goto-address (address)
- "Goto hexl-mode (decimal) address ADDRESS.
-Signal error if ADDRESS out of range."
+ "Go to hexl-mode (decimal) address ADDRESS.
+Signal error if ADDRESS is out of range."
(interactive "nAddress: ")
(if (or (< address 0) (> address hexl-max-address))
(error "Out of hexl region"))
(hexl-goto-address (- (hexl-current-address) arg)))
(defun hexl-forward-char (arg)
- "Move right ARG bytes (left if ARG negative) in hexl-mode."
+ "Move to right ARG bytes (left if ARG negative) in hexl-mode."
(interactive "p")
(hexl-goto-address (+ (hexl-current-address) arg)))
address)))
(defun hexl-forward-short (arg)
- "Move right ARG shorts (left if ARG negative) in hexl-mode."
+ "Move to right ARG shorts (left if ARG negative) in hexl-mode."
(interactive "p")
(hexl-backward-short (- arg)))
address)))
(defun hexl-forward-word (arg)
- "Move right ARG words (left if ARG negative) in hexl-mode."
+ "Move to right ARG words (left if ARG negative) in hexl-mode."
(interactive "p")
(hexl-backward-word (- arg)))
(defun hexl-previous-line (arg)
"Move vertically up ARG lines [16 bytes] (down if ARG negative) in hexl-mode.
-If there is byte at the target address move to the last byte in that line."
+If there is no byte at the target address move to the last byte in that line."
(interactive "p")
(hexl-next-line (- arg)))
(recenter 0)))
(defun hexl-beginning-of-1k-page ()
- "Go to beginning of 1k boundary."
+ "Go to beginning of 1KB boundary."
(interactive)
(hexl-goto-address (logand (hexl-current-address) -1024)))
(defun hexl-end-of-1k-page ()
- "Go to end of 1k boundary."
+ "Go to end of 1KB boundary."
(interactive)
(hexl-goto-address (let ((address (logior (hexl-current-address) 1023)))
(if (> address hexl-max-address)
"Convert a binary buffer to hexl format.
This discards the buffer's undo information."
(interactive)
- (and buffer-undo-list
+ (and (consp buffer-undo-list)
(or (y-or-n-p "Converting to hexl format discards undo info; ok? ")
- (error "Aborted")))
- (setq buffer-undo-list nil)
+ (error "Aborted"))
+ (setq buffer-undo-list nil))
;; Don't decode text in the ASCII part of `hexl' program output.
(let ((coding-system-for-read 'raw-text)
(coding-system-for-write buffer-file-coding-system)
"Convert a hexl format buffer to binary.
This discards the buffer's undo information."
(interactive)
- (and buffer-undo-list
+ (and (consp buffer-undo-list)
(or (y-or-n-p "Converting from hexl format discards undo info; ok? ")
- (error "Aborted")))
- (setq buffer-undo-list nil)
+ (error "Aborted"))
+ (setq buffer-undo-list nil))
(let ((coding-system-for-write 'raw-text)
(coding-system-for-read buffer-file-coding-system)
(buffer-undo-list t))
(defun hexl-printable-character (ch)
"Return a displayable string for character CH."
- (format "%c" (if hexl-iso
- (if (or (< ch 32) (and (>= ch 127) (< ch 160)))
+ (format "%c" (if (equal hexl-iso "")
+ (if (or (< ch 32) (>= ch 127))
46
ch)
- (if (or (< ch 32) (>= ch 127))
+ (if (or (< ch 32) (and (>= ch 127) (< ch 160)))
46
ch))))
(coding (if (or (null buffer-file-coding-system)
;; coding-system-type equals t means undecided.
(eq (coding-system-type buffer-file-coding-system) t))
- default-buffer-file-coding-system
+ (default-value 'buffer-file-coding-system)
buffer-file-coding-system)))
(cond ((and (> ch 0) (< ch 256))
(hexl-insert-char ch num))
Non-ASCII characters are first encoded with `buffer-file-coding-system',
and their encoded form is inserted byte by byte."
(interactive "p")
- (hexl-insert-multibyte-char last-command-char arg))
+ (hexl-insert-multibyte-char last-command-event arg))
(defun hexl-insert-char (ch num)
"Insert the character CH NUM times in a hexl buffer.
(defun hexl-highlight-line-range ()
"Return the range of address region for the point.
-This function is assumed to be used as call back function for `hl-line-mode'."
+This function is assumed to be used as callback function for `hl-line-mode'."
(cons
(line-beginning-position)
;; 9 stands for (length "87654321:")
(define-key hexl-mode-map "\C-x\C-s" 'hexl-save-buffer)
(define-key hexl-mode-map "\C-x\C-t" 'undefined))
+(easy-menu-define hexl-menu hexl-mode-map "Hexl Mode menu"
+ `("Hexl"
+ :help "Hexl-specific Features"
+
+ ["Backward short" hexl-backward-short
+ :help "Move to left a short"]
+ ["Forward short" hexl-forward-short
+ :help "Move to right a short"]
+ ["Backward word" hexl-backward-short
+ :help "Move to left a word"]
+ ["Forward word" hexl-forward-short
+ :help "Move to right a word"]
+ "-"
+ ["Beginning of 512b page" hexl-beginning-of-512b-page
+ :help "Go to beginning of 512 byte boundary"]
+ ["End of 512b page" hexl-end-of-512b-page
+ :help "Go to end of 512 byte boundary"]
+ ["Beginning of 1K page" hexl-beginning-of-1k-page
+ :help "Go to beginning of 1KB boundary"]
+ ["End of 1K page" hexl-end-of-1k-page
+ :help "Go to end of 1KB boundary"]
+ "-"
+ ["Go to address" hexl-goto-address
+ :help "Go to hexl-mode (decimal) address"]
+ ["Go to address" hexl-goto-hex-address
+ :help "Go to hexl-mode (hex string) address"]
+ "-"
+ ["Insert decimal char" hexl-insert-decimal-char
+ :help "Insert a character given by its decimal code"]
+ ["Insert hex char" hexl-insert-hex-char
+ :help "Insert a character given by its hexadecimal code"]
+ ["Insert octal char" hexl-insert-octal-char
+ :help "Insert a character given by its octal code"]
+ "-"
+ ["Exit hexl mode" hexl-mode-exit
+ :help "Exit hexl mode returning to previous mode"]))
+
(provide 'hexl)
;; arch-tag: d5a7aa8a-9bce-480b-bcff-6c4c7ca5ea4a