7

Do we have a special highlighting version for QGIS expressions?

Most of the expressions used are simple and therefore do not necessarily need to be highlighted, but if they become more complex, it can increase readability a lot.

I found this Syntax highlighting needed for expression tag? question about. But I think SQL only highlights comments well as for example:

array_to_string(
    array_foreach(
        array_foreach(
            string_to_array("idTargetLayer"), -- idTargetLayer is a string so we need to convert it to an array first
            to_int(@element)), -- idTargetLayer is a string field, so we need to convert the numbers to integer before we can look it up
    attributes(get_feature_by_id('myTargetLayer',@element+1))['myField'] -- get the attribute of ['myfield'] of the layer 'myTargetLayer' for the featureID '@element+1', where @element+1 is the extracted integer of 'idTargetLayer' array
    )
,',') -- convert the gathered array back to a string

So I was searching for another language, like java, which gets a little messy. I also tried some others, but I was not really satisfied.

Which existing language do you recommend to highlight QGIS expressions?

Here a few examples:

QGIS-Expression-Editor:

enter image description here

SQL:

enter image description here

Python:

enter image description here

Java:

enter image description here

C:

enter image description here

Of course there are more available...

If you want to test it yourself, you need go to main GIS SE and type a test-question (without actually asking of course) with the expression above or an example of your own to get a preview. Simply use ```lang-sql as start and ``` as end for the code block and replace sql by the language.

Related: Syntax highlighting language hints

8
  • 1
    To show here what these expressions currently look like on the Main site perhaps after the formatted text code you can include pictures of what the syntax highlighted code looks like with various options. Would a retagging of expression with qgis to a new tag of qgis-expression be of any help to syntax highlight them differently to other questions tagged expression?
    – PolyGeo Mod
    Dec 23 '20 at 21:25
  • Good idea, included some example pictures. Don't know if that would help, depends on how the syntax is highlighted then. Just tested with the tag qgsexpression, and got no highlight at all. Can we define the way it highlights ourself (or you as moderator?) or is that only up to SO-Staff?
    – MrXsquared
    Dec 23 '20 at 21:35
  • Only moderators can set the syntax highlighting choice, which they do on the Wiki editing page, but there are tags that anyone can include in their posts as one-offs to set the syntax highlighting for code that follows.
    – PolyGeo Mod
    Dec 23 '20 at 21:39
  • There is a Meta SE FAQ on syntax highlighting at meta.stackexchange.com/questions/184108/…
    – PolyGeo Mod
    Dec 23 '20 at 21:42
  • @PolyGeo Do you think a retag rather than two tags such as expression and python (or whatever the parser for qgis just happens to be)?
    – Midavalo Mod
    Dec 24 '20 at 0:30
  • @Midavalo I may be an outlier on the python tag because I think non-spatial tags should be rarely used here, preferring to see the spatial python library tags (sometimes python-parser) used instead. I won't support a retag until I know more about the current situation and what is being aimed for w.r.t. QGIS expression syntax highlighting.
    – PolyGeo Mod
    Dec 24 '20 at 0:40
  • 1
    I just set syntax highlighting on the qgisexpression tag to SQL but if the community wants another language instead then it’s easily changed by any moderator.
    – PolyGeo Mod
    Dec 24 '20 at 23:31
  • @PolyGeo thanks! For now this seems to be the best option. However, I thought there may be a language suiting better. Thats what my intention was by asking the community, maybe I need to re-formulate it, cause I actually am not really into figuring out how to implement a brand new highlightning as described on meta/github.
    – MrXsquared
    Dec 25 '20 at 0:55

You must log in to answer this question.

Browse other questions tagged .