diff options
| author | Stefan Monnier | 2019-04-29 16:32:52 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2019-04-29 16:32:52 -0400 |
| commit | 071a6927a89bc013d5e026e446d4ee503c59bc7b (patch) | |
| tree | 865259f35566958b54a9f04e645471b6ae6b16a3 | |
| parent | 21143f92db31e685242a0a372bc2e0846cde7bb0 (diff) | |
| download | emacs-071a6927a89bc013d5e026e446d4ee503c59bc7b.tar.gz emacs-071a6927a89bc013d5e026e446d4ee503c59bc7b.zip | |
* lisp/international/mule-util.el: Avoid setq; clarify meaning of -1.
| -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 8ad212796a5..de5e7d83231 100644 --- a/lisp/international/mule-util.el +++ b/lisp/international/mule-util.el | |||
| @@ -456,7 +456,7 @@ QUALITY can be: | |||
| 456 | (lineno (if (= eol 1) (1- (line-number-at-pos position)) 0)) | 456 | (lineno (if (= eol 1) (1- (line-number-at-pos position)) 0)) |
| 457 | (type (coding-system-type coding-system)) | 457 | (type (coding-system-type coding-system)) |
| 458 | (base (coding-system-base coding-system)) | 458 | (base (coding-system-base coding-system)) |
| 459 | byte) | 459 | (point-min 1)) ;Clarify what the `1' means. |
| 460 | (and (eq type 'utf-8) | 460 | (and (eq type 'utf-8) |
| 461 | ;; Any post-read/pre-write conversions mean it's not really UTF-8. | 461 | ;; Any post-read/pre-write conversions mean it's not really UTF-8. |
| 462 | (not (null (coding-system-get coding-system :post-read-conversion))) | 462 | (not (null (coding-system-get coding-system :post-read-conversion))) |
| @@ -471,19 +471,17 @@ QUALITY can be: | |||
| 471 | (setq type 'single-byte)) | 471 | (setq type 'single-byte)) |
| 472 | (pcase type | 472 | (pcase type |
| 473 | ('utf-8 | 473 | ('utf-8 |
| 474 | (setq byte (position-bytes position)) | 474 | (+ (or (position-bytes position) |
| 475 | (when (null byte) | 475 | (if (<= position 0) |
| 476 | (if (<= position 0) | 476 | point-min |
| 477 | (setq byte 1) | 477 | (position-bytes (point-max)))) |
| 478 | (setq byte (position-bytes (point-max))))) | ||
| 479 | (setq byte (1- byte)) | ||
| 480 | (+ byte | ||
| 481 | ;; Account for BOM, if any. | 478 | ;; Account for BOM, if any. |
| 482 | (if (coding-system-get coding-system :bom) 3 0) | 479 | (if (coding-system-get coding-system :bom) 3 0) |
| 483 | ;; Account for CR in CRLF pairs. | 480 | ;; Account for CR in CRLF pairs. |
| 484 | lineno)) | 481 | lineno |
| 482 | (- point-min))) | ||
| 485 | ('single-byte | 483 | ('single-byte |
| 486 | (+ position -1 lineno)) | 484 | (+ position (- point-min) lineno)) |
| 487 | ((and 'utf-16 | 485 | ((and 'utf-16 |
| 488 | ;; FIXME: For utf-16, we could use the same approach as used for | 486 | ;; FIXME: For utf-16, we could use the same approach as used for |
| 489 | ;; dos EOLs (counting the number of non-BMP chars instead of the | 487 | ;; dos EOLs (counting the number of non-BMP chars instead of the |
| @@ -491,14 +489,14 @@ QUALITY can be: | |||
| 491 | (guard (not (eq quality 'exact)))) | 489 | (guard (not (eq quality 'exact)))) |
| 492 | ;; In approximate mode, assume all characters are within the | 490 | ;; In approximate mode, assume all characters are within the |
| 493 | ;; BMP, i.e. each one takes up 2 bytes. | 491 | ;; BMP, i.e. each one takes up 2 bytes. |
| 494 | (+ (* (1- position) 2) | 492 | (+ (* (- position point-min) 2) |
| 495 | ;; Account for BOM, if any. | 493 | ;; Account for BOM, if any. |
| 496 | (if (coding-system-get coding-system :bom) 2 0) | 494 | (if (coding-system-get coding-system :bom) 2 0) |
| 497 | ;; Account for CR in CRLF pairs. | 495 | ;; Account for CR in CRLF pairs. |
| 498 | lineno)) | 496 | lineno)) |
| 499 | (_ | 497 | (_ |
| 500 | (pcase quality | 498 | (pcase quality |
| 501 | ('approximate (+ (position-bytes position) -1 lineno)) | 499 | ('approximate (+ (position-bytes position) (- point-min) lineno)) |
| 502 | ('exact | 500 | ('exact |
| 503 | ;; Rather than assume that the file exists and still holds the right | 501 | ;; Rather than assume that the file exists and still holds the right |
| 504 | ;; data, we reconstruct its relevant portion. | 502 | ;; data, we reconstruct its relevant portion. |
| @@ -511,7 +509,7 @@ QUALITY can be: | |||
| 511 | (widen) | 509 | (widen) |
| 512 | (encode-coding-region (point-min) (min (point-max) position) | 510 | (encode-coding-region (point-min) (min (point-max) position) |
| 513 | coding-system tmp-buf))) | 511 | coding-system tmp-buf))) |
| 514 | (1- (point-max))))))))))) | 512 | (buffer-size)))))))))) |
| 515 | 513 | ||
| 516 | (provide 'mule-util) | 514 | (provide 'mule-util) |
| 517 | 515 | ||