unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Two minor problems with CUA rectangles
@ 2005-11-25 13:23 martin rudalics
  2005-11-26 23:37 ` Problem with revert-buffer and overlays [was: Two minor problems with CUA rectangles] Kim F. Storm
  0 siblings, 1 reply; 12+ messages in thread
From: martin rudalics @ 2005-11-25 13:23 UTC (permalink / raw)


Suppose I have a TAB with a text-property that specifies a background
color.  Consequently, all characters from TAB to TAB + tab-width are
displayed with that color.  If I now install a CUA rectangle on the
right of the TAB and subsequently expand the rectangle to a position
between TAB and TAB + tab-width, the characters between the TAB and that
position are displayed with default background.

M-x revert-buffer with an active rectangle in that buffer apparently
deactivates the rectangle but overlays used for the rectangle are not
removed.  C-l does not remove them either.

With

(custom-set-variables
   ;; custom-set-variables was added by Custom.
   ;; If you edit it by hand, you could mess it up, so be careful.
   ;; Your init file should contain only one such instance.
   ;; If there is more than one, they won't work right.
  '(cua-enable-cursor-indications t)
  '(cua-mode t nil (cua-base)))

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

* Problem with revert-buffer and overlays [was: Two minor problems with CUA rectangles]
  2005-11-25 13:23 Two minor problems with CUA rectangles martin rudalics
@ 2005-11-26 23:37 ` Kim F. Storm
  2005-11-27  3:28   ` Richard M. Stallman
  0 siblings, 1 reply; 12+ messages in thread
From: Kim F. Storm @ 2005-11-26 23:37 UTC (permalink / raw)
  Cc: emacs-devel

martin rudalics <rudalics@gmx.at> writes:

> Suppose I have a TAB with a text-property that specifies a background
> color. [...]

I have installed a fix for this.  Thanks for noticing...


> M-x revert-buffer with an active rectangle in that buffer apparently
> deactivates the rectangle but overlays used for the rectangle are not
> removed.  C-l does not remove them either.

The problem for cua is that revert-buffer kills all local variables in
the buffer, so the list of overlays (which cua keeps in a local
variable) is no longer available to cua's post-command hook which
would otherwise have cleaned this up.

I don't really see how cua work around this, or force revert-buffer to
do that, as there are no hooks which a guaranteed to be called by
revert ... 


This seems to be a generic problem with revert-buffer, as other modes
may also have overlays in the buffer which should be removed by
revert-buffer.  It seems like it should unconditionally delete all
overlays in that buffer.

Perhaps things which kills all local variables should also kill all
overlays in the buffer.

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

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

* Re: Problem with revert-buffer and overlays [was: Two minor problems with CUA rectangles]
  2005-11-26 23:37 ` Problem with revert-buffer and overlays [was: Two minor problems with CUA rectangles] Kim F. Storm
@ 2005-11-27  3:28   ` Richard M. Stallman
  2005-11-27 21:02     ` Problem with revert-buffer and overlays Kim F. Storm
  0 siblings, 1 reply; 12+ messages in thread
From: Richard M. Stallman @ 2005-11-27  3:28 UTC (permalink / raw)
  Cc: rudalics, emacs-devel

    This seems to be a generic problem with revert-buffer, as other modes
    may also have overlays in the buffer which should be removed by
    revert-buffer.  It seems like it should unconditionally delete all
    overlays in that buffer.

This seems plausible to me.  In general, one must expect those
overlays to be relocated to garbage, so preserving them cannot work
reliably.

Would you like to do that?

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

* Re: Problem with revert-buffer and overlays
  2005-11-27  3:28   ` Richard M. Stallman
@ 2005-11-27 21:02     ` Kim F. Storm
  2005-11-28  4:47       ` Richard M. Stallman
  0 siblings, 1 reply; 12+ messages in thread
From: Kim F. Storm @ 2005-11-27 21:02 UTC (permalink / raw)
  Cc: rudalics, emacs-devel

"Richard M. Stallman" <rms@gnu.org> writes:

>     This seems to be a generic problem with revert-buffer, as other modes
>     may also have overlays in the buffer which should be removed by
>     revert-buffer.  It seems like it should unconditionally delete all
>     overlays in that buffer.
>
> This seems plausible to me.  In general, one must expect those
> overlays to be relocated to garbage, so preserving them cannot work
> reliably.
>
> Would you like to do that?

I looked at the code, and it is not obvious to me where this should be done.
It could be done in one of: revert-buffer, after-find-file, normal-mode.

I think someone more familiar with revert-buffer should work on this.

BTW, I noticed that revert-buffer does not deactivate the mark.



In any case, I realized that I _can_ fix this in cua-mode by making the
local variable holding the overlays permanent-local.  Perhaps that would 
be safer this close to the release.

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

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

* Re: Problem with revert-buffer and overlays
  2005-11-27 21:02     ` Problem with revert-buffer and overlays Kim F. Storm
@ 2005-11-28  4:47       ` Richard M. Stallman
  2005-11-28 10:17         ` martin rudalics
  0 siblings, 1 reply; 12+ messages in thread
From: Richard M. Stallman @ 2005-11-28  4:47 UTC (permalink / raw)
  Cc: rudalics, emacs-devel

    > This seems plausible to me.  In general, one must expect those
    > overlays to be relocated to garbage, so preserving them cannot work
    > reliably.
    >
    > Would you like to do that?

    I looked at the code, and it is not obvious to me where this should be done.
    It could be done in one of: revert-buffer, after-find-file, normal-mode.

It should be done in revert-buffer, I think.
after-find-file is not the right place,
and normal-mode should NOT mess with overlays.

    BTW, I noticed that revert-buffer does not deactivate the mark.

That seems like a bug, too.

    In any case, I realized that I _can_ fix this in cua-mode by making the
    local variable holding the overlays permanent-local.  Perhaps that would 
    be safer this close to the release.

Ok.

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

* Re: Problem with revert-buffer and overlays
  2005-11-28  4:47       ` Richard M. Stallman
@ 2005-11-28 10:17         ` martin rudalics
  2005-11-28 12:38           ` Kim F. Storm
  2005-11-28 21:00           ` Richard M. Stallman
  0 siblings, 2 replies; 12+ messages in thread
From: martin rudalics @ 2005-11-28 10:17 UTC (permalink / raw)
  Cc: emacs-devel, Kim F. Storm

 > This seems to be a generic problem with revert-buffer, as other modes
 > may also have overlays in the buffer which should be removed by
 > revert-buffer.  It seems like it should unconditionally delete all
 > overlays in that buffer.
 >
 > Perhaps things which kills all local variables should also kill all
 > overlays in the buffer.

 > It should be done in revert-buffer, I think.
 > after-find-file is not the right place,
 > and normal-mode should NOT mess with overlays.

Why not do this in kill-all-local-variables then?

Although solving this problem is tricky in general.  Consider two
buffers A and B.  A buffer-local variable in A may reference an overlay
in buffer B.  When A is reverted how remove the overlay in B?

 >     BTW, I noticed that revert-buffer does not deactivate the mark.
 >
 > That seems like a bug, too.

Deactivating the mark would have to be done by insert-file-contents if
it finds out that the mark has been invalidated during reversion.  I'd
leave this alone until someone complains.  In a similar way, I don't
think it necessary to remove the CUA rectangle when a buffer is
reverted.

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

* Re: Problem with revert-buffer and overlays
  2005-11-28 10:17         ` martin rudalics
@ 2005-11-28 12:38           ` Kim F. Storm
  2005-11-28 21:00           ` Richard M. Stallman
  1 sibling, 0 replies; 12+ messages in thread
From: Kim F. Storm @ 2005-11-28 12:38 UTC (permalink / raw)
  Cc: rms, emacs-devel

martin rudalics <rudalics@gmx.at> writes:

>  > This seems to be a generic problem with revert-buffer, as other modes
>  > may also have overlays in the buffer which should be removed by
>  > revert-buffer.  It seems like it should unconditionally delete all
>  > overlays in that buffer.
>  >
>  > Perhaps things which kills all local variables should also kill all
>  > overlays in the buffer.
>
>  > It should be done in revert-buffer, I think.
>  > after-find-file is not the right place,
>  > and normal-mode should NOT mess with overlays.
>
> Why not do this in kill-all-local-variables then?
>
> Although solving this problem is tricky in general.  Consider two
> buffers A and B.  A buffer-local variable in A may reference an overlay
> in buffer B.  When A is reverted how remove the overlay in B?

This looks like a can of works best left alone for now.

>
>  >     BTW, I noticed that revert-buffer does not deactivate the mark.
>  >
>  > That seems like a bug, too.
>
> Deactivating the mark would have to be done by insert-file-contents if
> it finds out that the mark has been invalidated during reversion.  I'd
> leave this alone until someone complains.  

Ok with me.  Still, I'll fix it for cua.

>                                            In a similar way, I don't
> think it necessary to remove the CUA rectangle when a buffer is
> reverted.

It may not be necessary, but since most of the cua state is kept in
buffer local variables, that state is lost when you do revert-buffer,
so to keep the rectangle, cua must do "extra work" to ensure it is
still valid after revert-buffer.  So it is simpler to remove it.

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

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

* Re: Problem with revert-buffer and overlays
  2005-11-28 10:17         ` martin rudalics
  2005-11-28 12:38           ` Kim F. Storm
@ 2005-11-28 21:00           ` Richard M. Stallman
  2005-11-29  9:15             ` martin rudalics
  1 sibling, 1 reply; 12+ messages in thread
From: Richard M. Stallman @ 2005-11-28 21:00 UTC (permalink / raw)
  Cc: emacs-devel, storm

    Why not do this in kill-all-local-variables then?

The reason to get rid of the overlays after revert is because they
cannot reliably point to the right place any more.

Changing the major mode should not delete the overlays--that would be
incorrect.  (Some might be used by minor modes or other features.)
Instead, the major mode should explicitly delete the overlays that it
uses.

    Deactivating the mark would have to be done by insert-file-contents if
    it finds out that the mark has been invalidated during reversion.  I'd
    leave this alone until someone complains.

I just tried it and revert-buffer did deactivate the mark.
Can someone describe a test case where it fails to do so?

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

* Re: Problem with revert-buffer and overlays
  2005-11-28 21:00           ` Richard M. Stallman
@ 2005-11-29  9:15             ` martin rudalics
  2005-11-29 21:47               ` Richard M. Stallman
  0 siblings, 1 reply; 12+ messages in thread
From: martin rudalics @ 2005-11-29  9:15 UTC (permalink / raw)
  Cc: emacs-devel, storm

 >     Why not do this in kill-all-local-variables then?
 >
 > The reason to get rid of the overlays after revert is because they
 > cannot reliably point to the right place any more.
 >
 > Changing the major mode should not delete the overlays--that would be
 > incorrect.  (Some might be used by minor modes or other features.)
 > Instead, the major mode should explicitly delete the overlays that it
 > uses.

Might be I don't understand this correctly but to get rid of an overlay
you have to find it in the first place.  The original problem was that
kill-all-local-variables killed the reference to the overlay and CUA's
post-command hook wasn't able to find it any more.  Hence, any attempt
to correct this problem (semi-)automatically would have to do that in
kill-all-local-variables.  Suppose I have a CUA rectangle in cperl-mode
and do M-x perl-mode.  The overlay would become inaccessible and any fix
of revert-buffer wouldn't help here.

I believe that Kim's approach to make such variables permanent-local is
the right one to handle this - when and if the problem shows up again.
The only thing I would do is leave a note about this, somewhere.

 >     Deactivating the mark would have to be done by insert-file-contents if
 >     it finds out that the mark has been invalidated during reversion.  I'd
 >     leave this alone until someone complains.
 >
 > I just tried it and revert-buffer did deactivate the mark.
 > Can someone describe a test case where it fails to do so?

With text-mode it doesn't.  And I never had any problems with that.

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

* Re: Problem with revert-buffer and overlays
  2005-11-29  9:15             ` martin rudalics
@ 2005-11-29 21:47               ` Richard M. Stallman
  2005-11-30  9:52                 ` martin rudalics
  0 siblings, 1 reply; 12+ messages in thread
From: Richard M. Stallman @ 2005-11-29 21:47 UTC (permalink / raw)
  Cc: emacs-devel, storm

    Might be I don't understand this correctly but to get rid of an overlay
    you have to find it in the first place.  The original problem was that
    kill-all-local-variables killed the reference to the overlay and CUA's
    post-command hook wasn't able to find it any more.

That is easy to fix with a change-major-mode-hook.
The revert-buffer problem is something completely different.

     > I just tried it and revert-buffer did deactivate the mark.
     > Can someone describe a test case where it fails to do so?

    With text-mode it doesn't.

Please provide a precise test case.  It is not obvious.

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

* Re: Problem with revert-buffer and overlays
  2005-11-29 21:47               ` Richard M. Stallman
@ 2005-11-30  9:52                 ` martin rudalics
  2005-12-04 21:19                   ` Richard M. Stallman
  0 siblings, 1 reply; 12+ messages in thread
From: martin rudalics @ 2005-11-30  9:52 UTC (permalink / raw)
  Cc: emacs-devel, storm

 > Please provide a precise test case.  It is not obvious.

I use a file foobar consisting of the three lines

foo
bar
baz

and an .emacs file

(setq inhibit-startup-message t)
(find-file "~/foobar")
(display-buffer "foobar")
(transient-mark-mode 1)
(forward-line)
(delete-char 3)
(set-mark (point-min))
(forward-line)
(revert-buffer)


If I answer "yes" the region remains highlighted.

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

* Re: Problem with revert-buffer and overlays
  2005-11-30  9:52                 ` martin rudalics
@ 2005-12-04 21:19                   ` Richard M. Stallman
  0 siblings, 0 replies; 12+ messages in thread
From: Richard M. Stallman @ 2005-12-04 21:19 UTC (permalink / raw)
  Cc: storm, emacs-devel

    and an .emacs file

    (setq inhibit-startup-message t)
    (find-file "~/foobar")
    (display-buffer "foobar")
    (transient-mark-mode 1)
    (forward-line)
    (delete-char 3)
    (set-mark (point-min))
    (forward-line)
    (revert-buffer)

    If I answer "yes" the region remains highlighted.

This appears to fail only when run in .emacs.
I will install some fixes.

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

end of thread, other threads:[~2005-12-04 21:19 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-11-25 13:23 Two minor problems with CUA rectangles martin rudalics
2005-11-26 23:37 ` Problem with revert-buffer and overlays [was: Two minor problems with CUA rectangles] Kim F. Storm
2005-11-27  3:28   ` Richard M. Stallman
2005-11-27 21:02     ` Problem with revert-buffer and overlays Kim F. Storm
2005-11-28  4:47       ` Richard M. Stallman
2005-11-28 10:17         ` martin rudalics
2005-11-28 12:38           ` Kim F. Storm
2005-11-28 21:00           ` Richard M. Stallman
2005-11-29  9:15             ` martin rudalics
2005-11-29 21:47               ` Richard M. Stallman
2005-11-30  9:52                 ` martin rudalics
2005-12-04 21:19                   ` Richard M. Stallman

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