(custom-face-value-create): If face name doesn't end with "face", add
[bpt/emacs.git] / lisp / hexl.el
index e5d55b4..293226a 100644 (file)
@@ -600,17 +600,7 @@ This discards the buffer's undo information."
   (setq buffer-undo-list nil)
   ;; Don't decode text in the ASCII part of `hexl' program output.
   (let ((coding-system-for-read 'raw-text)
-       ;; If the buffer was read with EOL conversions, be sure to use the
-       ;; same conversions when passing the region to the `hexl' program.
-       (coding-system-for-write
-        (let ((eol-type (coding-system-eol-type buffer-file-coding-system)))
-          (cond ((eq eol-type 1)
-                 'raw-text-dos)
-                ((eq eol-type 2)
-                 'raw-text-mac)
-                ((eq eol-type 0)
-                 'raw-text-unix)
-                (t 'no-conversion))))
+       (coding-system-for-write buffer-file-coding-system)
        (buffer-undo-list t))
     (shell-command-on-region (point-min) (point-max) hexlify-command t)
     (if (> (point) (hexl-address-to-marker hexl-max-address))
@@ -625,15 +615,7 @@ This discards the buffer's undo information."
           (error "Aborted")))
   (setq buffer-undo-list nil)
   (let ((coding-system-for-write 'raw-text)
-       (coding-system-for-read
-        (let ((eol-type (coding-system-eol-type buffer-file-coding-system)))
-          (cond ((eq eol-type 1)
-                 'raw-text-dos)
-                ((eq eol-type 2)
-                 'raw-text-mac)
-                ((eq eol-type 0)
-                 'raw-text-unix)
-                (t 'no-conversion))))
+       (coding-system-for-read buffer-file-coding-system)
        (buffer-undo-list t))
     (shell-command-on-region (point-min) (point-max) dehexlify-command t)))
 
@@ -717,6 +699,31 @@ This discards the buffer's undo information."
        (error "Hex number out of range")
       (hexl-insert-char num arg))))
 
+(defun hexl-insert-hex-string (str arg)
+  "Insert hexadecimal string STR at point ARG times.
+Embedded whitespace, dashes, and periods in the string are ignored."
+  (interactive "sHex string: \np")
+  (setq str (replace-regexp-in-string "[- \t.]" "" str))
+  (let ((chars '()))
+    (let ((len (length str))
+         (idx 0))
+      (if (eq (logand len 1) 1)
+         (let ((num (hexl-hex-string-to-integer (substring str 0 1))))
+           (setq chars (cons num chars))
+           (setq idx 1)))
+      (while (< idx len)
+       (let* ((nidx (+ idx 2))
+              (num (hexl-hex-string-to-integer (substring str idx nidx))))
+         (setq chars (cons num chars))
+         (setq idx nidx))))
+    (setq chars (nreverse chars))
+    (while (> arg 0)
+      (let ((chars chars))
+       (while chars
+         (hexl-insert-char (car chars) 1)
+         (setq chars (cdr chars))))
+      (setq arg (- arg 1)))))
+
 (defun hexl-insert-decimal-char (arg)
   "Insert a ASCII char ARG times at point for a given decimal number."
   (interactive "p")