diff mbox series

docs: add vim syntax modeline [RFC]

Message ID pull.1874.git.git.1736802194760.gitgitgadget@gmail.com (mailing list archive)
State New
Headers show
Series docs: add vim syntax modeline [RFC] | expand

Commit Message

M Hickford Jan. 13, 2025, 9:03 p.m. UTC
From: M Hickford <mirth.hickford@gmail.com>

Git documentation is written in AsciiDoc. This format is easily
mistaken for the pervasive Markdown.

Add a vim modeline to help editors identify the format and provide
syntax highlighting, rendering and autocomplete.

This makes editing the documentation easier for prospective
contributors. This is particularly important because new contributors
often start with documentation changes.

An alternative could be to move the modeline up or down the file (the
location is not important).

A simpler alternative could be to rename files *.adoc. This would have
the advantage of being recognised by even more tools.

Signed-off-by: M Hickford <mirth.hickford@gmail.com>
---
    docs: add vim syntax modeline [RFC]

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1874%2Fhickford%2Fasciidoc-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1874/hickford/asciidoc-v1
Pull-Request: https://github.com/git/git/pull/1874

 Documentation/git-add.txt | 1 +
 1 file changed, 1 insertion(+)


base-commit: fbe8d3079d4a96aeb4e4529cc93cc0043b759a05

Comments

brian m. carlson Jan. 13, 2025, 9:33 p.m. UTC | #1
On 2025-01-13 at 21:03:14, M Hickford via GitGitGadget wrote:
> From: M Hickford <mirth.hickford@gmail.com>
> 
> Git documentation is written in AsciiDoc. This format is easily
> mistaken for the pervasive Markdown.
> 
> Add a vim modeline to help editors identify the format and provide
> syntax highlighting, rendering and autocomplete.

I don't think this is a good idea.  To be clear, I use Vim and Neovim
(mostly the latter), but I just don't think we should litter our project
with editor-specific contents.  I know Junio uses Emacs, and other
contributors use other things, and there's no uniform syntax that works
everywhere.  (Nor could there be, because different editors have
different names for different languages.)

We also don't set editor-specific ignore files in our `.gitignore`.
Emacs users are responsible for ignoring backup files in the global
(per-user) config, Vim users for swap files, and so on.

> This makes editing the documentation easier for prospective
> contributors. This is particularly important because new contributors
> often start with documentation changes.

I suspect prospective contributors who are moderately proficient with
Vim and its descendants know how to do `:setf asciidoc`.  If this were a
different editor that were easier to start with (say, one that didn't
have tons of Internet posts asking how to quit it), such as VS Code or
even Emacs, then I would be more convinced by this argument.

> A simpler alternative could be to rename files *.adoc. This would have
> the advantage of being recognised by even more tools.

This I would be in favour of.  I use this extension on my personal
AsciiDoc files and already have appropriate configuration set up.  In
conjunction with appropriate settings in our `.editorconfig` file (to
configure indents properly), I think this would be valuable indeed, and,
importantly, helpful to users of all editors.
D. Ben Knoble Jan. 13, 2025, 10:37 p.m. UTC | #2
On Mon, Jan 13, 2025 at 4:05 PM M Hickford via GitGitGadget
<gitgitgadget@gmail.com> wrote:
>
> From: M Hickford <mirth.hickford@gmail.com>
>
> Git documentation is written in AsciiDoc. This format is easily
> mistaken for the pervasive Markdown.
>
> Add a vim modeline to help editors identify the format and provide
> syntax highlighting, rendering and autocomplete.

FWIW, Vim by default only has a single autocommand for *.txt files,
and it's to see if they are help files.

Now, there is a fallback $VIMRUNTIME/scripts.vim mechanism that
performs various "heuristic" checks, but I can't find a reference to
markdown in it either. So stock Vim treats them as "filetype=text."

>
> This makes editing the documentation easier for prospective
> contributors. This is particularly important because new contributors
> often start with documentation changes.
>
> An alternative could be to move the modeline up or down the file (the
> location is not important).

Not quite. :help modeline says

    The number of lines that are checked can be set with the 'modelines' option.
    If 'modeline' is off or 'modelines' is 0 no lines are checked.

and the default value of 'modelines' is 5.

>
> A simpler alternative could be to rename files *.adoc. This would have
> the advantage of being recognised by even more tools.

Indeed, Vim knows that *.adoc and *.asciidoc are "filetype=asciidoc".

You could also see about submitting a patch to Vim to check *.txt
files for asciidoc syntax, or add your own ftdetect rules [1] that say
that files with %:p matching "git.*/Documentation" (for example) get
the filetype asciidoc.

[1]: https://vi.stackexchange.com/a/23251/10604,
https://vi.stackexchange.com/a/18493/10604,
https://vi.stackexchange.com/a/28109/10604, etc.
M Hickford Jan. 13, 2025, 10:50 p.m. UTC | #3
On 2025-01-13 21:33, brian m. carlson wrote:
> On 2025-01-13 at 21:03:14, M Hickford via GitGitGadget wrote:
>> From: M Hickford <mirth.hickford@gmail.com>
>>
>> Git documentation is written in AsciiDoc. This format is easily
>> mistaken for the pervasive Markdown.
>>
>> Add a vim modeline to help editors identify the format and provide
>> syntax highlighting, rendering and autocomplete.
> 
> I don't think this is a good idea.  To be clear, I use Vim and Neovim
> (mostly the latter), but I just don't think we should litter our project
> with editor-specific contents.  I know Junio uses Emacs, and other
> contributors use other things, and there's no uniform syntax that works
> everywhere.  (Nor could there be, because different editors have
> different names for different languages.)
> 
> We also don't set editor-specific ignore files in our `.gitignore`.
> Emacs users are responsible for ignoring backup files in the global
> (per-user) config, Vim users for swap files, and so on.
> 
>> This makes editing the documentation easier for prospective
>> contributors. This is particularly important because new contributors
>> often start with documentation changes.
> 
> I suspect prospective contributors who are moderately proficient with
> Vim and its descendants know how to do `:setf asciidoc`.  If this were a
> different editor that were easier to start with (say, one that didn't
> have tons of Internet posts asking how to quit it), such as VS Code or
> even Emacs, then I would be more convinced by this argument.
> 
>> A simpler alternative could be to rename files *.adoc. This would have
>> the advantage of being recognised by even more tools.
> 
> This I would be in favour of.  I use this extension on my personal
> AsciiDoc files and already have appropriate configuration set up.  In
> conjunction with appropriate settings in our `.editorconfig` file (to
> configure indents properly), I think this would be valuable indeed, and,
> importantly, helpful to users of all editors.

The more I think about it, I prefer renaming to *.adoc too. It's easy to 
identify and obviously distinct from Markdown. GitHub and GitLab render 
adoc files beautifully [1][2]. Visual Studio Code offers to install an 
extension with syntax highlighting and previewing.

The vim modeline had no effect in Visual Studio Code. It could also be 
intimidating.

[1] 
https://github.com/couchbase-guides/how-to-write-a-guide/blob/master/README.adoc
[2] https://docs.gitlab.com/ee/user/asciidoc.html
Junio C Hamano Jan. 13, 2025, 10:52 p.m. UTC | #4
"brian m. carlson" <sandals@crustytoothpaste.net> writes:

>> A simpler alternative could be to rename files *.adoc. This would have
>> the advantage of being recognised by even more tools.
>
> This I would be in favour of.

Sounds quite sensible.

Thanks.
diff mbox series

Patch

diff --git a/Documentation/git-add.txt b/Documentation/git-add.txt
index 5f2c3592b8d..123c98541b1 100644
--- a/Documentation/git-add.txt
+++ b/Documentation/git-add.txt
@@ -1,5 +1,6 @@ 
 git-add(1)
 ==========
+// vim: syntax=asciidoc
 
 NAME
 ----