Subject: bug#78262: 30.1; comint-delchar-or-maybe-eof doesn't respect delete-active-region

From: Stefan Monnier <[email-masked]>
Date: Sun, 11 May 2025 02:01:16 -0400

>> > This assumes that everyone will want the same command bound to C-d
>> > globally to be invoked by C-d in comint-mode.  But is that assumption
>> > necessarily true?
>> 
>> It's hard to handle all possible worlds at the same time, so I think
>> we have to presume the answer is "yes".  If they want something
>> different, they'll have to rebind it explicitly in `comint-mode-map`.
>
> The issue here is whether to support active region (which C-d does).
> Are we sure users of comint want that in respective modes?

The default global binding of `C-d` does not obey `delete-active-region`.

>> -(defun comint-delchar-or-maybe-eof (arg)
>> -  "Delete ARG characters forward or send an EOF to subprocess.
>> +(defun comint-delchar-or-maybe-eof ()
>> +  "Do like the global binding or send an EOF to subprocess.
>
> I think we need to leave ARG in place, at least as an optional
> argument, since otherwise this would be a breaking change.

Fair enough,

        Stefan

diff --git a/lisp/comint.el b/lisp/comint.el
index 188989ff8a4..56e18ac829b 100644
--- a/lisp/comint.el
+++ b/lisp/comint.el
@@ -2789,14 +2789,14 @@ comint-kill-input
     (if (> (point) (marker-position pmark))
 	(kill-region pmark (point)))))
 
-(defun comint-delchar-or-maybe-eof (arg)
-  "Delete ARG characters forward or send an EOF to subprocess.
+(defun comint-delchar-or-maybe-eof (&optional _arg)
+  "Do like the global binding or send an EOF to subprocess.
 Sends an EOF only if point is at the end of the buffer and there is no input."
-  (interactive "p" comint-mode)
+  (interactive nil comint-mode)
   (let ((proc (get-buffer-process (current-buffer))))
     (if (and (eobp) proc (= (point) (marker-position (process-mark proc))))
 	(comint-send-eof)
-      (delete-char arg))))
+      (call-interactively (lookup-key global-map (this-command-keys))))))
 
 (defun comint-send-eof ()
   "Send an EOF to the current buffer's process."