Open bradyt opened 5 years ago
I like that idea. We could have a per-formatter regexp. Even better would be if all the formatters could emit to a standard error format. But that may be too much to hope for, at least in the near future.
Should have been more specific in my response. I don't have a lot of time/energy to implement features at the moment so if someone wants to speed this along, please collect some samples of what errors/warnings look like from the different formatters supported by format-all. I hope there are enough commonalities in the error output formats that we could have just one global regexp that covers most formatters. If there are lots of differences, we'll have to add an :error-regexp
field to define-format-all-formatter
. Thanks to anyone who volunteers to do the legwork :)
Most compilers use a format like file.ext:line:column: error|warning: message
. It would be nice if we could convince most of the formatter authors to switch to that format (or add a command line flag to support it).
The *compilation*
buffer just uses a list of regex and checks them all.
Maybe using compilation mode is the most idiomatic? As one IRC'er puts it,
13:50 it would make things easier and more consistent
13:51 generally I tend to reuse the built-in stuff unless I can't for some reason
I have the project cloned, but I'll have to find time to learn where to "insert" (compilation-mode)
, etc.
Thanks for taking this up :)
Unfortunately it may not be as straightforward as re-using compilation-mode
since it is geared toward running a subprocess. For one, it binds the g
key to recompile
which won't be natural for format-all (if you press g
in *format-all-errors*
it would be surprising if it runs a compiler instead of a formatter). There may be other things like that. There is define-derived-mode
that we might be able to use to subclass compilation-mode
but future versions of Emacs may add more stuff to compilation-mode, so we'd get into an arms race where they add new stuff and we put in code to remove it :)
From reading the Emacs source, compilation-mode
does most of its magic by running the compilation-setup
function. Maybe we could call that one, or copy/paste the relevant stuff from it.
If we can have a global list of regexps and always run through all of them, that's definitely better than adding another per-formatter field to the definitions. It won't be slow even if there are useless regexps since formatters don't print tons of messages per file.
The place to insert this stuff is in the format-all--show-or-hide-errors
function.
For
M-x dart-server-format
, they provide the following regex,This made it easy to jump to the location from error contents such as the following:
Perhaps it is possible if your buffer is
*compilation*
then any regex like the above will apply to to your formatter?