unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Remove mouse-face in Occur buffers
@ 2005-10-28 22:06 Juri Linkov
  2005-10-29  5:13 ` Richard M. Stallman
  2005-10-29 17:35 ` Kim F. Storm
  0 siblings, 2 replies; 9+ messages in thread
From: Juri Linkov @ 2005-10-28 22:06 UTC (permalink / raw)


When `keep-props' arg is non-nil, occur copies text properties from
the original buffer to the Occur buffer.  But when the original buffer
contains areas with `mouse-face' properties, highlighting these copied
areas in the Occur buffer interferes with highlighted areas indicating
the matching lines.  This can be reproduced for example by calling
`C-u M-x occur RET' on Info buffers.

The following patch removes `mouse-face' properties from the copied text:

Index: lisp/replace.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/replace.el,v
retrieving revision 1.227
diff -c -r1.227 replace.el
*** lisp/replace.el	27 Oct 2005 18:22:00 -0000	1.227
--- lisp/replace.el	28 Oct 2005 22:05:42 -0000
***************
*** 894,903 ****
  	    (if (fboundp 'jit-lock-fontify-now)
  		(jit-lock-fontify-now beg end)))
  	(push
! 	 (funcall (if keep-props
! 		      #'buffer-substring
! 		    #'buffer-substring-no-properties)
! 		  beg end)
  	 result)
  	(forward-line (if forwardp 1 -1)))
        (nreverse result))))
--- 898,908 ----
  	    (if (fboundp 'jit-lock-fontify-now)
  		(jit-lock-fontify-now beg end)))
  	(push
! 	 (if keep-props
! 	     (let ((str (buffer-substring beg end)))
! 	       (remove-text-properties 0 (length str) '(mouse-face nil) str)
! 	       str)
! 	   (buffer-substring-no-properties beg end))
  	 result)
  	(forward-line (if forwardp 1 -1)))
        (nreverse result))))
***************
*** 1102,1114 ****
  			     (text-property-not-all begpt endpt 'fontified t))
  			(if (fboundp 'jit-lock-fontify-now)
  			    (jit-lock-fontify-now begpt endpt)))
! 		    (setq curstring (buffer-substring begpt endpt))
! 		    ;; Depropertize the string, and maybe
! 		    ;; highlight the matches
  		    (let ((len (length curstring))
  			  (start 0))
! 		      (unless keep-props
! 			(set-text-properties 0 len nil curstring))
  		      (while (and (< start len)
  				  (string-match regexp curstring start))
  			(add-text-properties
--- 1107,1121 ----
  			     (text-property-not-all begpt endpt 'fontified t))
  			(if (fboundp 'jit-lock-fontify-now)
  			    (jit-lock-fontify-now begpt endpt)))
! 		    (setq curstring
! 			  (if keep-props
! 			      (buffer-substring begpt endpt)
! 			    (buffer-substring-no-properties begpt endpt)))
! 		    ;; Highlight the matches
  		    (let ((len (length curstring))
  			  (start 0))
! 		      (if keep-props
! 			  (remove-text-properties 0 len '(mouse-face nil) curstring))
  		      (while (and (< start len)
  				  (string-match regexp curstring start))
  			(add-text-properties

-- 
Juri Linkov
http://www.jurta.org/emacs/

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

* Re: Remove mouse-face in Occur buffers
  2005-10-28 22:06 Remove mouse-face in Occur buffers Juri Linkov
@ 2005-10-29  5:13 ` Richard M. Stallman
  2005-10-29 17:35 ` Kim F. Storm
  1 sibling, 0 replies; 9+ messages in thread
From: Richard M. Stallman @ 2005-10-29  5:13 UTC (permalink / raw)
  Cc: emacs-devel

Thanks for debugging this.  Please install your fix.

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

* Re: Remove mouse-face in Occur buffers
  2005-10-28 22:06 Remove mouse-face in Occur buffers Juri Linkov
  2005-10-29  5:13 ` Richard M. Stallman
@ 2005-10-29 17:35 ` Kim F. Storm
  2005-10-29 19:48   ` Juri Linkov
  1 sibling, 1 reply; 9+ messages in thread
From: Kim F. Storm @ 2005-10-29 17:35 UTC (permalink / raw)
  Cc: emacs-devel

Juri Linkov <juri@jurta.org> writes:

> When `keep-props' arg is non-nil, occur copies text properties from
> the original buffer to the Occur buffer.  But when the original buffer
> contains areas with `mouse-face' properties, highlighting these copied
> areas in the Occur buffer interferes with highlighted areas indicating
> the matching lines.  This can be reproduced for example by calling
> `C-u M-x occur RET' on Info buffers.

I'm not sure I understand reason for this change, so I don't know
whether it really just applies to the mouse-face property.

But to me it sounds as if remove-yank-excluded-properties could be
useful here.  Can you pls. think about it.

-- 
Kim F. Storm <storm@cua.dk> http://www.cua.dk

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

* Re: Remove mouse-face in Occur buffers
  2005-10-29 17:35 ` Kim F. Storm
@ 2005-10-29 19:48   ` Juri Linkov
  2005-10-29 21:40     ` Kim F. Storm
  0 siblings, 1 reply; 9+ messages in thread
From: Juri Linkov @ 2005-10-29 19:48 UTC (permalink / raw)
  Cc: emacs-devel

>> When `keep-props' arg is non-nil, occur copies text properties from
>> the original buffer to the Occur buffer.  But when the original buffer
>> contains areas with `mouse-face' properties, highlighting these copied
>> areas in the Occur buffer interferes with highlighted areas indicating
>> the matching lines.  This can be reproduced for example by calling
>> `C-u M-x occur RET' on Info buffers.
>
> I'm not sure I understand reason for this change, so I don't know
> whether it really just applies to the mouse-face property.

To see what I mean you can type `C-h i d C-u M-x occur RET emacs RET'
and to move the mouse cursor on menu items in occur context lines.
Mouse highlighting is misleading here, because pressing mouse-1 or
mouse-2 doesn't work.  I proposed to remove mouse highlighting on
copied text.

> But to me it sounds as if remove-yank-excluded-properties could be
> useful here.  Can you pls. think about it.

`remove-yank-excluded-properties' is surely related to this, but
I think it is a different thing.  It defines text properties to
remove when yanking, but displaying copied lines in the occur buffer
is not quite yanking.  For example, I customized `yank-excluded-properties'
to t in .emacs, because I want to remove all text properties on yanked text,
but using the same value of `yank-excluded-properties' to remove
all text properties in the occur buffer seems as unexpected and unrelated
thing to me.  Maybe, there should be a separate variable defining a list
of text properties to remove on copied text in the occur buffer.
Do you think it would be useful?

-- 
Juri Linkov
http://www.jurta.org/emacs/

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

* Re: Remove mouse-face in Occur buffers
  2005-10-29 19:48   ` Juri Linkov
@ 2005-10-29 21:40     ` Kim F. Storm
  2005-10-31  7:44       ` Juri Linkov
  0 siblings, 1 reply; 9+ messages in thread
From: Kim F. Storm @ 2005-10-29 21:40 UTC (permalink / raw)
  Cc: emacs-devel

Juri Linkov <juri@jurta.org> writes:

> To see what I mean you can type `C-h i d C-u M-x occur RET emacs RET'
> and to move the mouse cursor on menu items in occur context lines.
> Mouse highlighting is misleading here, because pressing mouse-1 or
> mouse-2 doesn't work.  I proposed to remove mouse highlighting on
> copied text.

That is a good change.

>
>> But to me it sounds as if remove-yank-excluded-properties could be
>> useful here.  Can you pls. think about it.
>
> `remove-yank-excluded-properties' is surely related to this, but
> I think it is a different thing.  It defines text properties to
> remove when yanking, but displaying copied lines in the occur buffer
> is not quite yanking. 

But it is "close"...  

The yank-excluded-properties is a list of properties which typically
causes problems when they are inserted "out of context" in some other
buffer.


> Maybe, there should be a separate variable defining a list
> of text properties to remove on copied text in the occur buffer.
> Do you think it would be useful?

Yes, that sounds like a good idea.

The default value could be the same as the initial value of
yank-excluded-properties (I haven't checked).

Some people may want to set that to t as well.

Look at function remove-list-of-text-properties.

-- 
Kim F. Storm <storm@cua.dk> http://www.cua.dk

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

* Re: Remove mouse-face in Occur buffers
  2005-10-29 21:40     ` Kim F. Storm
@ 2005-10-31  7:44       ` Juri Linkov
  2005-10-31 11:14         ` Kim F. Storm
  0 siblings, 1 reply; 9+ messages in thread
From: Juri Linkov @ 2005-10-31  7:44 UTC (permalink / raw)
  Cc: emacs-devel

>> Maybe, there should be a separate variable defining a list
>> of text properties to remove on copied text in the occur buffer.
>> Do you think it would be useful?
>
> Yes, that sounds like a good idea.
>
> The default value could be the same as the initial value of
> yank-excluded-properties (I haven't checked).

The default value of `yank-excluded-properties' also includes
`invisible' which will unhide copied invisible text in the Occur buffer.
This is better than displaying lines with hidden matches.  But maybe
occur should skip invisible text in the original buffer, and not to copy
lines where matches have invisible properties on them (i.e. like
isearch skips invisible text)?

Anyway, in the patch below the default value of `occur-excluded-properties'
is the same as of `yank-excluded-properties'.  And it also servers as
the default value of the `keep-props' argument (which before this patch
was unconditionally non-nil).

Index: lisp/replace.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/replace.el,v
retrieving revision 1.228
diff -c -r1.228 replace.el
*** lisp/replace.el	29 Oct 2005 19:49:20 -0000	1.228
--- lisp/replace.el	31 Oct 2005 07:43:23 -0000
***************
*** 878,883 ****
--- 878,893 ----
    :type 'face
    :group 'matching)
  
+ (defcustom occur-excluded-properties
+   '(read-only invisible intangible field mouse-face help-echo local-map keymap
+     yank-handler follow-link)
+   "*Text properties to discard when copying lines to the *Occur* buffer.
+ The value should be a list of text properties to discard or t,
+ which means to discard all text properties."
+   :type '(choice (const :tag "All" t) (repeat symbol))
+   :group 'matching
+   :version "22.1")
+ 
  (defun occur-accumulate-lines (count &optional keep-props)
    (save-excursion
      (let ((forwardp (> count 0))
***************
*** 894,903 ****
  	    (if (fboundp 'jit-lock-fontify-now)
  		(jit-lock-fontify-now beg end)))
  	(push
! 	 (funcall (if keep-props
! 		      #'buffer-substring
! 		    #'buffer-substring-no-properties)
! 		  beg end)
  	 result)
  	(forward-line (if forwardp 1 -1)))
        (nreverse result))))
--- 904,915 ----
  	    (if (fboundp 'jit-lock-fontify-now)
  		(jit-lock-fontify-now beg end)))
  	(push
! 	 (if (and keep-props (not (eq occur-excluded-properties t)))
! 	     (let ((str (buffer-substring beg end)))
! 	       (remove-list-of-text-properties
! 		0 (length str) occur-excluded-properties str)
! 	       str)
! 	   (buffer-substring-no-properties beg end))
  	 result)
  	(forward-line (if forwardp 1 -1)))
        (nreverse result))))
***************
*** 1033,1039 ****
  		      (and case-fold-search
  			   (isearch-no-upper-case-p regexp t))
  		      list-matching-lines-buffer-name-face
! 		      nil list-matching-lines-face t)))
  	  (let* ((bufcount (length active-bufs))
  		 (diff (- (length bufs) bufcount)))
  	    (message "Searched %d buffer%s%s; %s match%s for `%s'"
--- 1045,1052 ----
  		      (and case-fold-search
  			   (isearch-no-upper-case-p regexp t))
  		      list-matching-lines-buffer-name-face
! 		      nil list-matching-lines-face
! 		      (not (eq occur-excluded-properties t)))))
  	  (let* ((bufcount (length active-bufs))
  		 (diff (- (length bufs) bufcount)))
  	    (message "Searched %d buffer%s%s; %s match%s for `%s'"
***************
*** 1102,1114 ****
  			     (text-property-not-all begpt endpt 'fontified t))
  			(if (fboundp 'jit-lock-fontify-now)
  			    (jit-lock-fontify-now begpt endpt)))
! 		    (setq curstring (buffer-substring begpt endpt))
! 		    ;; Depropertize the string, and maybe
! 		    ;; highlight the matches
  		    (let ((len (length curstring))
  			  (start 0))
- 		      (unless keep-props
- 			(set-text-properties 0 len nil curstring))
  		      (while (and (< start len)
  				  (string-match regexp curstring start))
  			(add-text-properties
--- 1115,1129 ----
  			     (text-property-not-all begpt endpt 'fontified t))
  			(if (fboundp 'jit-lock-fontify-now)
  			    (jit-lock-fontify-now begpt endpt)))
! 		    (if (and keep-props (not (eq occur-excluded-properties t)))
! 			(progn
! 			  (setq curstring (buffer-substring begpt endpt))
! 			  (remove-list-of-text-properties
! 			   0 (length curstring) occur-excluded-properties curstring))
! 		      (setq curstring (buffer-substring-no-properties begpt endpt)))
! 		    ;; Highlight the matches
  		    (let ((len (length curstring))
  			  (start 0))
  		      (while (and (< start len)
  				  (string-match regexp curstring start))
  			(add-text-properties

-- 
Juri Linkov
http://www.jurta.org/emacs/

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

* Re: Remove mouse-face in Occur buffers
  2005-10-31  7:44       ` Juri Linkov
@ 2005-10-31 11:14         ` Kim F. Storm
  2005-11-01  9:17           ` Juri Linkov
  0 siblings, 1 reply; 9+ messages in thread
From: Kim F. Storm @ 2005-10-31 11:14 UTC (permalink / raw)
  Cc: emacs-devel

Juri Linkov <juri@jurta.org> writes:

> The default value of `yank-excluded-properties' also includes
> `invisible' which will unhide copied invisible text in the Occur buffer.
> This is better than displaying lines with hidden matches.  But maybe
> occur should skip invisible text in the original buffer, and not to copy
> lines where matches have invisible properties on them (i.e. like
> isearch skips invisible text)?

I have no opinion about that.

> Anyway, in the patch below the default value of `occur-excluded-properties'
> is the same as of `yank-excluded-properties'. 

Looks good to me.

> And it also servers as
> the default value of the `keep-props' argument (which before this patch
> was unconditionally non-nil).

Ok, but then these checks in occur-accumulate-lines and occur-engine
seems superfluous:


>   	    (if (fboundp 'jit-lock-fontify-now)
>   		(jit-lock-fontify-now beg end)))
>   	(push
> ! 	 (if (and keep-props (not (eq occur-excluded-properties t)))
             
Just test keep-props here (it is nil if occur-excluded-properties = t.

>   			     (text-property-not-all begpt endpt 'fontified t))
>   			(if (fboundp 'jit-lock-fontify-now)
>   			    (jit-lock-fontify-now begpt endpt)))
> ! 		    (if (and keep-props (not (eq occur-excluded-properties t)))

Likewise...

-- 
Kim F. Storm <storm@cua.dk> http://www.cua.dk

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

* Re: Remove mouse-face in Occur buffers
  2005-10-31 11:14         ` Kim F. Storm
@ 2005-11-01  9:17           ` Juri Linkov
  2005-11-01 11:06             ` Kim F. Storm
  0 siblings, 1 reply; 9+ messages in thread
From: Juri Linkov @ 2005-11-01  9:17 UTC (permalink / raw)
  Cc: emacs-devel

>> And it also servers as the default value of the `keep-props'
>> argument (which before this patch was unconditionally non-nil).
>
> Ok, but then these checks in occur-accumulate-lines and occur-engine
> seems superfluous:
>
>>   	    (if (fboundp 'jit-lock-fontify-now)
>>   		(jit-lock-fontify-now beg end)))
>>   	(push
>> ! 	 (if (and keep-props (not (eq occur-excluded-properties t)))
>
> Just test keep-props here (it is nil if occur-excluded-properties = t.

I added this double test intentionally, because someone might call
`occur-engine' directly with `keep-props'=t, and at the same time
`occur-excluded-properties' may have the default value t.  In this
case `remove-list-of-text-properties' will fail.

Why I suspect that someone already might have code to call
`occur-engine' directly is because so far the value for keeping
text properties was hard-coded in `occur-1' with the value t
(and I recall that at some moment it was hard-coded with nil),
and how someone can customize this behavior other than calling
`occur-engine' directly?

-- 
Juri Linkov
http://www.jurta.org/emacs/

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

* Re: Remove mouse-face in Occur buffers
  2005-11-01  9:17           ` Juri Linkov
@ 2005-11-01 11:06             ` Kim F. Storm
  0 siblings, 0 replies; 9+ messages in thread
From: Kim F. Storm @ 2005-11-01 11:06 UTC (permalink / raw)
  Cc: emacs-devel

Juri Linkov <juri@jurta.org> writes:

> I added this double test intentionally, because someone might call
> `occur-engine' directly with `keep-props'=t, and at the same time
> `occur-excluded-properties' may have the default value t.  In this
> case `remove-list-of-text-properties' will fail.

Ok.


-- 
Kim F. Storm <storm@cua.dk> http://www.cua.dk

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

end of thread, other threads:[~2005-11-01 11:06 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-10-28 22:06 Remove mouse-face in Occur buffers Juri Linkov
2005-10-29  5:13 ` Richard M. Stallman
2005-10-29 17:35 ` Kim F. Storm
2005-10-29 19:48   ` Juri Linkov
2005-10-29 21:40     ` Kim F. Storm
2005-10-31  7:44       ` Juri Linkov
2005-10-31 11:14         ` Kim F. Storm
2005-11-01  9:17           ` Juri Linkov
2005-11-01 11:06             ` Kim F. Storm

Code repositories for project(s) associated with this public inbox

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

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