From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Constantin Kulikov Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] Make rectangle-select able to skip lines(empty one, for example) Date: Tue, 31 Jan 2023 18:05:18 +0300 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="00000000000093625305f390a985" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="28864"; mail-complaints-to="usenet@ciao.gmane.io" To: emacs-devel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Jan 31 16:06:34 2023 Return-path: Envelope-to: ged-emacs-devel@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 1pMsDR-0007Is-DM for ged-emacs-devel@m.gmane-mx.org; Tue, 31 Jan 2023 16:06:33 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pMsCn-0002tN-PV; Tue, 31 Jan 2023 10:05:53 -0500 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 1pMsCX-0002oP-O4 for emacs-devel@gnu.org; Tue, 31 Jan 2023 10:05:40 -0500 Original-Received: from mail-ed1-x52f.google.com ([2a00:1450:4864:20::52f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pMsCR-00022U-SP for emacs-devel@gnu.org; Tue, 31 Jan 2023 10:05:34 -0500 Original-Received: by mail-ed1-x52f.google.com with SMTP id n6so12042143edo.9 for ; Tue, 31 Jan 2023 07:05:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=+0Qs2HhBSKCPnalhel3fziv7Tch2SK5Cu8WWyruGNSc=; b=BprUg5PzpKK+0zjPK1fugsWYCF7z6WkencQbUAqw3B+Xaj/XQHZnxXnkqc1ptI19r3 0lzT+aBjOgpi0/KYOWBsr7MRIFhfNceLoon3ZlNHA4eN0Pq/oZj948eWU9DPV4y3uOwv wKtciVjfqIzfgWA5SqHM2ZpCPM5+WGN/anj0Y0/Zy33n4fIarh9Cqa3zFQKSMczDJKCB v4O5if57ivFfB9PmLGuoYYRlYGzQNLUDr2pbnySsGPDuTCfGNrP38yS7pRqcEWILdnA1 oHHcV0q9jmpoWg6p3izD4VtZjzUJlUEEAuGvUhfW28G7DxwB6MJ1e34O0b8Hxvgr1BN/ y4Ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=+0Qs2HhBSKCPnalhel3fziv7Tch2SK5Cu8WWyruGNSc=; b=bvqBoscy/Qw1oCuokIlvaiAPvZKNzJNqIQmJhZ3KHziS4MAPtUejZCp/3I9CWm8PH0 +vlKKsS2vKi1r1h9VO5L6nuRZ6ggw2crBlAgxv0f6Jn6MVZtk3eH7cBhCJ6a3KsdEDBy wDtpegoWD5niKxPg+DJdarG8l93Q2cXNiCaSPOldgVKOeX87yar3UXowAu2/GdrxoJ/c HDyk6Xha2L+CnhAIDixsMI/6hlCIFm571LUZ3P5fezMnE0O4INghffk9hiuNxidhRHKd hGb07uZPo7JFIN31YVgR7IViB6fSzA9qla+5TGSL/BmS/N/LDZ6lzsgNcvhz55xiQUiS 8CDw== X-Gm-Message-State: AO0yUKXfGSN9+Di4JeyalKLrcgQuMKX6HRbCJt8xc1q+TqKJesYX+2C5 Wb2fS4Fm1ZfgM9yMflw536Q9eAhfobGvIaHCn0ysNZxqurw= X-Google-Smtp-Source: AK7set+Vj0lAn5ldzGAljJjMZhmN+oOF1g1kgEHi/07f08iyRQOZtMyRHbE7R+IyPqM7CBeZEcLAbz6dNvyvixelq/c= X-Received: by 2002:aa7:d819:0:b0:4a2:121d:1d3d with SMTP id v25-20020aa7d819000000b004a2121d1d3dmr4395894edq.82.1675177529394; Tue, 31 Jan 2023 07:05:29 -0800 (PST) In-Reply-To: Received-SPF: pass client-ip=2a00:1450:4864:20::52f; envelope-from=zxnotdead@gmail.com; helo=mail-ed1-x52f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:302834 Archived-At: --00000000000093625305f390a985 Content-Type: multipart/alternative; boundary="00000000000093625105f390a983" --00000000000093625105f390a983 Content-Type: text/plain; charset="UTF-8" Treat lines with whitespaces only as 'empty'. --- rect-orig.el 2023-01-31 17:25:08.498658466 +0300 +++ rect-patched.el 2023-01-31 17:30:02.163121185 +0300 @@ -144,11 +144,16 @@ ;;; Rectangle operations. +(defvar *rectangle-skip-lines* nil + "If `t' -- skip empty lines, if `function' -- skip line when it returns `nil'. +The function gets all arguments of `apply-on-rectangle' as input.") + (defun apply-on-rectangle (function start end &rest args) "Call FUNCTION for each line of rectangle with corners at START, END. FUNCTION is called with two arguments: the start and end columns of the rectangle, plus ARGS extra arguments. Point is at the beginning of line when the function is called. +Application of the FUNCTION is affected by the `*rectangle-skip-lines*'. The final point after the last operation will be returned." (save-excursion (let* ((cols (rectangle--pos-cols start end)) @@ -166,7 +171,14 @@ (goto-char startpt) (while (progn - (apply function startcol endcol args) + (when (cond + ((null *rectangle-skip-lines*) + t) + ((functionp *rectangle-skip-lines*) + (apply *rectangle-skip-lines* function start end args)) + (t + (not (string-match-p "\\`\\s-*$" (thing-at-point 'line))))) + (apply function startcol endcol args)) (setq final-point (point)) (and (zerop (forward-line 1)) (bolp) (<= (point) endpt)))) ------------------------------ (with-eval-after-load "rect.el" (defvar *rectangle-skip-lines* nil "If `t' -- skip empty lines, if `function' -- skip line when it returns `nil'. The function gets all arguments of `apply-on-rectangle' as input.") (defun apply-on-rectangle (function start end &rest args) "Call FUNCTION for each line of rectangle with corners at START, END. FUNCTION is called with two arguments: the start and end columns of the rectangle, plus ARGS extra arguments. Point is at the beginning of line when the function is called. Application of the FUNCTION is affected by the `*rectangle-skip-lines*'. The final point after the last operation will be returned." (save-excursion (let* ((cols (rectangle--pos-cols start end)) (startcol (car cols)) (endcol (cdr cols)) (startpt (progn (goto-char start) (line-beginning-position))) (endpt (progn (goto-char end) (copy-marker (line-end-position)))) final-point) ;; Ensure the start column is the left one. (if (< endcol startcol) (let ((col startcol)) (setq startcol endcol endcol col))) ;; Start looping over lines. (goto-char startpt) (while (progn (when (cond ((null *rectangle-skip-lines*) t) ((functionp *rectangle-skip-lines*) (apply *rectangle-skip-lines* function start end args)) (t (not (string-match-p "\\`\\s-*$" (thing-at-point 'line))))) (apply function startcol endcol args)) (setq final-point (point)) (and (zerop (forward-line 1)) (bolp) (<= (point) endpt)))) final-point)))) On Mon, 30 Jan 2023 at 17:36, Constantin Kulikov wrote: > Actually it must be named: "*Make `apply-on-rectangle' able to skip lines* > ". > Reattaching the patch as .txt > > On Mon, 30 Jan 2023 at 16:47, Constantin Kulikov > wrote: > >> >> --00000000000093625105f390a983 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Treat lines with whitespaces only as= 'empty'.

--- rec= t-orig.el 2023-01-31 17:25:08.498658466 +0300
+++ rect-patched.el 2023-01-31 17:30:02.163121185 +0300@@ -144,11 +144,16 @@
=C2=A0
=C2=A0;;; Rectangle operations.
=C2= =A0
+(defvar *rectangle-skip-lines* nil
+ =C2=A0"If `t' -- s= kip empty lines, if `function' -- skip line when it returns `nil'.<= br>+The function gets all arguments of `apply-on-rectangle' as input.&q= uot;)
+
=C2=A0(defun apply-on-rectangle (function start end &rest= args)
=C2=A0 =C2=A0"Call FUNCTION for each line of rectangle with = corners at START, END.
=C2=A0FUNCTION is called with two arguments: the = start and end columns of the
=C2=A0rectangle, plus ARGS extra arguments.= =C2=A0 Point is at the beginning of line when
=C2=A0the function is call= ed.
+Application of the FUNCTION is affected by the `*rectangle-skip-lin= es*'.
=C2=A0The final point after the last operation will be returne= d."
=C2=A0 =C2=A0(save-excursion
=C2=A0 =C2=A0 =C2=A0(let* ((col= s (rectangle--pos-cols start end))
@@ -166,7 +171,14 @@
=C2=A0 =C2=A0= =C2=A0 =C2=A0(goto-char startpt)
=C2=A0 =C2=A0 =C2=A0 =C2=A0(while
= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(progn
- =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0(apply function startcol endcol args)
+ =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(when (cond
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ((null *rectangle-skip-lines*)
+ =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0t)
+ = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ((functionp = *rectangle-skip-lines*)
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0(apply *rectangle-skip-lines* function start end ar= gs))
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (t=
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= (not (string-match-p "\\`\\s-*$" (thing-at-point 'line)))))+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(apply function startco= l endcol args))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(setq fi= nal-point (point))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(and = (zerop (forward-line 1)) (bolp)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 (<=3D (point) endpt))))

------------------------------

(with-eval-after-load "rect.el"=
=C2=A0 (defvar *rectangle-skip-lines* nil
"If `t' -- skip = empty lines, if `function' -- skip line when it returns `nil'.
T= he function gets all arguments of `apply-on-rectangle' as input.")=
=C2=A0 (defun apply-on-rectangle (function start end &rest args) "Call FUNCTION for each line of rectangle with corners at START, END= .
FUNCTION is called with two arguments: the start and end columns of th= e
rectangle, plus ARGS extra arguments.=C2=A0 Point is at the beginning = of line when
the function is called.
Application of the FUNCTION is a= ffected by the `*rectangle-skip-lines*'.
The final point after the l= ast operation will be returned."
(save-excursion
=C2=A0(let* = ((cols (rectangle--pos-cols start end))
(startcol (car cols))
= (endcol (cdr cols))
(startpt (progn (goto-char start) (line-beginni= ng-position)))
(endpt (progn (goto-char end)
=C2=A0 (copy-= marker (line-end-position))))
final-point)
;; Ensure the start = column is the left one.
(if (< endcol startcol)
(let ((col st= artcol))
=C2=A0(setq startcol endcol endcol col)))
;; Start loo= ping over lines.
(goto-char startpt)
(while
(progn
= =C2=A0(when (cond
((null *rectangle-skip-lines*)
=C2=A0t)=
((functionp *rectangle-skip-lines*)
=C2=A0(apply *rectan= gle-skip-lines* function start end args))
(t
=C2=A0(not (= string-match-p "\\`\\s-*$" (thing-at-point 'line)))))
= (apply function startcol endcol args))
=C2=A0(setq final-point (poin= t))
=C2=A0(and (zerop (forward-line 1)) (bolp)
=C2=A0 (<= =3D (point) endpt))))
final-point))))


<= /div>
O= n Mon, 30 Jan 2023 at 17:36, Constantin Kulikov <zxnotdead@gmail.com> wrote:
Actual= ly it must be named: "Make `apply-on-rectangle' able to skip li= nes".
Reattaching the patch as .txt

On Mon, 30 Jan 2023 at 16:47, Constantin Kulikov <zxnotdead@gmail.com> wrote:
=

--00000000000093625105f390a983-- --00000000000093625305f390a985 Content-Type: text/plain; charset="US-ASCII"; name="rect.el.patch.txt" Content-Disposition: attachment; filename="rect.el.patch.txt" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_ldkd85kg0 LS0tIHJlY3Qtb3JpZy5lbAkyMDIzLTAxLTMxIDE3OjI1OjA4LjQ5ODY1ODQ2NiArMDMwMAorKysg cmVjdC1wYXRjaGVkLmVsCTIwMjMtMDEtMzEgMTc6MzA6MDIuMTYzMTIxMTg1ICswMzAwCkBAIC0x NDQsMTEgKzE0NCwxNiBAQAogCiA7OzsgUmVjdGFuZ2xlIG9wZXJhdGlvbnMuCiAKKyhkZWZ2YXIg KnJlY3RhbmdsZS1za2lwLWxpbmVzKiBuaWwKKyAgIklmIGB0JyAtLSBza2lwIGVtcHR5IGxpbmVz LCBpZiBgZnVuY3Rpb24nIC0tIHNraXAgbGluZSB3aGVuIGl0IHJldHVybnMgYG5pbCcuCitUaGUg ZnVuY3Rpb24gZ2V0cyBhbGwgYXJnd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3RhbmdsZS1z a2lwLWxpbmVzKikKKyAgICAgICAgICAgICAgICAgICAgKGFwcGx5ICpyZWN0YW5nbGUtc2tpcC1s aW5lcyogZnVuY3Rpb24gc3RhcnQgZW5kIGFyZ3MpKQorICAgICAgICAgICAgICAgICAgICh0Cisg ICAgICAgICAgICAgICAgICAgIChub3QgKHN0cmluZy1tYXRjaC1wICJcXGBcXHMtKiQiICh0aGlu Zy1hdC1wb2ludCAnbGluZSkpKSkpCisgICAgICAgICAgICAgIChhcHBseSBmdW5jdGlvbiBzdGFy dGNvbCBlbmRjb2wgYXJncykpCiAgICAgICAgICAgICAoc2V0cSBmaW5hbC1wb2ludCAocG9pbnQp KQogICAgICAgICAgICAgKGFuZCAoemVyb3AgKGZvcndhcmQtbGluZSAxKSkgKGJvbHApCiAgICAg ICAgICAgICAgICAgICg8PSAocG9pbnQpIGVuZHB0KSkpKQo= --00000000000093625305f390a985--