From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Visuwesh Newsgroups: gmane.emacs.bugs Subject: bug#55764: 29.0.50; sh-mode: Support mksh's alternate case brace syntax Date: Thu, 02 Jun 2022 19:31:18 +0530 Message-ID: <87k09zp3kh.fsf@gmail.com> References: <87o7zbp4uc.fsf@gmail.com> <87o7zbw5dz.fsf@gnus.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="4872"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) Cc: 55764@debbugs.gnu.org, Stefan Monnier To: Lars Ingebrigtsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Jun 02 16:02:34 2022 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 1nwlPE-00016t-Uh for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 02 Jun 2022 16:02:33 +0200 Original-Received: from localhost ([::1]:45956 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nwlPD-0001bV-UA for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 02 Jun 2022 10:02:31 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:47084) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nwlOk-0001Yc-Qx for bug-gnu-emacs@gnu.org; Thu, 02 Jun 2022 10:02:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:60451) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nwlOk-0003YI-GD for bug-gnu-emacs@gnu.org; Thu, 02 Jun 2022 10:02:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nwlOk-0002Md-EK for bug-gnu-emacs@gnu.org; Thu, 02 Jun 2022 10:02:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Visuwesh Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 02 Jun 2022 14:02:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 55764 X-GNU-PR-Package: emacs Original-Received: via spool by 55764-submit@debbugs.gnu.org id=B55764.16541784919040 (code B ref 55764); Thu, 02 Jun 2022 14:02:02 +0000 Original-Received: (at 55764) by debbugs.gnu.org; 2 Jun 2022 14:01:31 +0000 Original-Received: from localhost ([127.0.0.1]:54346 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nwlOF-0002Lk-2A for submit@debbugs.gnu.org; Thu, 02 Jun 2022 10:01:31 -0400 Original-Received: from mail-pf1-f195.google.com ([209.85.210.195]:40635) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nwlOD-0002LW-FL for 55764@debbugs.gnu.org; Thu, 02 Jun 2022 10:01:29 -0400 Original-Received: by mail-pf1-f195.google.com with SMTP id z17so4835987pff.7 for <55764@debbugs.gnu.org>; Thu, 02 Jun 2022 07:01:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=J24xUZcFQ6uHYiqQxa91VUqCnO7ugSToxPx7wuPH/Oc=; b=Tt938TlqrqtibBR8IsoyZkSy5ljJyojbL4cnyiu2oLfaNbyG/T7KknLbgIcEq2/EDR Qknmv7WFtY8v41haflupofnSW32RHcaPNRxMIkCl0bffY2RMPUHf0RlDzH+ePHf/ZY7L JyFGD/aqSsM8bk6RDQof+tgdOvStMXz38hFPq8WiGrBBPWe5OGtS2ER6r0JQ0W7nqf5l kptyLxpd1nK691QWHP2X3J8aMj0y5gzl2CBeciSf1yMOXOeS4Kn3DnHZzwotIURvL29q 4Bm9pqb0IwEFbqlK2OiEYMwcXGL4p0KGOh47as48OCEZsdNWkRfSMdOUMLgrlZsAFHRS USMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=J24xUZcFQ6uHYiqQxa91VUqCnO7ugSToxPx7wuPH/Oc=; b=FN9h462+nXf25lfoVoVBRXnpUnl9yJhUm4H6JVbOZYYXnQeli0keZ5eGxeE2nt/uF0 09k6GMspOG0tDUGAmyDB1dWs3OQwmc+/Thv7CyULlAIGNPHXHhdLbx01a9OotpKMdcaP BPdRCaxlJPfbZwq70Q1Chc5KAFZVLcsVxAt64A6ECErU0+QtAiMxrFugNgULw/1v5G+7 +qmKR1v/Wg5UpDJYnVRmohdRriTYJaQfo1mPTAr4tLCEIgy6Rjl+VY8RjbNB1JWAP+rk 1cw++emELVhQtizNlk+30QQ0aPaXXTkEcLe1ymbubFtaa5Hp94H6cjjfqj8iRRNVUyhr +NCw== X-Gm-Message-State: AOAM532e5NVDYh4tqNuCYaFxrOop86HsVBUPIyS1Ws9NwxkhwI0X1goV ayR0CvJbJyk+tcxzFdWOEno= X-Google-Smtp-Source: ABdhPJzXhjm9t2ir9HPJYOIJFrfbj8d8Y5CkS4TMFMy3uPJyGhoyB2x0zAl2Z/bKe/l0HVX7ucbpxw== X-Received: by 2002:a63:4d0:0:b0:3fc:4f01:dac6 with SMTP id 199-20020a6304d0000000b003fc4f01dac6mr4451214pge.263.1654178483601; Thu, 02 Jun 2022 07:01:23 -0700 (PDT) Original-Received: from localhost ([49.204.135.220]) by smtp.gmail.com with ESMTPSA id j187-20020a638bc4000000b003db822e2170sm3418304pge.23.2022.06.02.07.01.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Jun 2022 07:01:22 -0700 (PDT) In-Reply-To: <87o7zbw5dz.fsf@gnus.org> (Lars Ingebrigtsen's message of "Thu, 02 Jun 2022 15:40:08 +0200") 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" Xref: news.gmane.io gmane.emacs.bugs:233553 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable [=E0=AE=B5=E0=AE=BF=E0=AE=AF=E0=AE=BE=E0=AE=B4=E0=AE=A9=E0=AF=8D =E0=AE=9C= =E0=AF=82=E0=AE=A9=E0=AF=8D 02, 2022] Lars Ingebrigtsen wrote: > Visuwesh writes: > >> mksh and OpenBSD's ksh support an alternative case syntax for historical >> reasons [1], >> >> case $i { >> *pattern) do ;; >> *pattern2) do2 ;; >> } >> >> Currently, sh-mode cannot handle this and the easy way out of writing a >> semicolon after $i is out since, >> >> % case "foo"; { *o) echo 1;; } >> /bin/mksh: syntax error: unexpected ';' >> >> I came with the attached patch after a bit of trial and error but I'm >> not sure if it is the right way to do it. > > I think that might make sense, but perhaps Stefan has some comments here > (added to the CCs). To no one's surprise, the patch is not the right approach. IIUC, when I use braces, *pattern) thingies are not recognised as "case-)" anymore so sh-indent-for-case-label does not get applied. I tried a bit more but I only got it to respect the first line but still it is definitely not the right approach, --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=mksh-braces.patch diff --git a/lisp/progmodes/sh-script.el b/lisp/progmodes/sh-script.el index 4d2554c087..96ff8e8627 100644 --- a/lisp/progmodes/sh-script.el +++ b/lisp/progmodes/sh-script.el @@ -1971,9 +1971,9 @@ sh-smie-sh-rules (sh-var-value 'sh-indent-for-case-label))) (`(:before . ,(or "(" "{" "[" "while" "if" "for" "case")) (cond - ((and (equal token "{") (smie-rule-parent-p "for")) + ((and (equal token "{") (smie-rule-parent-p "for" "case")) (let ((data (smie-backward-sexp "in"))) - (when (equal (nth 2 data) "for") + (when (member (nth 2 data) '("for" "case")) `(column . ,(smie-indent-virtual))))) ((not (smie-rule-prev-p "&&" "||" "|")) (when (smie-rule-hanging-p) @@ -2021,10 +2021,13 @@ sh-smie-sh-rules ('(:after . "in") (sh-var-value 'sh-indent-for-case-label)) ;; sh-indent-for-continuation: Line continuations are handled differently. (`(:after . ,(or "(" "{" "[")) - (if (not (looking-at ".[ \t]*[^\n \t#]")) - (sh-var-value 'sh-indent-after-open) - (goto-char (1- (match-end 0))) - `(column . ,(current-column)))) + (cond + ((smie-rule-parent-p "case") + (sh-var-value 'sh-indent-for-case-label)) + ((not (looking-at ".[ \t]*[^\n \t#]")) + (sh-var-value 'sh-indent-after-open)) + (t (goto-char (1- (match-end 0))) + `(column . ,(current-column))))) ;; sh-indent-after-function: we don't handle it differently. )) --=-=-=--