[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Text highlighter functiontionality
From: |
Teemu Likonen |
Subject: |
Re: Text highlighter functiontionality |
Date: |
Thu, 23 Jul 2009 15:25:57 +0300 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (gnu/linux) |
On 2009-07-23 04:44 (-0700), stephan zimmer wrote:
> Is anyone aware of a text highlighter functionality in emacs? I would
> like to highlight (possibly non-connected) portions of text in a
> buffer in such a way, that the highlighting persists within one emacs
> session (i.e., when I change the buffer and return to it again, the
> highlighting should still be there).
Sounds pretty much like "M-s h r" (highlight-regexp) to me.
But if you want to mark a region and highlight it you could use a simple
function to create an overlay. Here's an example function which
highlights current active region. You can remove the highlighting by
just editing text inside it.
--8<---------------cut here---------------start------------->8---
(defun my-overlay (beg end)
"Create an overlay between BEG and END.
If called interactively BEG and END are the region."
(interactive "r")
(require 'hi-lock)
(let ((ol (make-overlay beg end)))
(dolist (prop '((modification-hooks (lambda (ol after &rest ignore)
(when after
(delete-overlay ol))))
(face . hi-yellow)
(evaporate . t)))
(overlay-put ol (car prop) (cdr prop)))))
--8<---------------cut here---------------end--------------->8---