Subject: bug#10725: Hexl-Mode:Feature: Direct hex input in hex-area

From: Andreas Kremser <[email-masked]>
Date: Sat, 4 Feb 2012 20:03:16 +0100

** Description

Allow directly entering hex-values in hexl mode while in
hex-area. Changed hexl-insert-char to treat text entered into the
hex-area differnt from text enterd into the ascii-area.

** ChangeLog

2012-02-04  Andreas Kremser  <[email-masked]>

        * hexl.el (hexl-insert-char): Allow directly entering
hex-values in hexl mode while in hex-area.
# Bazaar merge directive format 2 (Bazaar 0.90)
# revision_id: [email-masked]\
#   vshwnek1lbyc32vb
# target_branch: bzr://bzr.savannah.gnu.org/emacs/trunk/
# testament_sha1: 4774810212441e716205190945f17efbf28fa08f
# timestamp: 2012-02-04 19:59:34 +0100
# base_revision_id: [email-masked]
# 
# Begin patch
=== modified file 'lisp/ChangeLog'
--- lisp/ChangeLog	2012-02-04 09:57:09 +0000
+++ lisp/ChangeLog	2012-02-04 18:42:27 +0000
@@ -1,3 +1,7 @@
+2012-02-04  Andreas Kremser  <[email-masked]>
+
+	* hexl.el (hexl-insert-char): Allow directly entering hex-values in hexl mode while in hex-area.
+
 2012-02-04  Lars Ljung  <[email-masked]>  (tiny change)
 
 	* eshell/esh-ext.el (eshell-windows-shell-file): Match "cmdproxy"

=== modified file 'lisp/hexl.el'
--- lisp/hexl.el	2012-01-19 07:21:25 +0000
+++ lisp/hexl.el	2012-02-04 18:40:09 +0000
@@ -918,6 +918,52 @@
 		(/ (% address 16) 2)))
 	    (ascii-position
 	     (+ (* (/ address 16) 68) 51 (point-min) (% address 16)))
+	    (low-ch (downcase ch)))
+	(if (= (point) ascii-position)
+	    (progn
+	      (goto-char hex-position)
+	      (delete-char 2)
+	      (insert (format "%02x" ch))
+	      (goto-char ascii-position)
+	      (delete-char 1)
+	      (insert (hexl-printable-character ch))
+	      (or (eq address hexl-max-address)
+		  (setq address (1+ address)))
+	      (hexl-goto-address address)
+	      (beginning-of-line)
+	      (forward-char 51)
+	      (forward-char (% address 16)))
+	  (if (or (and (>= ch (string-to-char "0")) (<= ch (string-to-char "9")))
+		  (and (>= low-ch (string-to-char "a")) (<=  low-ch (string-to-char "f"))))
+	      (progn
+		(goto-char (max (- (point) (point-min) -1)
+				(hexl-address-to-marker address)))
+		(delete-char 1)
+		(insert  low-ch)
+		(let ((curp (point))
+		      (av (+ (* 16 (hexl-hex-char-to-integer (char-after  hex-position )))
+			     (hexl-hex-char-to-integer (char-after (+ 1 hex-position))))))
+		  (goto-char ascii-position)
+		  (delete-char 1)
+		  (insert (hexl-printable-character av))
+		  (goto-char curp)))))
+	(setq num (1- num))))))
+
+(defun hexl-insert-char (ch num)
+  "Insert the character CH NUM times in a hexl buffer.
+
+CH must be a unibyte character whose value is between 0 and 255."
+  (if (or (< ch 0) (> ch 255))
+      (error "Invalid character 0x%x -- must be in the range [0..255]" ch))
+  (let ((address (hexl-current-address t)))
+    (while (> num 0)
+      (let ((hex-position
+	     (+ (* (/ address 16) 68)
+		10 (point-min)
+		(* 2 (% address 16))
+		(/ (% address 16) 2)))
+	    (ascii-position
+	     (+ (* (/ address 16) 68) 51 (point-min) (% address 16)))
 	    at-ascii-position)
 	(if (= (point) ascii-position)
 	    (setq at-ascii-position t))

# Begin bundle