all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* How to programmatically highlight region?
@ 2006-11-15 20:10 David Abrahams
  2006-11-15 21:41 ` Perry Smith
  0 siblings, 1 reply; 7+ messages in thread
From: David Abrahams @ 2006-11-15 20:10 UTC (permalink / raw)



Hi,

Could someone tell me how to get the effect of an "activated mark" in
transient mark mode from within elisp?  In other words, I'd like to be
able to set up the point and mark, and when my elisp completes, see
the region highlighted.  Seems like it should be simple, but nothing I
do seems to work.

TIA,

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: How to programmatically highlight region?
  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
  0 siblings, 1 reply; 7+ messages in thread
From: Perry Smith @ 2006-11-15 21:41 UTC (permalink / raw)
  Cc: help-gnu-emacs


[-- Attachment #1.1: Type: text/plain, Size: 955 bytes --]


On Nov 15, 2006, at 2:10 PM, David Abrahams wrote:

> Hi,
>
> Could someone tell me how to get the effect of an "activated mark" in
> transient mark mode from within elisp?  In other words, I'd like to be
> able to set up the point and mark, and when my elisp completes, see
> the region highlighted.  Seems like it should be simple, but nothing I
> do seems to work.

You might be asking how transient mark mode works.  It seems to be  
just a variable that commands look at.  But this works for me:

(defun dog-test ()
   (interactive)
   (transient-mark-mode 1)
   (set-mark (point))
   (forward-char 20))

execute dog-test from the minibuffer and the current point plus 20  
characters are highlighted -- basically just turn on transient mark  
more, set point and mark, and thats it.

HTH,
Perry Smith
Ease Software, Inc.
pedz@easesoftware.com
http://www.easesoftware.com

Low cost SATA Disk Systems for IBMs p5, pSeries, and RS/6000 AIX systems




[-- Attachment #1.2: Type: text/html, Size: 5257 bytes --]

[-- Attachment #2: Type: text/plain, Size: 152 bytes --]

_______________________________________________
help-gnu-emacs mailing list
help-gnu-emacs@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gnu-emacs

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: How to programmatically highlight region?
  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>
  0 siblings, 2 replies; 7+ messages in thread
From: David Abrahams @ 2006-11-15 22:48 UTC (permalink / raw)
  Cc: help-gnu-emacs

Perry Smith <pedz@easesoftware.com> writes:

> On Nov 15, 2006, at 2:10 PM, David Abrahams wrote:
>
>     Hi,
>    
>     Could someone tell me how to get the effect of an "activated mark" in
>     transient mark mode from within elisp?  In other words, I'd like to be
>     able to set up the point and mark, and when my elisp completes, see
>     the region highlighted.  Seems like it should be simple, but nothing I
>     do seems to work.
>
> You might be asking how transient mark mode works.  

I don't think that's what I'm asking.

> It seems to be just a variable that commands look at.  But this
> works for me:
>
> (defun dog-test ()
>  (interactive)
>  (transient-mark-mode 1)
>  (set-mark (point))
>  (forward-char 20))
>
> execute dog-test from the minibuffer and the current point plus 20
> characters are highlighted

Not for me. :(

Thanks for responding.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: How to programmatically highlight region?
  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>
  1 sibling, 0 replies; 7+ messages in thread
From: Perry Smith @ 2006-11-16  0:50 UTC (permalink / raw)
  Cc: help-gnu-emacs


[-- Attachment #1.1: Type: text/plain, Size: 1720 bytes --]

On Nov 15, 2006, at 4:48 PM, David Abrahams wrote:

> Perry Smith <pedz@easesoftware.com> writes:
>
>> On Nov 15, 2006, at 2:10 PM, David Abrahams wrote:
>>
>>     Hi,
>>
>>     Could someone tell me how to get the effect of an "activated  
>> mark" in
>>     transient mark mode from within elisp?  In other words, I'd  
>> like to be
>>     able to set up the point and mark, and when my elisp  
>> completes, see
>>     the region highlighted.  Seems like it should be simple, but  
>> nothing I
>>     do seems to work.
>>
>> You might be asking how transient mark mode works.
>
> I don't think that's what I'm asking.
>
>> It seems to be just a variable that commands look at.  But this
>> works for me:
>>
>> (defun dog-test ()
>>  (interactive)
>>  (transient-mark-mode 1)
>>  (set-mark (point))
>>  (forward-char 20))
>>
>> execute dog-test from the minibuffer and the current point plus 20
>> characters are highlighted
>
> Not for me. :(
>
> Thanks for responding.

I felt challenged :-)

You make a face.  Put the attributes that you want in it.  Then use  
put-text-property to apply that face to the region.

(make-face 'my-blue-face)

(set-face-attribute 'my-blue-face nil :background "blue")

(defun dog-test3 ()
   (interactive)
   (put-text-property (point) (mark) 'face 'my-blue-face))

Set your mark and point, then do M-x dog-test3

There is something I don't understand though.  If you have font-lock- 
mode set, then it does not work.  I'm not sure what is happening in  
that case.  I'm curious to see if others reply.

Hope this help...
Perry Smith
Ease Software, Inc.
pedz@easesoftware.com
http://www.easesoftware.com

Low cost SATA Disk Systems for IBMs p5, pSeries, and RS/6000 AIX systems




[-- Attachment #1.2: Type: text/html, Size: 9042 bytes --]

[-- Attachment #2: Type: text/plain, Size: 152 bytes --]

_______________________________________________
help-gnu-emacs mailing list
help-gnu-emacs@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gnu-emacs

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: How to programmatically highlight region?
       [not found]     ` <mailman.691.1163638542.2155.help-gnu-emacs@gnu.org>
@ 2006-11-18  2:35       ` Mirko
  2006-11-22  9:38         ` Mathias Dahl
  0 siblings, 1 reply; 7+ messages in thread
From: Mirko @ 2006-11-18  2:35 UTC (permalink / raw)



Perry Smith wrote:
> On Nov 15, 2006, at 4:48 PM, David Abrahams wrote:
>
> > Perry Smith <pedz@easesoftware.com> writes:
> >
> >> On Nov 15, 2006, at 2:10 PM, David Abrahams wrote:
> >>
> >>     Hi,
> >>
> >>     Could someone tell me how to get the effect of an "activated
> >> mark" in
> >>     transient mark mode from within elisp?  In other words, I'd
> >> like to be
> >>     able to set up the point and mark, and when my elisp
> >> completes, see
> >>     the region highlighted.  Seems like it should be simple, but
> >> nothing I
> >>     do seems to work.
> >>
> >> You might be asking how transient mark mode works.
> >
> > I don't think that's what I'm asking.
> >
> >> It seems to be just a variable that commands look at.  But this
> >> works for me:
> >>
> >> (defun dog-test ()
> >>  (interactive)
> >>  (transient-mark-mode 1)
> >>  (set-mark (point))
> >>  (forward-char 20))
> >>
> >> execute dog-test from the minibuffer and the current point plus 20
> >> characters are highlighted
> >
> > Not for me. :(
> >
> > Thanks for responding.
>
> I felt challenged :-)
>
> You make a face.  Put the attributes that you want in it.  Then use
> put-text-property to apply that face to the region.
>
> (make-face 'my-blue-face)
>
> (set-face-attribute 'my-blue-face nil :background "blue")
>
> (defun dog-test3 ()
>    (interactive)
>    (put-text-property (point) (mark) 'face 'my-blue-face))
>
> Set your mark and point, then do M-x dog-test3
>
> There is something I don't understand though.  If you have font-lock-
> mode set, then it does not work.  I'm not sure what is happening in
> that case.  I'm curious to see if others reply.
>
> Hope this help...
> Perry Smith
> Ease Software, Inc.
> pedz@easesoftware.com
> http://www.easesoftware.com
>
> Low cost SATA Disk Systems for IBMs p5, pSeries, and RS/6000 AIX systems
>
>
Um, could someone comment on how to accomplish the following:

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.

Thanks,

Mirko

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: How to programmatically highlight region?
  2006-11-18  2:35       ` Mirko
@ 2006-11-22  9:38         ` Mathias Dahl
  2006-11-22 13:36           ` Ehud Karni
  0 siblings, 1 reply; 7+ messages in thread
From: Mathias Dahl @ 2006-11-22  9:38 UTC (permalink / raw)


"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.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: How to programmatically highlight region?
  2006-11-22  9:38         ` Mathias Dahl
@ 2006-11-22 13:36           ` Ehud Karni
  0 siblings, 0 replies; 7+ messages in thread
From: Ehud Karni @ 2006-11-22 13:36 UTC (permalink / raw)
  Cc: help-gnu-emacs

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2006-11-22 13:36 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.