summaryrefslogtreecommitdiff
path: root/lisp/simple.el
diff options
context:
space:
mode:
authorKévin Le Gouguec <kevin.legouguec@gmail.com>2023-01-29 11:23:01 +0100
committerKévin Le Gouguec <kevin.legouguec@gmail.com>2023-02-02 19:39:39 +0100
commitc4988840598b7da84b25d21a1936ce1ab6f6d666 (patch)
tree0899a6fd53ebd903540b5f2e57f02a2d0b565ac4 /lisp/simple.el
parent382ab516cefc974d65622479fb7e844fd982011d (diff)
downloademacs-c4988840598b7da84b25d21a1936ce1ab6f6d666.tar.gz
Avoid spurious pause in kill-ring-save (Bug#60841)
'indicate-copied-region' checks whether the region is "highlighted" and if not, briefly moves point to mark to give a visual cue of the extent of text that was saved to the kill ring. The region is considered "highlighted" if (a) it is active and (b) its face specifies a :background. That latter condition does not account for the multiple ways in which the face can make the region "visually distinct" from the default face, so switch to the more extensive predicate face-differs-from-default-p. The patch also fixes a couple of issues with the predicate's implementation, and introduces a new user option in case anyone happened to enjoy unconditional blinking. * lisp/faces.el (face-differs-from-default-p): Filter out :extend; add rationale for the attributes we ignore. * lisp/simple.el (copy-region-blink-predicate): Add option to let users explicitly opt into or out of blinking point and mark. (region-indistinguishable-p): New function to detect "if there is currently no active region highlighting", leveraging face-differs-from-default-p. (indicate-copied-region): Use it. * src/xfaces.c (merge_face_ref): Allow :stipple to be nil, since it is a documented valid value for that attribute. * etc/NEWS: Announce user option.
Diffstat (limited to 'lisp/simple.el')
-rw-r--r--lisp/simple.el22
1 files changed, 20 insertions, 2 deletions
diff --git a/lisp/simple.el b/lisp/simple.el
index 861fe193fb8..c58acfe3adc 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -5852,6 +5852,25 @@ The value 0 disables blinking."
:group 'killing
:version "28.1")
+(defcustom copy-region-blink-predicate #'region-indistinguishable-p
+ "Whether the cursor must be blinked after a copy.
+When this condition holds, and the copied region fits in the
+current window, `kill-ring-save' will blink the cursor between
+point and mark for `copy-region-blink-delay' seconds."
+ :type '(radio (function-item region-indistinguishable-p)
+ (function-item :doc "Always blink point and mark." always)
+ (function-item :doc "Never blink point and mark." ignore)
+ (function :tag "Other predicate function"))
+ :group 'killing
+ :version "29.1")
+
+(defun region-indistinguishable-p ()
+ "Whether the current region is not denoted visually.
+This holds when the region is inactive, or when the `region' face
+cannot be distinguished from the `default' face."
+ (not (and (region-active-p)
+ (face-differs-from-default-p 'region))))
+
(defun indicate-copied-region (&optional message-len)
"Indicate that the region text has been copied interactively.
If the mark is visible in the selected window, blink the cursor between
@@ -5872,8 +5891,7 @@ of this sample text; it defaults to 40."
;; was selected. Don't do it if the region is highlighted.
(when (and (numberp copy-region-blink-delay)
(> copy-region-blink-delay 0)
- (or (not (region-active-p))
- (not (face-background 'region nil t))))
+ (funcall copy-region-blink-predicate))
;; Swap point and mark.
(set-marker (mark-marker) (point) (current-buffer))
(goto-char mark)