[cfe-dev] clang-format custom format specification

Kyle Knoepfel via cfe-dev cfe-dev at lists.llvm.org
Wed Sep 16 07:40:03 PDT 2020


Sam thanks for the response.  Yes, a version of Typz's patch with only absolute- and relative-path support is uncontroversial (from my POV) and it would address the complications I have encountered.  Please let me know if there may be a way I could contribute to the progress of the patch....not that I would have the time to work on it. ;)

Best,
Kyle

> On Sep 16, 2020, at 3:05 AM, Sam McCall via cfe-dev <cfe-dev at lists.llvm.org> wrote:
> 
> Hi Kyle,
> 
> A similar feature has been proposed: allowing -style to refer to a filename. Could be style=file:<path> which is pretty close...
> I guess it's a little clumsier for the user (and a little less work for the style authors) than what you propose. But it's simple, which is worth something - I don't like the idea of adding things to the format file itself to facilitate this.
> And it would satisfy your goal around error-reporting: -style=foobar fails with "Invalid value for -style" and a nonexistent file could do the same.
> 
> The patch https://reviews.llvm.org/D50147 <https://reviews.llvm.org/D50147> got stalled over whether the files should be searched for relative to some predefined search path. I think a version that handled absolute or working-dir-relative paths would be uncontroversial. Would this work for you?
> 
> cc Typz who wrote that patch and Mydeveloperday who is the most active clang-format maintainer.
> 
> Cheers, Sam
> 
> On Tue, Sep 15, 2020 at 9:28 AM Kyle Knoepfel via cfe-dev <cfe-dev at lists.llvm.org <mailto:cfe-dev at lists.llvm.org>> wrote:
> Forgive me if this has already been discussed.  
> 
> I work on projects with different formatting guidelines.  For simple cases, it is simple to embed the .clang-format file in the correct (parent) directory, run `clang-format -style=file ...` and everyone's happy.  However, it is easy to get into a situation where the wrong format is applied, especially if you accidentally invoke the command from the wrong directory.
> 
> Would Clang be opposed to a specification like:
> 
> clang-format -style=custom:my-projects-format ...
> 
> where a field in the .clang-format file would have the value 'my-projects-format', thus attributing the file to the format name?  If a user specified something like -style=custom:my-unsupported-format, and such a format name could not be discovered in the .clang-format file, then it would be a hard failure, not letting a silent error slip by.
> 
> Thanks for your input.  If it is favorable, then I'm happy to explore implementing it.
> 
> Kyle Knoepfel
> 
> Software framework group leader, Fermilab
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org <mailto:cfe-dev at lists.llvm.org>
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev <https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20200916/7c500d85/attachment-0001.html>


More information about the cfe-dev mailing list