From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Ehud Karni" Newsgroups: gmane.emacs.help Subject: Re: How to programmatically highlight region? Date: Wed, 22 Nov 2006 15:36:33 +0200 Organization: Mivtach-Simon Insurance agencies Message-ID: <200611221336.kAMDaXiG024164@beta.mvs.co.il> References: <87d57osc7s.fsf@pereiro.luannocracy.com> <147F5C25-BD32-4B93-96E7-00E3D8D596CD@easesoftware.com> <87lkmcqqc3.fsf@pereiro.luannocracy.com> <1163817330.364336.26340@m7g2000cwm.googlegroups.com> Reply-To: ehud@unix.mvs.co.il NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-8-i Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1164203234 979 80.91.229.2 (22 Nov 2006 13:47:14 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 22 Nov 2006 13:47:14 +0000 (UTC) Cc: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Nov 22 14:47:09 2006 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1GmsRC-0008KQ-0L for geh-help-gnu-emacs@m.gmane.org; Wed, 22 Nov 2006 14:46:54 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GmsRA-0002Gm-Id for geh-help-gnu-emacs@m.gmane.org; Wed, 22 Nov 2006 08:46:52 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1GmsHR-0003rF-Fz for help-gnu-emacs@gnu.org; Wed, 22 Nov 2006 08:36:49 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1GmsHO-0003pa-O1 for help-gnu-emacs@gnu.org; Wed, 22 Nov 2006 08:36:49 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GmsHO-0003pE-8p for help-gnu-emacs@gnu.org; Wed, 22 Nov 2006 08:36:46 -0500 Original-Received: from [193.16.147.12] (helo=unix.mvs.co.il) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA:32) (Exim 4.52) id 1GmsHN-00066m-7G for help-gnu-emacs@gnu.org; Wed, 22 Nov 2006 08:36:46 -0500 Original-Received: from beta.mvs.co.il (beta [10.253.0.3]) by unix.mvs.co.il (8.13.7/8.13.7) with ESMTP id kAMDaYq6030692; Wed, 22 Nov 2006 15:36:34 +0200 Original-Received: from beta.mvs.co.il (localhost.localdomain [127.0.0.1]) by beta.mvs.co.il (8.13.8/8.13.8) with ESMTP id kAMDaXom024167; Wed, 22 Nov 2006 15:36:33 +0200 Original-Received: (from root@localhost) by beta.mvs.co.il (8.13.8/8.13.8/Submit) id kAMDaXiG024164; Wed, 22 Nov 2006 15:36:33 +0200 Original-To: brakjoller@gmail.com In-reply-to: (message from Mathias Dahl on Wed, 22 Nov 2006 10:38:18 +0100) X-Mailer: Emacs 21.3.1 rmail (send-msg 1.108) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:38892 Archived-At: On Wed, 22 Nov 2006 10:38:18 Mathias Dahl wrote: > > "Mirko" 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 Better Safe Than Sorry