From unknown Tue Jun 17 20:21:05 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#61523 <61523@debbugs.gnu.org> To: bug#61523 <61523@debbugs.gnu.org> Subject: Status: python.el first prompt missing field=output Reply-To: bug#61523 <61523@debbugs.gnu.org> Date: Wed, 18 Jun 2025 03:21:05 +0000 retitle 61523 python.el first prompt missing field=3Doutput reassign 61523 emacs submitter 61523 JD Smith severity 61523 normal thanks From debbugs-submit-bounces@debbugs.gnu.org Tue Feb 14 21:35:05 2023 Received: (at submit) by debbugs.gnu.org; 15 Feb 2023 02:35:05 +0000 Received: from localhost ([127.0.0.1]:57489 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pS7dQ-0002sh-Tf for submit@debbugs.gnu.org; Tue, 14 Feb 2023 21:35:05 -0500 Received: from lists.gnu.org ([209.51.188.17]:39824) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pS7dP-0002sa-FY for submit@debbugs.gnu.org; Tue, 14 Feb 2023 21:35:04 -0500 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 1pS7dP-0002ke-6G for bug-gnu-emacs@gnu.org; Tue, 14 Feb 2023 21:35:03 -0500 Received: from mail-qt1-x834.google.com ([2607:f8b0:4864:20::834]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pS7dM-0004lU-GH for bug-gnu-emacs@gnu.org; Tue, 14 Feb 2023 21:35:02 -0500 Received: by mail-qt1-x834.google.com with SMTP id m12so20491737qth.4 for ; Tue, 14 Feb 2023 18:34:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:date:message-id:subject:mime-version:from:from:to:cc:subject :date:message-id:reply-to; bh=jTgHJ7+Y5NoYrMTUAwJY0SMs4umyupYSLSUQdSxAPik=; b=VpjcguHsrRKFm0ICRQBF3TXfVhf9i3i6I754lXYf3A8BMgfMonEMA+eXqhODgh/NyI lPNjRBqWVfCbGDU+kLvasFMQMq+jdpbL15B42UUHyVcxKfqqs6re22M9yps99Z7Mw6sy w/54b7l8OwhhHybj1UJ+l13D5fOczyXq/ysUTKaXNen0Sed8zyZZcsbX6H7vcVlnwj7K Bt4/7Ejg4e3K6q+6keW5R+N9WobYVi3tKTUUVmiHwdZ0uqZxxxsK4UBK9rZaBfTq+Cd8 LZIlNB0GScRnj0Gmxio+zu3PSe0m7crhWcXPv5RRs7tOblhjN984uprWcnldeaz6XE3O gt4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:date:message-id:subject:mime-version:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=jTgHJ7+Y5NoYrMTUAwJY0SMs4umyupYSLSUQdSxAPik=; b=jkEAWEK6ec82usIgWSWl8yxFoEUmdMnvjwHywZXUwQhh+oRbq5RPXJby19MAEpVcfz pwGGgl21CKMSg+I501VvFeX5LqCbC4be5H79YJ8X8fC7cbmYGVb4tHuuszEIBsvJczZ7 4i/mLIMVwTWPePRX4W2XAls+5c+9cSreHIlTEFzJxBPn7QzNBGlHq/R8m6SaIG/qRt+d giLcoUnWcrMs5AbN6vriADZiYndVR4OwYNGnYLn5kvh1CdN3eIDVmJf+pw5oMJB+Hrwh qwcYVa0onGSMNmsdTaQ4BX8sZ0c0E0oWIpESOxikfhqhpTzm6fGH66XIwfFO7bQw0Xe5 jF4A== X-Gm-Message-State: AO0yUKUix8hRuUjYmLu8nS/kGeLqSAvgCQ+lk9JR8poRN3WqiyEQU0iZ bvCQynWgtThKu/IdNXMg8equ3JA2PnL0zA== X-Google-Smtp-Source: AK7set+xkx22mVyThgMTclo5abDpZpC4asvHA0KmSfpfKwBrydecch4RCmqsysefHgqfHHJI7BbsJA== X-Received: by 2002:ac8:5891:0:b0:3ba:1d8d:f6eb with SMTP id t17-20020ac85891000000b003ba1d8df6ebmr785766qta.58.1676428498496; Tue, 14 Feb 2023 18:34:58 -0800 (PST) Received: from smtpclient.apple (cm-24-53-184-207.buckeyecom.net. [24.53.184.207]) by smtp.gmail.com with ESMTPSA id y10-20020ac8128a000000b003b68ea3d5c8sm12286260qti.41.2023.02.14.18.34.57 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 Feb 2023 18:34:57 -0800 (PST) From: JD Smith Content-Type: multipart/alternative; boundary="Apple-Mail=_C0418AB0-C293-42F2-940A-4C5AA3AE1A9D" Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\)) Subject: python.el first prompt missing field=output Message-Id: <5C4372CF-01C1-4867-9BCD-B5D1CDE6F70C@gmail.com> Date: Tue, 14 Feb 2023 21:34:52 -0500 To: bug-gnu-emacs@gnu.org X-Mailer: Apple Mail (2.3696.120.41.1.1) Received-SPF: pass client-ip=2607:f8b0:4864:20::834; envelope-from=jdtsmith@gmail.com; helo=mail-qt1-x834.google.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, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.3 (-) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) --Apple-Mail=_C0418AB0-C293-42F2-940A-4C5AA3AE1A9D Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 The first >>> python prompt in an inferior-python-mode comint buffer is = incorrectly missing its field=3Doutput text property. This causes a few = problems: C-c C-a at the first prompt moves back to before the prompt. Mouse-2 clicking on the first input brings the first prompt along with = it forward to the current prompt. If you recall history at the first prompt, then change your mind and = =E2=80=9Crestore=E2=80=9D(missing) input, comint=E2=80=99s history = mechanism mistakenly identifies the prompt text (and sometimes text = before the first prompt like python version information) as input, = copying it to the prompt line. =20 If the prompt is read-only, that will now be stuck on the input line. = Only Return and adding it to history is possible from here, which is not = ideal. The reason for the missing field property is subtle: python.el sets up = `python-shell-comint-watch-for-first-prompt-output-filter' among the = `comint-output-filter-functions=E2=80=99. These filter functions are = run just after the prompt string is inserted by `comint-output-filter'. That function arranges to send setup code to define __PYTHON_EL_eval and = perform other setup, with no output. This process interaction = recursively calls `comint-output-filter=E2=80=99 several times. The setup code places a function on = `comint-preoutput-filter-functions=E2=80=99 to accumulate the hidden = output, and search for the next prompt. It finally returns the empty = string to avoid placing any output in the comint buffer. Even though no output is placed in the buffer in these recursive calls, = `comint-last-output-start=E2=80=99 gets moved forward to the end of the = first prompt (which again, is already in the buffer): =20 (set-marker comint-last-output-start (point)). When the recursive process filter calls finally finish and control = returns to the =E2=80=9Couter=E2=80=9D filter function invocation =E2=80=94= the one which has originally inserted the prompt text =E2=80=94 the = application of the field=3Doutput property to the original prompt is now = erroneously made over a zero character range at the very end of the = buffer: (add-text-properties comint-last-output-start (point) `(rear-nonsticky ,comint--prompt-rear-nonsticky front-sticky (field = inhibit-line-move-field-capture) field output inhibit-line-move-field-capture = t)) A simple fix (in python.el) would be to run the python setup from the = main event loop instead of in place, i.e. to avoid recursively calling = the process filter. A more defensive fix (in comint) would be to store = the value of `comint-last-output-start' (or use some other =E2=80=9Cstarti= ng marker=E2=80=9D) to guard against filter-function disturbance. This = is already done for the process mark. --Apple-Mail=_C0418AB0-C293-42F2-940A-4C5AA3AE1A9D Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 The = first >>> python prompt in an inferior-python-mode comint = buffer is incorrectly missing its field=3Doutput text property. =  This causes a few problems:
  1. C-c C-a at the first prompt moves back to before the = prompt.
  2. Mouse-2 clicking on the first input brings = the first prompt along with it forward to the current prompt.
  3. If you recall history at the first prompt, then change your = mind and =E2=80=9Crestore=E2=80=9D(missing)  input, comint=E2=80=99s = history mechanism mistakenly identifies the prompt text (and sometimes = text before the first prompt like python version information) as input, = copying it to the prompt line.  
  4. If the prompt = is read-only, that will now be stuck on the input line.  Only = Return and adding it to history is possible from here, which is not = ideal.
The reason for the missing field = property is subtle:

  1. python.el sets up = `python-shell-comint-watch-for-first-prompt-output-filter' among the = `comint-output-filter-functions=E2=80=99.  These filter functions = are run just after the prompt string is inserted by = `comint-output-filter'.
  2. That function arranges = to send setup code to define __PYTHON_EL_eval and perform other setup, = with no output.  This process interaction recursively calls = `comint-output-filter=E2=80=99 several times.
  3. The = setup code places a function on `comint-preoutput-filter-functions=E2=80=99= to accumulate the hidden output, and search for the next prompt. =  It finally returns the empty string to avoid placing any output in = the comint buffer.
  4. Even though no output is placed in = the buffer in these recursive calls, `comint-last-output-start=E2=80=99 = gets moved forward to the end of the first prompt (which again, is = already in the buffer):  
    • (set-marker comint-last-output-start (point)).
  5. When the recursive process filter calls finally finish and = control returns to the =E2=80=9Couter=E2=80=9D filter function = invocation =E2=80=94 the one which has originally inserted the prompt = text =E2=80=94 the application of the field=3Doutput property to the = original prompt is now erroneously made over a zero character range at = the very end of the buffer:

= (add-text-properties comint-last-output-start (point)
                =                     =  `(rear-nonsticky
  =     ,comint--prompt-rear-nonsticky
=       front-sticky
=       (field = inhibit-line-move-field-capture)
=       field output
=       inhibit-line-move-field-capture = t))

A = simple fix (in python.el) would be to run the python setup from the main = event loop instead of in place, i.e. to avoid recursively calling the = process filter.  A more defensive fix (in comint) would be to store = the value of `comint-last-output-start' (or use some other =E2=80=9Cstarti= ng marker=E2=80=9D) to guard against filter-function disturbance. =  This is already done for the process mark.

= --Apple-Mail=_C0418AB0-C293-42F2-940A-4C5AA3AE1A9D--