-
-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Highlight the contents of cmd macros as if they were standard code #132
Comments
I wonder if this functionality could be a minor-mode on top of julia-mode itself. It seems a bit icky to special-case different string-macro names to have/not-have this behavior based on common usage rather than language semantics. You might not even have to modify julia-mode to create a "hook" to do this... I don't think I've ever seen a cmd macro in the wild. Do you have some examples of them? |
I guess my thought was to just treat the contents of a cmd block as if it were a completely separate block of julia code, both for highlighting and possibly even indentation. Having custom overrides to use e.g. python syntax highlighting in a pycall string macro would be a bonus, but I don't think necessary.
They're not actually used a ton, but on an ecosystem level, I think it might make sense to encourage their use over string macros for containing code, rather than just funky strings. One example would be https://github.com/JuliaInterop/MathLink.jl Amusingly enough, another example is the undecorated cmd syntax: https://github.com/JuliaLang/julia/blob/24f033c9517cd186448acc3bededa1a64eaad09f/base/cmd.jl#L388 |
I am sorry, but I still don't get what a cmd macro is (ie how it is different from a string macro). The Julia issue linked looks like a feature request which may not even make it, so it is unclear to me what is requested here. An example would help. |
The fault is probably mine. let me try to explain more carefully: As far as I understand, a cmd macro is exactly like a string macro, expect they use backticks macro foo_cmd(s)
QuoteNode(Meta.parse(s))
end
foo`(1+1)^2-2`
#+RESULTS:
:((1 + 1) ^ 2 - 2) Julia itself defines only one cmd macro, the undecorated one My thinking is that if we have these cmd macros which have highly overlapping functionality with string macros, but appear to be only used for enclosing code, it might make sense to do something to make the contents of a cmd macro feel more like code rather than a string. This would include applying syntax highlighting at an editor level to the contents of a cmd macro.
In that julia issue, I requested reader macros a-la lisp and the reaction from the devs appears to still be somewhat firmly on the side of "we already have string and cmd macros, we don't need reader macros.", but it was suggested that this can mostly be aleiviated by just applying syntax highlighting to the contents of these macros, hence I'm taking the request here.
Forgetting about language interop for the moment, I think one use-case I care about is using cmd macros to write syntax that's not supported by Julia's parser. One that comes to mind for me is Dirac Bra-Ket notation. Here's a quick and dirty demo of a cmd macro for this: https://gist.github.com/MasonProtter/4c5de8afc431dea3596cf803bc91fffb What I would like is when I write e.g. d```
[⟨→|*σz*|→⟩ ⟨→|*σz*|←⟩
⟨←|*σz*|→⟩ ⟨←|*σz*|←⟩]
``` I want the contents of the macro to be highlighted as regular julia code, rather than as if they were inside a string, so the above would look more like [⟨→|*σz*|→⟩ ⟨→|*σz*|←⟩
⟨←|*σz*|→⟩ ⟨←|*σz*|←⟩] |
I should note that I'm personally fine with doing this for string macros as well, but I thought it might be a good idea to start with cmd macros since they're more likely to contain code than string macros and they're also used less often, so it'd be good for working out the kinks. |
Thanks for explaining, now I understand the use case. However, I don't understand why the cmd macros should be highlighted as Julia syntax. Isn't having different languages between the |
Continued from JuliaLang/julia#36590.
Currently, string and cmd macros are often used for syntax extensions. While the contents of a string macro might sometimes be code or sometimes a special form of string like LaTeXStrings.jl, cmd macros on the other hand seem to always contain code. However, we highlight their contents as if they were strings.
I think it'd be nice if we just applied regular julia syntax highlighting to the contents of a cmd macro, or even provided hooks so that people can customize the highlighting of specific string / cmd macros.
The text was updated successfully, but these errors were encountered: