Subject: Re: 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 00:14:16 -0400

>> Does the solution proposed by Augusto in bug#73527 fix your use case?
>> 
>> diff --git a/lisp/comint.el b/lisp/comint.el
>> index 188989ff8a4..2189b10e826 100644
>> --- a/lisp/comint.el
>> +++ b/lisp/comint.el
>> @@ -2796,7 +2796,7 @@ comint-delchar-or-maybe-eof
>>    (let ((proc (get-buffer-process (current-buffer))))
>>      (if (and (eobp) proc (= (point) (marker-position (process-mark proc))))
>>  	(comint-send-eof)
>> -      (delete-char arg))))
>> +      (funcall-interactively (keymap-lookup global-map "C-d") arg))))

I'd rather not make assumptions about what arguments that command takes
(i.e. use `call-interactively`, as in the code below).

> 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`.

Similarly, we could worry about the case where `C-d` is globally bound
to something that's completely different from some kind of "delete
char" command, in which case turning it into an "EOF" signal may make
very little sense, but there's not much we can do about that: the usual
way to accommodate that is to rely on `remap` instead but here we can't
do that because we specifically want to handle `C-d` bindings
differently from other bindings (e.g. `delete`) to the same command.

        Stefan

diff --git a/lisp/comint.el b/lisp/comint.el
index 188989ff8a4..35765c8427e 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 ()
+  "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."