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#62092: 30.0.50; "case" does not work as dedenter in Python Date: Fri, 10 Mar 2023 14:33:14 +0900 Message-ID: Mime-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: multipart/mixed; boundary="Multipart_Fri_Mar_10_14:33:14_2023-1" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="32520"; 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) Cc: Lele Gaifax To: 62092@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Mar 10 06:34:27 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 1paVOc-0008K7-IK for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 10 Mar 2023 06:34:26 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1paVOL-00031C-I4; Fri, 10 Mar 2023 00:34:09 -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 1paVOE-0002tr-M7 for bug-gnu-emacs@gnu.org; Fri, 10 Mar 2023 00:34: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 1paVOE-0003YP-DR for bug-gnu-emacs@gnu.org; Fri, 10 Mar 2023 00:34:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1paVOD-0002oI-Su for bug-gnu-emacs@gnu.org; Fri, 10 Mar 2023 00:34:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: kobarity Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 10 Mar 2023 05:34:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 62092 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.167842640910756 (code B ref -1); Fri, 10 Mar 2023 05:34:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 10 Mar 2023 05:33:29 +0000 Original-Received: from localhost ([127.0.0.1]:53467 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1paVNg-0002nQ-Kc for submit@debbugs.gnu.org; Fri, 10 Mar 2023 00:33:29 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:46386) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1paVNf-0002nI-6v for submit@debbugs.gnu.org; Fri, 10 Mar 2023 00:33:27 -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 1paVNe-0002NG-Np for bug-gnu-emacs@gnu.org; Fri, 10 Mar 2023 00:33:26 -0500 Original-Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1paVNc-0003TM-Vu for bug-gnu-emacs@gnu.org; Fri, 10 Mar 2023 00:33:26 -0500 Original-Received: by mail-pf1-x432.google.com with SMTP id ce7so2924878pfb.9 for ; Thu, 09 Mar 2023 21:33:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678426401; h=mime-version:user-agent:subject:cc:to:from:message-id:date:from:to :cc:subject:date:message-id:reply-to; bh=Pf1KAmaCiTCbo6ouc1fZcglvbN+4d2dNZiaAwlFaImI=; b=p7RJGX2i4UWyAGQvTTFd80N83/BlKnc0lKYrvEDEVopOn1nKUtx5rjIiaa6IF8pfT6 MjcDTQJEmg+bSTich44Ds+iaDi6Pd2xGJSN4/A/CmeL6ZQhMsEnSQzMNbw+LUMlxeG2F J7ZkKAgPmwBkHOEWKm8QMM+zxeCFchA7idhvVaQ7GPa68c+Iuh54Dj9K6pDES6nu6eY0 IfLD9HdW+XizuFSqSCRIxfY/KBfsRp2XutRwbR++5eAoTNKXIs1kKl/lbKn8h4sXGMEz lhmcJnRgVIQikigiqCYzm740QGP3FkgRcwgayHvruN9eYMcmVGpOrtR3sAeoi3iolnPK Y8ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678426401; h=mime-version:user-agent:subject:cc:to:from:message-id:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Pf1KAmaCiTCbo6ouc1fZcglvbN+4d2dNZiaAwlFaImI=; b=OL/m+qux7JEX0N0V26Ie0HJg6jETDgpoi5QOYVm+xBwdeFHTIyKmglTM6kjWsiiFOg 0YYGEJLRXdsTQOmkXnEacqTh7prLksbO+BTEAlg6H/SGcbUkTe/9DN6IUZVBxf+tPM+S 2gmOq4X35rlAhBPl+3OA4mJu+nPK4tR2Hb0EtW62m07nPgOfYJbKnkqaIqao/6hWrTPf Ja3p+lE1MXSEKS/tjqDpkpBcenmqTaj+DoYn39UOMgR9qbksJWBx7YgVip+DGnanOCgJ +mnHJpuXLTvK1g3Zlq8EI81FVHKt61O5jq5wsTAY+xvQSKF0oqlQEMudZULOORMwrRoZ rVfg== X-Gm-Message-State: AO0yUKUWJn01cwxjpUHhd/ce76p53TbfFJnkAU+KUpXC6gxeo4WULVnY TJJ2rnTeOI5VugT/AVjUPy8C05EzQaEevA== X-Google-Smtp-Source: AK7set/WdQkypKwoCRz8URPV997pux8RQyWfLMdKCHWBenH4JDSPBW4U561g/Ld4zhqo3Jy9W3/RHQ== X-Received: by 2002:aa7:97a2:0:b0:5a8:ea06:662 with SMTP id d2-20020aa797a2000000b005a8ea060662mr22067161pfq.20.1678426400960; Thu, 09 Mar 2023 21:33:20 -0800 (PST) Original-Received: from localhost (58x12x133x161.ap58.ftth.ucom.ne.jp. [58.12.133.161]) by smtp.gmail.com with ESMTPSA id d23-20020aa78e57000000b005e00086250asm487646pfr.125.2023.03.09.21.33.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Mar 2023 21:33:20 -0800 (PST) Received-SPF: pass client-ip=2607:f8b0:4864:20::432; envelope-from=kobarity@gmail.com; helo=mail-pf1-x432.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:257648 Archived-At: --Multipart_Fri_Mar_10_14:33:14_2023-1 Content-Type: text/plain; charset=US-ASCII Hi, New keywords "match" and "case" were added to block-start in `python-rx', which enables basic indentation support for these keywords. However, "case" does not work as a dedenter. For example, try the following code. #+begin_src python match a: case 1: print(1) case 2: #+end_src At the "case 2:" line, inputting ":" does not dedent the line. Several TAB keys are needed for correct indentation. Attached is a patch to make "case" a dedenter with an ERT. -- In GNU Emacs 30.0.50 (build 3, x86_64-pc-linux-gnu, X toolkit, cairo version 1.16.0, Xaw scroll bars) of 2023-03-10 built on ubuntu Repository revision: 8ee205d232574e12921b052c7e93b7e16d6f1187 Repository branch: master System Description: Ubuntu 22.04.2 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: Python 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 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 mm-decode mm-bodies mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mail-utils python json subr-x map rx project pcase treesit cl-seq comint ansi-osc ring cl-loaddefs cl-lib ansi-color 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 60054 7620) (symbols 48 7362 0) (strings 32 20143 1278) (string-bytes 1 593570) (vectors 16 11583) (vector-slots 8 139242 9455) (floats 8 30 11543) (intervals 56 239 0) (buffers 984 12)) --Multipart_Fri_Mar_10_14:33:14_2023-1 Content-Type: application/octet-stream; type=patch; name="0001-Make-case-keyword-a-dedenter-in-Python.patch" Content-Disposition: attachment; filename="0001-Make-case-keyword-a-dedenter-in-Python.patch" Content-Transfer-Encoding: 7bit >From 93801015034ee6e5072051641acab227de74082a Mon Sep 17 00:00:00 2001 From: kobarity Date: Fri, 10 Mar 2023 14:26:22 +0900 Subject: [PATCH] Make "case" keyword a dedenter in Python * lisp/progmodes/python.el (python-rx): Add "case" to dedenter. (python-info-dedenter-opening-block-positions): Add "case" to pairs. * test/lisp/progmodes/python-tests.el (python-indent-dedenters-9): New test. --- lisp/progmodes/python.el | 5 +++-- test/lisp/progmodes/python-tests.el | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 630250c15c3..2d85d059d97 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -426,7 +426,7 @@ python-rx (or "def" "for" "with"))) symbol-end)) (dedenter (seq symbol-start - (or "elif" "else" "except" "finally") + (or "elif" "else" "except" "finally" "case") symbol-end)) (block-ender (seq symbol-start (or @@ -5784,7 +5784,8 @@ python-info-dedenter-opening-block-positions (pairs '(("elif" "elif" "if") ("else" "if" "elif" "except" "for" "while") ("except" "except" "try") - ("finally" "else" "except" "try"))) + ("finally" "else" "except" "try") + ("case" "case"))) (dedenter (match-string-no-properties 0)) (possible-opening-blocks (cdr (assoc-string dedenter pairs))) (collected-indentations) diff --git a/test/lisp/progmodes/python-tests.el b/test/lisp/progmodes/python-tests.el index 6928e313dc4..7bb6f8617e7 100644 --- a/test/lisp/progmodes/python-tests.el +++ b/test/lisp/progmodes/python-tests.el @@ -1658,6 +1658,21 @@ python-indent-dedenters-8 (python-indent-line t) (should (= (python-indent-calculate-indentation t) 6)))) +(ert-deftest python-indent-dedenters-9 () + "Test de-indentation for the case keyword." + (python-tests-with-temp-buffer + " +match a: + case 1: + print(1) + case 2 +" + (python-tests-look-at "case 2") + (should (eq (car (python-indent-context)) :at-dedenter-block-start)) + (should (= (python-indent-calculate-indentation) 4)) + (python-indent-line t) + (should (= (python-indent-calculate-indentation t) 4)))) + (ert-deftest python-indent-inside-string-1 () "Test indentation for strings." (python-tests-with-temp-buffer -- 2.34.1 --Multipart_Fri_Mar_10_14:33:14_2023-1--