From: Constantin Kulikov <zxnotdead@gmail.com>
To: emacs-devel <emacs-devel@gnu.org>
Subject: Re: [PATCH] Make rectangle-select able to skip lines(empty one, for example)
Date: Mon, 30 Jan 2023 17:36:05 +0300 [thread overview]
Message-ID: <CAFkz2yqKz-KRHnp6LFuT0_miJejsrji_KcHb-3RMdSGA4Z--Ng@mail.gmail.com> (raw)
In-Reply-To: <CAFkz2ypJVCVKxGGvT6bT9FHvxVLr6-HOnbcy4VtqirG_POWiaA@mail.gmail.com>
[-- Attachment #1.1: Type: text/plain, Size: 1614 bytes --]
Actually it must be named: "*Make `apply-on-rectangle' able to skip lines*".
Reattaching the patch as .txt
--- rect.el 2023-01-30 14:18:22.542176710 +0300
+++ rect-patched.el 2023-01-30 15:44:14.953579566 +0300
@@ -143,12 +143,16 @@
(rectangle--reset-point-crutches))
;;; Rectangle operations.
+(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))
@@ -166,7 +170,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
+ (/= (line-beginning-position) (line-end-position))))
+ (apply function startcol endcol args))
(setq final-point (point))
(and (zerop (forward-line 1)) (bolp)
(<= (point) endpt))))
On Mon, 30 Jan 2023 at 16:47, Constantin Kulikov <zxnotdead@gmail.com>
wrote:
>
>
[-- Attachment #1.2: Type: text/html, Size: 2323 bytes --]
[-- Attachment #2: rect.el.patch.txt --]
[-- Type: text/plain, Size: 1449 bytes --]
--- rect.el 2023-01-30 14:18:22.542176710 +0300
+++ rect-patched.el 2023-01-30 15:44:14.953579566 +0300
@@ -143,12 +143,16 @@
(rectangle--reset-point-crutches))
;;; Rectangle operations.
+(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))
@@ -166,7 +170,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
+ (/= (line-beginning-position) (line-end-position))))
+ (apply function startcol endcol args))
(setq final-point (point))
(and (zerop (forward-line 1)) (bolp)
(<= (point) endpt))))
next prev parent reply other threads:[~2023-01-30 14:36 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-30 13:47 [PATCH] Make rectangle-select able to skip lines(empty one, for example) Constantin Kulikov
2023-01-30 14:36 ` Constantin Kulikov [this message]
2023-01-31 15:05 ` Constantin Kulikov
2023-01-31 16:18 ` [External] : " Drew Adams
2023-02-02 18:26 ` Constantin Kulikov
2023-02-02 19:53 ` Drew Adams
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAFkz2yqKz-KRHnp6LFuT0_miJejsrji_KcHb-3RMdSGA4Z--Ng@mail.gmail.com \
--to=zxnotdead@gmail.com \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).