From 033dec727e6eb381cae288aaacbce63eba76a7bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Le=20Gouguec?= Date: Sun, 15 Jan 2023 19:23:17 +0100 Subject: [PATCH] Avoid spurious pause in kill-ring-save '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 a more extensive predicate. * lisp/simple.el (region-highlighted-p): New function to detect "if the region is highlighted", leveraging display-supports-face-attributes-p. (indicate-copied-region): Use it. * lisp/faces.el (face-differs-from-default-p): Also ignore :extend, since the answers display-supports-face-attributes-p gives for that attribute do not help determine whether FACE is visually distinct from default. --- lisp/faces.el | 4 ++-- lisp/simple.el | 10 ++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lisp/faces.el b/lisp/faces.el index 3323eab205..53a4ee5e09 100644 --- a/lisp/faces.el +++ b/lisp/faces.el @@ -303,8 +303,8 @@ face-differs-from-default-p If the optional argument FRAME is given, report on face FACE in that frame. If FRAME is t, report on the defaults for face FACE (for new frames). If FRAME is omitted or nil, use the selected frame." - (let ((attrs - (delq :inherit (mapcar 'car face-attribute-name-alist))) + (let ((attrs (seq-difference (mapcar 'car face-attribute-name-alist) + '(:extend :inherit))) (differs nil)) (while (and attrs (not differs)) (let* ((attr (pop attrs)) diff --git a/lisp/simple.el b/lisp/simple.el index 844cfa68b0..e2828caf39 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -5865,6 +5865,13 @@ copy-region-blink-delay :group 'killing :version "28.1") +(defun region-highlighted-p () + "Say whether the region is visibly highlighted. +This takes into account whether the region is active, and whether +the `region' face displays differently from the default face." + (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 @@ -5885,8 +5892,7 @@ indicate-copied-region ;; 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)))) + (not (region-highlighted-p))) ;; Swap point and mark. (set-marker (mark-marker) (point) (current-buffer)) (goto-char mark) -- 2.39.0