Is mark active if and only if region is active in Emacs?
Asked Answered
C

2

8

Does "mark is active" simply mean the same thing as "region is active" in Emacs, regardless of whether Transient Mark mode is enabled? Therefore to activate mark is the same as to activate region?

I am confused because two phrases seem to be used interchangeably in many places, while the definition of region-active-p seems to take the stance that region is considered active if and only if Transient Mark mode is enabled and mark is active.

(defun region-active-p ()
  "Return t if Transient Mark mode is enabled and the mark is active.

Some commands act specially on the region when Transient Mark
mode is enabled.  Usually, such commands should use
`use-region-p' instead of this function, because `use-region-p'
also checks the value of `use-empty-active-region'."
  (and transient-mark-mode mark-active))

What is the relation between

  • region is highlighted (i.e. the region is in different background color)

  • region is active

  • mark is active

when Transient Mark mode is enabled, and when it is disabled, respectively?

Clair answered 9/9, 2013 at 12:40 Comment(0)
P
9
  1. Region is active = mark is active. But it is not necessarily highlighted.

  2. The region is highlighted if active and transient-mark-mode is on.

  3. The region is also highlighted temporarily if you set it using the mouse or using Shift + cursor keys, i.e., even if transient-mark-mode is off.

Except that if the region is empty you won't see any highlighting.

From my point of view, "active" applies only to transient-mark-mode. It has no sense when the mode is turned off. Any function whose behavior depends on whether the region is active only does so when t-m-mode is enabled. As the Emacs manual (node Persistent Mark) says: "When Transient Mark mode is off, the mark is never deactivated"

But this is not how it is spoken of sometimes recently. The reason has to do with "temporary transient-mark-mode" (see the Elisp manual, node The Mark).

(Keep in mind too that if there is not yet any mark in the buffer then there is also no region there.)

Profant answered 9/9, 2013 at 14:34 Comment(1)
The cited passages in the manual all seem to have been rewritten. The current definitive (to me) phrase is "Once the mark exists in a buffer, it normally never ceases to exist. However, it may become “inactive”, if Transient Mark mode is enabled."Succumb
C
1

Side note. Here is a way to track when mark-active is true. Evaluate the following code:

(defun my-message-mark-active ()
  (set-background-color
   (if mark-active "grey90" "white")))
(defvar my-watch-mark-active-mode nil)
(defun my-watch-mark-active-mode ()
  (interactive)
  (if my-watch-mark-active-mode
      (progn
        (cancel-timer my-watch-mark-active-mode)
        (setq my-watch-mark-active-mode nil)
        (message "off"))
    (setq my-watch-mark-active-mode
          (run-with-idle-timer 0.1 t #'my-message-mark-active))
    (message "on")))

Then type M-x my-watch-mark-active-mode to turn on watching mark-active. Background color is grey90 while mark-active is true, otherwise white. Type M-x my-watch-mark-active-mode again to turn it off.

This will help verify that when transient mark mode is enabled, mark is active if and only if region is highlighted. And this will also verify that when transient mark mode is disabled, mark-active becomes true at some point and then never becomes false, this is per buffer.

Clair answered 10/9, 2013 at 12:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.