From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Newsgroups: gmane.emacs.bugs Subject: bug#72830: Big rectangular selections are slow Date: Thu, 29 Aug 2024 12:22:08 +0200 Message-ID: References: <87zfow2d90.fsf@web.de> Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.15\)) Content-Type: multipart/mixed; boundary="Apple-Mail=_02B8ABC5-85B5-46A4-B410-6607750EE046" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="3565"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Eli Zaretskii , 72830@debbugs.gnu.org, Stefan Monnier , Juri Linkov To: Michael Heerdegen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Aug 29 12:24:27 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sjcKI-0000jL-OO for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 29 Aug 2024 12:24:26 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sjcK0-000782-Bu; Thu, 29 Aug 2024 06:24:08 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sjcJy-00077M-UD for bug-gnu-emacs@gnu.org; Thu, 29 Aug 2024 06:24:06 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sjcJy-0002y3-Kj for bug-gnu-emacs@gnu.org; Thu, 29 Aug 2024 06:24:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=References:In-Reply-To:Date:Mime-Version:From:To:Subject; bh=PFd9DSvTOZ2A1DL/MUTs+THiM8Y2kgnMGNWnrllqj50=; b=M9NXoK9ZV1MvhXUpOx2JtpEfEJbQStIJXqN4VBJbjLeZfVUdlnkPasH/wnLZlGzn9jQ+vTErDFafewHBwaevj8a5JkvxHcfpWJs2ysQO+3FkLGv+YLyihfF0/gaJsqIhWdyWV4vYi7wjdpXB8lVP6GRiTGe4Yq2pOg89e+tYI3jAgjC2Z/+MhP5SHUWtgONgmaQRn+YbK72Z8HZ8TPAuQXNUR/wFpybiUlNp8CtgxBC/6Fd9ub9GJJ6278D9hqSE4UDL4LrGPDPwrRuy0yiCWo15oR5ZM9Gjba5O6wzkatPDJKgazyP9YMJNzByoMVoYNesIe/RI0Y2tOFUeHmkk0g==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sjcKr-0002CO-Q5 for bug-gnu-emacs@gnu.org; Thu, 29 Aug 2024 06:25:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 29 Aug 2024 10:25:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 72830 X-GNU-PR-Package: emacs Original-Received: via spool by 72830-submit@debbugs.gnu.org id=B72830.17249270548379 (code B ref 72830); Thu, 29 Aug 2024 10:25:01 +0000 Original-Received: (at 72830) by debbugs.gnu.org; 29 Aug 2024 10:24:14 +0000 Original-Received: from localhost ([127.0.0.1]:50524 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sjcK6-0002B3-3D for submit@debbugs.gnu.org; Thu, 29 Aug 2024 06:24:14 -0400 Original-Received: from mail-lf1-f46.google.com ([209.85.167.46]:52652) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sjcK4-0002Ai-A5 for 72830@debbugs.gnu.org; Thu, 29 Aug 2024 06:24:13 -0400 Original-Received: by mail-lf1-f46.google.com with SMTP id 2adb3069b0e04-533521cd1c3so564028e87.1 for <72830@debbugs.gnu.org>; Thu, 29 Aug 2024 03:23:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724926931; x=1725531731; darn=debbugs.gnu.org; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:sender:from:to:cc:subject:date:message-id:reply-to; bh=PFd9DSvTOZ2A1DL/MUTs+THiM8Y2kgnMGNWnrllqj50=; b=nRG3k5RXcfVmG11Wha/Gd/q5IiSXM69mvE5IPOEutX2SV90KGmLMlR0wH88yB5XEKR rkf2Vjvy4DZ5u9Z1RKm8DJvrTgmDlaCC8d1PPj8XR5jIuYOGAleUcX0WbijpnpAfcMwt 22SqCEhpW45Y4iMfWNMVnaLRX3FEfRZb1/bO0u9ZLwIvJ0bQMlrbtQEXXtixK0XBlM99 MIheX6Ay3x3an5aGTc7t6cA4wX3yU5Mht/4iH/qInytcT4og8sL+3Qkk5flDswWY9/FS F7ImIV8a4EsdeWT7k8PoaOEljgO509BxfAkzxUnfZ5s7QklAGzTwPXLn6/UvyyxyHuF2 mypA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724926931; x=1725531731; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:sender:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=PFd9DSvTOZ2A1DL/MUTs+THiM8Y2kgnMGNWnrllqj50=; b=QNjf95QZMiAviMJH6xnpHLu0E+2AVQVTTJ7ym+lfJ/rv5FS/uxfmm2KydowY8gJBWu YP457mlfw8L/7zIsK7afSL4FUs/+wGc1xv/6rxIuwfEXcIdZiNL5bEOfD5BEgPojrKtq rzyv26gnv6NFdBbZFJWVUYR3lH1kQ13hQy5yiEv6s7JwlPiH2crRcTrxuoSdTbe7kBWH da7EqRq+uyE2wVjxTSMqUcKrJfvlWUalTDX+x+i5zjgcNyk8gpqs4tgzB/HXyuxwQ3rD GfPpaFBdHeA+V8JKnWdWoVale5ArkBjerR0HN/VJDccgLmH13ScktZg+4gWFoH8GGPNZ TbGQ== X-Forwarded-Encrypted: i=1; AJvYcCWSipMUWOPvAx9ArGat9nXfXV8jB56yZ+K+85qChR1CLK7Tf1qzxny2NPNPoWZAEicUgNLi1Q==@debbugs.gnu.org X-Gm-Message-State: AOJu0YzhFHpdayd++/d19P9epWzmRM3Q0LJqYg17CY+poU8o1RZpXVPP nbwa75et4IIT0U2BRPBl3f6LhhNwOpxiTbgeecLGO2Tm4W/K8sT3 X-Google-Smtp-Source: AGHT+IFbq59AkCGkZfqIKXnjqCB5FXu1K5sqq4nCVHMGqcFoKH38NDol096z1JFbAKv4lWyuBkGQDA== X-Received: by 2002:a05:6512:3986:b0:533:77d:115f with SMTP id 2adb3069b0e04-5353e5b7527mr1712100e87.56.1724926930161; Thu, 29 Aug 2024 03:22:10 -0700 (PDT) Original-Received: from smtpclient.apple (c188-150-191-82.bredband.tele2.se. [188.150.191.82]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-535407ac17asm115967e87.81.2024.08.29.03.22.08 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Aug 2024 03:22:09 -0700 (PDT) In-Reply-To: <87zfow2d90.fsf@web.de> X-Mailer: Apple Mail (2.3654.120.0.1.15) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:290918 Archived-At: --Apple-Mail=_02B8ABC5-85B5-46A4-B410-6607750EE046 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii 29 aug. 2024 kl. 05.56 skrev Michael Heerdegen = : > My idea would be: highlight from or up to "rectangle point" maximally > (window-height) lines. Here I was digging into the redisplay code in the hope of finding an = obscure hook to subvert, and you turn up and give us the obvious, simple = and correct solution right away. Thank you, Michael! The patch below is crude but seems to work. Please give it a try. If the original recipe is still stuttering, try setting = `select-active-regions` to nil. --Apple-Mail=_02B8ABC5-85B5-46A4-B410-6607750EE046 Content-Disposition: attachment; filename=rect-highlight.diff Content-Type: application/octet-stream; x-unix-mode=0644; name="rect-highlight.diff" Content-Transfer-Encoding: 7bit diff --git a/lisp/rect.el b/lisp/rect.el index 93007824679..1fadb4c768a 100644 --- a/lisp/rect.el +++ b/lisp/rect.el @@ -869,81 +869,107 @@ rectangle--highlight-for-redisplay (cl-assert (eq (window-buffer window) (current-buffer))) ;; `rectangle--pos-cols' looks up the `selected-window's parameter! (with-selected-window window - (apply-on-rectangle - (lambda (leftcol rightcol) - (let* ((mleft (move-to-column leftcol)) - (left (point)) - ;; BEWARE: In the presence of other overlays with - ;; before/after/display-strings, this happens to move to - ;; the column "as if the overlays were not applied", which - ;; is sometimes what we want, tho it can be - ;; considered a bug in move-to-column (it should arguably - ;; pay attention to the before/after-string/display - ;; properties when computing the column). - (mright (move-to-column rightcol)) - (right (point)) - (ol - (if (not old) - (let ((ol (make-overlay left right))) - (overlay-put ol 'window window) - (overlay-put ol 'face 'region) - ol) - (let ((ol (pop old))) - (move-overlay ol left right (current-buffer)) - ol)))) - ;; `move-to-column' may stop before the column (if bumping into - ;; EOL) or overshoot it a little, when column is in the middle - ;; of a char. - (cond - ((< mleft leftcol) ;`leftcol' is past EOL. - (overlay-put ol 'before-string (rectangle--space-to leftcol)) - (setq mright (max mright leftcol))) - ((and (> mleft leftcol) ;`leftcol' is in the middle of a char. - (eq (char-before left) ?\t)) - (setq left (1- left)) - (move-overlay ol left right) - (goto-char left) - (overlay-put ol 'before-string (rectangle--space-to leftcol))) - ((overlay-get ol 'before-string) - (overlay-put ol 'before-string nil))) - (cond - ;; While doing rectangle--string-preview, the two sets of - ;; overlays steps on the other's toes. I fixed some of the - ;; problems, but others remain. The main one is the two - ;; (rectangle--space-to rightcol) below which try to virtually - ;; insert missing text, but during "preview", the text is not - ;; missing (it's provided by preview's own overlay). - (rectangle--string-preview-state - (if (overlay-get ol 'after-string) - (overlay-put ol 'after-string nil))) - ((< mright rightcol) ;`rightcol' is past EOL. - (let ((str (rectangle--space-to rightcol))) - (put-text-property 0 (length str) 'face 'region str) - ;; If cursor happens to be here, draw it at the right place. - (rectangle--place-cursor leftcol left str) - (overlay-put ol 'after-string str))) - ((and (> mright rightcol) ;`rightcol's in the middle of a char. - (eq (char-before right) ?\t)) - (setq right (1- right)) - (move-overlay ol left right) - (if (= rightcol leftcol) - (overlay-put ol 'after-string nil) - (goto-char right) - (let ((str (rectangle--space-to rightcol))) - (put-text-property 0 (length str) 'face 'region str) - (when (= left right) - (rectangle--place-cursor leftcol left str)) - (overlay-put ol 'after-string str)))) - ((overlay-get ol 'after-string) - (overlay-put ol 'after-string nil))) - (when (and (= leftcol rightcol) (display-graphic-p)) - ;; Make zero-width rectangles visible! - (overlay-put ol 'after-string - (concat (propertize " " - 'face '(region (:height 0.2))) - (overlay-get ol 'after-string)))) - (push ol nrol))) - start end)) + (let* ((pt (point)) + (cols (rectangle--pos-cols start end)) + (startcol (car cols)) + (endcol (cdr cols)) + (leftcol (min startcol endcol)) + (rightcol (max startcol endcol)) + ;; We don't know what lines will actually be displayed, + ;; so add highlight overlays on lines within the window + ;; height from point. + (height (window-height)) + (start-pt (max (point-min) start + (progn (forward-line (- height)) (point)))) + (end-pt (min (point-max) end + (progn (goto-char pt) + (forward-line height) + (point))))) + (goto-char start-pt) + (beginning-of-line) + (while + (let* ((mleft (move-to-column leftcol)) + (left (point)) + ;; BEWARE: In the presence of other overlays with + ;; before/after/display-strings, this happens to move to + ;; the column "as if the overlays were not applied", + ;; which is sometimes what we want, tho it can be + ;; considered a bug in move-to-column (it should + ;; arguably pay attention to the + ;; before/after-string/display properties when computing + ;; the column). + (mright (move-to-column rightcol)) + (right (point)) + (ol + (if (not old) + (let ((ol (make-overlay left right))) + (overlay-put ol 'window window) + (overlay-put ol 'face 'region) + ol) + (let ((ol (pop old))) + (move-overlay ol left right (current-buffer)) + ol)))) + ;; `move-to-column' may stop before the column (if bumping + ;; into EOL) or overshoot it a little, when column is in the + ;; middle of a char. + (cond + ((< mleft leftcol) ;`leftcol' is past EOL. + (overlay-put ol 'before-string + (rectangle--space-to leftcol)) + (setq mright (max mright leftcol))) + ((and (> mleft leftcol) ;`leftcol' is in the middle of a char + (eq (char-before left) ?\t)) + (setq left (1- left)) + (move-overlay ol left right) + (goto-char left) + (overlay-put ol 'before-string + (rectangle--space-to leftcol))) + ((overlay-get ol 'before-string) + (overlay-put ol 'before-string nil))) + (cond + ;; While doing rectangle--string-preview, the two sets of + ;; overlays steps on the other's toes. I fixed some of the + ;; problems, but others remain. The main one is the two + ;; (rectangle--space-to rightcol) below which try to + ;; virtually insert missing text, but during "preview", the + ;; text is not missing (it's provided by preview's own + ;; overlay). + (rectangle--string-preview-state + (if (overlay-get ol 'after-string) + (overlay-put ol 'after-string nil))) + ((< mright rightcol) ;`rightcol' is past EOL. + (let ((str (rectangle--space-to rightcol))) + (put-text-property 0 (length str) 'face 'region str) + ;; If cursor happens to be here, draw it at the right + ;; place. + (rectangle--place-cursor leftcol left str) + (overlay-put ol 'after-string str))) + ((and (> mright rightcol) ;`rightcol' in the middle of a char + (eq (char-before right) ?\t)) + (setq right (1- right)) + (move-overlay ol left right) + (if (= rightcol leftcol) + (overlay-put ol 'after-string nil) + (goto-char right) + (let ((str (rectangle--space-to rightcol))) + (put-text-property 0 (length str) 'face 'region str) + (when (= left right) + (rectangle--place-cursor leftcol left str)) + (overlay-put ol 'after-string str)))) + ((overlay-get ol 'after-string) + (overlay-put ol 'after-string nil))) + (when (and (= leftcol rightcol) (display-graphic-p)) + ;; Make zero-width rectangles visible! + (overlay-put ol 'after-string + (concat (propertize + " " 'face '(region (:height 0.2))) + (overlay-get ol 'after-string)))) + (push ol nrol) + (and (zerop (forward-line 1)) + (bolp) + (<= (point) end-pt)))) + ) + ) (mapc #'delete-overlay old) `(rectangle ,(buffer-chars-modified-tick) ,start ,end ,(rectangle--crutches) --Apple-Mail=_02B8ABC5-85B5-46A4-B410-6607750EE046--