Giter Club home page Giter Club logo

Comments (20)

del2z avatar del2z commented on May 16, 2024 6

A simple solution for highlighting functions is putting codes below in ~/.vim/after/syntax/julia.vim.

syntax cluster  juliaParScope           contains=@juliaParItems,juliaParBlockInRange
syntax cluster  juliaBlockScope         contains=@juliaBlocksItems,juliaConditionalEIBlock,juliaConditionalEBlock
syntax cluster  juliaTotalScope         contains=@juliaParScope,@juliaMacroItems,@juliaBlockScope
syntax match    juliaFunction           display "\<[a-z_][a-zA-Z0-9_]*\>!\?\.\?("me=e-1 containedin=@juliaTotalScope
hi def link     juliaFunction           Function

Most function names are highlighted perfectly except in a macro line. And I cannot figure out why this doesn't work. Need improvements.

from julia-vim.

jessebett avatar jessebett commented on May 16, 2024 5

I'm testing out vim as my main Julia editing environment and I am also very much interested in this.

In particular, I would like if the default behavior was as close as possible to that of OhMyREPL.jl as was suggested by @KadeG

To demonstrate the differences I've attached some highlighted code in julia-vim and the equivalent highlighted code slimed over to the REPL:

screen shot 2018-06-08 at 5 20 38 pm

In particular here's a few things I notice are missing in this syntax highlighting:

  • Highlighting of user defined types. Built in types like Float64 are highlighted inconsistently from my custom types.

  • infix operations like +, =, . ...

  • As mentioned above, user defined functions are highlighted in the default behaviour of OhMyREPL.

Would it be possible to have this behaviour as default or maybe optional for julia-vim?

from julia-vim.

KadeG avatar KadeG commented on May 16, 2024 4

To be clear, my ideal would be to replicate OhMYREPL.jl's style. If I can figure out what's going on in the Vim script, I'll try to push OhMyREPL-esk options. Any hints on where to start with the function/call pattern?

from julia-vim.

tomchor avatar tomchor commented on May 16, 2024 3

I've noticed that so far by default the functions aren't being highlighted (or maybe it's just me?) but I feel like some functions in the base are useful enough that they should. Some examples that pop into my mind are include, println, enumerate (and I'm sure there are more).

The fortran and python highlighting schemes (and probably others) use a very soft green color for the basis functions. It doesn't distract or pollute, but it is, in my opinion, nice to the eyes and helpful when coding. Based on that I'm thinking that it would be better if we started highlighting the functions on the base.

Any thoughts?

from julia-vim.

KadeG avatar KadeG commented on May 16, 2024 3

+1 More thorough highlighting would be great.

from julia-vim.

bstellato avatar bstellato commented on May 16, 2024 3

I would also appreciate more colors. Other editors such as Atom or VSCode highlight more things such as default/user-defined function calls:
screen shot 2018-05-18 at 9 46 38 am

from julia-vim.

carlobaldassi avatar carlobaldassi commented on May 16, 2024 1

@jessebett some of the dullness in your vim screenshot is due to your colorscheme, at least the operators should be highlighted. It's also possible to highlight the parentheses by an option (see the docs).

As for making things similar to OhMyREPL: there is a fundamental difference between the way that works and the vim plugin, since OhMyREPL has access to a running Julia version, can use a full-fledged Julia parser, and recognize on the fly what each syntax element is. The vim plugin on the other hand cannot, for example, recognize that something is a user-defined type, it can only recognize the types it knows about.

As for highlighting functions, again it's doable (probably) purely by syntactic inspection, by checking whether an identifier is followed by an open parenthesis (with an optional preceding dot). Note that there is no reasonable sure way that we can discriminate between function declaration and function call though. Anyway one problem with this is that Julia is very permissive with identifier names and that creates some serious performance issues which I'm not sure how to address exactly (the plugin is already quite slow as-is).

from julia-vim.

jessebett avatar jessebett commented on May 16, 2024 1

@carlobaldassi Thanks for your response. I do know that the colour schemes are responsible for the different colours, this post was just to draw the attention to the highlighting itself.

I also appreciate that OhMyREPL does get privileged access to the syntax in a way vim does not. However, do you know if this is also true for the syntax highlighter used by Juno in Atom? Because, for example, it can highlight user defined types.

Actually, discriminating between function declaration and call isn't even consistent in OhMyREPL. for example defining functions inline myfun(x) = x.a would highlight as a call.

However, at least with user defined types it should be possible to syntax after :: and around <: right?
And for function definitions and calls before () and .().

No idea about speed, however.

from julia-vim.

carlobaldassi avatar carlobaldassi commented on May 16, 2024

Variable names and function names are not highlighted in any way at the moment, and I don't know whether it's reasonable to highlight them (for example, this behaviour is the same which you get with C/C++; in python highlighting is done for some built-in functions and function names at the place of definition - which is trickier to do in Julia, although possible I suppose; variables are normally not highlighted in any way to mmy knowledge). Do you have any specific examples in mind?

Operators are highlighted specially (unless you explicitly set g:julia_highlight_operators=0), so that's a problem with your colorscheme, which should define a binding for highlightihg Operator, e.g. hi Operator fg=#ffffff.

At the moment, only exported Base type names are recognized. I'm not sure if it's possible to extend this to all user-defined types (including those which come from using packages) - this would probably require to have a Julia session running in background, which is something I'm thinking about since a while, but never got around to actually try to do (and which would require quite a lot of effort to get right).

from julia-vim.

rafaqz avatar rafaqz commented on May 16, 2024

+1 Nvim R highlights commas and all bracket types in red. I find it helps parsing blocks of otherwise white text. Would be great if this plugin did the same.

from julia-vim.

carlobaldassi avatar carlobaldassi commented on May 16, 2024

Note that brackets highlighting is disabled by default, but you can use something like this to enable it:

:hi link juliaParDelim Delimiter

(this would use the Delimiter color specified by your colorscheme.)

An analogous option can be used for juliaSemicolon (e.g. linking it to Operator), and I have just added another one for juliaComma. If you want red commas and to override your colorscheme, you could do something like this

:hi juliaComma guifg=Red ctermfg=Red

from julia-vim.

rafaqz avatar rafaqz commented on May 16, 2024

from julia-vim.

carlobaldassi avatar carlobaldassi commented on May 16, 2024

I've noticed that so far by default the functions aren't being highlighted (or maybe it's just me?) but I feel like some functions in the base are useful enough that they should. Some examples that pop into my mind are include, println, enumerate (and I'm sure there are more).

Functions aren't highlighted because 1) there are just too many functions in Base, and 2) they change rather rapidly between versions (this may change when 1.0 is out), and 3) the distinction between Base functions and user-defined functions is much less sharp than in other languages, and 4) not all language plugins highlight functions (e.g. C doesn't). If we were to choose a subset, it's very much unclear which criterion we would use. Why println and enumerate and not sin, of mark, or normpath for example?

I must confess that, personally, I don't feel the need for more colors in the typical Julia code that I see, now that symbols are highlighted, and parentheses and commas can optionally be highlighted too...

The fortran and python highlighting schemes (and probably others) use a very soft green color for the basis functions. It doesn't distract or pollute, but it is, in my opinion, nice to the eyes and helpful when coding. Based on that I'm thinking that it would be better if we started highlighting the functions on the base.

The actual colors used, and whether they are nice to the eyes or not, depend on you color scheme...
As for helpful, the only use case that comes to my mind is that I constantly write pritnln and the lack of highlighting in that case may help. But then I should probably just use an autocorrect feature...

from julia-vim.

KadeG avatar KadeG commented on May 16, 2024

I know nothing about Vim script, so forgive the potentially obvious question: Does all highlighting have to be manually defined, or can it be defined by a pattern? e.g. all text connected to a ( gets color x, which would cover all functions.

from julia-vim.

carlobaldassi avatar carlobaldassi commented on May 16, 2024

That would highlight every function definition and call (so not only a few important ones as was suggested above), It is doable. But no other language plugin that I know of does that.
(Yes, all highlighting is pattern-based, the file where the patterns are specified for julia is this one).

from julia-vim.

briochemc avatar briochemc commented on May 16, 2024

@carlobaldassi I see now that not coloring functions was the intended behavior, but I also see that I am not the only one wanting more colors... Would it be possible to add an option to highlight those?

You mentioned that

It is doable. But no other language plugin that I know of does that.

But as I was googling for a vim plugin that would highlight Julia functions, I saw that there was a vim plugin that highlights C++ functions here. [Disclaimer: I have not tried it, but the screenshots seem to show what color fans like me are looking for.] Maybe someone could somehow replicate this for Julia functions? (I personally have no clue how to edit julia-vim to do that.)

from julia-vim.

KristofferC avatar KristofferC commented on May 16, 2024

Actually, discriminating between function declaration and call isn't even consistent in OhMyREPL. for example defining functions inline myfun(x) = x.a would highlight as a call.

Yes, I didn't add the distinction for the short form of function declarations yet.

from julia-vim.

tomchor avatar tomchor commented on May 16, 2024

Just dropping to check if there are any improvements to this. I came back to julia-vim after 2 years and it looks exactly the same to me. It would indeed be nice to make some OhMyREPL color schemes available such as @KadeG suggested.

from julia-vim.

carlobaldassi avatar carlobaldassi commented on May 16, 2024

I don't think there's anything more to do here after #231.
We are now highlighting:

  • blocks and keywords
  • built-in constants
  • symbols and quoted expressions
  • all operators (including ternary and ranges, with special parsing within square brackets of begin and end)
  • types (both built-in and valid identifiers in type expressions)
  • macros
  • numbers
  • characters, special characters, strings and docstrings (you can link juliaDocString to distinguish them from regular strings)
  • commands
  • comments
  • some syntax errors
  • function definitions (in function blocks)
  • function calls (optionally)
  • brackets, commas, semicolons (optionally)

If you don't see some of these as colored, either see the docs (for the optional ones) or change your colorscheme.

I think it's unlikely that it is possible to reasonably detect function definitions given in assignment form, so for now they will (optionally) stay highlighted as function calls.
I also don't think functions from Base can reasonably be highlighted.

from julia-vim.

tomchor avatar tomchor commented on May 16, 2024

We are now highlighting:
blocks and keywords
built-in constants
symbols and quoted expressions
all operators (including ternary and ranges, with special parsing within square brackets of begin and end)
types (both built-in and valid identifiers in type expressions)
macros
numbers
characters, special characters, strings and docstrings (you can link juliaDocString to distinguish them from regular strings)
commands
comments
some syntax errors
function definitions (in function blocks)
function calls (optionally)
brackets, commas, semicolons (optionally)

Thanks! I appreciate the effort.

from julia-vim.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.