From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Yuan Fu Newsgroups: gmane.emacs.bugs Subject: bug#67488: [PATCH] Fix typescript-ts-mode indentation for switch statements Date: Mon, 27 Nov 2023 21:53:49 -0800 Message-ID: <249b56d1-1345-4b59-98c7-3f019564fa82@gmail.com> References: <3420a38f-6ae7-fd20-28d8-e4815c8fa3cc@gutov.dev> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="38729"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla Thunderbird Cc: theo@thornhill.no To: 67488@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Nov 28 06:55:28 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 1r7r4C-0009vy-5O for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 28 Nov 2023 06:55:28 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r7r3g-0006Lm-OW; Tue, 28 Nov 2023 00:54:56 -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 1r7r3f-0006LH-Bs for bug-gnu-emacs@gnu.org; Tue, 28 Nov 2023 00:54:55 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r7r3f-0007vT-4A for bug-gnu-emacs@gnu.org; Tue, 28 Nov 2023 00:54:55 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1r7r3l-0008Mj-MV for bug-gnu-emacs@gnu.org; Tue, 28 Nov 2023 00:55:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Yuan Fu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 28 Nov 2023 05:55:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 67488 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.170115085632087 (code B ref -1); Tue, 28 Nov 2023 05:55:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 28 Nov 2023 05:54:16 +0000 Original-Received: from localhost ([127.0.0.1]:45335 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r7r31-0008LR-SY for submit@debbugs.gnu.org; Tue, 28 Nov 2023 00:54:16 -0500 Original-Received: from lists.gnu.org ([2001:470:142::17]:56480) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r7r30-0008LD-09 for submit@debbugs.gnu.org; Tue, 28 Nov 2023 00:54:14 -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 1r7r2j-0006IN-87 for bug-gnu-emacs@gnu.org; Tue, 28 Nov 2023 00:53:58 -0500 Original-Received: from mail-oo1-xc34.google.com ([2607:f8b0:4864:20::c34]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r7r2e-0007sO-Kg for bug-gnu-emacs@gnu.org; Tue, 28 Nov 2023 00:53:54 -0500 Original-Received: by mail-oo1-xc34.google.com with SMTP id 006d021491bc7-58d956c8c38so731844eaf.2 for ; Mon, 27 Nov 2023 21:53:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701150831; x=1701755631; darn=gnu.org; h=content-transfer-encoding:in-reply-to:from:cc:references:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=53Ji56O5bfW33D6u42mCpSN89PS2ALStd/pbeyEuTdI=; b=k1nlNUNVr0syQ/HqmBexzzzLjQZGlwCPY5MBDIBXybSZxTvarv7H/ZytQNhXg24xoN 24FkEhNOjTyetejvWXMOwF3lJR3csrd7dmqREF4OcjRveArmA8snH/9S8RJH6RE7g4SQ 6fsi+ZAfdi2P2loaQFopioQ8hSogKG1ZNHIEJqDPK/dAZy1tZQXGA0/dkGI/3olAxT4N F1OLXV2gToN06PSOiltWEYpKDS4x2lMABYDnXhL74NuE5jQVPoxwnQfsLbDfWsUtBxhw gKxw/YCYKteg01El5sQSXtABXCd3fQVk/dzjj9Ro4o7JprEQMsK6+5Ar/aSH4rIeg1f0 M5mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701150831; x=1701755631; h=content-transfer-encoding:in-reply-to:from:cc:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=53Ji56O5bfW33D6u42mCpSN89PS2ALStd/pbeyEuTdI=; b=ZwVtxWH/4LK/jez3WldcNCTbwPOoLQRdM9eGRuIkSLnmzlGNaboY4Kibq92CZjECNx 9QBCtYJ+fo2HU1BP5UFMa1q9Kn7yxDcyE7U6GquCsnsETiMA/hSBaxxHDJMpMvrKldg1 dxBwYnFBb8EhYUc852dM/ujC3clYHR8VP6EqZza3BCvJa9IPZIC7vkmVcIs14+Z0+h7h T7z9XDc+NX9D81zXi0r1QfBl5BszZS/IWhtG2gKBBbKiZ3lyJK4qeYr96RgKtb+0gVJz Z4RljQ3otPRVQgR2V4ofC26iCLeYTmPZaNyFzcADsz6UB3E3O+FoqD8HlFI+cVxX28ZL jwNQ== X-Gm-Message-State: AOJu0YzGywCONiS/Jo5kLQXyXhfK6Yisfx+RRh4k1vMzpcq4jQv+gvhb lx4o6QH3I+6hYBynMInJ/K8x+gDNZjDlpQ== X-Google-Smtp-Source: AGHT+IGeiF5n4K1ft3kkjw4k2RVJtP3FK4sdQYiXRMz7/JX0F5Qswlsmrov8FfoAH9EyLGGJu2gG9A== X-Received: by 2002:a05:6358:52c6:b0:16b:c479:d6c1 with SMTP id z6-20020a05635852c600b0016bc479d6c1mr17042068rwz.9.1701150831071; Mon, 27 Nov 2023 21:53:51 -0800 (PST) Original-Received: from [192.168.1.7] (cpe-172-117-161-177.socal.res.rr.com. [172.117.161.177]) by smtp.gmail.com with ESMTPSA id a22-20020a63d216000000b005bdd8dcfe19sm8652474pgg.10.2023.11.27.21.53.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 27 Nov 2023 21:53:50 -0800 (PST) Content-Language: en-US In-Reply-To: <3420a38f-6ae7-fd20-28d8-e4815c8fa3cc@gutov.dev> Received-SPF: pass client-ip=2607:f8b0:4864:20::c34; envelope-from=casouri@gmail.com; helo=mail-oo1-xc34.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, T_SCC_BODY_TEXT_LINE=-0.01 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:275156 Archived-At: On 11/27/23 4:39 PM, Dmitry Gutov wrote: > On 27/11/2023 19:07, Noah Peart wrote: >> Tags: patch >> >> * lisp/progmodes/typescript-ts-mode.el(typescript-ts-mode): Add >> indentation >> rule for switch case and default keywords. >> >> Bug: `typescript-ts-mode` is missing indentation rules for 'case' and >> 'default' keywords in switch statements. >> >> Recipe to reproduce: >> Copy the following code into a buffer: >> >>      const foo = (x: string) => { >>        switch (x) { >>                    case "a": >>                    console.log(x); >>                    return 1; >>      case "b": >>        return 2; >>                    case "c": >>                    default: >>                      return 0; >>        } >>      }; >> >> And call the following function to configure typescript-ts-mode and >> indent the buffer >> >>      (defun my-ts-indentation () >>        (interactive) >>        (setq indent-tabs-mode nil) >>        (setq typescript-ts-mode-indent-offset 2) >>        (typescript-ts-mode) >>        (indent-region (point-min) (point-max))) >> >> The indentation for the 'case' and 'default' branches within the switch >> statement should still be unchanged due to missing indent rules. >> Bug applies to emacs 29 as well. > > Thanks! Can repro. The fix looks good as well. > LGTM. The only thing I'll add is that you can probably use a single regular expression rather than using the "or" matcher. But that's largely personal preference. Yuan