]> code.delx.au - gnu-emacs/blobdiff - lisp/hexl.el
(ibuffer-compressed-file-name-regexp): Avoid loading
[gnu-emacs] / lisp / hexl.el
index b67ab7876b4db8fccbb081d30224bdd3e59f7735..1e724aa418ac82c6081816af9a22c79399b52c39 100644 (file)
@@ -1,6 +1,7 @@
 ;;; hexl.el --- edit a file in a hex dump format using the hexl filter
 
-;; Copyright (C) 1989, 1994, 1998, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
+;; Copyright (C) 1989, 1994, 1998, 2001, 2002, 2003, 2004,
+;;   2005, 2006 Free Software Foundation, Inc.
 
 ;; Author: Keith Gabryelski <ag@wheaties.ai.mit.edu>
 ;; Maintainer: FSF
@@ -20,8 +21,8 @@
 
 ;; 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., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
 
 ;;; Commentary:
 
@@ -37,7 +38,7 @@
 ;; grouping.
 ;;
 ;; -iso in `hexl-options' will allow iso characters to display in the
-;; ASCII region of the screen (if your emacs supports this) instead of
+;; ASCII region of the screen (if your Emacs supports this) instead of
 ;; changing them to dots.
 
 ;;; Code:
@@ -61,7 +62,7 @@ and \"-de\" when dehexlifying a buffer."
   :group 'hexl)
 
 (defcustom hexl-iso ""
-  "If your emacs can handle ISO characters, this should be set to
+  "If your Emacs can handle ISO characters, this should be set to
 \"-iso\" otherwise it should be \"\"."
   :type 'string
   :group 'hexl)
@@ -84,12 +85,12 @@ Quoting cannot be used, so the arguments cannot themselves contain spaces."
   :options '(hexl-follow-line hexl-activate-ruler turn-on-eldoc-mode)
   :group 'hexl)
 
-(defface hexl-address-area
+(defface hexl-address-region
   '((t (:inherit header-line)))
   "Face used in address are of hexl-mode buffer."
   :group 'hexl)
 
-(defface hexl-ascii-area
+(defface hexl-ascii-region
   '((t (:inherit header-line)))
   "Face used in ascii are of hexl-mode buffer."
   :group 'hexl)
@@ -120,8 +121,8 @@ Quoting cannot be used, so the arguments cannot themselves contain spaces."
 (defvar hexl-font-lock-keywords
   '(("^\\([0-9a-f]+:\\).\\{40\\}  \\(.+$\\)"
      ;; "^\\([0-9a-f]+:\\).+  \\(.+$\\)"
-     (1 'hexl-address-area t t)
-     (2 'hexl-ascii-area t t)))
+     (1 'hexl-address-region t t)
+     (2 'hexl-ascii-region t t)))
   "Font lock keywords used in `hexl-mode'.")
 
 ;; routines
@@ -228,7 +229,7 @@ You can use \\[hexl-find-file] to visit a file in Hexl mode.
                                  original-point))
          (or (bolp) (setq original-point (1- original-point))))
         (hexlify-buffer)
-        (set-buffer-modified-p modified))
+        (restore-buffer-modified-p modified))
       (make-local-variable 'hexl-max-address)
       (setq hexl-max-address max-address)
       (condition-case nil
@@ -287,7 +288,7 @@ You can use \\[hexl-find-file] to visit a file in Hexl mode.
     (set (make-local-variable 'eldoc-documentation-function)
         'hexl-print-current-point-info)
     (eldoc-add-command-completions "hexl-")
-    (eldoc-remove-command "hexl-save-buffer" 
+    (eldoc-remove-command "hexl-save-buffer"
                          "hexl-current-address")
 
     (if hexl-follow-ascii (hexl-follow-ascii 1)))
@@ -299,9 +300,16 @@ You can use \\[hexl-find-file] to visit a file in Hexl mode.
       (lambda (string &optional bound noerror count)
        (funcall
         (if isearch-forward 're-search-forward 're-search-backward)
-        (if (> (length string) 80)
-            (regexp-quote string)
-          (mapconcat 'string string "\\(?:\n\\(?:[:a-f0-9]+ \\)+ \\)?"))
+         (let ((textre
+                (if (> (length string) 80)
+                    (regexp-quote string)
+                  (mapconcat (lambda (c) (regexp-quote (string c))) string
+                             "\\(?:\n\\(?:[:a-f0-9]+ \\)+ \\)?"))))
+           (if (string-match "\\` ?\\([a-f0-9]+ \\)*[a-f0-9]+ ?\\'" string)
+               (concat textre "\\|"
+                       (mapconcat 'regexp-quote (split-string string " ")
+                                  " \\(?: .+\n[a-f0-9]+: \\)?"))
+             textre))
         bound noerror count))
     (let ((isearch-search-fun-function nil))
       (isearch-search-fun))))
@@ -317,34 +325,33 @@ You can use \\[hexl-find-file] to visit a file in Hexl mode.
   "Save a hexl format buffer as binary in visited file if modified."
   (interactive)
   (if hexl-in-save-buffer nil
-    (set-buffer-modified-p (if (buffer-modified-p)
-                              (save-excursion
-                                (let ((buf (generate-new-buffer " hexl"))
-                                      (name (buffer-name))
-                                      (file-name (buffer-file-name))
-                                      (start (point-min))
-                                      (end (point-max))
-                                      modified)
-                                  (set-buffer buf)
-                                  (insert-buffer-substring name start end)
-                                  (set-buffer name)
-                                  (dehexlify-buffer)
-                                  ;; Prevent infinite recursion.
-                                  (let ((hexl-in-save-buffer t))
-                                    (save-buffer))
-                                  (setq modified (buffer-modified-p))
-                                  (delete-region (point-min) (point-max))
-                                  (insert-buffer-substring buf start end)
-                                  (kill-buffer buf)
-                                  modified))
-                            (message "(No changes need to be saved)")
-                            nil))
+    (restore-buffer-modified-p
+     (if (buffer-modified-p)
+         (let ((buf (generate-new-buffer " hexl"))
+               (name (buffer-name))
+               (start (point-min))
+               (end (point-max))
+               modified)
+           (with-current-buffer buf
+             (insert-buffer-substring name start end)
+             (set-buffer name)
+             (dehexlify-buffer)
+             ;; Prevent infinite recursion.
+             (let ((hexl-in-save-buffer t))
+               (save-buffer))
+             (setq modified (buffer-modified-p))
+             (delete-region (point-min) (point-max))
+             (insert-buffer-substring buf start end)
+             (kill-buffer buf)
+             modified))
+       (message "(No changes need to be saved)")
+       nil))
     ;; Return t to indicate we have saved t
     t))
 
 ;;;###autoload
 (defun hexl-find-file (filename)
-  "Edit file FILENAME in hexl-mode.
+  "Edit file FILENAME in `hexl-mode'.
 Switch to a buffer visiting file FILENAME, creating one in none exists."
   (interactive
    (list
@@ -366,7 +373,7 @@ With arg, don't unhexlify buffer."
            (original-point (1+ (hexl-current-address))))
        (dehexlify-buffer)
        (remove-hook 'write-contents-functions 'hexl-save-buffer t)
-       (set-buffer-modified-p modified)
+       (restore-buffer-modified-p modified)
        (goto-char original-point)
        ;; Maybe adjust point for the removed CR characters.
        (when (eq (coding-system-eol-type buffer-file-coding-system) 1)
@@ -402,7 +409,7 @@ Ask the user for confirmation."
            (original-point (1+ (hexl-current-address))))
        (dehexlify-buffer)
        (remove-hook 'write-contents-functions 'hexl-save-buffer t)
-       (set-buffer-modified-p modified)
+       (restore-buffer-modified-p modified)
        (goto-char original-point))))
 
 (defun hexl-current-address (&optional validate)
@@ -425,7 +432,7 @@ Ask the user for confirmation."
 
 (defun hexl-print-current-point-info ()
   "Return current hexl-address in string.
-This function is indented to be used as eldoc callback."
+This function is intended to be used as eldoc callback."
   (let ((addr (hexl-current-address)))
     (format "Current address is %d/0x%08x" addr addr)))
 
@@ -916,25 +923,25 @@ Customize the variable `hexl-follow-ascii' to disable this feature."
            )))))
 
 (defun hexl-activate-ruler ()
-  "Activate `ruler-mode'"
+  "Activate `ruler-mode'."
   (require 'ruler-mode)
-  (set (make-local-variable 'ruler-mode-ruler-function) 
+  (set (make-local-variable 'ruler-mode-ruler-function)
        'hexl-mode-ruler)
   (ruler-mode 1))
 
 (defun hexl-follow-line ()
-  "Activate `hl-line-mode'"
+  "Activate `hl-line-mode'."
   (require 'frame)
   (require 'hl-line)
   (with-no-warnings
     (set (make-local-variable 'hl-line-range-function)
         'hexl-highlight-line-range)
-    (set (make-local-variable 'hl-line-face) 
+    (set (make-local-variable 'hl-line-face)
         'highlight))
   (hl-line-mode 1))
 
 (defun hexl-highlight-line-range ()
-  "Return the range of address area for the point.
+  "Return the range of address region for the point.
 This function is assumed to be used as call back function for `hl-line-mode'."
   (cons
    (line-beginning-position)
@@ -988,7 +995,9 @@ This function is assumed to be used as call back function for `hl-line-mode'."
   (define-key hexl-mode-map [up] 'hexl-previous-line)
   (define-key hexl-mode-map [down] 'hexl-next-line)
   (define-key hexl-mode-map [M-left] 'hexl-backward-short)
+  (define-key hexl-mode-map [?\e left] 'hexl-backward-short)
   (define-key hexl-mode-map [M-right] 'hexl-forward-short)
+  (define-key hexl-mode-map [?\e right] 'hexl-forward-short)
   (define-key hexl-mode-map [next] 'hexl-scroll-up)
   (define-key hexl-mode-map [prior] 'hexl-scroll-down)
   (define-key hexl-mode-map [home] 'hexl-beginning-of-line)
@@ -1007,7 +1016,8 @@ This function is assumed to be used as call back function for `hl-line-mode'."
   (define-key hexl-mode-map "\C-e" 'hexl-end-of-line)
   (define-key hexl-mode-map "\C-f" 'hexl-forward-char)
 
-  (if (not (eq (key-binding (char-to-string help-char)) 'help-command))
+  (if (not (memq (key-binding (char-to-string help-char))
+                 '(help-command ehelp-command)))
       (define-key hexl-mode-map (char-to-string help-char) 'undefined))
 
   (define-key hexl-mode-map "\C-k" 'undefined)
@@ -1067,5 +1077,5 @@ This function is assumed to be used as call back function for `hl-line-mode'."
 
 (provide 'hexl)
 
-;;; arch-tag: d5a7aa8a-9bce-480b-bcff-6c4c7ca5ea4a
+;; arch-tag: d5a7aa8a-9bce-480b-bcff-6c4c7ca5ea4a
 ;;; hexl.el ends here