Skip to contentSkip to conversation

.dir-locals.el: add makefiles to auto-mode

PATCH In review Marc-André Lureau 3 participants 5 messages Aug 31, 2017 – Sep 1, 2017 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 .dir-locals.el: add makefiles to auto-mode

QEMU uses non-conventional makefile filenames. Ease the life of emacs developpers a bit by appending to the auto-mode-alist.

---
 .dir-locals.el      | 7 ++++++-
 Makefile.target     | 2 --
 trace/Makefile.objs | 2 --
 3 files changed, 6 insertions(+), 5 deletions(-)
.dir-locals.el +6 -1
index 3ac0cfc6f0..13ec483765 100644
@@ -1,2 +1,7 @@
 ((c-mode . ((c-file-style . "stroustrup")
-	    (indent-tabs-mode . nil))))
+            (indent-tabs-mode . nil)))
+ (nil . ((eval . (setq auto-mode-alist (append
+                                        '(("Makefile.*" . makefile-gmake-mode)
+                                          ("\\.mak\\'" . makefile-gmake-mode))
+                                        auto-mode-alist))))
+      ))
Makefile.target +0 -2
index 7f42c45db8..159602c83c 100644
@@ -1,5 +1,3 @@
-# -*- Mode: makefile -*-
-
 BUILD_DIR?=$(CURDIR)/..
 
 include ../config-host.mak
trace/Makefile.objs +0 -2
index afd571c3ec..d1f1e646e5 100644
@@ -1,5 +1,3 @@
-# -*- mode: makefile -*-
-
 $(BUILD_DIR)/trace-events-all: $(trace-events-files)
 	$(call quiet-command,cat $^ > $@)
 
Signature · 1 line
2.14.1.146.gd35faa819
#1 lore raw

PATCH 2/2 .dir-locals.el: add json schema to auto-mode

The json schema is more friendly to python-mode since it doesn't follow strictly json (comments to start with).

All schema files add file variables to set the python mode, but most tests didn't. This will cover all json files now.

---
 qapi-schema.json                        | 1 -
 qapi/block-core.json                    | 2 --
 qapi/block.json                         | 2 --
 qapi/common.json                        | 2 --
 qapi/crypto.json                        | 3 ---
 qapi/event.json                         | 2 --
 qapi/introspect.json                    | 1 -
 qapi/rocker.json                        | 2 --
 qapi/trace.json                         | 1 -
 .dir-locals.el                          | 4 +++-
 qga/qapi-schema.json                    | 2 --
 tests/qapi-schema/doc-good.json         | 1 -
 tests/qapi-schema/qapi-schema-test.json | 2 --
 13 files changed, 3 insertions(+), 22 deletions(-)
qapi-schema.json +0 -1
index 802ea53d00..232fafeb65 100644
@@ -1,4 +1,3 @@
-# -*- Mode: Python -*-
 ##
 # = Introduction
 #
qapi/block-core.json +0 -2
index 833c602150..5bd14554aa 100644
@@ -1,5 +1,3 @@
-# -*- Mode: Python -*-
-
 ##
 # == QAPI block core definitions (vm unrelated)
 ##
qapi/block.json +0 -2
index 414b61bde7..979906625d 100644
@@ -1,5 +1,3 @@
-# -*- Mode: Python -*-
-
 ##
 # = QAPI block definitions
 ##
qapi/common.json +0 -2
index 8355d5a2f3..25a9fdcbfd 100644
@@ -1,5 +1,3 @@
-# -*- Mode: Python -*-
-
 ##
 # = QAPI common definitions
 ##
qapi/crypto.json +0 -3
index 6b6fde367a..9ec7777603 100644
@@ -1,6 +1,3 @@
-# -*- Mode: Python -*-
-#
-
 ##
 # = QAPI crypto definitions
 ##
qapi/event.json +0 -2
index 6d22b025cc..6f15ec1542 100644
@@ -1,5 +1,3 @@
-# -*- Mode: Python -*-
-
 ##
 # = Other events
 ##
qapi/introspect.json +0 -1
index cf77ff0669..83eaed3e43 100644
@@ -1,4 +1,3 @@
-# -*- Mode: Python -*-
 #
 # QAPI/QMP introspection
 #
qapi/rocker.json +0 -2
index 3587661161..0026c7fd59 100644
@@ -1,5 +1,3 @@
-# -*- Mode: Python -*-
-
 ##
 # = Rocker switch device
 ##
qapi/trace.json +0 -1
index de6588d9f7..679b1e298a 100644
@@ -1,4 +1,3 @@
-# -*- mode: python -*-
 #
 # Copyright (C) 2011-2016 Lluís Vilanova <[email protected]>
 #
.dir-locals.el +3 -1
index 13ec483765..46a6c73ed1 100644
@@ -2,6 +2,8 @@
             (indent-tabs-mode . nil)))
  (nil . ((eval . (setq auto-mode-alist (append
                                         '(("Makefile.*" . makefile-gmake-mode)
-                                          ("\\.mak\\'" . makefile-gmake-mode))
+                                          ("\\.mak\\'" . makefile-gmake-mode)
+                                          ;; json schema is not pure json
+                                          ("\\.json\\'" . python-mode))
                                         auto-mode-alist))))
       ))
qga/qapi-schema.json +0 -2
index 90a0c8602b..757bb42521 100644
@@ -1,5 +1,3 @@
-# *-*- Mode: Python -*-*
-
 ##
 #
 # General note concerning the use of guest agent interfaces:
tests/qapi-schema/doc-good.json +0 -1
index cfdc0a8a81..4a34eaf3d1 100644
@@ -1,4 +1,3 @@
-# -*- Mode: Python -*-
 # Positive QAPI doc comment tests
 
 { 'pragma': { 'doc-required': true } }
tests/qapi-schema/qapi-schema-test.json +0 -2
index c72dbd8050..6e5635ef66 100644
@@ -1,5 +1,3 @@
-# *-*- Mode: Python -*-*
-
 # This file is a stress test of supported qapi constructs that must
 # parse and compile correctly.
 
Signature · 1 line
2.14.1.146.gd35faa819
#2 lore raw

Re: [Qemu-devel] [PATCH 2/2] .dir-locals.el: add json schema to auto-mode

Quoted 2 lines · Marc-André Lureau

The json schema is more friendly to python-mode since it doesn't follow strictly json (comments to start with).

I found that hard to read, and missing a key word of 'emacs'. Maybe reword it as:

Under emacs, our QAPI files (.json suffix) are more friendly to edit under python-mode than the per-suffix default of json-mode (in part because of our use of comments).

Quoted 9 lines

All schema files add file variables to set the python mode, but most tests didn't. This will cover all json files now.

---

+++ b/.dir-locals.el

.dir-locals.el line 9

Quoted 9 lines
.dir-locals.el +3 -1
@@ -2,6 +2,8 @@
             (indent-tabs-mode . nil)))
  (nil . ((eval . (setq auto-mode-alist (append
                                         '(("Makefile.*" . makefile-gmake-mode)
-                                          ("\\.mak\\'" . makefile-gmake-mode))
+                                          ("\\.mak\\'" . makefile-gmake-mode)
+                                          ;; json schema is not pure json
+                                          ("\\.json\\'" . python-mode))
                                         auto-mode-alist))))
       ))

Not sure if the comment could be worded better, maybe:

;; Our .json files are QAPI, and allow more than pure json

Again, the idea makes sense to me, but you may want to get feedback from other power emacs users.

[Also, don't forget the 0/2 cover letter if you send v2]

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
#3 lore raw
In reply to Marc-André Lureau
Quoted 2 lines · Marc-André Lureau

QEMU uses non-conventional makefile filenames. Ease the life of emacs developpers a bit by appending to the auto-mode-alist.

s/emacs developpers/developers using emacs/ (typo, and avoids an ambiguity on whether you are describing people that develop emacs rather than qemu)

Quoted 3 lines

---

The idea itself makes sense to me; although I'm not enough of a Lisp guru to state if your changes are the ideal way to do it.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
#4 lore raw
In reply to Marc-André Lureau
Quoted 15 lines · Marc-André Lureau

QEMU uses non-conventional makefile filenames. Ease the life of emacs developpers a bit by appending to the auto-mode-alist.

---
 .dir-locals.el      | 7 ++++++-
 Makefile.target     | 2 --
 trace/Makefile.objs | 2 --
 3 files changed, 6 insertions(+), 5 deletions(-)
.dir-locals.el +0 -0
index 3ac0cfc6f0..13ec483765 100644

.dir-locals.el line 7

Quoted 8 lines
.dir-locals.el +6 -1
@@ -1,2 +1,7 @@
 ((c-mode . ((c-file-style . "stroustrup")
-	    (indent-tabs-mode . nil))))
+            (indent-tabs-mode . nil)))
+ (nil . ((eval . (setq auto-mode-alist (append
+                                        '(("Makefile.*" . makefile-gmake-mode)
+                                          ("\\.mak\\'" . makefile-gmake-mode))
+                                        auto-mode-alist))))
+      ))

This makes Emacs ask for confirmation like this:

The local variables list in /home/armbru/work/qemu/ contains values that may not be safe (*).

Do you want to apply it? You can type
y -- to apply the local variables list.
n -- to ignore the local variables list.
! -- to apply the local variables list, and permanently mark these
values (*) as safe (in the future, they will be set automatically.)

* eval : (setq auto-mode-alist (append (quote (("Makefile.*" . makefile-gmake-mode) ("\\.mak\\'" . makefile-gmake-mode) ("\\.json\\'" . python-mode))) auto-mode-alist))

Not a nice user experience. For detailed information why and how this stuff works, see
https://www.gnu.org/software/emacs/manual/html_node/emacs/Safe-File-Variables.html

Why can't we simply use the usual file name extension like a normal person?

If that's too much to ask, then I'd recommend adding modelines (like the ones you delete) to the Makefiles that lack one.

Quoted 19 lines
Makefile.target +0 -2
index 7f42c45db8..159602c83c 100644
@@ -1,5 +1,3 @@
-# -*- Mode: makefile -*-
-
 BUILD_DIR?=$(CURDIR)/..
 
 include ../config-host.mak
trace/Makefile.objs +0 -2
index afd571c3ec..d1f1e646e5 100644
@@ -1,5 +1,3 @@
-# -*- mode: makefile -*-
-
 $(BUILD_DIR)/trace-events-all: $(trace-events-files)
 	$(call quiet-command,cat $^ > $@)