From: Theodor Thornhill <theo@thornhill.no>
To: Alan Mackenzie <acm@muc.de>
Cc: emacs-devel@gnu.org
Subject: Re: CC Mode lambda function help
Date: Fri, 09 Oct 2020 14:43:38 +0200 [thread overview]
Message-ID: <87sgan36yt.fsf@thornhill.no> (raw)
In-Reply-To: <20201009105703.GA4027@ACM>
Hello!
>
> What does "the" manual mean? If it doesn't mean the CC Mode manual,
> then it should. It's available in .../emacs/info/ccmode.info, or
> some very similar address. It contains a wealth of information, being
> largely written by myself. :-)
I'm using CC Mode manual from the master branch, recompiled
regularly-ish. Also the code has progressed quite a bit since this mail
was sent, so the issues have largely been solved (though I'm still
unsure whether the solutions I picked are considered bad/good style)
[...]
>
> OK, just to be quite clear, c-lang-defconsts are intended for the use of
> hackers maintaining CC Mode or modes derived from it (as you are doing),
> to specify modes. They are not for users' configuration, for which see
> things like "styles" and c-offsets-alist and other things in the
> configuration section of the CC Mode manual.
>
Yeah! Right now the rework branch is merged into master, and as such it
should be easy to get the code I'm describing.
> I think it likely you have run into a configuration bug, possibly an old
> bug, where a "syntactic offset" was inappropriately set. To see the
> syntactic symbol(s) for a source line, put point on it and do C-c C-s.
> To see the offset currently configured for that/those symbol(s), do C-c
> C-o (again, see the CC Mode manual for any needed explanations).
Yeah, these bindings are essential, and I use them all the time :-)
Actually, I fixed this behaviour by adding a new syntax construct by
advising the appropriate functions. Exactly what I have done to get the
lambdas working correctly is:
--------------------------------------------------
(advice-add 'c-looking-at-inexpr-block
:around 'csharp-looking-at-inexpr-block)
(defun csharp-looking-at-inexpr-block (orig-fun &rest args)
(let ((res (csharp-at-lambda-header)))
(if res
res
(apply orig-fun args))))
(defun csharp-at-lambda-header ()
(unless (bobp)
(save-excursion
(c-backward-syntactic-ws)
(backward-char)
(c-safe (goto-char (scan-sexps (point) -1)))
(when (or (looking-at "([[:alnum:][:space:]_,]*)[ \t\n]*=>[ \t\n]*{")
(looking-at "[[:alnum:]_]+[ \t\n]*=>[ \t\n]*{"))
;; If we are at a C# lambda header
(cons 'inexpr (point))))))
--------------------------------------------------
As for the Attributes part:
[...]
>
> I think you know the answer: fix csharp--at-vsemi-p. It seems intended
> to detect the attribute in square brackets and signal a virtual
> semicolon. Why is it not working?
I got this working using vsemi some time ago, but I've moved to using
the 'annotation-top-cont' as used in 'java-mode', since those are
similar enough.
The way I did this is:
--------------------------------------------------
(advice-add 'c-guess-basic-syntax
:around 'csharp-guess-basic-syntax)
(defun csharp-guess-basic-syntax (orig-fun &rest args)
(cond
(;; Attributes
(save-excursion
(goto-char (c-point 'iopl))
(and
(eq (char-after) ?\[)
(save-excursion
(c-go-list-forward)
(and (eq (char-before) ?\])
(not (eq (char-after) ?\;))))))
`((annotation-top-cont ,(c-point 'iopl))))
(t
(apply orig-fun args))))
--------------------------------------------------
Again, this enables 'csharp-mode' to detect and use the available
syntactic constructs, and would also enable people to configure this in
their 'styles-alists'
I am not sure if this is at all 'ok' seen from your perspective, but
this was the only way I could get these constructs to indent correctly
without either monkey-patching or creating some very complicated things
myself. I try to keep things very simple, relying only on CC Mode apis,
but some things just doesn't seem to work out of the box.
However, there is one bug still with this that not the mentioned
approach nor vsemi helped with. Fontification for the line after the
attribute/annotation doesn't work. That is, keywords are still
fontified, but types are not. I think this has to do with the
fontification levels, and the complex-font-lock mechanisms. This is
described in fairly good detail in:
https://github.com/josteink/csharp-mode/issues/142
I think I need to use the 'c-type' 'c-decl-end' text properties, but I
cannot seem to understand how that works right now. I've tried to look
at how Objective-C handles the '@'-annotations, but to no avail yet :)
Apart from these things, I think I have most everything covered, apart
from twiddling the fontification, and the multiline strings issues I
seem to have. (Mentioned in a separate issue - I'll respond to your
thorough answer there). The code base is reduced from 3500 lines to
less than 600, while keeping all the same functionality.
>
>> To reproduce this, you have to (unfortunately...) clone the
>> abovementioned repo, checkout the 'rework' branch, then byte compile
>> that file. I am sorry there is no quicker way to get to that code.
>
>> These snippets should be enough to illustrate my issues.
No need to do this anymore. It is available from Melpa now.
--
Theo
prev parent reply other threads:[~2020-10-09 12:43 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-25 21:05 CC Mode lambda function help Theodor Thornhill
2020-10-09 10:57 ` Alan Mackenzie
2020-10-09 12:43 ` Theodor Thornhill [this message]
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87sgan36yt.fsf@thornhill.no \
--to=theo@thornhill.no \
--cc=acm@muc.de \
--cc=emacs-devel@gnu.org \
/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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.