From: kobarity Date: Sun, 1 Jan 2023 12:09:10 +0000 (+0900) Subject: Fix 'python-shell-buffer-substring' when START is in middle of 1st line X-Git-Tag: emacs-29.0.90~814 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=f58452e3ae7ed595566028010128c99e3afb572b;p=emacs.git Fix 'python-shell-buffer-substring' when START is in 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. (Bug#60466) * test/lisp/progmodes/python-tests.el (python-shell-buffer-substring-18): New test. --- 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 @@ the python shell: (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 @@ def foo(): (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