-
-
Notifications
You must be signed in to change notification settings - Fork 21
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
Support custom variable to indicate current filename #13
Comments
the this means you can hook custom logic into it. this is essential for some formatters. see my package python-black.el for a practical example. |
@wbolster This will be good to document. |
The problem with this approach is that you shouldn't have to save the file to reformat it, and it should be possible to reformat a buffer that is not backed by a file. So in that case, if a formatter needs to be given the path to a file, it should be the path of a temporary file to which the buffer contents have been written. And then there comes the question of where to write that temporary file, e.g. in a temp dir or the current dir, and certain choices in that regard can upset linters. For example, a linter might search directories upwards from the input file to find its config file. This is why flymake has a bunch of different functions for making temporary copies of files in various ways. We might consider allowing
|
Sorry, ignore me: you're not passing the filename itself... I think I'm just tired today. |
@purcell eslint only requires a file name for stdin when there are linting rules that needs to read the file name, this is a problem with formatters that mixes linting and formatting in the same program. Eslint doesn't use the file name to read off a file. This is a separate issue from #18. @wbolster 's approach will enable eslint_d and eslint to work as in #25 . I think we just need to document it if it becomes a recurrent issue. |
I like the simple implementation but wonder if it would make sense to interpolate some variable as current buffer filename. Of course this comes with the complication, should it be only the filename, the full path or the project local one. Perhaps even the possibility to provide a custom function to deterimine the file-name if it is too complicated for the project.
The reason I am asking is that some formatters want the file name and act differently depending on the filename, e.g. prettier/eslint. Right now I have solved this by creating different formatters for the different file-extensions, where I just put a static file, such as
f.ts
. However I have learned with slow formatters such as ESlint that it makes it really slow, I guess it is using the actual filename to determine some cache.Sample timings:
So in order to make this formatter useable I would need to provide the filename.
My current formatter looks like:
What would be nice:
or something like this using the symbol to figure out what to do:
The text was updated successfully, but these errors were encountered: