From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Liran Zvibel Newsgroups: gmane.emacs.bugs Subject: bug#18158: Fix extra indent of d-mode "else static if" statements in cc-engine.el Date: Tue, 28 Jan 2020 17:26:41 -0800 Message-ID: <8B3ABB9B-7A39-428A-A65B-B77D0614C9FE@gmail.com> References: <87blqxq12q.fsf@marxist.se> <20200126152931.GA4829@ACM> Mime-Version: 1.0 (Mac OS X Mail 13.0 \(3608.40.2.2.4\)) Content-Type: multipart/alternative; boundary="Apple-Mail=_2CC2DABF-8B2F-430B-B000-CD99C843583F" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="27689"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 18158@debbugs.gnu.org, Stefan Kangas To: Alan Mackenzie Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Jan 29 02:28:16 2020 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 1iwc9Q-00078C-2O for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 29 Jan 2020 02:28:16 +0100 Original-Received: from localhost ([::1]:39478 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iwc9O-000150-M0 for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 28 Jan 2020 20:28:14 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:42184) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iwc9E-00014p-SR for bug-gnu-emacs@gnu.org; Tue, 28 Jan 2020 20:28:06 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iwc9C-0007F4-SP for bug-gnu-emacs@gnu.org; Tue, 28 Jan 2020 20:28:04 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:55369) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iwc9C-0007Ev-NO; Tue, 28 Jan 2020 20:28:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1iwc9C-000573-IS; Tue, 28 Jan 2020 20:28:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Liran Zvibel Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org, bug-cc-mode@gnu.org Resent-Date: Wed, 29 Jan 2020 01:28:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 18158 X-GNU-PR-Package: emacs,cc-mode X-GNU-PR-Keywords: moreinfo Original-Received: via spool by 18158-submit@debbugs.gnu.org id=B18158.158026125119619 (code B ref 18158); Wed, 29 Jan 2020 01:28:02 +0000 Original-Received: (at 18158) by debbugs.gnu.org; 29 Jan 2020 01:27:31 +0000 Original-Received: from localhost ([127.0.0.1]:33109 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iwc8g-00056M-Fa for submit@debbugs.gnu.org; Tue, 28 Jan 2020 20:27:30 -0500 Original-Received: from mail-pj1-f54.google.com ([209.85.216.54]:54112) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iwc8e-000569-9x for 18158@debbugs.gnu.org; Tue, 28 Jan 2020 20:27:29 -0500 Original-Received: by mail-pj1-f54.google.com with SMTP id n96so1854349pjc.3 for <18158@debbugs.gnu.org>; Tue, 28 Jan 2020 17:27:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=nawrB93myEZJss7q8kOsXvEp85BZcv2l4+/4ks7j1hE=; b=W46K9/bnLcSDGx1z/Ckp/29FhrAoa2V1LktqtWUUiBsCYDWBj1/jZJJLmWuc93nVlA NPMPcOtLebjah1wBsXdMqLc8/3wKqFVOibsGPtALwtlkEgVVjXWQ45CqhrryHvcQci+K vvMLYw9BB1RAqSgOjuviRbhngJaNZdOADDdvWO3PCwNKobkXHU9lcq0t5ENR6/NGQaVP 3jMznDA0ntn5p6vhz25IcYtix/7xa3fA783K5C//ONxCtPsZrCr7B4VuCNJS08tot2md /dDfSfbxMDUjePM5B4aHOe5UHk8bfUyshIUprENXy5A4nj2rkcOVFseILjxOWs41dZl7 fN5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=nawrB93myEZJss7q8kOsXvEp85BZcv2l4+/4ks7j1hE=; b=IQpkceJ6pRIPKMqFH6vIlkyOTx5XJpJGrtRYt2oeOJOPD7JqfvHPICk9mz4tarpCys 4Kn6R50Bis7wa9Zzw5ymTB+5VUlweMrbultypIkovcJYY4PhodEkhkMtKGJMTidTA1Zy sMts5gZHmsWcTt+iyagFCjjkOdaWo9W9uz5Me5oZx00IUzOZ7y1ltoPqQNk5XAjNmowT K8rRK59HXBtQC66VNB4rsKHJTdu0S29ifs70HjfDb17BQoYm+f8X6GaFbYxnvZtK8yRs qmOs9WZGS5P8yocFqJsl6izSHie/PdA1zvL6XpxHRKTdq0t3DisOG9aNK1Mi4qjCtVij iRiA== X-Gm-Message-State: APjAAAX2fEYh36+wlq1cnqNgTOQI5JokPMmbHZMhOuagB7HVblKJ/1wo FJHhI1eApL6vLPckytHzbTo= X-Google-Smtp-Source: APXvYqxVBrjaYvxJq4VN/k00J/bvz7HDxEejUq0NetyVst35MTJUAQEusbAWnDx23F87D+l8qsj0tg== X-Received: by 2002:a17:90a:cb96:: with SMTP id a22mr8055256pju.96.1580261242186; Tue, 28 Jan 2020 17:27:22 -0800 (PST) Original-Received: from [172.19.248.166] ([38.98.37.134]) by smtp.gmail.com with ESMTPSA id r66sm282014pfc.74.2020.01.28.17.27.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Jan 2020 17:27:21 -0800 (PST) In-Reply-To: <20200126152931.GA4829@ACM> X-Mailer: Apple Mail (2.3608.40.2.2.4) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 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:175376 Archived-At: --Apple-Mail=_2CC2DABF-8B2F-430B-B000-CD99C843583F Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 @("notrace") JSONValue objToJSON(T)(auto ref const T obj) @trusted { alias U =3D Unqual!T; static if (is(U =3D=3D JSONValue)) { return obj; } else static if (__traits(compiles, obj.toJSON())) { return obj.toJSON(); } else static if (is(U =3D=3D typeof(null))) { return JSONValue(null); } else static if (is(U =3D=3D enum)) { // before the JSONValue casts = as int return JSONValue(obj.to!string); } else static if (isSomeString!U) { if (obj is null) { return JSONValue(null); } else { return JSONValue(obj); } } else static if(is(U =3D=3D SysTime)) { if (obj =3D=3D SysTime.init) { return JSONValue(null); } else { return JSONValue(obj.toUTC().toISOExtString()); } } else static if(is(U =3D=3D Duration)) { auto hns =3D obj.total!"hnsecs"(); if (hns % 10_000_000 =3D=3D 0) { return JSONValue(hns / 10_000_000); } else { return JSONValue(hns / 10_000_000.0); } } else static if (is(U =3D=3D UUID)) { return JSONValue(obj.toString()); } else static if (isFloatingPoint!U) { if (obj !=3D obj || obj =3D=3D U.infinity || obj =3D=3D = -U.infinity) { return JSONValue(null); } else { auto tmp =3D cast(long)obj; if (tmp =3D=3D obj) { // dump as long, to avoid losing percision return JSONValue(tmp); } else { return JSONValue(obj); } } } : > On Jan 26, 2020, at 7:29 AM, Alan Mackenzie wrote: >=20 > Hello, Stefan and Liran. >=20 > On Mon, Jan 20, 2020 at 22:18:05 +0100, Stefan Kangas wrote: >> Hi Alan, >=20 >> Could you please help review also the below patch for cc-engine.el? >=20 > I'm less than happy about putting a special purpose workaround into a > critical bit of CC Mode (c-add-stmt-syntax) without having even seen = the > problem. >=20 > Liran, if you're still there and still interested, could you possibly > supply me with a sample of D source code containing the problem? I > would hope to be able to enhance CC Mode to handle it in a more = general > and useful fashion. >=20 >> Thanks in advance. >=20 >> Best regards, >> Stefan Kangas >=20 > --=20 > Alan Mackenzie (Nuremberg, Germany). >=20 >=20 >=20 >> Liran Zvibel writes: >=20 >>> Hi, >>>=20 >>> I=E2=80=99m not subscribed to this list (or to -devel), so please = reply also to my email when responding. >>>=20 >>> Thanks, >>> Liran Zvibel. >>>=20 >>> ** Description: >>>=20 >>> Fix extra indent of d-mode "else static if" statements=20 >>>=20 >>> The D programming language has a notion of =E2=80=9Cstatic if=E2=80=9D= conditionals. >>> The d-mode (from = https://github.com/Emacs-D-Mode-Maintainers/Emacs-D-Mode.git) >>> requires cc-mode. >>> When writing =E2=80=9Celse static if=E2=80=9D blocks, the code block = is getting indented twice, >>> as well as all future =E2=80=9Celse static if=E2=80=9Ds that come = later. This is very annoying. >>>=20 >>> This simple fix was originally suggested here:=20 >>> = http://www.prowiki.org/wiki4d/wiki.cgi?EditorSupport/EmacsDMode/ElseStatic= If >>> The simple fix treats "static if" same as =E2=80=9Cif" that comes = right after an =E2=80=9Celse". >>>=20 >>> I fixed it locally in my installed emacs long time ago, but today = when downloading=20 >>> trunk to test 24.4 I was disappointed it was not already fixed by = someone else.=20 >>> I know many D programmers that apply this change locally to their = installed Emacs,=20 >>> hopefully not for long. >>>=20 >>> ** ChangeLog >>>=20 >>> 2014-07-31 Liran Zvibel >>>=20 >>> * Small cc-mode change to make sure =E2=80=9Celse static if=E2=80=9D= does not get=20 >>> deeper and deeper indentation the same way that =E2=80=9Celse = if=E2=80=9D is treated=20 >>> for d-mode that requires cc-mode. >>>=20 >>> ** The patch : >>>=20 >>> =3D=3D=3D modified file 'lisp/progmodes/cc-engine.el' >>> *** lisp/progmodes/cc-engine.el 2014-06-29 11:26:47 +0000 >>> --- lisp/progmodes/cc-engine.el 2014-07-31 15:22:15 +0000 >>> *************** comment at the start of cc-engine.el for >>> *** 9053,9061 **** >>> (looking-at "else\\>[^_]") >>> (save-excursion >>> (goto-char old-pos) >>> ! (looking-at "if\\>[^_]"))) >>> ;; Special case to avoid deeper and deeper = indentation >>> ! ;; of "else if" clauses. >>> ) >>>=20 >>> ((and (not stop-at-boi-only) >>> --- 9053,9062 ---- >>> (looking-at "else\\>[^_]") >>> (save-excursion >>> (goto-char old-pos) >>> ! (or (looking-at "if\\>[^_]") >>> ! (looking-at "static\\>[^_]")))) >>> ;; Special case to avoid deeper and deeper = indentation >>> ! ;; of "else if"/"static else if" clauses. >>> ) >>>=20 >>> ((and (not stop-at-boi-only) --Apple-Mail=_2CC2DABF-8B2F-430B-B000-CD99C843583F Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8
@("notrace") JSONValue objToJSON(T)(auto ref const T obj) = @trusted {
    alias U =3D = Unqual!T;
    static if (is(U =3D=3D = JSONValue)) {
        return = obj;
    }
    else static if (__traits(compiles, obj.toJSON())) = {
        return = obj.toJSON();
    }
    else static if (is(U =3D=3D typeof(null))) = {
        return = JSONValue(null);
    }
    else static if (is(U =3D=3D enum)) { // before the = JSONValue casts as int
  =       return JSONValue(obj.to!string);
    }
  =   else static if (isSomeString!U) {
        if (obj is null) = {
          =   return JSONValue(null);
  =       } else {
  =           return = JSONValue(obj);
        = }
    }
    else static if(is(U =3D=3D SysTime)) = {
        if (obj =3D=3D= SysTime.init) {
          =   return JSONValue(null);
  =       } else {
  =           return = JSONValue(obj.toUTC().toISOExtString());
  =       }
  =   }
    else static if(is(U = =3D=3D Duration)) {
        auto hns =3D = obj.total!"hnsecs"();
  =       if (hns % 10_000_000 =3D=3D 0) {
            return = JSONValue(hns / 10_000_000);
  =       }
  =       else {
  =           return JSONValue(hns / = 10_000_000.0);
        = }
    }
    else static if (is(U =3D=3D UUID)) {
        return = JSONValue(obj.toString());
  =   }
    else static if = (isFloatingPoint!U) {
  =       if (obj !=3D obj || obj =3D=3D U.infinity || obj =3D=3D= -U.infinity) {
          =   return JSONValue(null);
  =       }
  =       else {
  =           auto tmp =3D = cast(long)obj;
          =   if (tmp =3D=3D obj) {
  =               // dump as long, to = avoid losing percision
  =               return = JSONValue(tmp);
          =   }
          =   else {
          =       return JSONValue(obj);
            }
        }
  =   }
:


On Jan 26, 2020, at 7:29 AM, = Alan Mackenzie <acm@muc.de> wrote:

Hello,= Stefan and Liran.

On Mon, Jan 20, 2020 at = 22:18:05 +0100, Stefan Kangas wrote:
Hi Alan,

Could you please help = review also the below patch for cc-engine.el?

I'm less than happy about putting = a special purpose workaround into a
critical bit of CC = Mode (c-add-stmt-syntax) without having even seen the
problem.

Liran, if you're still = there and still interested, could you possibly
supply me = with a sample of D source code containing the problem?  I
would hope to be able to enhance CC Mode to handle it in a = more general
and useful fashion.

Thanks in advance.

Best regards,
Stefan Kangas

--
Alan Mackenzie = (Nuremberg, Germany).



Liran Zvibel <liranz@gmail.com> = writes:

Hi,

I=E2=80=99m not subscribed to this list (or to = -devel), so please reply also to my email when responding.

Thanks,
Liran Zvibel.

** Description:

Fix= extra indent of d-mode  "else static if" statements 

The D programming language has a notion of = =E2=80=9Cstatic if=E2=80=9D conditionals.
The d-mode (from = https://github.com/Emacs-D-Mode-Maintainers/Emacs-D-Mode.git)
requires cc-mode.
When writing =E2=80=9Cels= e static if=E2=80=9D blocks, the code block is getting indented = twice,
as well as all future =E2=80=9Celse static if=E2=80=9D= s that come later. This is very annoying.

This simple fix was originally suggested here: 
http://www.prowiki.org/wiki4d/wiki.cgi?EditorSupport/EmacsDMode= /ElseStaticIf
The simple fix treats "static if" same = as =E2=80=9Cif" that comes right after an =E2=80=9Celse".

I fixed it locally in my installed emacs long = time ago, but today when downloading 
trunk to test = 24.4 I was disappointed it was not already fixed by someone = else. 
I know many D programmers that apply this = change locally to their installed Emacs, 
hopefully = not for long.

** ChangeLog

2014-07-31 Liran Zvibel <liranz@gmail.com>

* Small cc-mode change to make = sure =E2=80=9Celse static if=E2=80=9D does not get 
= deeper and deeper indentation the same way that =E2=80=9Celse = if=E2=80=9D is treated 
for d-mode that requires = cc-mode.

** The patch :

=3D=3D=3D modified file 'lisp/progmodes/cc-engine.el'
*** lisp/progmodes/cc-engine.el 2014-06-29 11:26:47 +0000
--- lisp/progmodes/cc-engine.el 2014-07-31 15:22:15 +0000
*************** comment at the start of cc-engine.el for
*** 9053,9061 ****
    =   (looking-at "else\\>[^_]")
    =   (save-excursion
        (goto-char = old-pos)
!       (looking-at = "if\\>[^_]")))
  ;; Special case to avoid deeper = and deeper indentation
! ;; of "else if" clauses.
  )

        ((and (not = stop-at-boi-only)
--- 9053,9062 ----
  = = = =     (looking-at "else\\>[^_]")
  = = = =     (save-excursion
    =     (goto-char old-pos)
!       =                     =      (or (looking-at "if\\>[^_]")
! = = = = =   (looking-at "static\\>[^_]"))))
  = = = = ;; Special case to avoid deeper and deeper indentation
! = = = ;; of "else if"/"static else if" clauses.
  = = = = )

    =     ((and (not stop-at-boi-only)

= --Apple-Mail=_2CC2DABF-8B2F-430B-B000-CD99C843583F--