aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Zaretskii2015-06-19 11:19:06 +0300
committerEli Zaretskii2015-06-19 11:19:06 +0300
commita2bb6c7bc19719eea3a84e3374f4da6781bc4bf0 (patch)
tree06573411eb12d21933a8ac8db51a381e89211358
parentc4151ebe15479de4c2e511b068cdf9af6a4576cf (diff)
downloademacs-a2bb6c7bc19719eea3a84e3374f4da6781bc4bf0.tar.gz
emacs-a2bb6c7bc19719eea3a84e3374f4da6781bc4bf0.zip
Minor fixes in filepos-to-bufferpos
* lisp/international/mule-util.el (filepos-to-bufferpos): Remove test for utf-8-emacs. Exempt single-byte encodings from the 'use-exact' path when QUALITY is 'exact'. Test UTF-16 encodings for BOM before subtracting 2 bytes. Use 'identity' when adjusting UTF-16 encoded files for CR-LF EOLs.
-rw-r--r--lisp/international/mule-util.el16
1 files changed, 9 insertions, 7 deletions
diff --git a/lisp/international/mule-util.el b/lisp/international/mule-util.el
index bbefdaa7324..9aa64dc8f7b 100644
--- a/lisp/international/mule-util.el
+++ b/lisp/international/mule-util.el
@@ -353,15 +353,10 @@ QUALITY can be:
353 (type (coding-system-type coding-system)) 353 (type (coding-system-type coding-system))
354 (base (coding-system-base coding-system)) 354 (base (coding-system-base coding-system))
355 (pm (save-restriction (widen) (point-min)))) 355 (pm (save-restriction (widen) (point-min))))
356 (and (eq type 'utf-8-emacs)
357 (setq type 'utf-8))
358 (and (eq type 'utf-8) 356 (and (eq type 'utf-8)
359 ;; 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.
360 (not (null (coding-system-get coding-system :pos-read-conversion))) 358 (not (null (coding-system-get coding-system :pos-read-conversion)))
361 (setq type 'not-utf-8)) 359 (setq type 'not-utf-8))
362 (and (not (eq type 'utf-8))
363 (eq quality 'exact)
364 (setq type 'use-exact))
365 (and (memq type '(charset raw-text undecided)) 360 (and (memq type '(charset raw-text undecided))
366 ;; The following are all of type 'charset', but they are 361 ;; The following are all of type 'charset', but they are
367 ;; actually variable-width encodings. 362 ;; actually variable-width encodings.
@@ -370,6 +365,12 @@ QUALITY can be:
370 japanese-iso-8bit chinese-big5-hkscs 365 japanese-iso-8bit chinese-big5-hkscs
371 japanese-cp932 korean-cp949))) 366 japanese-cp932 korean-cp949)))
372 (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))
373 (pcase type 374 (pcase type
374 (`utf-8 375 (`utf-8
375 (when (coding-system-get coding-system :bom) 376 (when (coding-system-get coding-system :bom)
@@ -379,12 +380,13 @@ QUALITY can be:
379 (byte-to-position (+ pm byte)))) 380 (byte-to-position (+ pm byte))))
380 (`utf-16 381 (`utf-16
381 ;; Account for BOM, which is always 2 bytes in UTF-16. 382 ;; Account for BOM, which is always 2 bytes in UTF-16.
382 (setq byte (- byte 2)) 383 (when (coding-system-get coding-system :bom)
384 (setq byte (- byte 2)))
383 ;; In approximate mode, assume all characters are within the 385 ;; In approximate mode, assume all characters are within the
384 ;; BMP, i.e. take up 2 bytes. 386 ;; BMP, i.e. take up 2 bytes.
385 (setq byte (/ byte 2)) 387 (setq byte (/ byte 2))
386 (if (= eol 1) 388 (if (= eol 1)
387 (filepos-to-bufferpos--dos (+ pm byte) #'byte-to-position) 389 (filepos-to-bufferpos--dos (+ pm byte) #'identity)
388 (byte-to-position (+ pm byte)))) 390 (byte-to-position (+ pm byte))))
389 (`single-byte 391 (`single-byte
390 (if (= eol 1) 392 (if (= eol 1)