This function lets you compare portions of the text in a buffer, without copying them into strings first.
This function lets you compare two substrings of the same buffer or two
different buffers. The first three arguments specify one substring,
giving a buffer and two positions within the buffer. The last three
arguments specify the other substring in the same way. You can use
nil for buffer1, buffer2, or both to stand for the
The value is negative if the first substring is less, positive if the first is greater, and zero if they are equal. The absolute value of the result is one plus the index of the first differing characters within the substrings.
This function ignores case when comparing characters
case-fold-search is non-
nil. It always ignores
Suppose the current buffer contains the text ‘foobarbar haha!rara!’; then in this example the two substrings are ‘rbar ’ and ‘rara!’. The value is 2 because the first substring is greater at the second character.
(compare-buffer-substring nil 6 11 nil 16 21) ⇒ 2