* cc-mode help - how to support literal strings in C# syntax? @ 2009-12-29 1:51 dino chiesa 2009-12-29 10:43 ` Andreas Roehler 0 siblings, 1 reply; 23+ messages in thread From: dino chiesa @ 2009-12-29 1:51 UTC (permalink / raw To: emacs-devel I'm improving the csharp-mode from http://www.emacswiki.org/emacs/CSharpMode . In case you're not aware, it's derived from cc-mode, something like Java, but with a few different syntactic quirks. The existing csharp-mode.el is pretty good. There were a couple things I fixed: - #if/else/endif was not being properly recognized, was indenting and fontifying strangely - a struct was not being treated as a class - indenting inside the block was broken. - class definitions that derived from other classes were not being parsed as a class. These are all minor things I was able to resolve by using c-lang-defconst on various constants: c-typeless-decl-kwds, c-other-block-decl-kwds, c-cpp-message-directives, c-cpp-expr-directives, c-colon-type-list-kwds, c-symbol-chars, c-block-prefix-disallowed-chars, and a few others. There's one think I haven't been able to resolve. In C# syntax, strings can be specified as they are in C - surrounded by quotes. There's also a special form of literal string that begins with @, n which all characters in the string are to be treated as "escaped". In other words @"\usr\bin" == "\\usr\\bin" The problem happens when the literal string ends in a slash. Eg @"\usr\bin\" The cc-mode syntax engine sees that as an unterminated string, the \" is an escaped double-quote. On the other hand the C# compiler sees it as a string of 9 chars. Because it isn't parsed correctly, the fontification and indenting is wrong after a @-prefixed string that ends in a slash. How can I get the prefixed strings to be treated correctly? Defining a special c-in-literal seems not to be it. That function uses parse-partial-sexp , which apparently determines if the point is within a string or not. Modifying the syntax table to insert @ as a special prefix is also not it. Any suggestions? dpchiesa@hotmail.com _________________________________________________________________ Hotmail: Trusted email with powerful SPAM protection. http://clk.atdmt.com/GBL/go/177141665/direct/01/ ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: cc-mode help - how to support literal strings in C# syntax? 2009-12-29 1:51 cc-mode help - how to support literal strings in C# syntax? dino chiesa @ 2009-12-29 10:43 ` Andreas Roehler 2009-12-30 4:40 ` dino chiesa 2009-12-30 5:01 ` first-class support for csharp in cc-mode.el dino chiesa 0 siblings, 2 replies; 23+ messages in thread From: Andreas Roehler @ 2009-12-29 10:43 UTC (permalink / raw To: dino chiesa; +Cc: bug-cc-mode, emacs-devel dino chiesa wrote: > > I'm improving the csharp-mode from http://www.emacswiki.org/emacs/CSharpMode . In case you're not aware, it's derived from cc-mode, something like Java, but with a few different syntactic quirks. > > The existing csharp-mode.el is pretty good. > There were a couple things I fixed: > > - #if/else/endif was not being properly recognized, > was indenting and fontifying strangely > > - a struct was not being treated as a class - indenting inside the block was broken. > > - class definitions that derived from other classes were not being parsed as a class. > > These are all minor things I was able to resolve by using c-lang-defconst on various constants: c-typeless-decl-kwds, c-other-block-decl-kwds, c-cpp-message-directives, c-cpp-expr-directives, c-colon-type-list-kwds, c-symbol-chars, c-block-prefix-disallowed-chars, and a few others. > > There's one think I haven't been able to resolve. In C# syntax, strings can be specified as they are in C - surrounded by quotes. There's also a special form of literal string that begins with @, n which all characters in the string are to be treated as "escaped". In other words > > @"\usr\bin" == "\\usr\\bin" > > The problem happens when the literal string ends in a slash. Eg @"\usr\bin\" The cc-mode syntax engine sees that as an unterminated string, the \" is an escaped double-quote. On the other hand the C# compiler sees it as a string of 9 chars. > > Because it isn't parsed correctly, the fontification and indenting is wrong after a @-prefixed string that ends in a slash. > > > How can I get the prefixed strings to be treated correctly? > Made a beg-end.el for this kind of parsings. Would try it with your problem. Feel free to send me your mode as far its done. Maybe some larger test-code too. Should you want to try it yourself, get beg-end.el at https://code.launchpad.net/s-x-emacs-werkstatt/ Andreas > > Defining a special c-in-literal seems not to be it. That function uses parse-partial-sexp , which apparently determines if the point is within a string or not. > > Modifying the syntax table to insert @ as a special prefix is also not it. > > Any suggestions? > > dpchiesa@hotmail.com > > _________________________________________________________________ > Hotmail: Trusted email with powerful SPAM protection. > http://clk.atdmt.com/GBL/go/177141665/direct/01/ > > ^ permalink raw reply [flat|nested] 23+ messages in thread
* RE: cc-mode help - how to support literal strings in C# syntax? 2009-12-29 10:43 ` Andreas Roehler @ 2009-12-30 4:40 ` dino chiesa 2010-01-01 11:43 ` Andreas Roehler 2010-01-01 16:04 ` Andreas Roehler 2009-12-30 5:01 ` first-class support for csharp in cc-mode.el dino chiesa 1 sibling, 2 replies; 23+ messages in thread From: dino chiesa @ 2009-12-30 4:40 UTC (permalink / raw To: andreas.roehler; +Cc: bug-cc-mode, emacs-devel Andreas, thanks for the reply. The mode is available at: http://www.emacswiki.org/emacs/csharp-mode.el And here is a source code module that exhibits the problem: //======================================== using System; using System.Collections.Generic; namespace Example.LiteralStrings { public class Pippo { // Problem: when the final char in an "escaped" string literal is a // slash, indenting and fontification breaks. List<string> directories = new List<string> { // string #1 in the list @"C:\Temp\sub1\", // The emacs parser thinks the string has not ended. // This comment is fontified and indented as if it is in // the middle of a string literal. // string #2 @"C:\Temp\sub2\", // Because we have another \" at the end of a string, // emacs now thinks we're "out" of the string literal. // This comment is now indented and fontified correctly. // string #3 @"C:\Home\" // A third \", and now emacs thinks we're back inside the string literal. // The rest of the code will be treated as if it were inside the string literal. }; // this is indented wrongly // and the incorrect indenting continues all the way through protected void Page_Load(object sender, EventArgs e) { Console.WriteLine("Hello {0}", "world"); } } } //======================================== I will check out the beg-end.el as well, to see if I can figure out how to use it in cc-mode. (csharp-mode). I'll be interested to see what you find. -Dino > Date: Tue, 29 Dec 2009 11:43:58 +0100 > From: andreas.roehler@online.de > To: dpchiesa@hotmail.com > CC: emacs-devel@gnu.org; bug-cc-mode@gnu.org > Subject: Re: cc-mode help - how to support literal strings in C# syntax? > > dino chiesa wrote: >> >> I'm improving the csharp-mode from http://www.emacswiki.org/emacs/CSharpMode . In case you're not aware, it's derived from cc-mode, something like Java, but with a few different syntactic quirks. >> >> The existing csharp-mode.el is pretty good. >> There were a couple things I fixed: >> >> - #if/else/endif was not being properly recognized, >> was indenting and fontifying strangely >> >> - a struct was not being treated as a class - indenting inside the block was broken. >> >> - class definitions that derived from other classes were not being parsed as a class. >> >> These are all minor things I was able to resolve by using c-lang-defconst on various constants: c-typeless-decl-kwds, c-other-block-decl-kwds, c-cpp-message-directives, c-cpp-expr-directives, c-colon-type-list-kwds, c-symbol-chars, c-block-prefix-disallowed-chars, and a few others. >> >> There's one think I haven't been able to resolve. In C# syntax, strings can be specified as they are in C - surrounded by quotes. There's also a special form of literal string that begins with @, n which all characters in the string are to be treated as "escaped". In other words >> >> @"\usr\bin" == "\\usr\\bin" >> >> The problem happens when the literal string ends in a slash. Eg @"\usr\bin\" The cc-mode syntax engine sees that as an unterminated string, the \" is an escaped double-quote. On the other hand the C# compiler sees it as a string of 9 chars. >> >> Because it isn't parsed correctly, the fontification and indenting is wrong after a @-prefixed string that ends in a slash. >> >> >> How can I get the prefixed strings to be treated correctly? >> > > Made a beg-end.el for this kind of parsings. > Would try it with your problem. > Feel free to send me your mode as far its done. > Maybe some larger test-code too. > > Should you want to try it yourself, get beg-end.el at > > https://code.launchpad.net/s-x-emacs-werkstatt/ > > > Andreas > > > > >> >> Defining a special c-in-literal seems not to be it. That function uses parse-partial-sexp , which apparently determines if the point is within a string or not. >> >> Modifying the syntax table to insert @ as a special prefix is also not it. >> >> Any suggestions? >> >> dpchiesa@hotmail.com >> >> _________________________________________________________________ >> Hotmail: Trusted email with powerful SPAM protection. >> http://clk.atdmt.com/GBL/go/177141665/direct/01/ >> >> > _________________________________________________________________ Hotmail: Trusted email with powerful SPAM protection. http://clk.atdmt.com/GBL/go/177141665/direct/01/ ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: cc-mode help - how to support literal strings in C# syntax? 2009-12-30 4:40 ` dino chiesa @ 2010-01-01 11:43 ` Andreas Roehler 2010-01-01 16:04 ` Andreas Roehler 1 sibling, 0 replies; 23+ messages in thread From: Andreas Roehler @ 2010-01-01 11:43 UTC (permalink / raw To: dino chiesa; +Cc: bug-cc-mode, emacs-devel ok, had to change beg-end.el still a little bit, as beg- and end-string are equal here Here its use in thingatpt-utils-base.el ;; Doublequoted (put 'doublequoted 'beginning-op-at (lambda () (beginning-of-form-base "\"" "\"" nil 1))) (put 'doublequoted 'end-op-at (lambda () (when (looking-at "\"") (end-of-form-base "\"" "\"" nil 1)))) It now returns things between regardless escapes. Not uploaded yet. Still some minor issues, checks to do. I'll send a message, if its ready. hopefully, happy new year Andreas dino chiesa wrote: > Andreas, thanks for the reply. > The mode is available at: > http://www.emacswiki.org/emacs/csharp-mode.el > > > And here is a source code module that exhibits the problem: > //======================================== > using System; > using System.Collections.Generic; > > namespace Example.LiteralStrings > { > public class Pippo > { > // Problem: when the final char in an "escaped" string literal is a > // slash, indenting and fontification breaks. > List<string> directories = new List<string> { > // string #1 in the list > @"C:\Temp\sub1\", > // The emacs parser thinks the string has not ended. > // This comment is fontified and indented as if it is in > // the middle of a string literal. > // string #2 > @"C:\Temp\sub2\", > // Because we have another \" at the end of a string, > // emacs now thinks we're "out" of the string literal. > // This comment is now indented and fontified correctly. > // string #3 > @"C:\Home\" > // A third \", and now emacs thinks we're back inside the string literal. > // The rest of the code will be treated as if it were inside the string literal. > }; // this is indented wrongly > // and the incorrect indenting continues all the way through > protected void Page_Load(object sender, EventArgs e) > { > Console.WriteLine("Hello {0}", "world"); > } > } > } > > //======================================== > > > I will check out the beg-end.el as well, to see if I can figure out how to use it in cc-mode. > (csharp-mode). > > I'll be interested to see what you find. > > > -Dino > > > >> Date: Tue, 29 Dec 2009 11:43:58 +0100 >> From: andreas.roehler@online.de >> To: dpchiesa@hotmail.com >> CC: emacs-devel@gnu.org; bug-cc-mode@gnu.org >> Subject: Re: cc-mode help - how to support literal strings in C# syntax? >> >> dino chiesa wrote: >>> I'm improving the csharp-mode from http://www.emacswiki.org/emacs/CSharpMode . In case you're not aware, it's derived from cc-mode, something like Java, but with a few different syntactic quirks. >>> >>> The existing csharp-mode.el is pretty good. >>> There were a couple things I fixed: >>> >>> - #if/else/endif was not being properly recognized, >>> was indenting and fontifying strangely >>> >>> - a struct was not being treated as a class - indenting inside the block was broken. >>> >>> - class definitions that derived from other classes were not being parsed as a class. >>> >>> These are all minor things I was able to resolve by using c-lang-defconst on various constants: c-typeless-decl-kwds, c-other-block-decl-kwds, c-cpp-message-directives, c-cpp-expr-directives, c-colon-type-list-kwds, c-symbol-chars, c-block-prefix-disallowed-chars, and a few others. >>> >>> There's one think I haven't been able to resolve. In C# syntax, strings can be specified as they are in C - surrounded by quotes. There's also a special form of literal string that begins with @, n which all characters in the string are to be treated as "escaped". In other words >>> >>> @"\usr\bin" == "\\usr\\bin" >>> >>> The problem happens when the literal string ends in a slash. Eg @"\usr\bin\" The cc-mode syntax engine sees that as an unterminated string, the \" is an escaped double-quote. On the other hand the C# compiler sees it as a string of 9 chars. >>> >>> Because it isn't parsed correctly, the fontification and indenting is wrong after a @-prefixed string that ends in a slash. >>> >>> >>> How can I get the prefixed strings to be treated correctly? >>> >> Made a beg-end.el for this kind of parsings. >> Would try it with your problem. >> Feel free to send me your mode as far its done. >> Maybe some larger test-code too. >> >> Should you want to try it yourself, get beg-end.el at >> >> https://code.launchpad.net/s-x-emacs-werkstatt/ >> >> >> Andreas >> >> >> >> >>> Defining a special c-in-literal seems not to be it. That function uses parse-partial-sexp , which apparently determines if the point is within a string or not. >>> >>> Modifying the syntax table to insert @ as a special prefix is also not it. >>> >>> Any suggestions? >>> >>> dpchiesa@hotmail.com >>> >>> _________________________________________________________________ >>> Hotmail: Trusted email with powerful SPAM protection. >>> http://clk.atdmt.com/GBL/go/177141665/direct/01/ >>> >>> >> > _________________________________________________________________ > Hotmail: Trusted email with powerful SPAM protection. > http://clk.atdmt.com/GBL/go/177141665/direct/01/ ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: cc-mode help - how to support literal strings in C# syntax? 2009-12-30 4:40 ` dino chiesa 2010-01-01 11:43 ` Andreas Roehler @ 2010-01-01 16:04 ` Andreas Roehler 1 sibling, 0 replies; 23+ messages in thread From: Andreas Roehler @ 2010-01-01 16:04 UTC (permalink / raw To: dino chiesa; +Cc: bug-cc-mode, emacs-devel Hi again, with little experimental form below `@-prefixed-csharp-string' is detected. See screenshot attached. It's core is built upon thingatpt-utils-base.el from https://code.launchpad.net/s-x-emacs-werkstatt/ Reporting borders and all kind of at-point-functions will be available likewise - it's just to put new form `@-Prefixed-csharp-string' into a template. If that kind of functions being useful, needed functions from thingatpt-utils-base.el might be extracted into a standalone app. Andreas ;;;;;;;; (require 'thingatpt-utils-base) ;; @-Prefixed-csharp-string (put '@-prefixed-csharp-string 'beginning-op-at (lambda () (beginning-of-form-base "@\"" "[^@]\"" nil 1))) (put '@-prefixed-csharp-string 'end-op-at (lambda () (when (looking-at "@\"") (end-of-form-base "@\"" "[^@]\"" nil 1)))) (defun @-prefixed-csharp-string (&optional arg) "Returns @-prefixed-csharp-string at point if any, nil otherwise. " (interactive "P") (th '@-prefixed-csharp-string arg (interactive-p))) ;;;;;;; ^ permalink raw reply [flat|nested] 23+ messages in thread
* first-class support for csharp in cc-mode.el 2009-12-29 10:43 ` Andreas Roehler 2009-12-30 4:40 ` dino chiesa @ 2009-12-30 5:01 ` dino chiesa 2009-12-30 6:17 ` Miles Bader 2009-12-30 15:19 ` Alan Mackenzie 1 sibling, 2 replies; 23+ messages in thread From: dino chiesa @ 2009-12-30 5:01 UTC (permalink / raw To: emacs-devel I don't have much experience with emacs-devel, but what would it take to get csharp to be supported as a first-class (built-in) language in cc-mode? The stuff done to support it in http://www.emacswiki.org/emacs/CSharpMode is all via documented cc-mode c-lang-const things, and it seems to me these could be folded into the cc-mode code without disturbing support for C/C++, Java, or other cc-mode languages. I would guess that more emacs people are using C# these days than CORBA IDL, which is supported in cc-mode. I have no idea if this is a friendly proposal or not, but it would make things nice for people who write C# and use emacs. There are still a few issues with that C# mode - lambdas have no special support, and the new dynamic keyword in .NET 4.0 isn't there (simple to add), and there is the literal string thing I described in my other mail thread - but mostly it works well. Including this would provide a good baseline of support in emacs for C#. -Dino _________________________________________________________________ Hotmail: Trusted email with Microsoft’s powerful SPAM protection. http://clk.atdmt.com/GBL/go/177141664/direct/01/ ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: first-class support for csharp in cc-mode.el 2009-12-30 5:01 ` first-class support for csharp in cc-mode.el dino chiesa @ 2009-12-30 6:17 ` Miles Bader 2009-12-30 7:18 ` dino chiesa 2009-12-30 15:19 ` Alan Mackenzie 1 sibling, 1 reply; 23+ messages in thread From: Miles Bader @ 2009-12-30 6:17 UTC (permalink / raw To: dino chiesa; +Cc: emacs-devel dino chiesa <dpchiesa@hotmail.com> writes: > I don't have much experience with emacs-devel, but what would it take > to get csharp to be supported as a first-class (built-in) language in > cc-mode? Not that hard i think, it's basically like java plus some tweaks. [when i need to look at a c# file, i just use java-mode and deal with exceptions manually] -Miles -- Neighbor, n. One whom we are commanded to love as ourselves, and who does all he knows how to make us disobedient. ^ permalink raw reply [flat|nested] 23+ messages in thread
* RE: first-class support for csharp in cc-mode.el 2009-12-30 6:17 ` Miles Bader @ 2009-12-30 7:18 ` dino chiesa 2009-12-30 11:09 ` Miles Bader 0 siblings, 1 reply; 23+ messages in thread From: dino chiesa @ 2009-12-30 7:18 UTC (permalink / raw To: miles; +Cc: emacs-devel Miles, I agree, I don't think it would be difficult. The csharp mode is just about done. What I mean is, are there hurdles to getting a new cc-mode language approved? Who does the work? Would that be me, or someone else? How difficult would it be to get it folded into cc-mode.el officially? -Dino ---------------------------------------- > From: miles@gnu.org > To: dpchiesa@hotmail.com > CC: emacs-devel@gnu.org > Subject: Re: first-class support for csharp in cc-mode.el > Date: Wed, 30 Dec 2009 15:17:16 +0900 > > dino chiesa writes: >> I don't have much experience with emacs-devel, but what would it take >> to get csharp to be supported as a first-class (built-in) language in >> cc-mode? > > Not that hard i think, it's basically like java plus some tweaks. > > [when i need to look at a c# file, i just use java-mode and deal with > exceptions manually] > > -Miles > > -- > Neighbor, n. One whom we are commanded to love as ourselves, and who does all > he knows how to make us disobedient. _________________________________________________________________ Hotmail: Trusted email with Microsoft’s powerful SPAM protection. http://clk.atdmt.com/GBL/go/177141664/direct/01/ ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: first-class support for csharp in cc-mode.el 2009-12-30 7:18 ` dino chiesa @ 2009-12-30 11:09 ` Miles Bader 2009-12-30 15:00 ` dino chiesa 0 siblings, 1 reply; 23+ messages in thread From: Miles Bader @ 2009-12-30 11:09 UTC (permalink / raw To: dino chiesa; +Cc: emacs-devel dino chiesa <dpchiesa@hotmail.com> writes: > I agree, I don't think it would be difficult. The csharp mode is just about done. > > What I mean is, are there hurdles to getting a new cc-mode language > approved? Who does the work? Would that be me, or someone else? Talk to acm at muc.de about the details, he's the cc-mode maintainer. -Miles -- "I distrust a research person who is always obviously busy on a task." --Robert Frosch, VP, GM Research ^ permalink raw reply [flat|nested] 23+ messages in thread
* RE: first-class support for csharp in cc-mode.el 2009-12-30 11:09 ` Miles Bader @ 2009-12-30 15:00 ` dino chiesa 0 siblings, 0 replies; 23+ messages in thread From: dino chiesa @ 2009-12-30 15:00 UTC (permalink / raw To: miles; +Cc: emacs-devel Thanks, Miles. ---------------------------------------- > From: miles@gnu.org > To: dpchiesa@hotmail.com > CC: emacs-devel@gnu.org > Subject: Re: first-class support for csharp in cc-mode.el > Date: Wed, 30 Dec 2009 20:09:00 +0900 > > dino chiesa writes: >> I agree, I don't think it would be difficult. The csharp mode is just about done. >> >> What I mean is, are there hurdles to getting a new cc-mode language >> approved? Who does the work? Would that be me, or someone else? > > Talk to acm at muc.de about the details, he's the cc-mode maintainer. > > -Miles > > -- > "I distrust a research person who is always obviously busy on a task." > --Robert Frosch, VP, GM Research _________________________________________________________________ Your E-mail and More On-the-Go. Get Windows Live Hotmail Free. http://clk.atdmt.com/GBL/go/171222985/direct/01/ ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: first-class support for csharp in cc-mode.el 2009-12-30 5:01 ` first-class support for csharp in cc-mode.el dino chiesa 2009-12-30 6:17 ` Miles Bader @ 2009-12-30 15:19 ` Alan Mackenzie 2009-12-30 15:39 ` Stefan Monnier 1 sibling, 1 reply; 23+ messages in thread From: Alan Mackenzie @ 2009-12-30 15:19 UTC (permalink / raw To: dino chiesa; +Cc: emacs-devel Hi, Dino, I'm the current maintainer of CC Mode. On Tue, Dec 29, 2009 at 09:01:00PM -0800, dino chiesa wrote: > I don't have much experience with emacs-devel, but what would it take > to get csharp to be supported as a first-class (built-in) language in > cc-mode? The current policy is not to add any more languages to the core of CC Mode, since it's hassle enough supporting the seven that are already there. There are certainly lots of users of C, C++, Java, several users of Objective C and AWK, but I just don't know about Pike and IDL. The problem is, when somebody implements support for a language directly in CC Mode and they move on a few years later, support for that langauge effectively vanishes. It was to fix this that Martin Stjernholm (my predecessor) implemented the c-lang-const mechanism. > The stuff done to support it in > http://www.emacswiki.org/emacs/CSharpMode is all via documented > cc-mode c-lang-const things, and it seems to me these could be folded > into the cc-mode code without disturbing support for C/C++, Java, or > other cc-mode languages. I would guess that more emacs people are > using C# these days than CORBA IDL, which is supported in cc-mode. If the c-lang-const stuff is inadequate to support, say, C#, then I would prefer to amend CC Mode so that C# can be supported. It looks like the @"....." syntax will need such an amendment. This will probably involve a large change, since the use of \ as an escape character is firmly embedded in the very fabric of CC Mode. Is @ used for anything else in C#? Is it forbidden to have whitespace between @ and "? In fact, I've just thought of a way of fixing this: in an after-change function, splat the syntax (using syntax-table text-properties) of anything within @"....". I think there's already a suitable hook in CC Mode for this. > I have no idea if this is a friendly proposal or not, but it would > make things nice for people who write C# and use emacs. Thanks for the proposal! Constructive suggestions are always welcome at CC Mode. By the way, CC Mode has its own mailing list at bug-cc-mode@gnu.org and is hosted on sourceforge for historical reasons. > There are still a few issues with that C# mode - lambdas have no > special support, and the new dynamic keyword in .NET 4.0 isn't there > (simple to add), and there is the literal string thing I described in > my other mail thread - but mostly it works well. Including this would > provide a good baseline of support in emacs for C#. Those are all issues for C# Mode's maintainer. > -Dino -- Alan Mackenzie (Nuremberg, Germany). ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: first-class support for csharp in cc-mode.el 2009-12-30 15:19 ` Alan Mackenzie @ 2009-12-30 15:39 ` Stefan Monnier 2009-12-30 16:29 ` dino chiesa 2009-12-30 20:19 ` Alan Mackenzie 0 siblings, 2 replies; 23+ messages in thread From: Stefan Monnier @ 2009-12-30 15:39 UTC (permalink / raw To: Alan Mackenzie; +Cc: dino chiesa, emacs-devel > If the c-lang-const stuff is inadequate to support, say, C#, then I > would prefer to amend CC Mode so that C# can be supported. So you're moving towards a CC-mode which is more like a "generic" engine? That's good to hear. Do you intend to then move support for AWK, IDL, Java, etc.. outside of the core CC-mode as well? > In fact, I've just thought of a way of fixing this: in an after-change > function, splat the syntax (using syntax-table text-properties) of > anything within @"....". My experience leads me to recommend to only change the syntax of the final \ (if any) rather than of everything. Stefan ^ permalink raw reply [flat|nested] 23+ messages in thread
* RE: first-class support for csharp in cc-mode.el 2009-12-30 15:39 ` Stefan Monnier @ 2009-12-30 16:29 ` dino chiesa 2009-12-30 16:57 ` Stefan Monnier ` (2 more replies) 2009-12-30 20:19 ` Alan Mackenzie 1 sibling, 3 replies; 23+ messages in thread From: dino chiesa @ 2009-12-30 16:29 UTC (permalink / raw To: monnier, acm; +Cc: emacs-devel Hi Alan, nice to meet you. Stefan, thanks for the input. acm@muc.de wrote: >> I don't have much experience with emacs-devel, but what would it take >> to get csharp to be supported as a first-class (built-in) language in >> cc-mode? > > The current policy is not to add any more languages to the core of CC > Mode, since it's hassle enough supporting the seven that are already > there. There are certainly lots of users of C, C++, Java, several users > of Objective C and AWK, but I just don't know about Pike and IDL. The > problem is, when somebody implements support for a language directly in > CC Mode and they move on a few years later, support for that langauge > effectively vanishes. It was to fix this that Martin Stjernholm (my > predecessor) implemented the c-lang-const mechanism. > Very clear. In that case I should be petitioning to get csharp-mode put into the emacs progmodes distrib separately, rather than petitioning to get csharp-mode folded into cc-mode. > If the c-lang-const stuff is inadequate to support, say, C#, then I > would prefer to amend CC Mode so that C# can be supported. It looks > like the @"....." syntax will need such an amendment. This will > probably involve a large change, since the use of \ as an escape > character is firmly embedded in the very fabric of CC Mode. Is @ used > for anything else in C#? Is it forbidden to have whitespace between @ > and "? Yes, according to the lang spec, the @ must immediately be followed by a double-quote. The symbol is not used for anything else in the language. I just looked and this is called a "verbatim string literal". http://www.go-mono.com/docs/index.aspx?link=ecmaspec%3a9.4.4.5 > > In fact, I've just thought of a way of fixing this: in an after-change > function, splat the syntax (using syntax-table text-properties) of > anything within @"....". I think there's already a suitable hook in CC > Mode for this. > Is this the approach used for handling of slashes within awk? (can be either a divide operator or a string delimiter). I tried wading through that code but didn't yet figure it out. In csharp, it is not only a trailing slash that is special - the verbatim string also allows verbatim newlines in the string. This is legal: var s = @"The quick brown fox jumps over the lazy dog"; and results in a string with a \n between the 4th and 5th words. I don't know how that might affect the final design of a solution, or if it recommends or disrecommends Stefan's suggestion to worry only about the final slash. >> I have no idea if this is a friendly proposal or not, but it would >> make things nice for people who write C# and use emacs. > > Thanks for the proposal! Constructive suggestions are always welcome at > CC Mode. By the way, CC Mode has its own mailing list at > bug-cc-mode@gnu.org and is hosted on sourceforge for historical reasons. > Ah, very good. Is bug-cc-mode intended to serve discussion related only to bugs or potential bugs, or is it also good for random discussion or questions from cc-derived modes? I mean, if I were to ask specifically about the verbatim string literals, should I ask on emacs-devel or is it better on bug-cc-mode ? >> There are still a few issues with that C# mode - lambdas have no >> special support, and the new dynamic keyword in .NET 4.0 isn't there >> (simple to add), and there is the literal string thing I described in >> my other mail thread - but mostly it works well. Including this would >> provide a good baseline of support in emacs for C#. > > Those are all issues for C# Mode's maintainer. > Right, those are issues for me (and friends) to own. I wasn't really asking for *that*, although I may ask for specific advice on some of those in the future, after I take a run at them, I hope you don't mind. My real goal regarding "first class support" is to make csharp-mode official and standard, so that someone downloading emacs 24 or 23.x will just get it. I had originally thought that meant major surgery on cc-mode, but you're telling me it could be simpler than that. monnier@iro.umontreal.ca wrote: > > So you're moving towards a CC-mode which is more like > a "generic" engine? That's good to hear. Do you intend to then move > support for AWK, IDL, Java, etc.. outside of the core CC-mode as well? > I'll let Alan address that. _________________________________________________________________ Hotmail: Powerful Free email with security by Microsoft. http://clk.atdmt.com/GBL/go/171222986/direct/01/ ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: first-class support for csharp in cc-mode.el 2009-12-30 16:29 ` dino chiesa @ 2009-12-30 16:57 ` Stefan Monnier 2009-12-30 21:01 ` Alan Mackenzie 2009-12-31 11:43 ` Vagn Johansen 2 siblings, 0 replies; 23+ messages in thread From: Stefan Monnier @ 2009-12-30 16:57 UTC (permalink / raw To: dino chiesa; +Cc: acm, emacs-devel > Very clear. In that case I should be petitioning to get csharp-mode > put into the emacs progmodes distrib separately, rather than > petitioning to get csharp-mode folded into cc-mode. Here are the hurdles: 1- The usual issue of getting the necessary paperwork in order (i.e. track down all the non-negligible contributors and get them to sign the copyright thingies). 2- Get the code into shape (follow coding conventions, mostly). 3- Figure out whether it's politically acceptable: the FSF doesn't like the .NET framework because it is too much under control of a company we distrust, so the FSF doesn't want to encourage the development of applications using the .NET platform. I would personally accept csharp-mode.el, as long as we're careful to support the Free part of .NET (i.e. Mono) rather than the MS-specific tools. > I don't know how that might affect the final design of a solution, or > if it recommends or disrecommends Stefan's suggestion to worry only > about the final slash. My main recommendation is to only add a syntax table on the chars where we know we need it (i.e. final backslash, and intermediate LFs if necessary, and whichever more is found to need such treatment), rather than blindly on the whole text. Stefan ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: first-class support for csharp in cc-mode.el 2009-12-30 16:29 ` dino chiesa 2009-12-30 16:57 ` Stefan Monnier @ 2009-12-30 21:01 ` Alan Mackenzie 2009-12-30 21:03 ` dino chiesa 2009-12-31 11:43 ` Vagn Johansen 2 siblings, 1 reply; 23+ messages in thread From: Alan Mackenzie @ 2009-12-30 21:01 UTC (permalink / raw To: dino chiesa; +Cc: monnier, emacs-devel Hi, Dino, On Wed, Dec 30, 2009 at 08:29:14AM -0800, dino chiesa wrote: > Hi Alan, nice to meet you. > Stefan, thanks for the input. > acm@muc.de wrote: > > The current policy is not to add any more languages to the core of CC > > Mode, since it's hassle enough supporting the seven that are already > > there. There are certainly lots of users of C, C++, Java, several > > users of Objective C and AWK, but I just don't know about Pike and > > IDL. The problem is, when somebody implements support for a language > > directly in CC Mode and they move on a few years later, support for > > that langauge effectively vanishes. It was to fix this that Martin > > Stjernholm (my predecessor) implemented the c-lang-const mechanism. > Very clear. In that case I should be petitioning to get csharp-mode put > into the emacs progmodes distrib separately, rather than petitioning to > get csharp-mode folded into cc-mode. I think so. I doubt Stefan will take that much persuading. ;-) > > If the c-lang-const stuff is inadequate to support, say, C#, then I > > would prefer to amend CC Mode so that C# can be supported. It looks > > like the @"....." syntax will need such an amendment. This will > > probably involve a large change, since the use of \ as an escape > > character is firmly embedded in the very fabric of CC Mode. Is @ used > > for anything else in C#? Is it forbidden to have whitespace between @ > > and "? > Yes, according to the lang spec, the @ must immediately be followed by > a double-quote. The symbol is not used for anything else in the > language. I just looked and this is called a "verbatim string literal". > http://www.go-mono.com/docs/index.aspx?link=ecmaspec%3a9.4.4.5 > > In fact, I've just thought of a way of fixing this: in an > > after-change function, splat the syntax (using syntax-table > > text-properties) of anything within @"....". I think there's already > > a suitable hook in CC Mode for this. I've had a look at this. The two hooks you want are c-get-state-before-change-function and c-before-font-lock-function, both of which are c-lang-defconsts. In the function you put in the first hook, you should see whether or not you're about to disrupt the status of one or more @"......\" constructs. There'll be some cunning special cases to check here. The function on the second hook will actually add the text-property to the pertinent \, or possibly remove it. > Is this the approach used for handling of slashes within awk? (can be > either a divide operator or a string delimiter). I tried wading through > that code but didn't yet figure it out. :-) I wrote that code some while ago, and I'm not sure I could figure it out any more. It's a fairly involved finite state machine implemented by regular expressions. > In csharp, it is not only a trailing slash that is special - the > verbatim string also allows verbatim newlines in the string. This is > legal: > var s = @"The quick brown fox > jumps over the lazy dog"; > and results in a string with a \n between the 4th and 5th words. > I don't know how that might affect the final design of a solution, or > if it recommends or disrecommends Stefan's suggestion to worry only > about the final slash. I couldn't say off-hand either. I suspect it would just work. > >> I have no idea if this is a friendly proposal or not, but it would > >> make things nice for people who write C# and use emacs. > > Thanks for the proposal! Constructive suggestions are always welcome at > > CC Mode. By the way, CC Mode has its own mailing list at > > bug-cc-mode@gnu.org and is hosted on sourceforge for historical reasons. > Ah, very good. Is bug-cc-mode intended to serve discussion related only > to bugs or potential bugs, or is it also good for random discussion or > questions from cc-derived modes? I mean, if I were to ask specifically > about the verbatim string literals, should I ask on emacs-devel or is > it better on bug-cc-mode ? Probably better on bug-cc-mode, but more people will see it on emacs-devel. > >> There are still a few issues with that C# mode - lambdas have no > >> special support, and the new dynamic keyword in .NET 4.0 isn't there > >> (simple to add), and there is the literal string thing I described > >> in my other mail thread - but mostly it works well. Including this > >> would provide a good baseline of support in emacs for C#. > > Those are all issues for C# Mode's maintainer. > Right, those are issues for me (and friends) to own. I wasn't really > asking for *that*, although I may ask for specific advice on some of > those in the future, after I take a run at them, I hope you don't mind. > My real goal regarding "first class support" is to make csharp-mode > official and standard, so that someone downloading emacs 24 or 23.x > will just get it. I had originally thought that meant major surgery on > cc-mode, but you're telling me it could be simpler than that. It should be, and if it's not, I should be able to make it so. -- Alan Mackenzie (Nuremberg, Germany). ^ permalink raw reply [flat|nested] 23+ messages in thread
* RE: first-class support for csharp in cc-mode.el 2009-12-30 21:01 ` Alan Mackenzie @ 2009-12-30 21:03 ` dino chiesa 2009-12-31 2:44 ` Miles Bader 0 siblings, 1 reply; 23+ messages in thread From: dino chiesa @ 2009-12-30 21:03 UTC (permalink / raw To: Alan MacKenzie; +Cc: Stefan Monnier, emacs-devel Hello again Alan, and thanks for having a look at this. > > I've had a look at this. The two hooks you want are > c-get-state-before-change-function and c-before-font-lock-function, both > of which are c-lang-defconsts. In the function you put in the first > hook, you should see whether or not you're about to disrupt the status of > one or more @"......\" constructs. There'll be some cunning special > cases to check here. The function on the second hook will actually add > the text-property to the pertinent \, or possibly remove it. > Ok, I understand all that. I started working through the special cases and yes, they are cunning. So far they are outsmarting me. I also understand the c-before-font-lock-function and adding or removing text properties. That should be easy once the state is understood. Question - Will adding and removing text properties allow parse-partial-sexp, c-in-literal, and their friends to work "correctly"? Right now c-in-literal gets confused by doubled double-quotes. Will these problems just go away when I get the text properties right? I haven't fully understood how text properties affect the rest of the cc engine. Thanks again. -Dino _________________________________________________________________ Hotmail: Trusted email with powerful SPAM protection. http://clk.atdmt.com/GBL/go/177141665/direct/01/ ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: first-class support for csharp in cc-mode.el 2009-12-30 21:03 ` dino chiesa @ 2009-12-31 2:44 ` Miles Bader 2009-12-31 2:58 ` Jason Rumney ` (2 more replies) 0 siblings, 3 replies; 23+ messages in thread From: Miles Bader @ 2009-12-31 2:44 UTC (permalink / raw To: dino chiesa; +Cc: Alan MacKenzie, Stefan Monnier, emacs-devel Incidentally the thing about C# which annoyed me (using java-mode to try and indent C# code) were all the "annotation" things (which start with "#"), which I _gather_ are supposed to be at the left margin, but generally cause following indentation to be all messed up. -Miles -- Liberty, n. One of imagination's most precious possessions. ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: first-class support for csharp in cc-mode.el 2009-12-31 2:44 ` Miles Bader @ 2009-12-31 2:58 ` Jason Rumney 2009-12-31 3:08 ` Deniz Dogan 2009-12-31 3:13 ` dino chiesa 2 siblings, 0 replies; 23+ messages in thread From: Jason Rumney @ 2009-12-31 2:58 UTC (permalink / raw To: Miles Bader; +Cc: dino chiesa, emacs-devel On 31/12/2009 10:44, Miles Bader wrote: > Incidentally the thing about C# which annoyed me (using java-mode to try > and indent C# code) were all the "annotation" things (which start with > "#"), which I _gather_ are supposed to be at the left margin, but > generally cause following indentation to be all messed up. > This is probably only due to using java-mode, since Java does not have pre-processor instructions. ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: first-class support for csharp in cc-mode.el 2009-12-31 2:44 ` Miles Bader 2009-12-31 2:58 ` Jason Rumney @ 2009-12-31 3:08 ` Deniz Dogan 2009-12-31 3:18 ` dino chiesa 2009-12-31 3:13 ` dino chiesa 2 siblings, 1 reply; 23+ messages in thread From: Deniz Dogan @ 2009-12-31 3:08 UTC (permalink / raw To: Miles Bader; +Cc: Alan MacKenzie, Stefan Monnier, dino chiesa, emacs-devel 2009/12/31 Miles Bader <miles@gnu.org>: > Incidentally the thing about C# which annoyed me (using java-mode to try > and indent C# code) were all the "annotation" things (which start with > "#"), which I _gather_ are supposed to be at the left margin, but > generally cause following indentation to be all messed up. > > -Miles > > -- > Liberty, n. One of imagination's most precious possessions. > > > Actually, Visual Studio 2008 indents #region and #endregion to the same level as the code, whereas I think other "preprocessor" instructions are at the left margin. (But I haven't seen any such things in C#, ever.) -- Deniz Dogan ^ permalink raw reply [flat|nested] 23+ messages in thread
* RE: first-class support for csharp in cc-mode.el 2009-12-31 3:08 ` Deniz Dogan @ 2009-12-31 3:18 ` dino chiesa 0 siblings, 0 replies; 23+ messages in thread From: dino chiesa @ 2009-12-31 3:18 UTC (permalink / raw To: deniz.a.m.dogan, Miles Bader; +Cc: Alan MacKenzie, Stefan Monnier, emacs-devel C# has #region/#endregion, #if/#else/#endif, #define/#undef, and #pragma. Using the csharp-mode.el v0.7.0, indenting for all of those was broken. Using the updated csharp-mode.el 0.7.1, indenting of those things works just fine. And, you have your choice to align #if/#else/#endif and #region/#endregion with either the 0'th column or to indent it to the current code scope. #pragma and #define/#undef always go to the 0'th column. The mode is pretty good now. There were some other problems that I clean up too. The one big remaining sticky point is verbatim literal strings, which is kind of tricky. -Dino ---------------------------------------- > From: deniz.a.m.dogan@gmail.com > Date: Thu, 31 Dec 2009 04:08:21 +0100 > Subject: Re: first-class support for csharp in cc-mode.el > To: miles@gnu.org > CC: dpchiesa@hotmail.com; acm@muc.de; monnier@iro.umontreal.ca; emacs-devel@gnu.org > > 2009/12/31 Miles Bader : >> Incidentally the thing about C# which annoyed me (using java-mode to try >> and indent C# code) were all the "annotation" things (which start with >> "#"), which I _gather_ are supposed to be at the left margin, but >> generally cause following indentation to be all messed up. >> >> -Miles >> >> -- >> Liberty, n. One of imagination's most precious possessions. >> >> >> > > Actually, Visual Studio 2008 indents #region and #endregion to the > same level as the code, whereas I think other "preprocessor" > instructions are at the left margin. (But I haven't seen any such > things in C#, ever.) > > -- > Deniz Dogan _________________________________________________________________ Hotmail: Free, trusted and rich email service. http://clk.atdmt.com/GBL/go/171222984/direct/01/ ^ permalink raw reply [flat|nested] 23+ messages in thread
* RE: first-class support for csharp in cc-mode.el 2009-12-31 2:44 ` Miles Bader 2009-12-31 2:58 ` Jason Rumney 2009-12-31 3:08 ` Deniz Dogan @ 2009-12-31 3:13 ` dino chiesa 2 siblings, 0 replies; 23+ messages in thread From: dino chiesa @ 2009-12-31 3:13 UTC (permalink / raw To: miles; +Cc: Alan MacKenzie, Stefan Monnier, emacs-devel Yes, I've noticed that, and fixed it. It happens in Csharp-mode v0.7.0 which has been out for some time, but it doesn't happen in v0.7.1, which I just posted to emacswiki this week. It was due to a bad regexp in csharp-mode.el. ---------------------------------------- > From: miles@gnu.org > To: dpchiesa@hotmail.com > CC: acm@muc.de; monnier@iro.umontreal.ca; emacs-devel@gnu.org > Subject: Re: first-class support for csharp in cc-mode.el > Date: Thu, 31 Dec 2009 11:44:26 +0900 > > Incidentally the thing about C# which annoyed me (using java-mode to try > and indent C# code) were all the "annotation" things (which start with > "#"), which I _gather_ are supposed to be at the left margin, but > generally cause following indentation to be all messed up. > > -Miles > > -- > Liberty, n. One of imagination's most precious possessions. _________________________________________________________________ Hotmail: Trusted email with Microsoft’s powerful SPAM protection. http://clk.atdmt.com/GBL/go/177141664/direct/01/ ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: first-class support for csharp in cc-mode.el 2009-12-30 16:29 ` dino chiesa 2009-12-30 16:57 ` Stefan Monnier 2009-12-30 21:01 ` Alan Mackenzie @ 2009-12-31 11:43 ` Vagn Johansen 2 siblings, 0 replies; 23+ messages in thread From: Vagn Johansen @ 2009-12-31 11:43 UTC (permalink / raw To: emacs-devel dino chiesa <dpchiesa@hotmail.com> writes: > Yes, according to the lang spec, the @ must immediately be followed > by a double-quote. The symbol is not used for anything else in the > language. I just looked and this is called a "verbatim string > literal". > http://www.go-mono.com/docs/index.aspx?link=ecmaspec%3a9.4.4.5 @ can also be used in front of an identifier. If you want to use keywords like if and else as variable name you can write as @if @else in the code. See page 71 in ECMA-334.pdf or http://www.go-mono.com/docs/index.aspx?link=ecmaspec%3a9.4.2 -- Vagn Johansen ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: first-class support for csharp in cc-mode.el 2009-12-30 15:39 ` Stefan Monnier 2009-12-30 16:29 ` dino chiesa @ 2009-12-30 20:19 ` Alan Mackenzie 1 sibling, 0 replies; 23+ messages in thread From: Alan Mackenzie @ 2009-12-30 20:19 UTC (permalink / raw To: Stefan Monnier; +Cc: dino chiesa, emacs-devel Hi, Stefan, On Wed, Dec 30, 2009 at 01:39:31PM -0200, Stefan Monnier wrote: > > If the c-lang-const stuff is inadequate to support, say, C#, then I > > would prefer to amend CC Mode so that C# can be supported. > So you're moving towards a CC-mode which is more like a "generic" > engine? That's good to hear. Do you intend to then move support for > AWK, IDL, Java, etc.. outside of the core CC-mode as well? In my copious free time. ;-) > > In fact, I've just thought of a way of fixing this: in an > > after-change function, splat the syntax (using syntax-table > > text-properties) of anything within @"....". > My experience leads me to recommend to only change the syntax of the > final \ (if any) rather than of everything. I think so too. > Stefan -- Alan Mackenzie (Nuremberg, Germany). ^ permalink raw reply [flat|nested] 23+ messages in thread
end of thread, other threads:[~2010-01-01 16:04 UTC | newest] Thread overview: 23+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2009-12-29 1:51 cc-mode help - how to support literal strings in C# syntax? dino chiesa 2009-12-29 10:43 ` Andreas Roehler 2009-12-30 4:40 ` dino chiesa 2010-01-01 11:43 ` Andreas Roehler 2010-01-01 16:04 ` Andreas Roehler 2009-12-30 5:01 ` first-class support for csharp in cc-mode.el dino chiesa 2009-12-30 6:17 ` Miles Bader 2009-12-30 7:18 ` dino chiesa 2009-12-30 11:09 ` Miles Bader 2009-12-30 15:00 ` dino chiesa 2009-12-30 15:19 ` Alan Mackenzie 2009-12-30 15:39 ` Stefan Monnier 2009-12-30 16:29 ` dino chiesa 2009-12-30 16:57 ` Stefan Monnier 2009-12-30 21:01 ` Alan Mackenzie 2009-12-30 21:03 ` dino chiesa 2009-12-31 2:44 ` Miles Bader 2009-12-31 2:58 ` Jason Rumney 2009-12-31 3:08 ` Deniz Dogan 2009-12-31 3:18 ` dino chiesa 2009-12-31 3:13 ` dino chiesa 2009-12-31 11:43 ` Vagn Johansen 2009-12-30 20:19 ` Alan Mackenzie
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.