Subject: Re: bug#30085: 25.2: Documentation for cua-rectangle-mark-mode

From: Stefan Kangas <[email-masked]>
Date: Mon, 26 Oct 2020 18:50:35 -0700

Boruch Baum <[email-masked]> writes:

> 1. The docstring issue, until I realized I should ask.

Thanks, I've pushed that part to master in your name with some
touch-ups.  I also added a ChangeLog entry.  See commit cfc70e51c2 on
the master branch.

> 2. @Kim: At the end of the first diff block, I noted an issue about the
>   `cua--last-killed-rectangle' data structure. Could you set me right
>    about it?

I left this as a FIXME comment, since it doesn't seem like anyone knows
the answer.  Hopefully someone so inclined will take a closer look at
some point.

> 3. I noticed that `M-m' was bound to `cua-copy-rectangle-as-text'
>    instead of `back-to-indentation', so I took the liberty of writing a
>    function `cua-resize-rectangle-back-to-indentation' and binding it to
>    `M-m', which is what most users would expect. If this approved, to
>    what should be bound `cua-copy-rectangle-as-text'
>
> 4. Function `cua-resize-rectangle-bot' had a bug in that it always
>    placed point at the actual (point-max) even though the rectangle
>    corner would not be there. This would occur when (point-max) was at a
>    column number smaller than the left edge of the rectangle. The patch
>    file includes the fix.
>
> 5. Two commonly used navigation functions, normally bound to `C-a' and
>    `C-e' were not remapped. (DONE)

Could you please provide instructions for how to test the above parts?
I don't use this mode and it's not clear to me what to do.  Also, could
you perhaps split the patch up and make it clear which parts of your
code belong to which of the above points?

Ideally, if possible, you would also add ChangeLog entries as per
etc/CONTRIBUTE.

> 6. The help message is remapped from `C-?' to `M-?' for the sanity of
>    people like me who use emacs-nox and can only perform a `C-?' by
>    typing `C-x @ c ?'.

I don't understand which part of your patch this refers to, or how to
test it.  Could you please clarify?

> 7. The current keybindings are made using an old method of keystroke
>    definition that I find a bit scary. Is it OK / desirable to change
>    the method uniformly to use `kbd'?

I have no strong opinion on this, but it seems relatively minor.  Perhaps
it's not worth the code churn.

> First slow steps.

I've attached a diff with the parts of your patch that I didn't yet push
to master.

Thanks.
diff --git a/lisp/emulation/cua-rect.el b/lisp/emulation/cua-rect.el
index 7ca9dc1af1..52cdcd9767 100644
--- a/lisp/emulation/cua-rect.el
+++ b/lisp/emulation/cua-rect.el
@@ -423,10 +423,23 @@ cua-resize-rectangle-bol
         (cua--rectangle-corner -1))
     (cua--rectangle-resized)))
 
+(defun cua-resize-rectangle-back-to-indentation ()
+  "Resize rectangle to first non-whitespace character on the left."
+  (interactive)
+  (unless (bolp)
+    (back-to-indentation)
+    (cua--rectangle-left (current-column))
+    (if (cua--rectangle-right-side)
+        (cua--rectangle-corner -1))
+    (cua--rectangle-resized)))
+
 (defun cua-resize-rectangle-bot ()
   "Resize rectangle to bottom of buffer."
   (interactive)
   (goto-char (point-max))
+  (let ((col (cua--rectangle-column)))
+    (when (< (current-column) col)
+      (cua--forward-line -1)))
   (move-to-column (cua--rectangle-column))
   (cua--rectangle-bot t)
   (cua--rectangle-resized))
@@ -1503,6 +1516,8 @@ cua--init-rectangles
   (define-key cua--rectangle-keymap [remap previous-line]       'cua-resize-rectangle-up)
   (define-key cua--rectangle-keymap [remap end-of-line]         'cua-resize-rectangle-eol)
   (define-key cua--rectangle-keymap [remap beginning-of-line]   'cua-resize-rectangle-bol)
+  (define-key cua--rectangle-keymap [remap move-end-of-line]       'cua-resize-rectangle-eol)
+  (define-key cua--rectangle-keymap [remap move-beginning-of-line] 'cua-resize-rectangle-bol)
   (define-key cua--rectangle-keymap [remap end-of-buffer]       'cua-resize-rectangle-bot)
   (define-key cua--rectangle-keymap [remap beginning-of-buffer] 'cua-resize-rectangle-top)
   (define-key cua--rectangle-keymap [remap scroll-down]         'cua-resize-rectangle-page-up)
@@ -1522,7 +1537,7 @@ cua--init-rectangles
   (define-key cua--rectangle-keymap "\r"     'cua-rotate-rectangle)
   (define-key cua--rectangle-keymap "\t"     'cua-indent-rectangle)
 
-  (define-key cua--rectangle-keymap [(control ??)] 'cua-help-for-rectangle)
+  (define-key cua--rectangle-keymap (kbd "M-?") 'cua-help-for-rectangle)
 
   (define-key cua--rectangle-keymap [mouse-1]	   'cua-mouse-set-rectangle-mark)
   (define-key cua--rectangle-keymap [down-mouse-1] 'cua--mouse-ignore)
@@ -1547,6 +1562,9 @@ cua--init-rectangles
   (cua--rect-M/H-key ?k	'cua-cut-rectangle-as-text)
   (cua--rect-M/H-key ?l	'cua-downcase-rectangle)
   (cua--rect-M/H-key ?m	'cua-copy-rectangle-as-text)
+; (cua--rect-M/H-key ?m	'cua-copy-rectangle-as-text) ;; TBD
+  (define-key cua--rectangle-keymap [remap back-to-indentation] 'cua-resize-rectangle-back-to-indentation)
+
   (cua--rect-M/H-key ?n	'cua-sequence-rectangle)
   (cua--rect-M/H-key ?o	'cua-open-rectangle)
   (cua--rect-M/H-key ?p	'cua-toggle-rectangle-virtual-edges)