问题
Is there a way to highlight a string in a text (but not ALL such strings) in a buffer where font-lock-mode is on.
Let's imagine I have a buffer with SQL mode and I want to highlight a string in it. The following code does not work
(set-text-properties 10 20 '(face hi-yellow))
When I call
(font-lock-mode -1)
it works, but all sql highlighting disappears.
There must be a solution because it's possible to select a region and it will be highlighted but I can't figure out how to do it programmatically
回答1:
Have a look at http://www.emacswiki.org/emacs/HighlightTemporarily.
Both MarkerPens and Highlight provide functions to highlight a region.
回答2:
Maybe this helps:
- open ***scratch* buffer and enter:
(with-current-buffer "foo" (add-text-properties 1 10 '(comment t face highlight)))
- then evaluate with C-j
Characters 1-10 will be highlited in buffer "foo".
来源:https://stackoverflow.com/questions/491257/emacs-region-highlighting