GNU bug report logs - #55702
29.0.50; python-mark-defun does not handle backslash escaped newline

Previous Next

Package: emacs;

Reported by: kobarity <kobarity <at> gmail.com>

Date: Sun, 29 May 2022 12:23:01 UTC

Severity: normal

Found in version 29.0.50

Fixed in version 29.1

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 55702 in the body.
You can then email your comments to 55702 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#55702; Package emacs. (Sun, 29 May 2022 12:23:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to kobarity <kobarity <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sun, 29 May 2022 12:23:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: kobarity <kobarity <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 29.0.50; python-mark-defun does not handle backslash escaped newline
Date: Sun, 29 May 2022 21:22:18 +0900
When the following steps are performed, the first line "def \" will
not be included in the region.

1. emacs -Q
2. Load the following Python file using M-x find-file

#+begin_src python
def \
        foo(x):
    return x
#+end_src

3. M-x forward-line (Move point to the line "foo(x):".)
4. M-x python-mark-defun

In GNU Emacs 29.0.50 (build 4, x86_64-pc-linux-gnu)
 of 2022-05-21 built on ubuntu
Repository revision: 208102fa470e3417320062cdb48a9967d80bf092
Repository branch: master
System Description: Ubuntu 22.04 LTS

Configured using:
 'configure --without-x --with-gnutls=ifavailable'

Configured features:
ACL LIBXML2 MODULES NOTIFY INOTIFY PDUMPER SECCOMP SOUND SQLITE3 THREADS
XIM 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
  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 regexp-opt sort mail-extr face-remap help-mode tool-bar emacsbug
message mailcap yank-media rmc puny dired dired-loaddefs rfc822 mml
mml-sec password-cache epa derived epg rfc6068 epg-config gnus-util
text-property-search time-date seq 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 gv subr-x byte-opt bytecomp byte-compile
cconv iso-transl tooltip eldoc paren electric uniquify ediff-hook
vc-hooks lisp-float-type elisp-mode tabulated-list replace newcomment
text-mode lisp-mode prog-mode register page tab-bar menu-bar rfn-eshadow
isearch easymenu timer select mouse jit-lock font-lock syntax font-core
term/tty-colors frame minibuffer nadvice simple cl-generic 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 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
multi-tty make-network-process emacs)

Memory information:
((conses 16 48401 6401)
 (symbols 48 5803 1)
 (strings 32 16090 1890)
 (string-bytes 1 510153)
 (vectors 16 9643)
 (vector-slots 8 112266 9121)
 (floats 8 25 264)
 (intervals 56 385 66)
 (buffers 992 12))




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#55702; Package emacs. (Sun, 29 May 2022 12:29:02 GMT) Full text and rfc822 format available.

Message #8 received at 55702 <at> debbugs.gnu.org (full text, mbox):

From: kobarity <kobarity <at> gmail.com>
To: 55702 <at> debbugs.gnu.org
Subject: 29.0.50; python-mark-defun does not handle backslash escaped newline
Date: Sun, 29 May 2022 21:27:47 +0900
[Message part 1 (text/plain, inline)]
python-mark-defun and python-info-looking-at-beginning-of-defun do not
consider the presence of backslash escaped newline in defuns.
Attached is a patch to fix this issue.
[fix-55702.patch (application/octet-stream, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#55702; Package emacs. (Sun, 29 May 2022 13:13:01 GMT) Full text and rfc822 format available.

Message #11 received at 55702 <at> debbugs.gnu.org (full text, mbox):

From: kobarity <kobarity <at> gmail.com>
To: 55702 <at> debbugs.gnu.org
Subject: 29.0.50; python-mark-defun does not handle backslash escaped newline
Date: Sun, 29 May 2022 22:11:41 +0900
Sorry, it may not be good to change the behavior of
python-info-looking-at-beginning-of-defun.  I will reconsider the fix.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#55702; Package emacs. (Sun, 03 Jul 2022 08:58:02 GMT) Full text and rfc822 format available.

Message #14 received at 55702 <at> debbugs.gnu.org (full text, mbox):

From: kobarity <kobarity <at> gmail.com>
To: 55702 <at> debbugs.gnu.org
Subject: 29.0.50; python-mark-defun does not handle backslash escaped newline
Date: Sun, 3 Jul 2022 17:56:56 +0900
[Message part 1 (text/plain, inline)]
Hello,

I wrote:
> When the following steps are performed, the first line "def \" will
> not be included in the region.
>
> 1. emacs -Q
> 2. Load the following Python file using M-x find-file
>
> #+begin_src python
> def \
>         foo(x):
>     return x
> #+end_src
>
> 3. M-x forward-line (Move point to the line "foo(x):".)
> 4. M-x python-mark-defun

In fact, this is not only the issue in python-mark-defun, but also the
issue in python-nav-beginning-of-defun. In the example above,
python-nav-beginning-of-defun does not move the point if the point is
located at the beginning of the line "foo(x):". My previous patch was
not sufficient to solve the issue in python-nav-beginning-of-defun. So
I attach the revised patch.

On the other hand, I'm wondering if it is worth supporting such rarely
used forms, as there seems to be some more issues regarding the line
continuation using backslash. Is it better to leave such rarely used
forms unsupported and keep the code simple?

Below is the explanation of my patch:

> Sorry, it may not be good to change the behavior of
> python-info-looking-at-beginning-of-defun.  I will reconsider the fix.

Instead of changing the default behavior of
python-info-looking-at-beginning-of-defun, I added an argument to
change the behavior. When CHECK-STATEMENT is non-nil, the current
statement is checked instead of the current physical line.

This argument is used in python-nav--beginning-of-defun to be able
to recognize the defun with line continuation using backslash. When
ARG is positive, the point is moved to the end of the statement if the
point is located at the continuation line. This is necessary for
re-search-backward to find the defun regexp.

If the defun is found when ARG is negative, it is necessary to move
point to the beginning of the statement, because the point is at the
end of the defun regexp which may be in the different line from the
beginning of the statement.

Best Regards,
[fix-55702.patch (application/octet-stream, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#55702; Package emacs. (Sun, 03 Jul 2022 12:24:01 GMT) Full text and rfc822 format available.

Message #17 received at 55702 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: kobarity <kobarity <at> gmail.com>
Cc: 55702 <at> debbugs.gnu.org
Subject: Re: bug#55702: 29.0.50; python-mark-defun does not handle backslash
 escaped newline
Date: Sun, 03 Jul 2022 14:23:02 +0200
kobarity <kobarity <at> gmail.com> writes:

> On the other hand, I'm wondering if it is worth supporting such rarely
> used forms, as there seems to be some more issues regarding the line
> continuation using backslash. Is it better to leave such rarely used
> forms unsupported and keep the code simple?

It does seem slightly obscure, but the patch seems to make sense to me,
so I've pushed it to Emacs 29.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




bug marked as fixed in version 29.1, send any further explanations to 55702 <at> debbugs.gnu.org and kobarity <kobarity <at> gmail.com> Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Sun, 03 Jul 2022 12:24:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 01 Aug 2022 11:24:03 GMT) Full text and rfc822 format available.

This bug report was last modified 1 year and 269 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.