]> code.delx.au - gnu-emacs-elpa/blob - README.md
Squashed 'packages/gnome-c-style/' content from commit e84487c
[gnu-emacs-elpa] / README.md
1 gnome-c-style
2 ======
3
4 In the C coding style commonly used in GNOME, identifiers are written
5 in camel case and function arguments are aligned to the right end.
6 That makes it a bit cumbersome to keep your code consistent with the
7 style, even with align.el or plugins like yasnippet.
8
9 gnome-c-style is an Emacs minor mode intended to help editing C
10 source code in that style. It mainly provides two features: text
11 alignment and snippet insersion.
12
13 Install
14 ------
15
16 * Type "make"
17 * Copy .elc files somewhere in your load-path
18 * Add the following lines to ~/.emacs/init.el:
19
20 ```
21 (autoload 'gnome-c-style-mode "gnome-c-style" "GNOME-style C minor mode" t)
22 (add-hook 'c-mode-hook 'gnome-c-style-mode)
23 ```
24
25 Usage
26 ------
27
28 | Key | Command |
29 --------------|-----------------------------------------------------------|
30 | C-c C-g a | Align argument list at the current point |
31 | C-c C-g r | Align function declarations in the current region |
32 | C-c C-g C-g | Compute optimal alignment columns from the current region |
33 | C-c C-g g | Guess alignment columns from the current region |
34 | C-c C-g s | Set alignment column to the current point |
35 | C-c C-g c | Insert ```module_object``` |
36 | C-c C-g C | Insert ```MODULE_OBJECT``` |
37 | C-c C-g C-c | Insert ```ModuleObject``` |
38 | C-c C-g s | Insert custom snippet |
39
40 Example
41 ------
42
43 If you have the following code in a header file:
44 ```c
45 GGpgCtx *g_gpg_ctx_new (GError **error);
46
47 typedef void (*GGpgProgressCallback) (gpointer user_data,
48 const gchar *what,
49 gint type,
50 gint current,
51 gint total);
52
53 void g_gpg_ctx_set_progress_callback (GGpgCtx *ctx,
54 GGpgProgressCallback callback,
55 gpointer user_data,
56 GDestroyNotify destroy_data);
57 void g_gpg_ctx_add_signer (GGpgCtx *ctx, GGpgKey *key);
58 guint g_gpg_ctx_get_n_signers (GGpgCtx *ctx);
59 GGpgKey *g_gpg_ctx_get_signer (GGpgCtx *ctx, guint index);
60 void g_gpg_ctx_clear_signers (GGpgCtx *ctx);
61 ```
62
63 Mark the region, type ```C-c C-g C-g```, and you will see the optimum
64 alignment columns:
65
66 ```
67 identifier-start: 9, arglist-start: 41, arglist-identifier-start: 63
68 ```
69
70 Then, mark the region again, type ```C-c C-g r```, and you will get
71 the code aligned:
72
73 ```c
74 GGpgCtx *g_gpg_ctx_new (GError **error);
75
76 typedef void (*GGpgProgressCallback) (gpointer user_data,
77 const gchar *what,
78 gint type,
79 gint current,
80 gint total);
81
82 void g_gpg_ctx_set_progress_callback (GGpgCtx *ctx,
83 GGpgProgressCallback callback,
84 gpointer user_data,
85 GDestroyNotify destroy_data);
86 void g_gpg_ctx_add_signer (GGpgCtx *ctx,
87 GGpgKey *key);
88 guint g_gpg_ctx_get_n_signers (GGpgCtx *ctx);
89 GGpgKey *g_gpg_ctx_get_signer (GGpgCtx *ctx,
90 guint index);
91 void g_gpg_ctx_clear_signers (GGpgCtx *ctx);
92 ```
93
94 Note that ```typedef``` is skipped as it is not a function declaration.