[gnome-devel-docs] programming-guidelines: More stuff for the Whitespace section



commit 2582e2bfd98ca3b5de392562c304aef1e5ea6d3c
Author: Federico Mena Quintero <federico gnome org>
Date:   Tue Aug 6 17:56:05 2013 +0200

    programming-guidelines: More stuff for the Whitespace section

 programming-guidelines/C/c-coding-style.page |   58 ++++++++++++++++++++++++++
 1 files changed, 58 insertions(+), 0 deletions(-)
---
diff --git a/programming-guidelines/C/c-coding-style.page b/programming-guidelines/C/c-coding-style.page
index c0b2a0f..7cc6cf8 100644
--- a/programming-guidelines/C/c-coding-style.page
+++ b/programming-guidelines/C/c-coding-style.page
@@ -485,6 +485,64 @@ if(condition)
 if ( condition )
         do_my_things ( );
     </code>
+
+    <p>
+      When declaring a structure type use newlines to separate logical sections
+      of the structure:
+    </p>
+
+    <code>
+struct _GtkWrapBoxPrivate
+{
+        GtkOrientation        orientation;
+        GtkWrapAllocationMode mode;
+
+        GtkWrapBoxSpreading   horizontal_spreading;
+        GtkWrapBoxSpreading   vertical_spreading;
+
+        guint16               vertical_spacing;
+        guint16               horizontal_spacing;
+
+        guint16               minimum_line_children;
+        guint16               natural_line_children;
+
+        GList                *children;
+};
+    </code>
+
+    <p>
+      Do not eliminate whitespace and newlines just because something would
+      fit on a single line:
+    </p>
+
+    <code>
+/* invalid */
+if (condition) foo (); else bar ();
+    </code>
+
+    <p>
+      Do eliminate trailing whitespace on any line, preferably as a separate
+      patch or commit. Never use empty lines at the beginning or at the end of
+      a file.
+    </p>
+
+    <p>
+      This is a little Emacs function that you can use to clean up
+      lines with trailing whitespace:
+    </p>
+
+    <code>
+(defun clean-line-ends ()
+  (interactive)
+  (if (not buffer-read-only)
+      (save-excursion
+       (goto-char (point-min))
+       (let ((count 0))
+         (while (re-search-forward "[  ]+$" nil t)
+           (setq count (+ count 1))
+           (replace-match "" t t))
+         (message "Cleaned %d lines" count)))))
+    </code>
   </section>
 
   <section id="switch">


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]