It seems to me that an actual image would be more trouble than it's worth in c++-mode
or python-mode
. It could work in org-mode
though, which has a mechanism for storing the images and refreshing them. Even then, it's awkward for scrolling if the image has a large height.
But you can still fontify bits if you want. For instance, here's my setup for font-locking doxygen tags in C++:
(defface font-lock-doxygen-face
'((nil (:foreground "SaddleBrown" :background "#f7f7f7")))
"Special face to highlight doxygen tags such as <tt>...</tt>
and <code>...</code>."
:group 'font-lock-highlighting-faces)
(font-lock-add-keywords
'c++-mode
'(("\\(<\\(?:code\\|tt\\)>\"?\\)\\([^<]*?\\)\\(\"?</\\(?:code\\|tt\\)>\\)"
(0 (prog1 ()
(let* ((expr (match-string-no-properties 2))
(expr-len (length expr)))
(if (eq 1 expr-len)
(compose-region (match-beginning 0)
(match-end 0)
(aref expr 0))
(compose-region (match-beginning 1)
(1+ (match-end 1))
(aref expr 0))
(compose-region (1- (match-beginning 3))
(match-end 3)
(aref expr (1- expr-len)))))))
(0 'font-lock-doxygen-face t))))
It will replace <tt>foo</tt>
and <code>bar</code>
with colored symbols.