From: Liran Zvibel <liranz@gmail.com>
To: Alan Mackenzie <acm@muc.de>
Cc: 18158@debbugs.gnu.org, Stefan Kangas <stefan@marxist.se>
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 [thread overview]
Message-ID: <8B3ABB9B-7A39-428A-A65B-B77D0614C9FE@gmail.com> (raw)
In-Reply-To: <20200126152931.GA4829@ACM>
[-- Attachment #1: Type: text/plain, Size: 4987 bytes --]
@("notrace") JSONValue objToJSON(T)(auto ref const T obj) @trusted {
alias U = Unqual!T;
static if (is(U == JSONValue)) {
return obj;
}
else static if (__traits(compiles, obj.toJSON())) {
return obj.toJSON();
}
else static if (is(U == typeof(null))) {
return JSONValue(null);
}
else static if (is(U == 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 == SysTime)) {
if (obj == SysTime.init) {
return JSONValue(null);
} else {
return JSONValue(obj.toUTC().toISOExtString());
}
}
else static if(is(U == Duration)) {
auto hns = obj.total!"hnsecs"();
if (hns % 10_000_000 == 0) {
return JSONValue(hns / 10_000_000);
}
else {
return JSONValue(hns / 10_000_000.0);
}
}
else static if (is(U == UUID)) {
return JSONValue(obj.toString());
}
else static if (isFloatingPoint!U) {
if (obj != obj || obj == U.infinity || obj == -U.infinity) {
return JSONValue(null);
}
else {
auto tmp = cast(long)obj;
if (tmp == 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’m 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 “static if” conditionals.
>>> The d-mode (from https://github.com/Emacs-D-Mode-Maintainers/Emacs-D-Mode.git)
>>> requires cc-mode.
>>> When writing “else static if” blocks, the code block is getting indented twice,
>>> as well as all future “else static if”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 “if" that comes right after an “else".
>>>
>>> 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 “else static if” does not get
>>> deeper and deeper indentation the same way that “else if” is treated
>>> for d-mode that requires cc-mode.
>>>
>>> ** The patch :
>>>
>>> === 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)
[-- Attachment #2: Type: text/html, Size: 24780 bytes --]
next prev parent reply other threads:[~2020-01-29 1:26 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-31 15:33 bug#18158: Fix extra indent of d-mode "else static if" statements in cc-engine.el Liran Zvibel
2020-01-20 21:18 ` Stefan Kangas
2020-01-26 15:29 ` Alan Mackenzie
2020-01-29 1:26 ` Liran Zvibel [this message]
2020-01-31 19:41 ` Alan Mackenzie
2020-02-02 11:56 ` bug#18158: D Mode: Getting rid of the ugly advice on looking-at Alan Mackenzie
2020-02-02 16:59 ` Vladimir Panteleev
2020-02-07 21:31 ` Alan Mackenzie
[not found] ` <20200207213100.GB8591@ACM>
2020-02-13 13:37 ` Vladimir Panteleev
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8B3ABB9B-7A39-428A-A65B-B77D0614C9FE@gmail.com \
--to=liranz@gmail.com \
--cc=18158@debbugs.gnu.org \
--cc=acm@muc.de \
--cc=stefan@marxist.se \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).