From unknown Sun Jun 22 04:30:09 2025 X-Loop: help-debbugs@gnu.org Subject: bug#60466: 30.0.50; python-shell-send-region fails when the region starts in the middle of the first line Resent-From: kobarity Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 01 Jan 2023 12:24:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 60466 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: 60466@debbugs.gnu.org X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.16725757864813 (code B ref -1); Sun, 01 Jan 2023 12:24:01 +0000 Received: (at submit) by debbugs.gnu.org; 1 Jan 2023 12:23:06 +0000 Received: from localhost ([127.0.0.1]:40409 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pBxMo-0001FZ-1A for submit@debbugs.gnu.org; Sun, 01 Jan 2023 07:23:06 -0500 Received: from lists.gnu.org ([209.51.188.17]:33664) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pBxMl-0001FQ-0s for submit@debbugs.gnu.org; Sun, 01 Jan 2023 07:23: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 1pBxMk-0007e5-S9 for bug-gnu-emacs@gnu.org; Sun, 01 Jan 2023 07:23:02 -0500 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pBxMi-0002C7-Iq for bug-gnu-emacs@gnu.org; Sun, 01 Jan 2023 07:23:02 -0500 Received: by mail-pf1-x42b.google.com with SMTP id w203so527809pfc.12 for ; Sun, 01 Jan 2023 04:22:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:user-agent:subject:to:from:message-id:date:from:to:cc :subject:date:message-id:reply-to; bh=PllAdR/r3gocQdWg39K4XmmZkDSVlD1kole9+vKooeM=; b=pmXr0w9ah0jR3HU75dLmZ08/PVsZn8tEcM0rT2pBLM6MnIO0U+lePYL5F6JwhIOYhR xuKkFhRb7c4HGBA0vhLSYGlyxYWO1rGFdod2AhmDeq9HGzrw8ZgFloPMJq0NNWCfrJkL mNOOeqjR4eu0xTLx9NShpPqi0q2iTIB+2ONXywRS8Evcj9IIPssfWvrxy27oKmhuzS55 j6+zhnub3mHDFjLKedkpdR7OBRB8lunatE6xwXykelwrDu7uQcWHIAWqc8itPUR9aDrO WVB41HMhQdsxL099X9LS+13qYqIsi3bwbu/wSglrt2g9Q/aBc6JNMgJ7KLUNBLuvqUnT xBEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:user-agent:subject:to:from:message-id:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=PllAdR/r3gocQdWg39K4XmmZkDSVlD1kole9+vKooeM=; b=ndDngC2USLDqjVVm0BAi8aFpex2geiE+N7pz3MMBqAaNN4qSzpdnJn+YOpbTjqmXOq 0R6XNRuTOGnvV2s9ImplHJUcyfIu86TQnUXmYigPnbSVXilvoorqndSvQfVeWksd7/Gy pu52xwGYobiqGft/aaJBqUwGFyFJXyk1xqxjeq0FyaP4YK1tApaUiJO3lGj1Q6NvGHfV cLzqGQjGCZ82Bqggl6MK8WszRUz/K/T9WfOMeDCO4RllJ+w/viO5fqL3T4ZaiXcEu0uD pKziCiQl2jjr7+55WDKAaE9VNJCHuYt6q2PJMHlk6NdJ7dcJWz1BNWFsoTXKEKHMWfRK wpEQ== X-Gm-Message-State: AFqh2kq6ykbKEzx0JP+3YnM30gJcTwY9X8b9e68lZfKzwWrZ+5/GecNR X7jo+/QBZfRLIPIlmUxw98ofSIlr7dk= X-Google-Smtp-Source: AMrXdXvPdOkZ2+pD8qb4+oEgcn985rJxPtbpJSwZDdZ90vN1yybFniQDIuUNuTGIfFlpbWAppcDqXw== X-Received: by 2002:a62:55c3:0:b0:56b:dae1:e946 with SMTP id j186-20020a6255c3000000b0056bdae1e946mr36522426pfb.28.1672575777352; Sun, 01 Jan 2023 04:22:57 -0800 (PST) Received: from localhost (58x12x133x161.ap58.ftth.ucom.ne.jp. [58.12.133.161]) by smtp.gmail.com with ESMTPSA id 68-20020a620447000000b00578199ea5afsm16569603pfe.9.2023.01.01.04.22.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Jan 2023 04:22:55 -0800 (PST) Date: Sun, 01 Jan 2023 21:22:44 +0900 Message-ID: From: kobarity User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?Q?Goj=C5=8D?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/30.0.50 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: multipart/mixed; boundary="Multipart_Sun_Jan__1_21:22:44_2023-1" Received-SPF: pass client-ip=2607:f8b0:4864:20::42b; envelope-from=kobarity@gmail.com; helo=mail-pf1-x42b.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, 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-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 (--) --Multipart_Sun_Jan__1_21:22:44_2023-1 Content-Type: text/plain; charset=US-ASCII Hello, `python-shell-send-region' fails with the following error when the region starts in the middle of the first line. Wrong type argument: wholenump, -1 This is caused by the code to insert the coding cookie in `python-shell-buffer-substring'. I think that the current code assumes that the region begins at line beginning position. However, there are some use-cases where the region starts in the middle of the line as discussed in #60142. So I think the special treatment in case of point-min should be extended to case of first line. Attached is a patch to implement this. -- In GNU Emacs 30.0.50 (build 6, x86_64-pc-linux-gnu, X toolkit, cairo version 1.16.0, Xaw scroll bars) of 2023-01-01 built on ubuntu Repository revision: 9596e683834a36060497903b47b870b338d88095 Repository branch: master System Description: Ubuntu 22.04.1 LTS Configured features: ACL CAIRO FREETYPE GIF GLIB GMP GNUTLS GSETTINGS HARFBUZZ JPEG LIBSELINUX LIBXML2 MODULES NOTIFY INOTIFY PDUMPER PNG SECCOMP SOUND SQLITE3 THREADS TIFF TOOLKIT_SCROLL_BARS TREE_SITTER X11 XDBE XIM XPM LUCID ZLIB Important settings: value of $LANG: en_US.UTF-8 locale-coding-system: utf-8-unix Major mode: Lisp Interaction Minor modes in effect: tooltip-mode: t global-eldoc-mode: t eldoc-mode: t show-paren-mode: t electric-indent-mode: t mouse-wheel-mode: t tool-bar-mode: t menu-bar-mode: t file-name-shadow-mode: t global-font-lock-mode: t font-lock-mode: t blink-cursor-mode: t line-number-mode: t indent-tabs-mode: t transient-mark-mode: t auto-composition-mode: t auto-encryption-mode: t auto-compression-mode: t Load-path shadows: None found. Features: (shadow sort mail-extr emacsbug message mailcap yank-media puny dired dired-loaddefs rfc822 mml mml-sec password-cache epa derived epg rfc6068 epg-config gnus-util text-property-search time-date subr-x mm-decode mm-bodies mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader cl-loaddefs cl-lib sendmail rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mail-utils term/screen term/xterm xterm byte-opt gv bytecomp byte-compile rmc iso-transl tooltip cconv eldoc paren electric uniquify ediff-hook vc-hooks lisp-float-type elisp-mode mwheel term/x-win x-win term/common-win x-dnd tool-bar dnd fontset image regexp-opt fringe tabulated-list replace newcomment text-mode lisp-mode prog-mode register page tab-bar menu-bar rfn-eshadow isearch easymenu timer select scroll-bar mouse jit-lock font-lock syntax font-core term/tty-colors frame minibuffer nadvice seq simple cl-generic indonesian philippine cham georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek romanian slovak czech european ethiopic indian cyrillic chinese composite emoji-zwj charscript charprop case-table epa-hook jka-cmpr-hook help abbrev obarray oclosure cl-preloaded button loaddefs theme-loaddefs faces cus-face macroexp files window text-properties overlay sha1 md5 base64 format env code-pages mule custom widget keymap hashtable-print-readable backquote threads inotify dynamic-setting system-font-setting font-render-setting cairo x-toolkit x multi-tty make-network-process emacs) Memory information: ((conses 16 45803 5938) (symbols 48 5813 0) (strings 32 14944 1951) (string-bytes 1 421917) (vectors 16 8284) (vector-slots 8 104561 8256) (floats 8 24 281) (intervals 56 200 0) (buffers 984 10)) --Multipart_Sun_Jan__1_21:22:44_2023-1 Content-Type: application/octet-stream; type=patch; name="0001-Fix-python-shell-buffer-substring-when-START-is-in-t.patch" Content-Disposition: attachment; filename="0001-Fix-python-shell-buffer-substring-when-START-is-in-t.patch" Content-Transfer-Encoding: 7bit >From b3f58b9d3977ae52fed572e0a33cda02ade1fcc2 Mon Sep 17 00:00:00 2001 From: kobarity Date: Sun, 1 Jan 2023 21:09:10 +0900 Subject: [PATCH] Fix python-shell-buffer-substring when START is in the middle of 1st line * lisp/progmodes/python.el (python-shell-buffer-substring): Instead of checking whether START is point-min, check whether START is in the first line. * test/lisp/progmodes/python-tests.el (python-shell-buffer-substring-18): New test. --- lisp/progmodes/python.el | 9 +++++---- test/lisp/progmodes/python-tests.el | 10 ++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 59164d7d50c..c399bbc64f8 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -3766,15 +3766,16 @@ python-shell-buffer-substring (line-beginning-position) start)))) (substring (buffer-substring-no-properties start end)) - (starts-at-point-min-p (save-restriction - (widen) - (= (point-min) start))) + (starts-at-first-line-p (save-restriction + (widen) + (goto-char start) + (= (line-number-at-pos) 1))) (encoding (python-info-encoding)) (toplevel-p (zerop (save-excursion (goto-char start) (python-util-forward-comment 1) (current-indentation)))) - (fillstr (cond (starts-at-point-min-p + (fillstr (cond (starts-at-first-line-p nil) ((not no-cookie) (concat diff --git a/test/lisp/progmodes/python-tests.el b/test/lisp/progmodes/python-tests.el index eac558db10f..df71990278e 100644 --- a/test/lisp/progmodes/python-tests.el +++ b/test/lisp/progmodes/python-tests.el @@ -4520,6 +4520,16 @@ python-shell-buffer-substring-17 (python-tests-look-at "\"\"\"")) "# -*- coding: utf-8 -*-\n\nif True:\n a = 1\n b = 2\n\n")))) +(ert-deftest python-shell-buffer-substring-18 () + "Check substring from the part of the first line." + (python-tests-with-temp-buffer + "s = 'test' +" + (should (string= (python-shell-buffer-substring + (python-tests-look-at "'test'") + (pos-eol)) + "'test'")))) + ;;; Shell completion -- 2.34.1 --Multipart_Sun_Jan__1_21:22:44_2023-1-- From unknown Sun Jun 22 04:30:09 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.505 (Entity 5.505) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: kobarity Subject: bug#60466: closed (Re: bug#60466: 30.0.50; python-shell-send-region fails when the region starts in the middle of the first line) Message-ID: References: <83cz7qu3dx.fsf@gnu.org> X-Gnu-PR-Message: they-closed 60466 X-Gnu-PR-Package: emacs Reply-To: 60466@debbugs.gnu.org Date: Sat, 07 Jan 2023 08:59:01 +0000 Content-Type: multipart/mixed; boundary="----------=_1673081941-1743-1" This is a multi-part message in MIME format... ------------=_1673081941-1743-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #60466: 30.0.50; python-shell-send-region fails when the region starts in t= he middle of the first line which was filed against the emacs package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 60466@debbugs.gnu.org. --=20 60466: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D60466 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1673081941-1743-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 60466-done) by debbugs.gnu.org; 7 Jan 2023 08:58:53 +0000 Received: from localhost ([127.0.0.1]:56413 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pE52T-0000Rm-JG for submit@debbugs.gnu.org; Sat, 07 Jan 2023 03:58:53 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59096) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pE52R-0000RZ-Oi for 60466-done@debbugs.gnu.org; Sat, 07 Jan 2023 03:58:52 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pE52M-00078k-CH; Sat, 07 Jan 2023 03:58:46 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=gCVxyMbI6zZ11VcrX6g+Npx1M9v4MroQU6PCP/7JUD0=; b=IQciDSrzEYgD eQFpHvTjPAYbnxA3GWYN3+xsQGI+Qe+As91gZrs1ngw3X/S6TiPrz9M0XHbBHuBkHqxtdMGt8xQhA TwdnK/nYg2EnItPWuHKQshgdTlky6SPvYwdWUSl7hN9UykPWj110oU921D7/rhy9Y9UJJVPNid3eu grGuVvO6lfbVlBhSdsOlNJ++mBdRWs8G6LzK2CAYea2hf2SN8Mb4Vges9QCqkrGwupUybmhJVaGGS MvnJ7kwY7OoFp4/tlrql59xksBwoeiFCl5huKb+YqHwMhFwH4sNQgGA7n7jvWIslN+I1EKPeLCU3w mSQpgCcsf0PsRWmI+UPQrg==; Received: from [87.69.77.57] (helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pE52L-0005pn-Rh; Sat, 07 Jan 2023 03:58:46 -0500 Date: Sat, 07 Jan 2023 10:59:06 +0200 Message-Id: <83cz7qu3dx.fsf@gnu.org> From: Eli Zaretskii To: kobarity In-Reply-To: (message from kobarity on Sun, 01 Jan 2023 21:22:44 +0900) Subject: Re: bug#60466: 30.0.50; python-shell-send-region fails when the region starts in the middle of the first line References: X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 60466-done Cc: 60466-done@debbugs.gnu.org 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: -3.3 (---) > Date: Sun, 01 Jan 2023 21:22:44 +0900 > From: kobarity > > `python-shell-send-region' fails with the following error when the > region starts in the middle of the first line. > > Wrong type argument: wholenump, -1 > > This is caused by the code to insert the coding cookie in > `python-shell-buffer-substring'. I think that the current code > assumes that the region begins at line beginning position. However, > there are some use-cases where the region starts in the middle of the > line as discussed in #60142. So I think the special treatment in case > of point-min should be extended to case of first line. Attached is a > patch to implement this. Thanks, installed on the emacs-29 branch, and closing the bug. ------------=_1673081941-1743-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 1 Jan 2023 12:23:06 +0000 Received: from localhost ([127.0.0.1]:40409 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pBxMo-0001FZ-1A for submit@debbugs.gnu.org; Sun, 01 Jan 2023 07:23:06 -0500 Received: from lists.gnu.org ([209.51.188.17]:33664) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pBxMl-0001FQ-0s for submit@debbugs.gnu.org; Sun, 01 Jan 2023 07:23: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 1pBxMk-0007e5-S9 for bug-gnu-emacs@gnu.org; Sun, 01 Jan 2023 07:23:02 -0500 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pBxMi-0002C7-Iq for bug-gnu-emacs@gnu.org; Sun, 01 Jan 2023 07:23:02 -0500 Received: by mail-pf1-x42b.google.com with SMTP id w203so527809pfc.12 for ; Sun, 01 Jan 2023 04:22:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:user-agent:subject:to:from:message-id:date:from:to:cc :subject:date:message-id:reply-to; bh=PllAdR/r3gocQdWg39K4XmmZkDSVlD1kole9+vKooeM=; b=pmXr0w9ah0jR3HU75dLmZ08/PVsZn8tEcM0rT2pBLM6MnIO0U+lePYL5F6JwhIOYhR xuKkFhRb7c4HGBA0vhLSYGlyxYWO1rGFdod2AhmDeq9HGzrw8ZgFloPMJq0NNWCfrJkL mNOOeqjR4eu0xTLx9NShpPqi0q2iTIB+2ONXywRS8Evcj9IIPssfWvrxy27oKmhuzS55 j6+zhnub3mHDFjLKedkpdR7OBRB8lunatE6xwXykelwrDu7uQcWHIAWqc8itPUR9aDrO WVB41HMhQdsxL099X9LS+13qYqIsi3bwbu/wSglrt2g9Q/aBc6JNMgJ7KLUNBLuvqUnT xBEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:user-agent:subject:to:from:message-id:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=PllAdR/r3gocQdWg39K4XmmZkDSVlD1kole9+vKooeM=; b=ndDngC2USLDqjVVm0BAi8aFpex2geiE+N7pz3MMBqAaNN4qSzpdnJn+YOpbTjqmXOq 0R6XNRuTOGnvV2s9ImplHJUcyfIu86TQnUXmYigPnbSVXilvoorqndSvQfVeWksd7/Gy pu52xwGYobiqGft/aaJBqUwGFyFJXyk1xqxjeq0FyaP4YK1tApaUiJO3lGj1Q6NvGHfV cLzqGQjGCZ82Bqggl6MK8WszRUz/K/T9WfOMeDCO4RllJ+w/viO5fqL3T4ZaiXcEu0uD pKziCiQl2jjr7+55WDKAaE9VNJCHuYt6q2PJMHlk6NdJ7dcJWz1BNWFsoTXKEKHMWfRK wpEQ== X-Gm-Message-State: AFqh2kq6ykbKEzx0JP+3YnM30gJcTwY9X8b9e68lZfKzwWrZ+5/GecNR X7jo+/QBZfRLIPIlmUxw98ofSIlr7dk= X-Google-Smtp-Source: AMrXdXvPdOkZ2+pD8qb4+oEgcn985rJxPtbpJSwZDdZ90vN1yybFniQDIuUNuTGIfFlpbWAppcDqXw== X-Received: by 2002:a62:55c3:0:b0:56b:dae1:e946 with SMTP id j186-20020a6255c3000000b0056bdae1e946mr36522426pfb.28.1672575777352; Sun, 01 Jan 2023 04:22:57 -0800 (PST) Received: from localhost (58x12x133x161.ap58.ftth.ucom.ne.jp. [58.12.133.161]) by smtp.gmail.com with ESMTPSA id 68-20020a620447000000b00578199ea5afsm16569603pfe.9.2023.01.01.04.22.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Jan 2023 04:22:55 -0800 (PST) Date: Sun, 01 Jan 2023 21:22:44 +0900 Message-ID: From: kobarity To: bug-gnu-emacs@gnu.org Subject: 30.0.50; python-shell-send-region fails when the region starts in the middle of the first line User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?ISO-8859-4?Q?Goj=F2?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/30.0.50 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: multipart/mixed; boundary="Multipart_Sun_Jan__1_21:22:44_2023-1" Received-SPF: pass client-ip=2607:f8b0:4864:20::42b; envelope-from=kobarity@gmail.com; helo=mail-pf1-x42b.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, 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 (--) --Multipart_Sun_Jan__1_21:22:44_2023-1 Content-Type: text/plain; charset=US-ASCII Hello, `python-shell-send-region' fails with the following error when the region starts in the middle of the first line. Wrong type argument: wholenump, -1 This is caused by the code to insert the coding cookie in `python-shell-buffer-substring'. I think that the current code assumes that the region begins at line beginning position. However, there are some use-cases where the region starts in the middle of the line as discussed in #60142. So I think the special treatment in case of point-min should be extended to case of first line. Attached is a patch to implement this. -- In GNU Emacs 30.0.50 (build 6, x86_64-pc-linux-gnu, X toolkit, cairo version 1.16.0, Xaw scroll bars) of 2023-01-01 built on ubuntu Repository revision: 9596e683834a36060497903b47b870b338d88095 Repository branch: master System Description: Ubuntu 22.04.1 LTS Configured features: ACL CAIRO FREETYPE GIF GLIB GMP GNUTLS GSETTINGS HARFBUZZ JPEG LIBSELINUX LIBXML2 MODULES NOTIFY INOTIFY PDUMPER PNG SECCOMP SOUND SQLITE3 THREADS TIFF TOOLKIT_SCROLL_BARS TREE_SITTER X11 XDBE XIM XPM LUCID ZLIB Important settings: value of $LANG: en_US.UTF-8 locale-coding-system: utf-8-unix Major mode: Lisp Interaction Minor modes in effect: tooltip-mode: t global-eldoc-mode: t eldoc-mode: t show-paren-mode: t electric-indent-mode: t mouse-wheel-mode: t tool-bar-mode: t menu-bar-mode: t file-name-shadow-mode: t global-font-lock-mode: t font-lock-mode: t blink-cursor-mode: t line-number-mode: t indent-tabs-mode: t transient-mark-mode: t auto-composition-mode: t auto-encryption-mode: t auto-compression-mode: t Load-path shadows: None found. Features: (shadow sort mail-extr emacsbug message mailcap yank-media puny dired dired-loaddefs rfc822 mml mml-sec password-cache epa derived epg rfc6068 epg-config gnus-util text-property-search time-date subr-x mm-decode mm-bodies mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader cl-loaddefs cl-lib sendmail rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mail-utils term/screen term/xterm xterm byte-opt gv bytecomp byte-compile rmc iso-transl tooltip cconv eldoc paren electric uniquify ediff-hook vc-hooks lisp-float-type elisp-mode mwheel term/x-win x-win term/common-win x-dnd tool-bar dnd fontset image regexp-opt fringe tabulated-list replace newcomment text-mode lisp-mode prog-mode register page tab-bar menu-bar rfn-eshadow isearch easymenu timer select scroll-bar mouse jit-lock font-lock syntax font-core term/tty-colors frame minibuffer nadvice seq simple cl-generic indonesian philippine cham georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek romanian slovak czech european ethiopic indian cyrillic chinese composite emoji-zwj charscript charprop case-table epa-hook jka-cmpr-hook help abbrev obarray oclosure cl-preloaded button loaddefs theme-loaddefs faces cus-face macroexp files window text-properties overlay sha1 md5 base64 format env code-pages mule custom widget keymap hashtable-print-readable backquote threads inotify dynamic-setting system-font-setting font-render-setting cairo x-toolkit x multi-tty make-network-process emacs) Memory information: ((conses 16 45803 5938) (symbols 48 5813 0) (strings 32 14944 1951) (string-bytes 1 421917) (vectors 16 8284) (vector-slots 8 104561 8256) (floats 8 24 281) (intervals 56 200 0) (buffers 984 10)) --Multipart_Sun_Jan__1_21:22:44_2023-1 Content-Type: application/octet-stream; type=patch; name="0001-Fix-python-shell-buffer-substring-when-START-is-in-t.patch" Content-Disposition: attachment; filename="0001-Fix-python-shell-buffer-substring-when-START-is-in-t.patch" Content-Transfer-Encoding: 7bit >From b3f58b9d3977ae52fed572e0a33cda02ade1fcc2 Mon Sep 17 00:00:00 2001 From: kobarity Date: Sun, 1 Jan 2023 21:09:10 +0900 Subject: [PATCH] Fix python-shell-buffer-substring when START is in the middle of 1st line * lisp/progmodes/python.el (python-shell-buffer-substring): Instead of checking whether START is point-min, check whether START is in the first line. * test/lisp/progmodes/python-tests.el (python-shell-buffer-substring-18): New test. --- lisp/progmodes/python.el | 9 +++++---- test/lisp/progmodes/python-tests.el | 10 ++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 59164d7d50c..c399bbc64f8 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -3766,15 +3766,16 @@ python-shell-buffer-substring (line-beginning-position) start)))) (substring (buffer-substring-no-properties start end)) - (starts-at-point-min-p (save-restriction - (widen) - (= (point-min) start))) + (starts-at-first-line-p (save-restriction + (widen) + (goto-char start) + (= (line-number-at-pos) 1))) (encoding (python-info-encoding)) (toplevel-p (zerop (save-excursion (goto-char start) (python-util-forward-comment 1) (current-indentation)))) - (fillstr (cond (starts-at-point-min-p + (fillstr (cond (starts-at-first-line-p nil) ((not no-cookie) (concat diff --git a/test/lisp/progmodes/python-tests.el b/test/lisp/progmodes/python-tests.el index eac558db10f..df71990278e 100644 --- a/test/lisp/progmodes/python-tests.el +++ b/test/lisp/progmodes/python-tests.el @@ -4520,6 +4520,16 @@ python-shell-buffer-substring-17 (python-tests-look-at "\"\"\"")) "# -*- coding: utf-8 -*-\n\nif True:\n a = 1\n b = 2\n\n")))) +(ert-deftest python-shell-buffer-substring-18 () + "Check substring from the part of the first line." + (python-tests-with-temp-buffer + "s = 'test' +" + (should (string= (python-shell-buffer-substring + (python-tests-look-at "'test'") + (pos-eol)) + "'test'")))) + ;;; Shell completion -- 2.34.1 --Multipart_Sun_Jan__1_21:22:44_2023-1-- ------------=_1673081941-1743-1--