> 1. Lose the *...* earmuffs. Elisp doesn't embrace that CL convention for defvars. I wonder, is it because Emacs had only dynamic binding? Maybe now the "*..*" can be helpful to distinguish dynamic vars from lexical. > 2. The var's doc should say what it means by "skip". Apparently it means (only) that function `apply-on-rectangle' doesn't apply its FUNCTION arg to empty lines. I think it's important to say that the var affects (only) that function's behavior. I think the application of FUNCTION is the main part of `apply-on-rectangle', so it is more or less obvious. And you can easily see the effect in GUI, when using `rectangle-mark-mode' (C-x SPC). I'm not quite sure how to name the var. *What it does:* For example you have a buffer "env.sh" with content: *"FOO=1BAR=2"* Now if you do `M-<' beginning-of-buffer `C-x SPC' rectangle-mark-mode `C-n' next-line `C-n' next-line `C-t' string-rectangle `export RET' With standard rect.el you will get: *"export FOO=1export export BAR=2"* With patched version and `rectangle-select-skip-line'(new name of var) set to `t': *"export FOO=1export BAR=2"* *New version of patch:* --- rect-orig.el 2023-01-31 17:25:08.498658466 +0300 +++ rect-patched.el 2023-02-02 20:21:11.041198925 +0300 @@ -144,11 +144,18 @@ ;;; Rectangle operations. +(defvar rectangle-select-skip-line nil + "Control the `apply-on-rectangle' execution. +`nil' -- apply action to selected lines, `t' -- skip empty lines, +`function' -- skip line if it return non-`nil'. +The function get 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. +The `rectangle-select-skip-line' variable allow to skip lines. The final point after the last operation will be returned." (save-excursion (let* ((cols (rectangle--pos-cols start end)) @@ -166,7 +173,14 @@ (goto-char startpt) (while (progn - (apply function startcol endcol args) + (when (cond + ((null rectangle-select-skip-line) + t) + ((functionp rectangle-select-skip-line) + (apply rectangle-select-skip-line 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)))) On Tue, 31 Jan 2023 at 19:18, Drew Adams wrote: > >