help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [External] : What is the difference between (deactivate-mark) and (s


From: Marcin Borkowski
Subject: Re: [External] : What is the difference between (deactivate-mark) and (setq deactivate-mark t)?
Date: Wed, 07 Apr 2021 07:14:20 +0200
User-agent: mu4e 1.1.0; emacs 28.0.50

On 2021-04-03, at 06:11, Drew Adams <drew.adams@oracle.com> wrote:

>> Well, I understand what each of them does, but whay was the variable
>> introduced and why would I want to  say `(setq deactivate-mark t)' in
>> a command instead of just calling `(deactivate-mark)'?  I can't think of
>> any possible reasons.  Any ideas?
>
> I may be repeating what you say you already
> understand, but...
>
> Function `deactivate-mark' deactivates the mark
> (duh), and it does so right away.
>
> After a command finishes and returns, the command
> loop normally automatically deactivates the mark.
> IOW, for the next command the mark is inactive.

Well, I don't think that's the case.  Take this command:

(defun petrichor ()
  (interactive)
  (message "Smell of the dust after the rain"))

activate the region and say M-x petrichor - the region is still active.

If I want to change this, I can either say `(deactivate-mark)' or `(setq
deactivate-mark t)'.  My question was, why I would want to choose the
latter?

I think I now know the reason - while experimenting with this and
studying the docs, I probably found out.  Can anyone correct me if I'm
wrong?  It seems that its main use is to actually _prevent_ the code
from deactivating the region _if_ it would do it otherwise, by means of
_modifying_ the buffer.  Since every primitive that changes the buffer
(like `insert') sets it to `t', you can say `(setq deactivate-mark nil)`
at the end of a buffer-modifying command and the region will remain
active if it was before running it.  (The manual suggests temporarily
binding it with `let' which has a similar effect, as you mentioned.)

Does that make sense?

-- 
Marcin Borkowski
http://mbork.pl



reply via email to

[Prev in Thread] Current Thread [Next in Thread]