I wrote this code:
(defun compare-string-test (String1 String2)
(interactive)
(let ((Temp1 (make-temp-file "gitdiff" nil nil String1))
(Temp2 (make-temp-file "gitdiff" nil nil String2)))
(insert
(with-temp-buffer
(insert
(shell-command-to-string
(format
"git diff --no-index --word-diff=color --word-diff-regex=. %s %s"
Temp1 Temp2)))
(ansi-color-apply-on-region (point-min) (point-max))
(buffer-string)))))
I tried:
(compare-string-test "Ciao" "Miao")
I'd like to insert a "fontified" string but it doesn't work.
If I remove the ansi-color-apply-on-region
command I get:
[1mdiff --git a/tmp/gitdiffM8px4W b/tmp/gitdiffb5aHy4[m
[1mindex 11d8bbf..cf44f4e 100644[m
[1m--- a/tmp/gitdiffM8px4W[m
[1m+++ b/tmp/gitdiffb5aHy4[m
[36m@@ -1 +1 @@[m
[31mC[m[32mM[miao
and if I evaluate (ansi-color-apply-on-region (point-min) (point-max))
I get:
that it's what I need (I'm only interested in the last line).
How can I make my function inserting the string with this fontification?
Referring to this https://emacs.stackexchange.com/a/56223/15606, I tried the function both with font-lock-mode
active and disabled.
I also tried message
instead of insert
but the massage in the minibuffer appears without fontification.
I red the buffer-string
and insert
documentation and I think these functions should keep text properties.
Note. I also opened an issue to ask for a solution using elisp
tools only: Is there an Emacs function or package to visually compare two text strings?