From: "Ehud Karni" <ehud@unix.mvs.co.il>
Cc: help-gnu-emacs@gnu.org
Subject: Re: How to programmatically highlight region?
Date: Wed, 22 Nov 2006 15:36:33 +0200 [thread overview]
Message-ID: <200611221336.kAMDaXiG024164@beta.mvs.co.il> (raw)
In-Reply-To: <uy7q3stx1.fsf@gmail.com> (message from Mathias Dahl on Wed, 22 Nov 2006 10:38:18 +0100)
On Wed, 22 Nov 2006 10:38:18 Mathias Dahl wrote:
>
> "Mirko" <mvukovic@nycap.rr.com> writes:
>
> > If I have a string such as "self.foo" I would like to see only
> > foo(underlined), i.e. make the "self." invisible, and change the
> > appearance of foo.
> >
> > I think I understand how I could change the appearance of foo, but
> > the info on invisibility left me confused as how I can hide text.
>
> Then you could experiment with the invisible-propery of faces.
If it a temporary way of showing it (a_la isearch) I would have
used overlays, Something like:
(let ((ov (make-overlay BEG END)))
(overlay-put ov 'face FACE) ;; change appearance
(overlay-put ov 'priority 99))
(let ((ov (make-overlay BEG END)))
(overlay-put ov 'invisible t) ;; make invisible
(overlay-put ov 'priority 99))
You should accumulate the overlays in a list. To undo all your changes
(face/invisibility) just do: (mapc 'delete-overlay your-overlay-list)
This is almost how it is done in isearch.el (the deletion of the
overlays is less efficient).
A real working example is bellow.
Ehud.
;; ================ Hi(ghlight)-mark ======================================================
(defvar himark-overlay-list nil "list of high-mark overlays (himark-unset deletes them).")
(make-variable-buffer-local 'himark-overlay-list)
(defvar himark-overlay-face 'highlight "Name of face (quoted symbol) to use for himark.
e.g. (setq himark-overlay-face 'modeline)
Use list-faces-display to see all available faces")
(defun himark-unset () "Remove himark overlay"
(interactive)
(and faces-on
(mapc 'delete-overlay himark-overlay-list)
(setq himark-overlay-list nil)))
(defun himark-set () "Highlight all occurrence of string in this buffer)"
(interactive)
(let (ov
(pos (point))
(string (read-string "String to highlight: ")))
(goto-char (point-min))
(while (search-forward string nil t)
(setq ov (make-overlay (match-beginning 0)
(match-end 0)))
(overlay-put ov 'face himark-overlay-face)
(overlay-put ov 'priority 98)
(push ov himark-overlay-list))
(goto-char pos)))
--
Ehud Karni Tel: +972-3-7966-561 /"\
Mivtach - Simon Fax: +972-3-7966-667 \ / ASCII Ribbon Campaign
Insurance agencies (USA) voice mail and X Against HTML Mail
http://www.mvs.co.il FAX: 1-815-5509341 / \
GnuPG: 98EA398D <http://www.keyserver.net/> Better Safe Than Sorry
prev parent reply other threads:[~2006-11-22 13:36 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-11-15 20:10 How to programmatically highlight region? David Abrahams
2006-11-15 21:41 ` Perry Smith
2006-11-15 22:48 ` David Abrahams
2006-11-16 0:50 ` Perry Smith
[not found] ` <mailman.691.1163638542.2155.help-gnu-emacs@gnu.org>
2006-11-18 2:35 ` Mirko
2006-11-22 9:38 ` Mathias Dahl
2006-11-22 13:36 ` Ehud Karni [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200611221336.kAMDaXiG024164@beta.mvs.co.il \
--to=ehud@unix.mvs.co.il \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).