From mboxrd@z Thu Jan  1 00:00:00 1970
Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail
From: Jonathan via "Bug reports for GNU Emacs,
 the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
Newsgroups: gmane.emacs.bugs
Subject: bug#69914: comint-strip-ctrl-m doesn't function as documentation
 states
Date: Wed, 20 Mar 2024 14:15:39 +0000
Message-ID: <kWMjSzKANkjXjPs49Bb449174wXkfwg1AhbKEp-6Gi9eTpRRLlpt70_FIR0WnhBzYf3fh-uJ2BzoHE7L3kV7mvYAMdnK8VSVnzhCYs_IIhM=@jds.work>
Reply-To: Jonathan <public@jds.work>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214";
	logging-data="18818"; mail-complaints-to="usenet@ciao.gmane.io"
To: 69914@debbugs.gnu.org
Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Mar 20 15:20:43 2024
Return-path: <bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org>
Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org
Original-Received: from lists.gnu.org ([209.51.188.17])
	by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
	(Exim 4.92)
	(envelope-from <bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org>)
	id 1rmwo7-0004fG-2P
	for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 20 Mar 2024 15:20:43 +0100
Original-Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <bug-gnu-emacs-bounces@gnu.org>)
	id 1rmwnp-0001nF-PG; Wed, 20 Mar 2024 10:20:25 -0400
Original-Received: from eggs.gnu.org ([2001:470:142:3::10])
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <Debian-debbugs@debbugs.gnu.org>)
 id 1rmwnn-0001mR-R1
 for bug-gnu-emacs@gnu.org; Wed, 20 Mar 2024 10:20:23 -0400
Original-Received: from debbugs.gnu.org ([2001:470:142:5::43])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.90_1) (envelope-from <Debian-debbugs@debbugs.gnu.org>)
 id 1rmwnm-0006Vi-NU
 for bug-gnu-emacs@gnu.org; Wed, 20 Mar 2024 10:20:23 -0400
Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2)
 (envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1rmwoQ-0002gB-12
 for bug-gnu-emacs@gnu.org; Wed, 20 Mar 2024 10:21:02 -0400
X-Loop: help-debbugs@gnu.org
Resent-From: Jonathan <public@jds.work>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@gnu.org
Resent-Date: Wed, 20 Mar 2024 14:21:01 +0000
Resent-Message-ID: <handler.69914.B.171094444610251@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: report 69914
X-GNU-PR-Package: emacs
X-Debbugs-Original-To: "bug-gnu-emacs@gnu.org" <bug-gnu-emacs@gnu.org>
Original-Received: via spool by submit@debbugs.gnu.org id=B.171094444610251
 (code B ref -1); Wed, 20 Mar 2024 14:21:01 +0000
Original-Received: (at submit) by debbugs.gnu.org; 20 Mar 2024 14:20:46 +0000
Original-Received: from localhost ([127.0.0.1]:47995 helo=debbugs.gnu.org)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
 id 1rmwo4-0002ez-RX
 for submit@debbugs.gnu.org; Wed, 20 Mar 2024 10:20:46 -0400
Original-Received: from lists.gnu.org ([209.51.188.17]:46652)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <public@jds.work>) id 1rmwkR-0002W4-FU
 for submit@debbugs.gnu.org; Wed, 20 Mar 2024 10:16:56 -0400
Original-Received: from eggs.gnu.org ([2001:470:142:3::10])
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <public@jds.work>) id 1rmwjn-0000gG-Km
 for bug-gnu-emacs@gnu.org; Wed, 20 Mar 2024 10:16:15 -0400
Original-Received: from mail-40136.proton.ch ([185.70.40.136])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <public@jds.work>) id 1rmwjk-0005kP-Cb
 for bug-gnu-emacs@gnu.org; Wed, 20 Mar 2024 10:16:15 -0400
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jds.work;
 s=protonmail; t=1710944169; x=1711203369;
 bh=VN+Vlq2I1tRIu82vYvMnfPgX3Y8Rx+yh86aLEQMrZXw=;
 h=Date:To:From:Subject:Message-ID:Feedback-ID:From:To:Cc:Date:
 Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector;
 b=SniNoX3ZxTA+3Vij56Bo0I5zmVvHoCQh9Us42K/pE5+6s3U5j8SCQncgAsX7ChpGm
 hBJj2V0tUZKrhPhsBH8iUZIVGKtLVHRR1VGBSeGSpw6jnumYFopnvUr9yxuXZ6gcRw
 lPSGS7CadXEckwG12/oaKi0vyfnyq5TBAYy52r0SkCTP848wfbD4tzff24ofPw9Jcj
 6Ucz24VXLadAN/mSpg4CYXV8bJ9A/Kc8Z4qzB7L1Dh8SZeXE29G4XquTSlC5PI+lXi
 xCFy3NptEVIzOhK9KCRF0dg5pUc2rbUcG55vF1ldajrHhAicTn5LBRXXrvatvFqkF/
 +s4sgeOI91f5g==
Feedback-ID: 104505699:user:proton
Received-SPF: pass client-ip=185.70.40.136; envelope-from=public@jds.work;
 helo=mail-40136.proton.ch
X-Spam_score_int: 4
X-Spam_score: 0.4
X-Spam_bar: /
X-Spam_report: (0.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
 DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FROM_SUSPICIOUS_NTLD=0.499,
 FROM_SUSPICIOUS_NTLD_FP=1.999, RCVD_IN_MSPIKE_H4=0.001,
 RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001,
 T_PDS_OTHER_BAD_TLD=0.01,
 T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no
X-Spam_action: no action
X-Mailman-Approved-At: Wed, 20 Mar 2024 10:20:38 -0400
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
X-BeenThere: bug-gnu-emacs@gnu.org
List-Id: "Bug reports for GNU Emacs,
 the Swiss army knife of text editors" <bug-gnu-emacs.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-gnu-emacs>,
 <mailto:bug-gnu-emacs-request@gnu.org?subject=unsubscribe>
List-Archive: <https://lists.gnu.org/archive/html/bug-gnu-emacs>
List-Post: <mailto:bug-gnu-emacs@gnu.org>
List-Help: <mailto:bug-gnu-emacs-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-gnu-emacs>,
 <mailto:bug-gnu-emacs-request@gnu.org?subject=subscribe>
Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org
Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org
Xref: news.gmane.io gmane.emacs.bugs:281862
Archived-At: <http://permalink.gmane.org/gmane.emacs.bugs/281862>

Hey folks,

There appears to either be a bug or just inaccurate documentation of =3Dcom=
int-strip-ctrl-m=3D. At the very bottom, I've included some context about m=
y use case by which I discovered this bug that may or may not be relevant t=
o you. The documentation for that function states:

#+begin_quote
Strip trailing ^M characters from the current output group.

This function could be on comint-output-filter-functions or bound to a key.
#+end_quote

=3Dcomint-output-filter-functions=3D states the following:

#+begin_quote
...These functions get one argument, a string containing the text as origin=
ally
inserted.  Note that this might not be the same as the buffer contents betw=
een
comint-last-output-start and the buffer's process-mark, if other filter
functions have already modified the buffer.
#+end_quote

Looking at the implementation of =3Dcomint-strip-ctrl-m=3D it appears that =
it completely ignores the =3Dstring=3D argument and instead uses =3D(get-bu=
ffer-process (current-buffer))=3D in direct contradiction to the documentat=
ion.

#+begin_src emacs-lisp
(defun comint-strip-ctrl-m (&optional _string interactive)
  "Strip trailing `^M' characters from the current output group.
This function could be on `comint-output-filter-functions' or bound to a ke=
y."
  (interactive (list nil t))
  (let ((process (get-buffer-process (current-buffer))))
    (if (not process)
        ;; This function may be used in
        ;; `comint-output-filter-functions', and in that case, if
        ;; there's no process, then we should do nothing.  If
        ;; interactive, report an error.
        (when interactive
          (error "No process in the current buffer"))
      ;;; rest omitted for brevity
      )))
#+end_src

This represents unexpected and undocumented behavior, as you anticipate =3D=
comint-strip-ctrl-m=3D to behave like any other comint output filter functi=
ons. I'd like to propose 3 different possible solutions for a patch and wou=
ld like input on which is preferred as this code was originally introduced =
in 1994. I can submit a patch once a solution has been determined.

1. Update the documentation and leave as is. This is the simplest solution =
and would just require doc-string updates to indicate that =3Dcomint-strip-=
ctrl-m=3D is a "unique" filter function among the other filter functions th=
at exist. This does not seem preferable to me.

2. Update the implementation of =3Dcomint-strip-ctrl-m=3D itself to conform=
 it to the documented API. This would mean anything currently depending on =
it reading the =3Dcurrent-buffer=3D would break, and since there are plenty=
 of unknowns in that regard, this also does not seem preferable.

3. Add a new version of the function with a different name that conforms to=
 the documented API =3Dcomint-strip-ctrl-m-output=3D or something similar a=
nd deprecate the original.

If we do decide to deprecate the original, I'm happy to include a deprecati=
on warning and keep an eye on it popping up in core to ensure that we handl=
e those issues over time.

Any guidance would be useful. Thank you all for your hard work.

- Jonathan

PS: Additional Context as promised:

I was developing a package that runs SQL queries in a "hidden" SQLi buffer =
and so I needed to strip carriage return characters out of the output. Usin=
g this filter I had thought it would perform the task, but it did not. So d=
igging through the documentation I discovered this error. I think it's pret=
ty reasonable that filter functions conform to the documented api or should=
 at least be noted otherwise.