In order to format code in vscode it needs a plugin for coq. Searching for "category:formatters coq" finds nothing. Did anyone solved this? Perhaps piping it via some external formatter?
if you made a formatter you would become famous
I can run emacs in batch mode :)
there is also coqc -beautify
which I never tried myself. but it is still needs to be hooked up to vscode somehow
coqc -beautify is absolutely broken
idk about emacs batch mode but ig it just does autoindent
I could also do gg=G in Vim lol
would you like a chance to be famous?
also there is this: http://www.eelis.net/coqindent/
I wonder if there is some simple pluging or shortcut in vscode to run source buffer via external command and update with the output. then I would try to find some suitable formatter to try.
Code Runner
but anyway feel free to try out "formatters" you find online. you'll find them severely lacking
isn't it sad
Code runner does not seems to be able to replace the current buffer with the output
it will show it in "output" buffer instead
close enough. you can pass the current file as argument. and when the file is rewritten the buffer is automatically updated
ok, thanks. I will experiment with it
I am reasonable happy with emacs proof general Coq identation. I was not kidding about running emacs in batch mode :)
http://www.eelis.net/coqindent/
https://github.com/toku-sa-n/coqfmt (AGPL)
looks like this person will become famous
AGPL is unfortunately a minefield, in particular for something that spits out code (some background here)
For libraries, we can argue that strong copyleft discourages adoption, but for tools I disagree. A formatter cannot be claimed to spit out any code besides the one that you entered (so absolutely no licensing issue here). The fact that some big companies like Google are shy with AGPL is a fact that people might consider disqualifies this license if they want the widest use, but I would argue that the problem is on those companies (and I wouldn't expect smaller companies like, e.g., Bedrock Systems, to be afraid to use a code formatter that is licensed under AGPL).
AGPL is so strong that you basically need a lawyer to look at the program in question and determine whether its output is under the tool's license
see discussion about source code tools here.
I would be surprised if Bedrock allow any kind of external AGPL tools anywhere, but maybe Paolo or Janno could could comment...
I guess one question is if the formatter only ever outputs white spaces, newlines and the like. If it can sometimes add hardcoded code fragments, I'd say that may turn your code into AGPL. The question is how to even be sure it doesn't output hardcoded text
I think we should be careful about stating strong legal opinions here; there is little in the intent of the AGPL (with intent being often the most relevant legal term) that would indicate that a source code formatter would be allowed to alter the license of its input and more strikingly to claim copyright over it!
This would be AKIN to having Photoshop claim copyright of images it processed (which is now a problem due to their AI fill, but that's a different story), or Word's auto-format being able to have your text licensed by Microsoft.
Quoting the AGPL "Why section"
The purpose of the GNU Affero GPL is to prevent a problem that affects developers of free programs that are often used on servers.
So indeed, Hiroki-san formatter being AGPL means that if someone is going to run that formatter as a service, the actual source code should be available to the service's users under the AGPL; which in the context of the formatter, it seems fine.
AGPL is so strong that you basically need a lawyer to look at the program in question and determine whether its output is under the tool's license
That seems like quite a strong claim, in the sense that AGPL doesn't differ from GPL in this scenario. Can you point out an event where this happened?
As Théo correctly points out, it makes total sense for Google to be very wary of the AGPL as the AGPL is indeed precisely designed to target Google and other operators of cloud service as not to allow them to use free software in their servers without releasing its source code, something that for sure Google would like to prevent at all costs.
Making the jump from the needs of a large, service-oriented company to a code formatting tool is maybe too much of a jump.
what I mean with "strong" is that if the tool indeed embeds its own source code into its output, and you apply the output on a single file in a large project, the project as a whole may have to turn AGPL, and any clients of the project as well
actually even if the output doesn't fall under AGPL there might be other implications. CI workflows that automatically format code might be affected
How would such workflows be affected @Huỳnh Trần Khanh ?
Other than having to point out where the source code for the exact version of the tool used in the workflow is?
Which is the case for all CI workflows using open source linters that I know of. You are correct that AGPL would prevent using a private version of the formatter in CI that I can access, unless you share the modified version with me. But is this a real issue?
Karl Palmskog said:
what I mean with "strong" is that if the tool indeed embeds its own source code into its output, and you apply the output on a single file in a large project, the project as a whole may have to turn AGPL, and any clients of the project as well
I guess that indeed there are many strange things tools that process source code can do, but I fail to see how this applies here. Also, in that hypothetical case you describe, a tool doing that would hardly force a whole existing codebase not licensed under the AGPL to become AGPL, this is not how copyright works, in particular if the tool misrepresented what it is doing with your code.
one case in point. The lexer generator JFlex was previously under GPL. However, it had an additional clause stating that all the tool's output is owned by the user. Here is a tool under an even stronger copyleft license that makes no claim like this. Since I don't have time to do (A)GPL license analysis for specific tools, I'd just prefer to not use any (A)GPL licensed tool that outputs source code.
I give several more examples of GPL'd tools outputting source code and issues flagged up by FSF themselves here, as linked above
I'd just prefer to not use any (A)GPL licensed tool that outputs source code.
I can understand this is your preference, however that doesn't mean there is a problem with the tool, which you seem to imply. IMHO this creates unnecessary uncertainty and distracts from the primary purpose of the tool by a problem that is, IMVHO, not even hypothetical in the context of the tool.
AGPL is not more of a minefield for a tool that outputs "original" code than any of the GPL licenses. GPL / AGPL are widely considered to be non-issues for tools that transform inputs such as GIMP or Code Formatters (tho the legal framework is still far from settled)
Note that in the CoqFFI discussion the author indeed did not share your position, even if in the end he went for a relicensing. The issues you point out about bison or GCC are issues well understood (the output needs an essential library to work, which needs a different copyright), and have little to do with AGPL but with the GPL. But again, I'm not sure why pointing out problems in other contexts is relevant for the discussion of the formatting tool here.
are you saying you know exactly what a claimed formatter tool does? If a formatter tool author was interested in assuring their users, why wouldn't they add a "you own all output" clause?
the difference from GIMP is that GIMP doesn't embed its source code in edited images...
GPL and AGPL are the same in that they can both embed source code in their output and get code that uses it relicensed, but AGPL is much more large in scope of what code gets relicensed. I don't have time to figure out what "network interaction" means in my jurisdiction
Again I do understand what you may have your own reasons (whether founded on legal experience or not) to use or not to use a tool.
However I still do think we should be more careful about turning our own reasons into general advice or comment on a tool or a license, in particular when your own perceived "danger" of the license of the tool doesn't seem to the case here AFAICT. This does create unnecessary and unfounded uncertainty around the tool, whose license is fine unless you want to do a closed-source formatting service.
Karl Palmskog said:
the difference from GIMP is that GIMP doesn't embed its source code in edited images...
Neither does the formatter we are discussing, so how is this relevant?
Even if it did, any claim on this action affecting the copyright of the input would be legally void, trivially, in any court.
The relevant legal notion here is whether the output can be considered a "derived work" of the tool, that in itself is a very complex not fully developed notion.
Can someone with enough rights move this thread to Misc > AGPL for a formatting library?
I don't see any link with vscoq starting from the message questioning the choice of license.
Can you configure Emacs to defer indentation to this tool?
not sure you can do it for "live" indentation as you type. but you can probably configure indent-region
to call an external tool.
Can you disable live indentation?
yes
Interesting
(defvar indent-line-function 'indent-relative
"Function to indent the current line.
This function will be called with no arguments.
If it is called somewhere where it cannot auto-indent, the function
should return `noindent' to signal that it didn't.
Setting this function is all you need to make TAB indent appropriately.
Don't rebind TAB unless you really need to.")
i guess re-defining this variable to noindent
should do the trick. Maybe there is even more global way disabling indentation in emacs.
If this tool can be used with no additional burden for Emacs users, it'd be great.
That sounds promising, thanks.
@Karl Palmskog I haven't applied for using any AGPL tools yet, so I don't have statistics, I guess we'd have to look when that happens.
As I mentioned, I am pretty happy with coq indentation in emacs. The original question was about indentation in VsCoq. I miss a functionality where I can quickly re-ident whole buffer (file? window?)
I know of no such feature today, especially not in vscoq
this is how I do this in emacs:
(defun tidy-buffer ()
"Tidy up current buffer by re-identing and cleaning up whitespace"
(interactive)
(indent-region (point-min) (point-max))
(whitespace-cleanup-region (point-min) (point-max)))
This topic was moved here from #VsCoq devs & users > coq identation by Emilio Jesús Gallego Arias.
Moved as requested, I've used User Interfaces better than Misc, but happy to head to misc if you folks feel that's better.
Regarding use in VSCode or Emacs, it is easy to hook Hiroki-san formatter or any other formatter to for example coq-lsp, and use standard LSP-based facilities; happy to help with that project if someone is interested.
The hooks in coq-lsp are already there, so all you need is to write a function Ast.t -> string
, YMMV
The main pain point (as discussed with @Hiroki Tokunaga ) is that Coq doesn't offer facilities for formatters to access the AST.
That's a real problem; coq-lsp and serlib provide their own system, but it is often not enough.
@Vadim Zaliva this must be quite slow on big buffers, focusing on the current region may may be useful sometimes I suppose.
(defun tidy-region (min max)
"Tidy up current region by re-identing and cleaning up whitespace"
(interactive "r")
(indent-region min max)
(whitespace-cleanup-region min max))
Last updated: Oct 13 2024 at 01:02 UTC