Document and enforce the new spaces-only indentation policy.
authorJim Meyering <meyering@redhat.com>
Mon, 3 Aug 2009 14:55:34 +0000 (10:55 -0400)
committerJim Meyering <meyering@redhat.com>
Mon, 3 Aug 2009 16:05:17 +0000 (18:05 +0200)
* cfg.mk (disable_temporarily): Remove sc_TAB_in_indentation,
to enable the "make syntax-check" that enforces this.
* .x-sc_TAB_in_indentation: New file.  Exceptions.
* HACKING: Document the policy, with tips on how to conform.

.x-sc_TAB_in_indentation [new file with mode: 0644]
HACKING
cfg.mk

diff --git a/.x-sc_TAB_in_indentation b/.x-sc_TAB_in_indentation
new file mode 100644 (file)
index 0000000..c73edf2
--- /dev/null
@@ -0,0 +1,8 @@
+^appliance/debian/modules/
+^images/
+^COPYING$
+^\.gitmodules$
+(^|\/)ChangeLog[^/]*$
+(^|\/)(?:GNU)?[Mm]akefile[^/]*$
+\.(am|mk)$
+^po/Rules-quot$
diff --git a/HACKING b/HACKING
index c6a3022..815ee16 100644 (file)
--- a/HACKING
+++ b/HACKING
@@ -24,6 +24,29 @@ Please make sure that the code compiles without warnings.
 
 Please test any changes.
 
+Code indentation
+----------------------------------------------------------------------
+Our C source code generally adheres to some basic code-formatting
+conventions.  The existing code base is not totally consistent on this
+front, but we do prefer that contributed code be formatted similarly.
+In short, use spaces-not-TABs for indentation, use 2 spaces for each
+indentation level, and other than that, follow the K&R style.
+
+If you use Emacs, add the following to one of one of your start-up files
+(e.g., ~/.emacs), to help ensure that you get indentation right:
+
+  ;;; When editing C sources in libguestfs, use this style.
+  (defun libguestfs-c-mode ()
+    "C mode with adjusted defaults for use with libguestfs."
+    (interactive)
+    (c-set-style "K&R")
+    (setq indent-tabs-mode nil) ; indent using spaces, not TABs
+    (setq c-indent-level 2)
+    (setq c-basic-offset 2))
+  (add-hook 'c-mode-hook
+           '(lambda () (if (string-match "/libguestfs" (buffer-file-name))
+                           (libguestfs-c-mode))))
+
 Directories
 ----------------------------------------------------------------------
 
diff --git a/cfg.mk b/cfg.mk
index e92c34f..7130cea 100644 (file)
--- a/cfg.mk
+++ b/cfg.mk
@@ -65,7 +65,6 @@ local-checks-to-skip =                        \
 disable_temporarily =                  \
   sc_makefile_TAB_only_indentation     \
   sc_unmarked_diagnostics              \
-  sc_TAB_in_indentation                        \
   sc_prohibit_ctype_h                  \
   sc_prohibit_asprintf                 \
   sc_m4_quote_check                    \
@@ -107,10 +106,10 @@ sc_prohibit_ctype_h:
                1>&2; exit 1; } || :
 
 # Ensure that no C source file uses TABs for indentation.
+# Exclude some version-controlled symlinks.
 sc_TAB_in_indentation:
        @grep -lE '^ *  ' /dev/null                                     \
-            $$($(VC_LIST_EXCEPT)                                       \
-               | grep -E '\.[ch](\.in)?$$') &&                         \
+            $$($(VC_LIST_EXCEPT)) &&                                   \
          { echo '$(ME): found TAB(s) used for indentation in C sources;'\
              'use spaces' 1>&2; exit 1; } || :