From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Po Lu Newsgroups: gmane.emacs.devel Subject: Re: [BUG] comint-strip-ctrl-m doesn't function as documentation states Date: Wed, 20 Mar 2024 11:29:12 +0800 Message-ID: <87zfutpomv.fsf@yahoo.com> References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="40218"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: "emacs-devel@gnu.org" To: Jonathan Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Mar 20 04:30:23 2024 Return-path: Envelope-to: ged-emacs-devel@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 ) id 1rmmel-000AGn-7J for ged-emacs-devel@m.gmane-mx.org; Wed, 20 Mar 2024 04:30:23 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rmmds-00026T-92; Tue, 19 Mar 2024 23:29:28 -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 ) id 1rmmdq-00026J-OM for emacs-devel@gnu.org; Tue, 19 Mar 2024 23:29:26 -0400 Original-Received: from sonic315-22.consmr.mail.ne1.yahoo.com ([66.163.190.148]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rmmdo-0000OY-Vc for emacs-devel@gnu.org; Tue, 19 Mar 2024 23:29:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1710905361; bh=EQ12w0eiV6HVzCpZR4XxYIwKfXhtkDkVpe9LU45Gwp0=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From:Subject:Reply-To; b=tQNTmR7FthAvVgvUiN5h6/N/RewZDSeEtPskqGwIs64XMBhHZJAYbEjGG8jGI5vVl3eT+PFF40NPh5bNbuKHU7Tl2GUgFcthFKUpAzoxMb/vgyKhAN8ZeY/6STUvQuZNUgjwMdl53ZVsKYshtHOnBKDg5Itp5kgmbHVX7dhD4J4Yy2TYlMEkGLNGPx0KVuWVSgoX2W4EDXqkXsa8Ci9VthQ7FaMV4uChLrmptVUDZTJXVXuORkF3tXbbGmaH8340fGMNA8qVIAlaufFXk/ZSZ4aglSru0BB3YkIGGONgNagTTzQHZK0o4GgX2DyS3BuS9EYKWZC7V3m4Nu23+utPDw== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1710905361; bh=eWIBJRm5mHlAhsMZn9wIFd8Ua50rPQrS7v/QIbxZCX0=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=DtJEcz69wDxKI93LCOrgdihwwUgtGTmXMBySBzV3dbsWQ9U3dEgHII+3SgRwRA5MXjyNFiyt8ZVhyGr+B2fGUFZH1MUnQ4xEcB4HiaCQ6ZgHoj0/n+3jx7Gv9w1IGTILq23+ejfSWDUGZZjyZw/2cE0WeShbV6FQRUxux46owFMXc5azFnJe/zYorkNXa3lLkP4QDPZVkj9DBrsOg37KKXCZPhZ37RbBocIEwF9bA3fDc4WHuSfjzJAVbGsJNtbrdQEShNR5FdJ1QtVPv/5Uq6aOtyngRr2EB05gOQqfMQTkLQtiBGYDHDTeGxZD+FVjdTexTARvmnib2+Qe2LMX2w== X-YMail-OSG: PTtDPp0VM1kFIfl1RrlkbF.pKTor8zFJnejcbSwEeEPU.LctuTalDVHBXAKeSbc JdBR1S6w55_zU1L.K8KG5hIHyCFifz5Dj9bceYxORkvQRVBKgXuV0QvFTeAJBU9r7iaJDPeJGnoO DprNUuUYbDt2Aejn2DWyTxj8RfC5It7xx5EvhANSQ9rLcaofzsUZNPCGlumLm_3M61338Ct3Rd4B Wou1obcVb.3l5cWek9DkE5tfRK_H.AVSmS25CVcpeCn_NOrFKhetQlJL5Tz37OS.CbEK_4LL2rtr 0XnRPHtT6PRUP.Q2Za9F2A_XSMFZWJzAnu51C.Fms2MFuT9nTsKhebkYtHu7hKXFXU8_AM_hMiKL BFzG95B1H.paR7MZwhcULdSrPb9O45zSa80ONELfaGY_50SrzCYtcgWOeOUdl5kjr8JHEVwF9_Tg Jiz5y2pbgo6B4Kuo6diH3OyUTcuMgy4v2EnbgBxwlnUm8qq51x0lJpyRvIe9HIuk0oQKUQ7M9TyX 37kbuCE9PNyZuC.VoupcNwCIT8t3ly0kTOILnT260L2B0ehLcGoEgXyjc_lZ262YBM5F4pl4i2RR QcgRU2a8cJJH61CdCJ0qXF9qGF0mFp8eXRCg8JRuuMFXzaxy1L3dDeeAq9HsoStkZ0hiF_RGLTON 8JujN3s6iMOKJwxvJPNcqtumy4KwaMNlEo9v.J5QRUNUfYwBZZ746zyORkGF_KmPwBWhPMWhgMXP SuLVoHF8xgyzIP9971UGBTdzTbbDs.PcLghuJlpNFZSBLnGHjGTKrGp9TxXPfRjIChZrR_PTmQSq T.u0mVYO5OzHXRzzMfkauDt.lY_hfJkb8POcm_OeDH X-Sonic-MF: X-Sonic-ID: 675ebe3e-8d31-4b0c-ac4f-366947aa63da Original-Received: from sonic.gate.mail.ne1.yahoo.com by sonic315.consmr.mail.ne1.yahoo.com with HTTP; Wed, 20 Mar 2024 03:29:21 +0000 Original-Received: by hermes--production-sg3-6dc75bc8fb-smdnz (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 4351fc948a9e3aac918e55898ecb3e09; Wed, 20 Mar 2024 03:29:18 +0000 (UTC) In-Reply-To: (Jonathan's message of "Tue, 19 Mar 2024 19:55:55 +0000") X-Mailer: WebService/1.1.22129 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.yahoo Received-SPF: pass client-ip=66.163.190.148; envelope-from=luangruo@yahoo.com; helo=sonic315-22.consmr.mail.ne1.yahoo.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:317206 Archived-At: Jonathan writes: > Hey folks, > > There appears to either be a bug or just inaccurate documentation of > =comint-strip-ctrl-m=. At the very bottom, I've included some context > about my use case by which I discovered this bug that may or may not > be relevant to 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 > > > =comint-output-filter-functions= states the following: > > #+begin_quote > ...These functions get one argument, a string containing the text as originally > inserted. Note that this might not be the same as the buffer contents between > 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 =comint-strip-ctrl-m= it appears that > it completely ignores the =string= argument and instead uses > =(get-buffer-process (current-buffer))=. > > #+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 key." > (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 brefity > ))) > #+end_src > > This represents unexpected and undocumented behavior, as you > anticipate =comint-strip-ctrl-m= to behave like any other comint > output filter functions. I'd like to propose 3 different possible > solutions for a patch and would 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 > =comint-strip-ctrl-m= is a "unique" filter function among the other > filter functions that exist. This does not seem preferable to me. > > 2. Update the implementation of =comint-strip-ctrl-m= itself to > conform it to the documented API. This would mean anything currently > depending on it reading the =current-buffer= 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 =comint-strip-ctrl-m-output= or > something similar and deprecate the original. > > If we do decide to deprecate the original, I'm happy to include a > deprecation warning and keep an eye on it popping up in core to ensure > that we handle those issues over time. > > Any guidance would be useful. Thank you all for you're 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. Using this filter I had thought it would perform the task, but > it did not. So digging through the documentation I discovered this > error. I think it's pretty reasonable that filter functions conform to > the documented api or should at least be noted otherwise. Thanks. Please direct bug reports to bug-gnu-emacs@gnu.org that the bug tracker may record its progress: this list is for discussion that directly concerns development only.