From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: kobarity Newsgroups: gmane.emacs.bugs Subject: bug#60466: 30.0.50; python-shell-send-region fails when the region starts in the middle of the first line Date: Sun, 01 Jan 2023 21:22:44 +0900 Message-ID: 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" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="23563"; mail-complaints-to="usenet@ciao.gmane.io" 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) To: 60466@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Jan 01 13:24:23 2023 Return-path: 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 ) id 1pBxO3-00061b-Lc for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 01 Jan 2023 13:24:23 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pBxNk-0007lC-6C; Sun, 01 Jan 2023 07:24:04 -0500 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 1pBxNi-0007kG-V9 for bug-gnu-emacs@gnu.org; Sun, 01 Jan 2023 07:24:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pBxNi-0002GP-KI for bug-gnu-emacs@gnu.org; Sun, 01 Jan 2023 07:24:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pBxNi-0001Gt-2i for bug-gnu-emacs@gnu.org; Sun, 01 Jan 2023 07:24:02 -0500 X-Loop: help-debbugs@gnu.org 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-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.16725757864813 (code B ref -1); Sun, 01 Jan 2023 12:24:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 1 Jan 2023 12:23:06 +0000 Original-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 Original-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 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 1pBxMk-0007e5-S9 for bug-gnu-emacs@gnu.org; Sun, 01 Jan 2023 07:23:02 -0500 Original-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 Original-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) Original-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) 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-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" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-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:252240 Archived-At: --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--