Skip to content

Feature Request: Additional format specs #514

Open
@azriel91

Description

@azriel91

Sublime Text Version

E.g Sublime Text 4 (Build 4150)

Rust Enhanced Version

2.25.0

Operating system

Pop OS 22.04 / Linux 6.2.6

Feature Request

Heya 👋

TL;DR: Extend or provide some way to extend RustEnhanced.sublime-syntax with additional macros which take format specs, and highlight the args in them.

Description

The indoc crate provides macros to dedent whitespace in string literals. Example:

let arg = 123;
let string = formatdoc!("
        this is some text
            and an {arg}
        more text
        ");
//                 ^^^^ The {arg} is interpreted as it would be in a `format!()` macro
//      ^^^^ The spaces on the second line are kept.
// ^^^^^ these spaces are removed by the macro.

I'd like {arg}s inside these additional macros to also be highlighted since it makes it easier to spot format strings.

There are 4 macros that do the interpolation:

  • formatdoc!($fmt, ...) — equivalent to format!(indoc!($fmt), ...)
  • printdoc!($fmt, ...) — equivalent to print!(indoc!($fmt), ...)
  • eprintdoc!($fmt, ...) — equivalent to eprint!(indoc!($fmt), ...)
  • writedoc!($dest, $fmt, ...) — equivalent to write!($dest, indoc!($fmt), ...)

I think concatdoc!(...) doesn't interpolate.

Solutioning

I could just edit RustEnhanced.sublime-syntax#L149-L182 in a local clone of the plugin, though:

  • Maybe others want it as well
  • It would be nice to not have to remember to update my local copy

There's the "wrong-but-easy" solution to just include it in the regex; I haven't worked on sublime's plugin system to know if it can be made configurable, but I suspect it's possible.

Would this be something you're happy to have in the plugin?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions