diff mbox series

qapi: Add vim magic modelines for qapi definitions

Message ID 1f7db2e27758f26d4c10f7a8ed1d8232635f6909.1536044449.git.pkrempa@redhat.com (mailing list archive)
State New, archived
Headers show
Series qapi: Add vim magic modelines for qapi definitions | expand

Commit Message

Peter Krempa Sept. 4, 2018, 7:03 a.m. UTC
The files have a json suffix but look terrible with json syntax
hilighting enabled. Add a magic modeline for vim to switch to python
file format for hilighting similarly to the emacs modeline already
present.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
---
 qapi/block-core.json  | 1 +
 qapi/block.json       | 1 +
 qapi/char.json        | 1 +
 qapi/common.json      | 1 +
 qapi/crypto.json      | 1 +
 qapi/introspect.json  | 1 +
 qapi/job.json         | 1 +
 qapi/migration.json   | 1 +
 qapi/misc.json        | 1 +
 qapi/net.json         | 1 +
 qapi/qapi-schema.json | 1 +
 qapi/rocker.json      | 1 +
 qapi/run-state.json   | 1 +
 qapi/sockets.json     | 1 +
 qapi/tpm.json         | 1 +
 qapi/trace.json       | 1 +
 qapi/transaction.json | 1 +
 qapi/ui.json          | 1 +
 18 files changed, 18 insertions(+)

Comments

Peter Krempa Oct. 4, 2018, 11:34 a.m. UTC | #1
On Tue, Sep 04, 2018 at 09:03:10 +0200, Peter Krempa wrote:
> The files have a json suffix but look terrible with json syntax
> hilighting enabled. Add a magic modeline for vim to switch to python
> file format for hilighting similarly to the emacs modeline already
> present.
> 
> Signed-off-by: Peter Krempa <pkrempa@redhat.com>
> ---

Ping?
Peter Krempa Dec. 5, 2018, 12:33 p.m. UTC | #2
On Thu, Oct 04, 2018 at 13:34:12 +0200, Peter Krempa wrote:
> On Tue, Sep 04, 2018 at 09:03:10 +0200, Peter Krempa wrote:
> > The files have a json suffix but look terrible with json syntax
> > hilighting enabled. Add a magic modeline for vim to switch to python
> > file format for hilighting similarly to the emacs modeline already
> > present.
> > 
> > Signed-off-by: Peter Krempa <pkrempa@redhat.com>
> > ---
> 
> Ping?

Ping 2. It looks like no new json files were added meanwhile.
Marc-André Lureau Dec. 5, 2018, 2:09 p.m. UTC | #3
Hi

On Wed, Dec 5, 2018 at 4:34 PM Peter Krempa <pkrempa@redhat.com> wrote:
>
> On Thu, Oct 04, 2018 at 13:34:12 +0200, Peter Krempa wrote:
> > On Tue, Sep 04, 2018 at 09:03:10 +0200, Peter Krempa wrote:
> > > The files have a json suffix but look terrible with json syntax
> > > hilighting enabled. Add a magic modeline for vim to switch to python
> > > file format for hilighting similarly to the emacs modeline already
> > > present.
> > >
> > > Signed-off-by: Peter Krempa <pkrempa@redhat.com>
> > > ---
> >
> > Ping?
>
> Ping 2. It looks like no new json files were added meanwhile.

I use both emacs and vim. We solved this for me with emacs .editorconf
file_type_emacs.

The vim plugin doesn't have an equivalent, however, the documentation
suggest vim_filetype, but you need to add
to .vimrc:

function! FiletypeHook(config)
    if has_key(a:config, 'vim_filetype')
        let &filetype = a:config['vim_filetype']
    endif

    return 0   " Return 0 to show no error happened
endfunction

call editorconfig#AddNewHook(function('FiletypeHook'))

I think this is a better solution than having to add modelines
everywhere, what do you think?
Markus Armbruster Dec. 5, 2018, 4:20 p.m. UTC | #4
Marc-André Lureau <marcandre.lureau@gmail.com> writes:

> Hi
>
> On Wed, Dec 5, 2018 at 4:34 PM Peter Krempa <pkrempa@redhat.com> wrote:
>>
>> On Thu, Oct 04, 2018 at 13:34:12 +0200, Peter Krempa wrote:
>> > On Tue, Sep 04, 2018 at 09:03:10 +0200, Peter Krempa wrote:
>> > > The files have a json suffix but look terrible with json syntax
>> > > hilighting enabled. Add a magic modeline for vim to switch to python
>> > > file format for hilighting similarly to the emacs modeline already
>> > > present.
>> > >
>> > > Signed-off-by: Peter Krempa <pkrempa@redhat.com>
>> > > ---
>> >
>> > Ping?
>>
>> Ping 2. It looks like no new json files were added meanwhile.
>
> I use both emacs and vim. We solved this for me with emacs .editorconf
> file_type_emacs.
>
> The vim plugin doesn't have an equivalent, however, the documentation
> suggest vim_filetype, but you need to add
> to .vimrc:
>
> function! FiletypeHook(config)
>     if has_key(a:config, 'vim_filetype')
>         let &filetype = a:config['vim_filetype']
>     endif
>
>     return 0   " Return 0 to show no error happened
> endfunction
>
> call editorconfig#AddNewHook(function('FiletypeHook'))
>
> I think this is a better solution than having to add modelines
> everywhere, what do you think?

These .json files are not valid JSON.  They *are* valid Python (except
for a few tests, which could perhaps be fixed).  Makes me wonder why on
earth we insist on naming them .json and create all this trouble.
Eric Blake Dec. 5, 2018, 9:49 p.m. UTC | #5
On 12/5/18 10:20 AM, Markus Armbruster wrote:

>> The vim plugin doesn't have an equivalent, however, the documentation
>> suggest vim_filetype, but you need to add
>> to .vimrc:
>>
>> function! FiletypeHook(config)
>>      if has_key(a:config, 'vim_filetype')
>>          let &filetype = a:config['vim_filetype']
>>      endif
>>
>>      return 0   " Return 0 to show no error happened
>> endfunction
>>
>> call editorconfig#AddNewHook(function('FiletypeHook'))
>>
>> I think this is a better solution than having to add modelines
>> everywhere, what do you think?
> 
> These .json files are not valid JSON.  They *are* valid Python (except
> for a few tests, which could perhaps be fixed).  Makes me wonder why on
> earth we insist on naming them .json and create all this trouble.

I've previously posted patches that bulk-renames the QAPI files from 
.json to .qapi, but too close to a release cycle to be applied at the 
time. I'd have to refresh them to match new files in the meantime, but 
as long as we are arguing that editorconfig is a smart way to go, it's a 
fairly simple tweak to editorconfig to match the preferred suffix we use 
for QAPI files.
diff mbox series

Patch

diff --git a/qapi/block-core.json b/qapi/block-core.json
index 4c7a37afdc..e75bc8dd03 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -1,4 +1,5 @@ 
 # -*- Mode: Python -*-
+# vim: ft=python

 ##
 # == Block core (VM unrelated)
diff --git a/qapi/block.json b/qapi/block.json
index 11f01f28ef..f94ab0c09f 100644
--- a/qapi/block.json
+++ b/qapi/block.json
@@ -1,4 +1,5 @@ 
 # -*- Mode: Python -*-
+# vim: ft=python

 ##
 # = Block devices
diff --git a/qapi/char.json b/qapi/char.json
index b7b2a05766..d167f74699 100644
--- a/qapi/char.json
+++ b/qapi/char.json
@@ -1,4 +1,5 @@ 
 # -*- Mode: Python -*-
+# vim: ft=python
 #

 ##
diff --git a/qapi/common.json b/qapi/common.json
index c367adc4b6..5a3a71a5bf 100644
--- a/qapi/common.json
+++ b/qapi/common.json
@@ -1,4 +1,5 @@ 
 # -*- Mode: Python -*-
+# vim: ft=python

 ##
 # = Common data types
diff --git a/qapi/crypto.json b/qapi/crypto.json
index a51b434412..6ccb97079b 100644
--- a/qapi/crypto.json
+++ b/qapi/crypto.json
@@ -1,4 +1,5 @@ 
 # -*- Mode: Python -*-
+# vim: ft=python
 #

 ##
diff --git a/qapi/introspect.json b/qapi/introspect.json
index 3d22166b2b..ff6fb9fe52 100644
--- a/qapi/introspect.json
+++ b/qapi/introspect.json
@@ -1,4 +1,5 @@ 
 # -*- Mode: Python -*-
+# vim: ft=python
 #
 # Copyright (C) 2015 Red Hat, Inc.
 #
diff --git a/qapi/job.json b/qapi/job.json
index a121b615fb..ddef257f7e 100644
--- a/qapi/job.json
+++ b/qapi/job.json
@@ -1,4 +1,5 @@ 
 # -*- Mode: Python -*-
+# vim: ft=python

 ##
 # == Background jobs
diff --git a/qapi/migration.json b/qapi/migration.json
index f62d3f9a4b..17b0e00252 100644
--- a/qapi/migration.json
+++ b/qapi/migration.json
@@ -1,4 +1,5 @@ 
 # -*- Mode: Python -*-
+# vim: ft=python
 #

 ##
diff --git a/qapi/misc.json b/qapi/misc.json
index d450cfef21..2f04983517 100644
--- a/qapi/misc.json
+++ b/qapi/misc.json
@@ -1,4 +1,5 @@ 
 # -*- Mode: Python -*-
+# vim: ft=python
 #

 ##
diff --git a/qapi/net.json b/qapi/net.json
index c86f351161..e736e1a26b 100644
--- a/qapi/net.json
+++ b/qapi/net.json
@@ -1,4 +1,5 @@ 
 # -*- Mode: Python -*-
+# vim: ft=python
 #

 ##
diff --git a/qapi/qapi-schema.json b/qapi/qapi-schema.json
index 65b6dc2f6f..09d745bdcf 100644
--- a/qapi/qapi-schema.json
+++ b/qapi/qapi-schema.json
@@ -1,4 +1,5 @@ 
 # -*- Mode: Python -*-
+# vim: ft=python
 ##
 # = Introduction
 #
diff --git a/qapi/rocker.json b/qapi/rocker.json
index 3587661161..8e3486592b 100644
--- a/qapi/rocker.json
+++ b/qapi/rocker.json
@@ -1,4 +1,5 @@ 
 # -*- Mode: Python -*-
+# vim: ft=python

 ##
 # = Rocker switch device
diff --git a/qapi/run-state.json b/qapi/run-state.json
index 332e44897b..704a330a6c 100644
--- a/qapi/run-state.json
+++ b/qapi/run-state.json
@@ -1,4 +1,5 @@ 
 # -*- Mode: Python -*-
+# vim: ft=python
 #

 ##
diff --git a/qapi/sockets.json b/qapi/sockets.json
index fc81d8d5e8..b335b6b872 100644
--- a/qapi/sockets.json
+++ b/qapi/sockets.json
@@ -1,4 +1,5 @@ 
 # -*- Mode: Python -*-
+# vim: ft=python

 ##
 # = Socket data types
diff --git a/qapi/tpm.json b/qapi/tpm.json
index d50deef5e9..ae7953cb04 100644
--- a/qapi/tpm.json
+++ b/qapi/tpm.json
@@ -1,4 +1,5 @@ 
 # -*- Mode: Python -*-
+# vim: ft=python
 #

 ##
diff --git a/qapi/trace.json b/qapi/trace.json
index 799b254a18..e5ffbad800 100644
--- a/qapi/trace.json
+++ b/qapi/trace.json
@@ -1,4 +1,5 @@ 
 # -*- mode: python -*-
+# vim: ft=python
 #
 # Copyright (C) 2011-2016 Lluís Vilanova <vilanova@ac.upc.edu>
 #
diff --git a/qapi/transaction.json b/qapi/transaction.json
index d7e4274550..588112383a 100644
--- a/qapi/transaction.json
+++ b/qapi/transaction.json
@@ -1,4 +1,5 @@ 
 # -*- Mode: Python -*-
+# vim: ft=python
 #

 ##
diff --git a/qapi/ui.json b/qapi/ui.json
index 4ca91bb45a..918ab84a5a 100644
--- a/qapi/ui.json
+++ b/qapi/ui.json
@@ -1,4 +1,5 @@ 
 # -*- Mode: Python -*-
+# vim: ft=python
 #

 ##