From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Theodor Thornhill Newsgroups: gmane.emacs.devel Subject: Re: CC Mode lambda function help Date: Fri, 09 Oct 2020 14:43:38 +0200 Message-ID: <87sgan36yt.fsf@thornhill.no> References: <87h7rlr2hl.fsf@thornhill.no> <20201009105703.GA4027@ACM> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="39621"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Alan Mackenzie Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Oct 09 14:47:34 2020 Return-path: Envelope-to: ged-emacs-devel@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 1kQro5-000ABS-UY for ged-emacs-devel@m.gmane-mx.org; Fri, 09 Oct 2020 14:47:34 +0200 Original-Received: from localhost ([::1]:50424 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQro0-0002z0-2G for ged-emacs-devel@m.gmane-mx.org; Fri, 09 Oct 2020 08:47:28 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:43252) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQrmn-0002Uo-WF for emacs-devel@gnu.org; Fri, 09 Oct 2020 08:46:14 -0400 Original-Received: from out0.migadu.com ([2001:41d0:2:267::]:23740) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQrmj-0002ep-V6 for emacs-devel@gnu.org; Fri, 09 Oct 2020 08:46:13 -0400 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thornhill.no; s=key1; t=1602247565; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=iCvjLnOu9xC4ID3SXCUSL+wMZT7pphQzq5kwn/g3hKI=; b=iCimLTyGp+dn4LGGQUIw/TDqvrMDKOR8DagkYDl1GRGEOIhAoYo7Xm+6gYuMNXJKynRuBC b1hA1o4JVATumXeSy6FegCsPLJCX5GpSa21cKlCDHAsoJ1oeTppOvJuT3TZ+FdLnQeeiZe T9sCQ8Bp/IMOrit9nII1wHcziWPFwBzeMxfpUnW5lsTytSYii63sKS5ZwmauA6V0UosG09 gRQAer1LAvHy78ToSoJz/i2qW5T2XOa0/pTVVx/mNJMJCHBveudlyAQgj1xdx3D0feQ4sM M8Ahz4Pc5yb8idvef3bXkLH/FhcaBVCcj0XLilchAui8jieYJkfUu10KeB3yUg== In-Reply-To: <20201009105703.GA4027@ACM> Received-SPF: pass client-ip=2001:41d0:2:267::; envelope-from=theo@thornhill.no; helo=out0.migadu.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/09 08:46:06 X-ACL-Warn: Detected OS = ??? 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:257259 Archived-At: 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