diff options
| author | Wolfgang Jenkner | 2015-06-17 13:41:57 +0200 |
|---|---|---|
| committer | Wolfgang Jenkner | 2015-06-17 13:41:57 +0200 |
| commit | cf23c335acc7d3093001cdc54a56dda6bda25778 (patch) | |
| tree | 96421c414201dac91883593a6683ced48e2dc3cc /src | |
| parent | fd7bbfbe62a67dd1cceef45b649995b9ab045923 (diff) | |
| download | emacs-cf23c335acc7d3093001cdc54a56dda6bda25778.tar.gz emacs-cf23c335acc7d3093001cdc54a56dda6bda25778.zip | |
* src/editfns.c (Fbyte_to_position): Fix bytepos not at char boundary.
The behavior now matches the description in the manual. (Bug#20783)
Diffstat (limited to 'src')
| -rw-r--r-- | src/editfns.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/editfns.c b/src/editfns.c index bfa67e20e3e..e39eed6e870 100644 --- a/src/editfns.c +++ b/src/editfns.c | |||
| @@ -1025,10 +1025,20 @@ DEFUN ("byte-to-position", Fbyte_to_position, Sbyte_to_position, 1, 1, 0, | |||
| 1025 | If BYTEPOS is out of range, the value is nil. */) | 1025 | If BYTEPOS is out of range, the value is nil. */) |
| 1026 | (Lisp_Object bytepos) | 1026 | (Lisp_Object bytepos) |
| 1027 | { | 1027 | { |
| 1028 | ptrdiff_t pos_byte; | ||
| 1029 | |||
| 1028 | CHECK_NUMBER (bytepos); | 1030 | CHECK_NUMBER (bytepos); |
| 1029 | if (XINT (bytepos) < BEG_BYTE || XINT (bytepos) > Z_BYTE) | 1031 | pos_byte = XINT (bytepos); |
| 1032 | if (pos_byte < BEG_BYTE || pos_byte > Z_BYTE) | ||
| 1030 | return Qnil; | 1033 | return Qnil; |
| 1031 | return make_number (BYTE_TO_CHAR (XINT (bytepos))); | 1034 | if (Z != Z_BYTE) |
| 1035 | /* There are multibyte characters in the buffer. | ||
| 1036 | The argument of BYTE_TO_CHAR must be a byte position at | ||
| 1037 | a character boundary, so search for the start of the current | ||
| 1038 | character. */ | ||
| 1039 | while (!CHAR_HEAD_P (FETCH_BYTE (pos_byte))) | ||
| 1040 | pos_byte--; | ||
| 1041 | return make_number (BYTE_TO_CHAR (pos_byte)); | ||
| 1032 | } | 1042 | } |
| 1033 | 1043 | ||
| 1034 | DEFUN ("following-char", Ffollowing_char, Sfollowing_char, 0, 0, 0, | 1044 | DEFUN ("following-char", Ffollowing_char, Sfollowing_char, 0, 0, 0, |