Function: deactivate-mark
deactivate-mark is a byte-compiled function defined in simple.el.gz.
Signature
(deactivate-mark &optional FORCE)
Documentation
Deactivate the mark.
If Transient Mark mode is disabled, this function normally does nothing; but if FORCE is non-nil, it deactivates the mark anyway.
Deactivating the mark sets mark-active to nil, updates the
primary selection according to select-active-regions (unless
deactivate-mark(var)/deactivate-mark(fun) is dont-save), and runs
deactivate-mark-hook.
If Transient Mark mode was temporarily enabled, reset the value
of the variable transient-mark-mode(var)/transient-mark-mode(fun); if this causes Transient
Mark mode to be disabled, don't change mark-active to nil or
run deactivate-mark-hook.
Probably introduced at or before Emacs version 19.29.
Aliases
ediff-deactivate-mark (obsolete since 27.1)
viper-deactivate-mark (obsolete since 27.1)
Source Code
;; Defined in /usr/src/emacs/lisp/simple.el.gz
;; Behind display-selections-p.
(defun deactivate-mark (&optional force)
"Deactivate the mark.
If Transient Mark mode is disabled, this function normally does
nothing; but if FORCE is non-nil, it deactivates the mark anyway.
Deactivating the mark sets `mark-active' to nil, updates the
primary selection according to `select-active-regions' (unless
`deactivate-mark' is `dont-save'), and runs
`deactivate-mark-hook'.
If Transient Mark mode was temporarily enabled, reset the value
of the variable `transient-mark-mode'; if this causes Transient
Mark mode to be disabled, don't change `mark-active' to nil or
run `deactivate-mark-hook'."
(when (or (region-active-p) force)
(when (and (if (eq select-active-regions 'only)
(eq (car-safe transient-mark-mode) 'only)
select-active-regions)
(not (eq deactivate-mark 'dont-save))
(region-active-p)
(display-selections-p))
;; The var `saved-region-selection', if non-nil, is the text in
;; the region prior to the last command modifying the buffer.
;; Set the selection to that, or to the current region.
(cond (saved-region-selection
(if (gui-backend-selection-owner-p 'PRIMARY)
(gui-set-selection 'PRIMARY saved-region-selection))
(setq saved-region-selection nil))
;; If another program has acquired the selection, region
;; deactivation should not clobber it (Bug#11772).
((and (/= (region-beginning) (region-end))
(or (gui-backend-selection-owner-p 'PRIMARY)
(null (gui-backend-selection-exists-p 'PRIMARY))))
(gui-set-selection 'PRIMARY
(funcall region-extract-function nil)))))
(when mark-active (force-mode-line-update)) ;Refresh toolbar (bug#16382).
(cond
((eq (car-safe transient-mark-mode) 'only)
(setq transient-mark-mode (cdr transient-mark-mode))
(if (eq transient-mark-mode (default-value 'transient-mark-mode))
(kill-local-variable 'transient-mark-mode)))
((eq transient-mark-mode 'lambda)
(kill-local-variable 'transient-mark-mode)))
(setq mark-active nil)
(run-hooks 'deactivate-mark-hook)
(redisplay--update-region-highlight (selected-window))))