Hi Eli, > Thanks, but could you please show the minimal change required to fix > just the particular problem with this scenario I've attached a new self-contained patch based on yours, thank you for coming up with it. In my opinion, one of the problems is really as you said that len_mid (length in bytes) is uses where length of characters is expected. The patch contains an additional such case, and replaces (start1 + len1) in your patch with the equivalent but shorter end1. The other problem is that the branch len1_byte == len2_byte assumes len1 == len2 in several places: undo records, positions after the transposition, and the least obvious one is that even intervals between the region seem to need adjustment of positions. (I don't know enough of intervals to understand it, but had failed tests with text properties at wrong places.) Anyway, I've just added len1 == len2 as a condition to that branch with comments where I think the assumption is used. I've also added a new test for this case. > The patch > below passes both your test and the already-existing tests in > test/src/editfns-tests.el. For me after applying your patch, the tests crashed. The crash message was hidden in the end of the output: passed 21/24 transpose-nonascii-regions-test-1 (0.000067 sec) passed 22/24 transpose-nonascii-regions-test-2 (0.000068 sec) passed 23/24 transpose-regions-text-properties (0.000074 sec) Undo Undo make[1]: *** [Makefile:181: src/editfns-tests.log] segmentation fault make[1]: Leaving directory "/home/gabor/src/build/emacs-29.3/test" make: *** [Makefile:247: src/editfns-tests] Error 2 With the tests I intended to test all the branches in the code where the regions don't touch each other, catching mistakes where the wrong length is used. I hoped that byte length is not system dependent, it seems I have been mistaken, and the tests still need improvement to be thorough on all systems. So what differences exist or byte length? Best wishes, Gábor