1

We should add a default syntax highlighting language for . Although highlight.js supports the Excel formula language, Stack Exchange does not (and I doubt this will change soon as this is a pretty niche request compared to some of the other gaps). However, based on the question Syntax highlighting for Excel Formulae - language suggestions, it looks like there are a couple of existing languages we can use instead that do a good job, and so I propose we use one of those in the meantime.

A default tag is necessary because right now the auto-detector does a bad job of highlighting these.

Additional Context

  • At the time of writing lang-swift is the highest voted alternative, so that's what I would propose. However, if you think of anything better, go post an answer/vote on that question and we can iterate until we find something good. This question is not about any specific tag though, rather whether or not any default tag would be a good idea.

  • There are roughly 10x more questions in than . However, the latter is still the second most used Excel tag, so I think it's common enough to warrant its own syntax highlighting.

  • 5,665 of the 27,056 (20.9%) questions are also tagged with [vba]. Now if I remember correctly, when two or more tags on a question have default syntax highlighting, then Stack Overflow just uses auto-language detection.

    • Some fraction of these questions will contain code - hopefully currently rendered correctly as VBA. Some fraction of that code will be mis-categorised as something else by the default automatic categoriser (hopefully the VBA/VB.NET categoriser is good and this will be small).
    • Nevertheless this is a breaking change in terms of formatting for at least some of those 20% of questions which go from unambiguous vba highlighting to a mixture of tags (NB: this is only 2.8% of VBA questions that will be affected, but 20% of Excel-formula questions)
    • I think the benefit to the ~80% of the questions with no default syntax highlighting would outweigh the risk to the 20% going from VBA -> automatic detection. Some of those 20% may not even contain VBA code and are being mis-highlighted.

Incidentally I think should be synonymised with and then both could benefit from the syntax highlighting. But that's a topic for another post

2
  • 4
    highlight.js does support [excel]. SO doesn't.
    – TheMaster
    Commented Jun 28, 2022 at 20:18
  • @TheMaster oh missed that. Still I think it stands that for the time being SE seems pretty restrictive on languages to add owing to network restrictions, I don't think it's likely we'll get that one supported in favour of some much more significant gaps. I agree swift is clearly a workaround but quite an effective one in most cases I've used it, or I wouldn't be posting this.
    – Greedo
    Commented Jun 28, 2022 at 21:47

1 Answer 1

3

I recently posted a formula as an answer, so I tried Swift formatting on it, with this result:

=UNIQUE(FILTER(WkSht!G:G:INDEX(WkSht!G:Z,,VLOOKUP(F1,DH2:DI54,2,0)),WkSht!A:A=B1))

Since some people are focusing on the unusual G:G:INDEX part, consider some simple examples:

=SUM(A1:Z100)

In my opinion it doesn't add much that is useful, and is in parts harmful, as is mangles some of the range references.

Please don't apply swift as a default format. Something else might work though.

10
  • Shame. In the linked post it seems quite upvoted and I guess maybe it works most of the time but there are edge cases. I'm going for 80% better for 20% the cost (it's much easier to get this than to convince SE to add the real highlight.js Excel support to the network, considering how many languages don't have it). Also, although not ideal, it is always possible to disable the default with ````none` if it sometimes doesn't work like in your case. But in general swift works pretty well for most people, judging by the upvotes on the linked post.
    – Greedo
    Commented Jun 28, 2022 at 21:43
  • 1
    Also I'm probably being dumb but is that G:G:INDEX... valid syntax?
    – Greedo
    Commented Jun 28, 2022 at 21:45
  • 2
    @Greedo, in your linked post, scala seems to do a better job, at least with my formula (doesn't mangle the ranges). FWIW formula with imbedded range references are extremely common, so it's hardly an edge case. Re the G:G:INDEX, yes its valid. Have a look at my answer to see how it works Commented Jun 28, 2022 at 21:50
  • Is this valid too? WkSht!G:INDEX(WkSht!G:Z,,VLOOKUP(F1,DH2:DI54,2,0)),WkSht!A:A=B1))(Took out a G). I think this is edge case as well.
    – TheMaster
    Commented Jun 28, 2022 at 22:07
  • @TheMaster focusing on that part of the formula is not helpful in the context of this question. The swift formatting also mangle other range references, see DH2:DI54 further along in the Formula (if you want to discuss my formula, I'd suggest doing so on my answer) Commented Jun 28, 2022 at 22:13
  • Thanks for the clarifications, pretty neat! Ok I guess this is really 3 options then: 1) too much disruption to existing posts it's never going to be a good idea to add a default tag 2) a workaround default tag is fine but swift wouldn't be your first choice 3) only official language support would justify adding a default...
    – Greedo
    Commented Jun 28, 2022 at 22:50
  • ... I don't want to put words in your mouth, but it sounds like option 1 you're not really thinking about, option 3 might be what you're feeling, option 2 seems most likely though - you don't reject the idea entirely but you think swift has too many edge cases. In that case maybe you should vote on the linked question about best tag and I can update this question to say "whatever workaround is specified here, currently xyz, should be added as the default".
    – Greedo
    Commented Jun 28, 2022 at 22:53
  • Fwiw I've used it reasonably successfully for formulas containing ranges, as you say it's a very common usecase and there are lots of upvotes on that so chances are it's worked for some people.
    – Greedo
    Commented Jun 28, 2022 at 22:55
  • 2
    @Greedo I'd support syntax highlighting that works for most ( if not all) common formula structures. Perhaps update the Q to request a default, and maybe suggest a few candidates. Whatever is chosen I'd like to see a broad spectrum of test cases. An A here with tests would be useful (I might add one myself later today) Commented Jun 28, 2022 at 23:01
  • @chrisneilsen updated the question to make it clear this is discussing a default not necessarily swift. Probably worth posting a test page as an answer to the other question meta.stackexchange.com/questions/362351/… and voting there and then summarise your conclusions here if you think one is preferable (or they're all too buggy to use!)
    – Greedo
    Commented Jun 28, 2022 at 23:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .