* Proper use of `deactivate-mark'?
@ 2014-02-13 17:19 Thorsten Jolitz
2014-02-13 17:28 ` Stefan Monnier
0 siblings, 1 reply; 7+ messages in thread
From: Thorsten Jolitz @ 2014-02-13 17:19 UTC (permalink / raw)
To: help-gnu-emacs
Hi List,
in a function I switch from buffer A to buffer B, mark the
thing-at-point, do something with it, conditional on
,--------------------
| (and
| (use-region-p) ...
`--------------------
, then call `(deactivate-mark)' at the end of the function and switch
back to buffer A again.
But the next time I switch to buffer B, the mark that was region-end
before seems to be still active - the region between that mark and the
actual point position is highlighted also I did not set any new mark
again.
Isn't that the appropriate use of `deactivate-mark'?
How can I make sure that no mark is active anymore when I'm done in
buffer B and switch back to buffer A?
--
cheers,
Thorsten
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Proper use of `deactivate-mark'?
2014-02-13 17:19 Proper use of `deactivate-mark'? Thorsten Jolitz
@ 2014-02-13 17:28 ` Stefan Monnier
2014-02-13 17:59 ` Thorsten Jolitz
[not found] ` <mailman.14992.1392314356.10748.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 7+ messages in thread
From: Stefan Monnier @ 2014-02-13 17:28 UTC (permalink / raw)
To: help-gnu-emacs
> Isn't that the appropriate use of `deactivate-mark'?
Sounds right, yes.
> How can I make sure that no mark is active anymore when I'm done in
> buffer B and switch back to buffer A?
Not sure why the mark is re-activated. Could be because you call
deactivate-mark from with a save-excursion.
Stefan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Proper use of `deactivate-mark'?
2014-02-13 17:28 ` Stefan Monnier
@ 2014-02-13 17:59 ` Thorsten Jolitz
2014-02-13 18:39 ` Michael Heerdegen
[not found] ` <mailman.14992.1392314356.10748.help-gnu-emacs@gnu.org>
1 sibling, 1 reply; 7+ messages in thread
From: Thorsten Jolitz @ 2014-02-13 17:59 UTC (permalink / raw)
To: help-gnu-emacs
Stefan Monnier <monnier@iro.umontreal.ca> writes:
>> Isn't that the appropriate use of `deactivate-mark'?
>
> Sounds right, yes.
>
>> How can I make sure that no mark is active anymore when I'm done in
>> buffer B and switch back to buffer A?
>
> Not sure why the mark is re-activated. Could be because you call
> deactivate-mark from with a save-excursion.
Not really, but I found the culprit:
Inside the (and ...) deactivate-mark does not do its work properly (does
copy-to-register return nil?)
,-------------------------------------------------------
| (and
| (use-region-p)
| (copy-to-register ?s (region-beginning) (region-end))
| (deactivate-mark) )
`-------------------------------------------------------
but refactored like this the mark is actually deactivated:
,---------------------------------------------------------
| (and
| (use-region-p)
| (copy-to-register ?s (region-beginning) (region-end)) )
| (deactivate-mark)
`---------------------------------------------------------
--
cheers,
Thorsten
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Proper use of `deactivate-mark'?
[not found] ` <mailman.14992.1392314356.10748.help-gnu-emacs@gnu.org>
@ 2014-02-13 18:07 ` Barry Margolin
2014-02-13 18:52 ` Thorsten Jolitz
2014-02-14 6:51 ` Kevin Rodgers
0 siblings, 2 replies; 7+ messages in thread
From: Barry Margolin @ 2014-02-13 18:07 UTC (permalink / raw)
To: help-gnu-emacs
In article <mailman.14992.1392314356.10748.help-gnu-emacs@gnu.org>,
Thorsten Jolitz <tjolitz@gmail.com> wrote:
> Stefan Monnier <monnier@iro.umontreal.ca> writes:
>
> >> Isn't that the appropriate use of `deactivate-mark'?
> >
> > Sounds right, yes.
> >
> >> How can I make sure that no mark is active anymore when I'm done in
> >> buffer B and switch back to buffer A?
> >
> > Not sure why the mark is re-activated. Could be because you call
> > deactivate-mark from with a save-excursion.
>
> Not really, but I found the culprit:
>
> Inside the (and ...) deactivate-mark does not do its work properly (does
> copy-to-register return nil?)
>
> ,-------------------------------------------------------
> | (and
> | (use-region-p)
> | (copy-to-register ?s (region-beginning) (region-end))
> | (deactivate-mark) )
> `-------------------------------------------------------
>
> but refactored like this the mark is actually deactivated:
>
> ,---------------------------------------------------------
> | (and
> | (use-region-p)
> | (copy-to-register ?s (region-beginning) (region-end)) )
> | (deactivate-mark)
> `---------------------------------------------------------
Maybe it should be:
(and
(use-region-p)
(progn
(copy-to-register ?s (region-beginning) (region0end))
(deactivate-mark)))
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Proper use of `deactivate-mark'?
2014-02-13 17:59 ` Thorsten Jolitz
@ 2014-02-13 18:39 ` Michael Heerdegen
0 siblings, 0 replies; 7+ messages in thread
From: Michael Heerdegen @ 2014-02-13 18:39 UTC (permalink / raw)
To: help-gnu-emacs
Thorsten Jolitz <tjolitz@gmail.com> writes:
> Inside the (and ...) deactivate-mark does not do its work properly (does
> copy-to-register return nil?)
The return value is unspecified, which means it can be anything. And
yes, in your use case it returns nil, which means you should not use
`and' in your example.
Michael.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Proper use of `deactivate-mark'?
2014-02-13 18:07 ` Barry Margolin
@ 2014-02-13 18:52 ` Thorsten Jolitz
2014-02-14 6:51 ` Kevin Rodgers
1 sibling, 0 replies; 7+ messages in thread
From: Thorsten Jolitz @ 2014-02-13 18:52 UTC (permalink / raw)
To: help-gnu-emacs
Barry Margolin <barmar@alum.mit.edu> writes:
> Maybe it should be:
>
> (and
> (use-region-p)
> (progn
> (copy-to-register ?s (region-beginning) (region0end))
> (deactivate-mark)))
Yes, that looks like my intention translated into code - thanks.
--
cheers,
Thorsten
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Proper use of `deactivate-mark'?
2014-02-13 18:07 ` Barry Margolin
2014-02-13 18:52 ` Thorsten Jolitz
@ 2014-02-14 6:51 ` Kevin Rodgers
1 sibling, 0 replies; 7+ messages in thread
From: Kevin Rodgers @ 2014-02-14 6:51 UTC (permalink / raw)
To: help-gnu-emacs
On 2/13/14 11:07 AM, Barry Margolin wrote:
> Maybe it should be:
>
> (and
> (use-region-p)
> (progn
> (copy-to-register ?s (region-beginning) (region0end))
> (deactivate-mark)))
;; http://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node84.html
;; As a matter of style, `when' is normally used to conditionally produce
;; some side effects, and the value of the when form is normally not
;; used. If the value is relevant, then it may be stylistically more
;; appropriate to use `and' or `if'.
(when (use-region-p)
(copy-to-register ?s (region-beginning) (region0end))
(deactivate-mark))
--
Kevin Rodgers
Denver, Colorado, USA
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2014-02-14 6:51 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-13 17:19 Proper use of `deactivate-mark'? Thorsten Jolitz
2014-02-13 17:28 ` Stefan Monnier
2014-02-13 17:59 ` Thorsten Jolitz
2014-02-13 18:39 ` Michael Heerdegen
[not found] ` <mailman.14992.1392314356.10748.help-gnu-emacs@gnu.org>
2014-02-13 18:07 ` Barry Margolin
2014-02-13 18:52 ` Thorsten Jolitz
2014-02-14 6:51 ` Kevin Rodgers
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).