emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master cf23c33: * src/editfns.c (Fbyte_to_position): Fix b


From: Wolfgang Jenkner
Subject: [Emacs-diffs] master cf23c33: * src/editfns.c (Fbyte_to_position): Fix bytepos not at char boundary.
Date: Wed, 17 Jun 2015 12:28:20 +0000

branch: master
commit cf23c335acc7d3093001cdc54a56dda6bda25778
Author: Wolfgang Jenkner <address@hidden>
Commit: Wolfgang Jenkner <address@hidden>

    * src/editfns.c (Fbyte_to_position): Fix bytepos not at char boundary.
    
    The behavior now matches the description in the manual.  (Bug#20783)
---
 src/editfns.c |   14 ++++++++++++--
 1 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/editfns.c b/src/editfns.c
index bfa67e2..e39eed6 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,
 If BYTEPOS is out of range, the value is nil.  */)
   (Lisp_Object bytepos)
 {
+  ptrdiff_t pos_byte;
+
   CHECK_NUMBER (bytepos);
-  if (XINT (bytepos) < BEG_BYTE || XINT (bytepos) > Z_BYTE)
+  pos_byte = XINT (bytepos);
+  if (pos_byte < BEG_BYTE || pos_byte > Z_BYTE)
     return Qnil;
-  return make_number (BYTE_TO_CHAR (XINT (bytepos)));
+  if (Z != Z_BYTE)
+    /* There are multibyte characters in the buffer.
+       The argument of BYTE_TO_CHAR must be a byte position at
+       a character boundary, so search for the start of the current
+       character.  */
+    while (!CHAR_HEAD_P (FETCH_BYTE (pos_byte)))
+      pos_byte--;
+  return make_number (BYTE_TO_CHAR (pos_byte));
 }
 
 DEFUN ("following-char", Ffollowing_char, Sfollowing_char, 0, 0, 0,



reply via email to

[Prev in Thread] Current Thread [Next in Thread]