(defun encoded-string-description (str coding-system)
"Return a pretty description of STR that is encoded by CODING-SYSTEM."
(setq str (string-as-unibyte str))
- (let ((char (aref str 0))
- desc)
- (when (< char 128)
- (setq desc (or (cdr (assq char iso-2022-control-alist))
- (char-to-string char)))
- (let ((i 1)
- (len (length str)))
- (while (< i len)
- (setq char (aref str i))
- (if (>= char 128)
- (setq desc nil i len)
- (setq desc (concat desc " "
- (or (cdr (assq char iso-2022-control-alist))
- (char-to-string char)))
- i (1+ i))))))
- (or desc
- (mapconcat (function (lambda (x) (format "0x%02x" x))) str " "))))
+ (mapconcat
+ (if (eq (coding-system-type coding-system) 2)
+ ;; Try to get a pretty description for ISO 2022 escape sequences.
+ (function (lambda (x) (or (cdr (assq x iso-2022-control-alist))
+ (format "%02X" x))))
+ (function (lambda (x) (format "0x%02x" x))))
+ str " "))
(defun encode-coding-char (char coding-system)
"Encode CHAR by CODING-SYSTEM and return the resulting string.