patch 9.1.1243: diff mode is lacking for changes within lines

Problem:  Diff mode's inline highlighting is lackluster. It only
          performs a line-by-line comparison, and calculates a single
          shortest range within a line that could encompass all the
          changes. In lines with multiple changes, or those that span
          multiple lines, this approach tends to end up highlighting
          much more than necessary.

Solution: Implement new inline highlighting modes by doing per-character
          or per-word diff within the diff block, and highlight only the
          relevant parts, add "inline:simple" to the defaults (which is
          the old behaviour)

This change introduces a new diffopt option "inline:<type>". Setting to
"none" will disable all inline highlighting, "simple" (the default) will
use the old behavior, "char" / "word" will perform a character/word-wise
diff of the texts within each diff block and only highlight the
differences.

The new char/word inline diff only use the internal xdiff, and will
respect diff options such as algorithm choice, icase, and misc iwhite
options. indent-heuristics is always on to perform better sliding.

For character highlight, a post-process of the diff results is first
applied before we show the highlight. This is because a naive diff will
create a result with a lot of small diff chunks and gaps, due to the
repetitive nature of individual characters. The post-process is a
heuristic-based refinement that attempts to merge adjacent diff blocks
if they are separated by a short gap (1-3 characters), and can be
further tuned in the future for better results. This process results in
more characters than necessary being highlighted but overall less visual
noise.

For word highlight, always use first buffer's iskeyword definition.
Otherwise if each buffer has different iskeyword settings we would not
be able to group words properly.

The char/word diffing is always per-diff block, not per line, meaning
that changes that span multiple lines will show up correctly.
Added/removed newlines are not shown by default, but if the user has
'list' set (with "eol" listchar defined), the eol character will be be
highlighted correctly for the specific newline characters.

Also, add a new "DiffTextAdd" highlight group linked to "DiffText" by
default. It allows color schemes to use different colors for texts that
have been added within a line versus modified.

This doesn't interact with linematch perfectly currently. The linematch
feature splits up diff blocks into multiple smaller blocks for better
visual matching, which makes inline highlight less useful especially for
multi-line change (e.g. a line is broken into two lines). This could be
addressed in the future.

As a side change, this also removes the bounds checking introduced to
diff_read() as they were added to mask existing logic bugs that were
properly fixed in #16768.

closes: #16881

Signed-off-by: Yee Cheng Chin <ychin.git@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
diff --git a/runtime/doc/version9.txt b/runtime/doc/version9.txt
index 4f0da43..5868598 100644
--- a/runtime/doc/version9.txt
+++ b/runtime/doc/version9.txt
@@ -1,4 +1,4 @@
-*version9.txt*  For Vim version 9.1.  Last change: 2025 Mar 23
+*version9.txt*  For Vim version 9.1.  Last change: 2025 Mar 26
 
 
 		  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -41553,6 +41553,16 @@
 
 Support for protected _new() method
 
+Diff mode ~
+---------
+Include the "linematch" algorithm for the 'diffopt' setting.  This aligns
+changes between buffers on similar lines improving the diff highlighting in
+Vim
+
+Improve the diff highlighting for changes within a line.  Configurable using
+the "inline" sub option value for the 'diffopt' setting, with "inline:simple"
+being added to the default "diffopt" value (but this does not change how diff
+mode works).
 							*new-other-9.2*
 Other new features ~
 ------------------
@@ -41570,10 +41580,6 @@
 completion and command-line completion in |ins-completion-menu|, see
 |complete-items|
 
-Include the "linematch" algorithm for the 'diffopt' setting.  This aligns
-changes between buffers on similar lines improving the diff highlighting in
-Vim
-
 Support for the |Tuple| data type in Vim script and Vim9 script.
 
 							*changed-9.2*
@@ -41590,7 +41596,6 @@
 - the default value of the 'keyprotocol' option has been updated and support
   for the ghostty terminal emulator (using kitty protocol) has been added
 
-
 Completion: ~
 - allow to complete directories from 'cdpath' for |:cd| and similar commands,
   add the "cd_in_path" completion type for e.g. |:command-complete| and
@@ -41702,7 +41707,8 @@
 
 Highlighting: ~
 
-|hl-ComplMatchIns|	matched text of the currently inserted completion.
+|hl-ComplMatchIns|	matched text of the currently inserted completion
+|hl-DiffTextAdd|	added text within a changed line
 |hl-MsgArea|		highlighting of the Command-line and messages area
 |hl-PmenuMatch|		Popup menu: highlighting of matched text
 |hl-PmenuMatchSel|	Popup menu: highlighting of matched text in selected