all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Stuart D. Herring" <herring@lanl.gov>
To: "Ben North" <ben@redfrontdoor.org>
Cc: emacs-devel@gnu.org
Subject: Re: Possibly incorrect non-deactivation of mark from kbd macro
Date: Fri, 23 Feb 2007 11:14:03 -0800 (PST)	[thread overview]
Message-ID: <57762.128.165.123.18.1172258043.squirrel@webmail.lanl.gov> (raw)
In-Reply-To: <1172238343.45def0079b245@imp.hosting365.ie>

> Define
>
>    (defun insert-X-as-if-from-kbd-macro ()
>      (interactive)
>      (save-excursion (execute-kbd-macro "X")))
>
> Turn on `transient-mark-mode'.  In, say, the start-up scratch buffer,
> set mark to be the start of the buffer, move forward a word, then do
> `M-x insert-X-as-if-from-kbd-macro'.  The mark is not deactivated even
> though the buffer has been modified.  If you try
>
>    (defun insert-X-using-insert ()
>      (interactive)
>      (save-excursion (insert "X")))
>
> then the mark is correctly deactivated.  I tried to dig into where the C
> variable `Vdeactivate_mark' was getting cleared but didn't get very far,
> sorry.  Hope the report is useful anyway.

This is a case where the documentation must be read quite carefully.

 save-excursion is a special form.
 (save-excursion &rest BODY)

 Save point, mark, and current buffer; execute BODY; restore those things.
 Executes BODY just like `progn'.
 The values of point, mark and the current buffer are restored
 even in case of abnormal exit (throw or error).
 The state of activation of the mark is also restored.

 This construct does not save `deactivate-mark', and therefore
 functions that change the buffer will still cause deactivation
 of the mark at the end of the command.  To prevent that, bind
 `deactivate-mark' with `let'.

In your first example, the only buffer modification that occurs takes
place in a nested command -- one started by `execute-kbd-macro' (it calls
command_loop_1()).  When _it_ finishes, it does in fact deactivate the
mark.  But it finishes before `execute-kbd-macro' returns!  (After all,
`post-command-hook' must be run once for each command in a keyboard
macro.)  Then the macro finishes, and as you exit the `save-excursion' it
reactivates the mark.

In the second example, the (innermost) command that contains the buffer
modification _is_ your function, so `save-excursion' finishes before the
mark is deactivated and the mark stays deactivated.

Hope this helps,
Davis

-- 
This product is sold by volume, not by mass.  If it appears too dense or
too sparse, it is because mass-energy conversion has occurred during
shipping.

  reply	other threads:[~2007-02-23 19:14 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-02-23 13:45 Possibly incorrect non-deactivation of mark from kbd macro Ben North
2007-02-23 19:14 ` Stuart D. Herring [this message]
  -- strict thread matches above, loose matches on Subject: below --
2007-02-26  8:52 Ben North

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=57762.128.165.123.18.1172258043.squirrel@webmail.lanl.gov \
    --to=herring@lanl.gov \
    --cc=ben@redfrontdoor.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.