ziglang / zig.vim

Vim configuration for Zig
MIT License
448 stars 56 forks source link

Suggestion: Remove `formatprg` #61

Closed anand-bala closed 3 years ago

anand-bala commented 3 years ago

The primary use of gq or formatprg is to format a visual selected block or text-motion selected block. zig fmt --stdin requires the entire context of either the container you are writing or the file to be able to format reasonably. For example, one of my primary uses for gq is to wrap the text at some width, especially documentation comments. For example:

const Stage = struct {
    /// All the world’s a stage, And all the men and women merely players; They have their exits and their entrances; And one man in his time plays many parts, His acts being seven ages. At first the infant, Mewling and puking in the nurse’s arms;
    players: []const u32,
};

Now, zig fmt doesn't format the documentation comment to a fixed column size on save. But if I try to select the line I want wrapped and run gq, I get:

const Stage = struct {
<stdin>:1:5: error: unattached documentation comment
    players: []const u32,
};

On the other hand, if I select the entire context (struct definition), I run into the same issue that zig fmt doesn't care about column length.

I would suggest we remove formatprg altogether as I believe that anyone using this plugin is probably using zig fmt on save anyway.

haze commented 3 years ago

Thank you for your suggestion & commit <3

Fixed in fb534e7d12be7e529f79ad5ab99c08dc99f53294