[TxMt] Re: Code Formatting for keywords

Elia Schito elia at schito.me
Wed Dec 12 22:33:16 UTC 2012


Thanks Andrew!

Elia

☁ @elia <http://twitter.com/elia> ✎ elia at schito.me
☎ (+39) 348/9051393



On Wed, Dec 12, 2012 at 11:23 PM, Andrew Dupont <andrew at andrewdupont.net>wrote:

> Riki,
>
> Perhaps I can elaborate on Elia's behalf:
>
> 1. If you want to abide by TextMate conventions, don't pop up a tooltip;
> edit the Fortran grammar so that keywords are given a scope that begins
> with `invalid.illegal`. Most themes apply a style to `invalid.illegal` that
> makes it stand out as an error, and many bundles have rules to mark things
> that are known to be invalid or cause syntax errors. (For example: in the
> HTML grammar, the sequence `<>` is scoped as
> `invalid.illegal.incomplete.html` because it isn't valid HTML.)
>
> In order to add this rule, you will need to know a little about language
> grammars [1]. In particular, read about the `begin, end` keys in section
> 12.3. A begin/end pattern is the best way to create patterns that apply
> only in certain places, rather than document-wide. Unfortunately, I don't
> know anything about Fortran, so I can't give you further guidance on how
> the rule would look.
>
> If you still want to show a tooltip, you could try the approach I explain
> below. But I wouldn't recommend it.
>
> 2. There's no simple way to do this in TextMate 2.
>
> You could write a command like this [2]. This would activate whenever a
> user typed a keyword, then pressed the space bar. It would replace the
> input with an uppercase version, then insert the space key as the user
> expects.
>
> But this would only work in that specific instance. If Fortran does not
> mandate that a keyword must follow a space (as in C-style syntax, where
> both `if {` and `if{` are valid), then you'd have to figure out which other
> characters can follow identifiers, and then give each one its own command.
> Even so, this wouldn't work on code that is pasted into the editor.
>
> Better to take Elia's advice and create a command that does the
> transformation when the document is saved. Here's an example of how to
> create such a command [3].
>
> (Unfortunately, in your case, this would involve parsing the Fortran code
> so that you could be sure that you were uppercasing only keywords and
> nothing else.)
>
> Cheers,
> Andrew
>
> [1] http://manual.macromates.com/en/language_grammars#language_grammars
> [2] https://gist.github.com/0d6ce8625cf371f22734
> [3]
> http://reinteractive.net/posts/4-stripping-whitespace-out-of-textmate-2
>
> On Dec 7, 2012, at 7:42 AM, riki wrote:
>
> Dear Elia,
>
> Thank you very much for your kind response.
>
> BTW I am not expert in TextMate grammar. So could you please elaborate
> your suggestions?
>
> Kind Regards,
> Riki
>
>
> On Fri, 07 Dec 2012 15:04:26 +0530 wrote
> >1) yes, you can setup the language grammar to catch and highlight those
> keywords in a given scope (e.g. data decl)2) I
> don't think you can do that while you type, but probably you can create a
> command that does the transformation on
> demand (or hook it to the saving)
>
> Elia
> ☁ @elia ✎ elia at schito.me
>
> ☎ (+39) 348/9051393
>
>
>
> On Thu, Nov 29, 2012 at 1:37 PM, riki ** wrote:
>
>
> Hi all,
>
>
>
> How to accomplish the following things within TextMate 2 for Fortran
> language:
>
>
>
> 1) Is it possible to appear warning in a tool tip if we type Fortran
> keywords in data declarations? I am asking because if
>
> somehow or by mistake we are using those ones as variables and we know
> that Fortran does not complain about it.
>
>
>
> 2) The second thing is related to code formatting. Suppose we are writing
> a program in lower case letters and whenever we
>
> type any Fortran keyword we wish that it always came in upper case
> letters. Is there any way to do it?
>
>
>
> Kind Regards,
>
> Riki
>
>
>
> Catch India as it happens with the Rediff News App. To download it for
> FREE, click here
>
>
>
>
> _______________________________________________
>
> textmate mailing list
>
> textmate at lists.macromates.com
>
> http://lists.macromates.com/listinfo/textmate
>
>
>
>
> _______________________________________________
>
> textmate mailing list
>
> textmate at lists.macromates.com
>
> http://lists.macromates.com/listinfo/textmate
> <http://sigads.rediff.com/RealMedia/ads/click_nx.ads/www.rediffmail.com/signatureline.htm@Middle?>
> Follow *Rediff Deal ho jaye!<http://track.rediff.com/click?url=___http://dealhojaye.rediff.com?sc_cid=rediffmailsignature___&cmp=signature&lnk=rediffmailsignature&newservice=deals>
> * to get exciting offers in your city everyday.
> _______________________________________________
> textmate mailing list
> textmate at lists.macromates.com
> http://lists.macromates.com/listinfo/textmate**
>
>
>
>
> _______________________________________________
> textmate mailing list
> textmate at lists.macromates.com
> http://lists.macromates.com/listinfo/textmate
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macromates.com/textmate/attachments/20121212/b75d2efb/attachment.html>


More information about the textmate mailing list