changeset 47968:73b8f2ad9e28

(hexl-mode-old-write-contents-hooks): Remove. (hexl-mode, hexl-current-address, hexl-address-to-marker) (hexl-insert-char): Don't hardcode point-min == 1. (hexl-isearch-search-function): New fun. (hexl-mode-old-isearch-search-fun-function): New var. (hexl-mode): Use them. (hexl-mode, hexl-mode-exit, hexl-maybe-dehexlify-buffer): Use write-contents-functions rather then write-contents-hooks.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Mon, 21 Oct 2002 22:45:20 +0000
parents 0a8bff6f0168
children cdc87bc8e049
files lisp/hexl.el
diffstat 1 files changed, 29 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/hexl.el	Mon Oct 21 21:05:04 2002 +0000
+++ b/lisp/hexl.el	Mon Oct 21 22:45:20 2002 +0000
@@ -84,7 +84,7 @@
 (defvar hexl-mode-old-local-map)
 (defvar hexl-mode-old-mode-name)
 (defvar hexl-mode-old-major-mode)
-(defvar hexl-mode-old-write-contents-hooks)
+(defvar hexl-mode-old-isearch-search-fun-function)
 (defvar hexl-mode-old-require-final-newline)
 (defvar hexl-mode-old-syntax-table)
 
@@ -174,7 +174,7 @@
   (unless (eq major-mode 'hexl-mode)
     (let ((modified (buffer-modified-p))
 	  (inhibit-read-only t)
-	  (original-point (1- (point)))
+	  (original-point (- (point) (point-min)))
 	  max-address)
       (and (eobp) (not (bobp))
 	   (setq original-point (1- original-point)))
@@ -211,6 +211,11 @@
     (setq hexl-mode-old-mode-name mode-name)
     (setq mode-name "Hexl")
 
+    (set (make-local-variable 'hexl-mode-old-isearch-search-fun-function)
+	 isearch-search-fun-function)
+    (set (make-local-variable 'isearch-search-fun-function)
+	 'hexl-isearch-search-function)
+
     (make-local-variable 'hexl-mode-old-major-mode)
     (setq hexl-mode-old-major-mode major-mode)
     (setq major-mode 'hexl-mode)
@@ -219,10 +224,7 @@
     (setq hexl-mode-old-syntax-table (syntax-table))
     (set-syntax-table (standard-syntax-table))
 
-    (make-local-variable 'hexl-mode-old-write-contents-hooks)
-    (setq hexl-mode-old-write-contents-hooks write-contents-hooks)
-    (make-local-variable 'write-contents-hooks)
-    (add-hook 'write-contents-hooks 'hexl-save-buffer)
+    (add-hook 'write-contents-functions 'hexl-save-buffer nil t)
 
     (make-local-variable 'hexl-mode-old-require-final-newline)
     (setq hexl-mode-old-require-final-newline require-final-newline)
@@ -237,6 +239,19 @@
     (if hexl-follow-ascii (hexl-follow-ascii 1)))
   (run-hooks 'hexl-mode-hook))
 
+
+(defun hexl-isearch-search-function ()
+  (if (and (not isearch-regexp) (not isearch-word))
+      (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]+ \\)+ \\)?"))
+	 bound noerror count))
+    (let ((isearch-search-fun-function nil))
+      (isearch-search-fun))))
+
 (defun hexl-after-revert-hook ()
   (setq hexl-max-address (1- (buffer-size)))
   (hexlify-buffer)
@@ -294,7 +309,7 @@
 	    (inhibit-read-only t)
 	    (original-point (1+ (hexl-current-address))))
 	(dehexlify-buffer)
-	(remove-hook 'write-contents-hooks 'hexl-save-buffer)
+	(remove-hook 'write-contents-functions 'hexl-save-buffer t)
 	(set-buffer-modified-p modified)
 	(goto-char original-point)
 	;; Maybe adjust point for the removed CR characters.
@@ -309,9 +324,9 @@
   (remove-hook 'post-command-hook 'hexl-follow-ascii-find t)
   (setq hexl-ascii-overlay nil)
 
-  (setq write-contents-hooks hexl-mode-old-write-contents-hooks)
   (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)
   (use-local-map hexl-mode-old-local-map)
   (set-syntax-table hexl-mode-old-syntax-table)
   (setq major-mode hexl-mode-old-major-mode)
@@ -325,21 +340,21 @@
 	    (inhibit-read-only t)
 	    (original-point (1+ (hexl-current-address))))
 	(dehexlify-buffer)
-	(remove-hook 'write-contents-hooks 'hexl-save-buffer)
+	(remove-hook 'write-contents-functions 'hexl-save-buffer t)
 	(set-buffer-modified-p modified)
 	(goto-char original-point))))
 
 (defun hexl-current-address (&optional validate)
   "Return current hexl-address."
   (interactive)
-  (let ((current-column (- (% (point) 68) 11))
+  (let ((current-column (- (% (- (point) (point-min) -1) 68) 11))
 	(hexl-address 0))
     (if (< current-column 0)
 	(if validate
 	    (error "Point is not on a character in the file")
 	  (setq current-column 0)))
     (setq hexl-address
-	  (+ (* (/ (point) 68) 16)
+	  (+ (* (/ (- (point) (point-min) -1) 68) 16)
 	     (if (>= current-column 41)
 		 (- current-column 41)
 	       (/ (- current-column  (/ current-column 5)) 2))))
@@ -350,7 +365,7 @@
 (defun hexl-address-to-marker (address)
   "Return buffer position for ADDRESS."
   (interactive "nAddress: ")
-  (+ (* (/ address 16) 68) 11 (/ (* (% address 16) 5) 2)))
+  (+ (* (/ address 16) 68) 10 (point-min) (/ (* (% address 16) 5) 2)))
 
 (defun hexl-goto-address (address)
   "Goto hexl-mode (decimal) address ADDRESS.
@@ -730,11 +745,11 @@
     (while (> num 0)
       (let ((hex-position
 	     (+ (* (/ address 16) 68)
-		11
+		10 (point-min)
 		(* 2 (% address 16))
 		(/ (% address 16) 2)))
 	    (ascii-position
-	     (+ (* (/ address 16) 68) 52 (% address 16)))
+	     (+ (* (/ address 16) 68) 51 (point-min) (% address 16)))
 	    at-ascii-position)
 	(if (= (point) ascii-position)
 	    (setq at-ascii-position t))