10

I've hit a problem that region is deactivated (in transient-mark-mode). The function deactivate-mark is called and I would like to find out where (and why) it is called from.

I tried M-x debug-on-entry RET deactivate-mark and it stops but I found no way to find out the caller. Whole displayed stacktrace is:

Debugger entered--entering a function:
* deactivate-mark()

I tried M-x edebug-eval-defun but Edebug does not show the caller either.

How do I find out why (where from) deactivate-mark is called? I'm look for backtrace or stacktrace functinality.

EDIT:

An advice-add trick:

(defun message-show-backtrace ()
  (message "%s" (backtrace-frame 10)))

(advice-add deactivate-mark :before #'message-show-backtrace)

produces nil in *Messages*.

Edit: more info about deactivate-mark: http://emacshorrors.com/posts/deactivate-mark.html

6
  • 1
    I can reproduce the described behaviour and output. Run emacs -Q, turn on the debug M-x debug-on-entry deactivate-mark, activate mark C-<SPC>, type a character. Commented May 8, 2015 at 14:10
  • You could advise deactiveate-mark and in your advice function use backtrace-frames to get a view of the whole call stack if edebug is not showing what you expect. Commented May 8, 2015 at 16:08
  • Added edit about advice-add and backtrace-frame. It did not help. Commented May 9, 2015 at 6:29
  • Regarding the reproduction from @AndrewSwann, it is worth noting that typing a character typically runs self-insert-command and "self-insert-command is an interactive built-in function in 'C source code'." This, together with the other behavior noted so far, suggests that one will have to debug with gdb. Commented May 29, 2015 at 22:05
  • 1
    From reading the question, it sounded like mark was being unexpectedly deactivated. Meanwhile the behaviour described by @AndrewSwann is perfectly expected (the region is deactivated when you type something). If the behaviour you get matches Andrew's, please clarify what you want to do.
    – Malabarba
    Commented May 29, 2015 at 23:43

1 Answer 1

4

From command_loop_1 in keyboard.c.

  ...
  if (!NILP (BVAR (current_buffer, mark_active))
  && !NILP (Vrun_hooks))
{
  /* In Emacs 22, setting transient-mark-mode to `only' was a
     way of turning it on for just one command.  This usage is
     obsolete, but support it anyway.  */
  if (EQ (Vtransient_mark_mode, Qidentity))
    Vtransient_mark_mode = Qnil;
  else if (EQ (Vtransient_mark_mode, Qonly))
    Vtransient_mark_mode = Qidentity;

  if (!NILP (Vdeactivate_mark))
    /* If `select-active-regions' is non-nil, this call to
       `deactivate-mark' also sets the PRIMARY selection.  */
    call0 (Qdeactivate_mark);
  else
  ...

That seems to be the only place where Qdeactivate_mark is called in all of src/*.c. So my guess is that this what you're running into.


Note, I am not an expert on Emacs C. I poked around with gdb --args src/emacs -Q after reading How to compile emacs with debug symbols?.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.