diff options
| -rw-r--r-- | lisp/international/mule-util.el | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/lisp/international/mule-util.el b/lisp/international/mule-util.el index 9aa64dc8f7b..8dd83b43290 100644 --- a/lisp/international/mule-util.el +++ b/lisp/international/mule-util.el | |||
| @@ -355,7 +355,7 @@ QUALITY can be: | |||
| 355 | (pm (save-restriction (widen) (point-min)))) | 355 | (pm (save-restriction (widen) (point-min)))) |
| 356 | (and (eq type 'utf-8) | 356 | (and (eq type 'utf-8) |
| 357 | ;; Any post-read/pre-write conversions mean it's not really UTF-8. | 357 | ;; Any post-read/pre-write conversions mean it's not really UTF-8. |
| 358 | (not (null (coding-system-get coding-system :pos-read-conversion))) | 358 | (not (null (coding-system-get coding-system :post-read-conversion))) |
| 359 | (setq type 'not-utf-8)) | 359 | (setq type 'not-utf-8)) |
| 360 | (and (memq type '(charset raw-text undecided)) | 360 | (and (memq type '(charset raw-text undecided)) |
| 361 | ;; The following are all of type 'charset', but they are | 361 | ;; The following are all of type 'charset', but they are |
| @@ -365,12 +365,6 @@ QUALITY can be: | |||
| 365 | japanese-iso-8bit chinese-big5-hkscs | 365 | japanese-iso-8bit chinese-big5-hkscs |
| 366 | japanese-cp932 korean-cp949))) | 366 | japanese-cp932 korean-cp949))) |
| 367 | (setq type 'single-byte)) | 367 | (setq type 'single-byte)) |
| 368 | ;; Any encoding that's not single-byte and not UTF-8 must use the | ||
| 369 | ;; 'exact' path if QUALITY is 'exact', because we have no simple | ||
| 370 | ;; mappings for those cases. | ||
| 371 | (and (not (memq type '(utf-8 single-byte))) | ||
| 372 | (eq quality 'exact) | ||
| 373 | (setq type 'use-exact)) | ||
| 374 | (pcase type | 368 | (pcase type |
| 375 | (`utf-8 | 369 | (`utf-8 |
| 376 | (when (coding-system-get coding-system :bom) | 370 | (when (coding-system-get coding-system :bom) |
| @@ -378,19 +372,23 @@ QUALITY can be: | |||
| 378 | (if (= eol 1) | 372 | (if (= eol 1) |
| 379 | (filepos-to-bufferpos--dos (+ pm byte) #'byte-to-position) | 373 | (filepos-to-bufferpos--dos (+ pm byte) #'byte-to-position) |
| 380 | (byte-to-position (+ pm byte)))) | 374 | (byte-to-position (+ pm byte)))) |
| 381 | (`utf-16 | 375 | (`single-byte |
| 376 | (if (= eol 1) | ||
| 377 | (filepos-to-bufferpos--dos (+ pm byte) #'identity) | ||
| 378 | (+ pm byte))) | ||
| 379 | ((and `utf-16 | ||
| 380 | ;; FIXME: For utf-16, we could use the same approach as used for | ||
| 381 | ;; dos EOLs (counting the number of non-BMP chars instead of the | ||
| 382 | ;; number of lines). | ||
| 383 | (guard (not (eq quality 'exact)))) | ||
| 382 | ;; Account for BOM, which is always 2 bytes in UTF-16. | 384 | ;; Account for BOM, which is always 2 bytes in UTF-16. |
| 383 | (when (coding-system-get coding-system :bom) | 385 | (when (coding-system-get coding-system :bom) |
| 384 | (setq byte (- byte 2))) | 386 | (setq byte (max 0 (- byte 2)))) |
| 385 | ;; In approximate mode, assume all characters are within the | 387 | ;; In approximate mode, assume all characters are within the |
| 386 | ;; BMP, i.e. take up 2 bytes. | 388 | ;; BMP, i.e. take up 2 bytes. |
| 387 | (setq byte (/ byte 2)) | 389 | (setq byte (/ byte 2)) |
| 388 | (if (= eol 1) | 390 | (if (= eol 1) |
| 389 | (filepos-to-bufferpos--dos (+ pm byte) #'identity) | 391 | (filepos-to-bufferpos--dos (+ pm byte) #'identity) |
| 390 | (byte-to-position (+ pm byte)))) | ||
| 391 | (`single-byte | ||
| 392 | (if (= eol 1) | ||
| 393 | (filepos-to-bufferpos--dos (+ pm byte) #'identity) | ||
| 394 | (+ pm byte))) | 392 | (+ pm byte))) |
| 395 | (_ | 393 | (_ |
| 396 | (pcase quality | 394 | (pcase quality |