rust-lang / rust-mode

Emacs configuration for Rust
Apache License 2.0
1.11k stars 179 forks source link

highlight interpolation in arguments to more macros #228

Open tspiteri opened 7 years ago

tspiteri commented 7 years ago

The new argument interpolation highlighting from #220 handles the macros eprint!, eprintln!, format!, print!, println!, write! and writeln!.

It can be extended to also handle other macros that take format strings. I'm including a list below (I hope I didn't miss any).

  1. First argument can be format string (like eprint!, eprintln!, format!, print!, println!)
    • format_args!
    • panic!
    • unreachable!
    • unimplemented! (not in 1.19.0, but in the beta that is to become 1.20.0)
  2. Second argument can be format string (like write!, writeln!):
    • assert!
    • debug_assert!
  3. Third argument can be format string:
    • assert_eq!
    • assert_ne!
    • debug_assert_eq!
    • debug_assert_ne!
Aankhen commented 7 years ago

Thanks, that’s very helpful. I’ll work on adding these.

Aankhen commented 7 years ago

Adding the first group was simple. I’m uncertain about the remaining groups. At present, the formatting for write! cheats and assumes the first comma it encounters denotes the end of the first argument, which I figure should be good enough since you’re usually calling it with a single variable in that position (write!(out, "foo")). All the assert macros, in contrast, can easily contain commas along the lines of assert!(foo(bar, baz), "works"), and to deal with that I need a way to skip over Rust expressions. I’m going to give it a shot but I have no idea how feasible it is.

Dushistov commented 7 years ago

What about quite popular macros for logging from here: info!, warn!, error!, debug!?

Aankhen commented 7 years ago

That’s a good idea, but I’d be more hesitant to add those since they’re not builtin per se. Having sed said that, you could add them to your config manually if you like:

;; you will need to either restart Emacs or hit C-M-x on
;; `rust-mode-font-lock-keywords' after hitting C-x C-e on this
(dolist (macro '("debug" "error" "info" "warn"))
  (add-to-list 'rust-builtin-formatting-macros macro))