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: [PATCH] Make rectangle-select able to skip lines(empty one, for example) Date: Mon, 30 Jan 2023 16:47:07 +0300 Message-ID: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="0000000000004a550f05f37b7483" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="28084"; 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 Mon Jan 30 14:48:39 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 1pMUWV-0007Ah-34 for ged-emacs-devel@m.gmane-mx.org; Mon, 30 Jan 2023 14:48:39 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pMUVk-0003tU-Vv; Mon, 30 Jan 2023 08:47: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 1pMUVO-0003op-BS for emacs-devel@gnu.org; Mon, 30 Jan 2023 08:47:42 -0500 Original-Received: from mail-ej1-x62b.google.com ([2a00:1450:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pMUVI-0003WP-Gp for emacs-devel@gnu.org; Mon, 30 Jan 2023 08:47:26 -0500 Original-Received: by mail-ej1-x62b.google.com with SMTP id mf7so13123838ejc.6 for ; Mon, 30 Jan 2023 05:47:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=TDcr258sZNtNvVDUVbSeDNK4h6/+JJ7FsyP8ZhGPrJU=; b=Dhk/Fe4p7OVxYwAIEZ+g0L1C2xVQhgdVzvkVJWEntTAQtnMFmNiiAI4lRqvHmfbQ2a D8EgFjMtOvCCNLhI4i3JoZj0FAkLuDX5DdHUqeoJdLUAEtUaI4KXe+3rjr1KfepMiWma sJXIkRurxOsydqrJPE8hmzZuJKc+0OFoTsRENH2ZRK2QUjMGJT15nOZcYX9Y3qfI0JzU +/pveCa4q04D19fQASeThkhTS6mlQ4IjoELz4WkLQ5ayo8pPAzJLxuBV5LoIvMLIfoRS iOmMaBXRFxSWU3sisRDnmlZ+Cz+3Y8C6bV09u6li/W9JjIBxWUNT0izfkvjlXJinaeT0 OaMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=TDcr258sZNtNvVDUVbSeDNK4h6/+JJ7FsyP8ZhGPrJU=; b=AJ4lNHGiLvRDBMZqKasDTGWeUGgScCHWA2uKY8w9FEv1J06JDdwgQyUDzmZ4eOAcOO AUd8XdaZxwSX2Vbu3HCR64JoyeaXlRjkRvy6Z1tY4GzJLObDzaBuZGyHxcVuBWJJELsN H754ZuTyCYgOPpekOFBpfuo3ZTgrXtu3e7+hpcI42zgJKc9Jdnf+yFJmW7lJCdQk/Nyq h2sA16YTcLuhOD73gMTfGn2ciHVC0g/HZ9u9Nj4737N2VY5pQFZNz3iyArENOYqIkq5a UWJGZ5aQbY4K/s6XSBmPovMfDT1KrsHshhbtRXYF4tGQOoAhYBviKJVhm7SX3ELeG5l/ w+bg== X-Gm-Message-State: AO0yUKW4CIHRJlMnMdoHLPq7hc6fi1pJVIL9qdXtOy9E4EA6tzQpf9lQ /MLIbKDh81zTyWYid8aXS1JHXCHaj7NIkuCXCsYS/vni/kA= X-Google-Smtp-Source: AK7set+w/eCvGcl72536xWtQEMGz0nLB51Zioa8zw8+ytCZVLIvk5zFtXz0aM2e+kTMdSGM099V3SFlBsI/rvD4go30= X-Received: by 2002:a17:906:4e0e:b0:88a:9e08:330f with SMTP id z14-20020a1709064e0e00b0088a9e08330fmr349444eju.3.1675086441101; Mon, 30 Jan 2023 05:47:21 -0800 (PST) Received-SPF: pass client-ip=2a00:1450:4864:20::62b; envelope-from=zxnotdead@gmail.com; helo=mail-ej1-x62b.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:302783 Archived-At: --0000000000004a550f05f37b7483 Content-Type: multipart/alternative; boundary="0000000000004a550c05f37b7481" --0000000000004a550c05f37b7481 Content-Type: text/plain; charset="UTF-8" Code to try: (with-eval-after-load "rect.el" (defvar *rectangle-skip-lines* nil "If `t' -- skip empty lines, if `function' -- skip line if it returns `nil'. The function gets all arguments of `apply-to-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 (/= (line-beginning-position) (line-end-position)))) (apply function startcol endcol args)) (setq final-point (point)) (and (zerop (forward-line 1)) (bolp) (<= (point) endpt)))) final-point)))) --0000000000004a550c05f37b7481 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Code to try:

(with-eval-after-load "rect.el"
=C2=A0 (defvar *rectang= le-skip-lines* nil
"If `t' -- skip empty lines, if `function&#= 39; -- skip line if it returns `nil'.
The function gets all argument= s of `apply-to-rectangle' as input.")
=C2=A0 (defun apply-on-re= ctangle (function start end &rest args)
"Call FUNCTION for eac= h line of rectangle with corners at START, END.
FUNCTION is called with = two arguments: the start and end columns of the
rectangle, plus ARGS ext= ra arguments.=C2=A0 Point is at the beginning of line when
the function = is called.
Application of the FUNCTION is affected by the `*rectangle-sk= ip-lines*'.
The final point after the last operation will be returne= d."
(save-excursion
=C2=A0(let* ((cols (rectangle--pos-cols s= tart end))
(startcol (car cols))
(endcol (cdr cols))
(= startpt (progn (goto-char start) (line-beginning-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 startcol))
=C2=A0(setq s= tartcol endcol endcol col)))
;; Start looping over lines.
(goto-c= har startpt)
(while
(progn
=C2=A0(when (cond
((n= ull *rectangle-skip-lines*)
=C2=A0t)
((functionp *rectang= le-skip-lines*)
=C2=A0(apply *rectangle-skip-lines* function start= end args))
(t
=C2=A0(/=3D (line-beginning-position) (lin= e-end-position))))
(apply function startcol endcol args))
=C2= =A0(setq final-point (point))
=C2=A0(and (zerop (forward-line 1)) (b= olp)
=C2=A0 (<=3D (point) endpt))))
final-point))))
<= br>

--0000000000004a550c05f37b7481-- --0000000000004a550f05f37b7483 Content-Type: application/octet-stream; name="rect.el.patch" Content-Disposition: attachment; filename="rect.el.patch" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_ldiv2de80 LS0tIHJlY3QuZWwJMjAyMy0wMS0zMCAxNDoxODoyMi41NDIxNzY3MTAgKzAzMDAKKysrIHJlY3Qt cGF0Y2hlZC5lbAkyMDIzLTAxLTMwIDE1OjQ0OjE0Ljk1MzU3OTU2NiArMDMwMApAQCAtMTQzLDEy ICsxNDMsMTYgQEAKICAgKHJlY3RhbmdsZS0tcmVzZXQtcG9pbnQtY3J1dGNoZXMpKQogCiA7Ozsg UmVjdGFuZ2xlIG9wZXJhdGlvbnMuCisoZGVmdmFyICpyZWN0YW5nbGUtc2tpcC1saW5lcyogbmls CisgICJJZiBgdCcgLS0gc2tpcCBlbXB0eSBsaW5lcywgaWYgYGZ1bmN0aW9uJyAtLSBza2lwIGxp bmUgaWYgaXQgcmV0dXJucyBgbmlsJy4KK1RoZSBmdW5jdGlvbiBnZXRzIGFsbCBhcmd1bWVudHMg b2YgYGFwcGx5LXRvLXJlY3RhbmdsZScgYXMgaW5wdXQuIikKIAogKGRlZnVuIGFwcGx5LW9uLXJl Y3RhbmdsZSAoZnVuY3Rpb24gc3RhcnQgZW5kICZyZXN0IGFyZ3MpCiAgICJDYWxsIEZVTkNUSU9O IGZvciBlYWNoIGxpbmUgb2YgcmVjdGFuZ2xlIHdpdGggY29ybmVycyBhdCBTVEFSVCwgRU5ELgog RlVOQ1RJT04gaXMgY2FsbGVkIHdpdGggdHdvIGFyZ3VtZW50czogdGhlIHN0YXJ0IGFuZCBlbmQg Y29sdW1ucy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