]> code.delx.au - gnu-emacs-elpa/blob - packages/gnome-c-style/README.md
Merge commit '1054ea1bc5b07a1438a18c1b33f4266b28ff9d77'
[gnu-emacs-elpa] / packages / gnome-c-style / README.md
1 gnome-c-style
2 ======
3
4 gnome-c-style is an Emacs minor mode for editing C source code in [GNOME C coding style](https://developer.gnome.org/programming-guidelines/stable/c-coding-style.html.en). In particular, it is useful to properly line-up [function arguments](https://developer.gnome.org/programming-guidelines/stable/c-coding-style.html.en#functions) and [function declarations in header files](https://developer.gnome.org/programming-guidelines/stable/c-coding-style.html.en#functions).
5
6 Install
7 ------
8
9 * M-x package-install gnome-c-style
10 * Add the following lines to ~/.emacs/init.el:
11
12 ```
13 (add-hook 'c-mode-hook 'gnome-c-style-mode)
14 ```
15
16 Usage
17 ------
18
19 | Key | Command |
20 --------------|-----------------------------------------------------------|
21 | C-c C-g a | Align argument list at the current point |
22 | C-c C-g r | Align function declarations in the current region |
23 | C-c C-g C-g | Compute optimal alignment columns from the current region |
24 | C-c C-g g | Guess alignment columns from the current region |
25 | C-c C-g s | Set alignment column to the current point |
26 | C-c C-g c | Insert ```module_object``` |
27 | C-c C-g C | Insert ```MODULE_OBJECT``` |
28 | C-c C-g C-c | Insert ```ModuleObject``` |
29 | C-c C-g s | Insert custom snippet |
30
31 Example
32 ------
33
34 If you have the following code in a header file:
35 ```c
36 GGpgCtx *g_gpg_ctx_new (GError **error);
37
38 typedef void (*GGpgProgressCallback) (gpointer user_data,
39 const gchar *what,
40 gint type,
41 gint current,
42 gint total);
43
44 void g_gpg_ctx_set_progress_callback (GGpgCtx *ctx,
45 GGpgProgressCallback callback,
46 gpointer user_data,
47 GDestroyNotify destroy_data);
48 void g_gpg_ctx_add_signer (GGpgCtx *ctx, GGpgKey *key);
49 guint g_gpg_ctx_get_n_signers (GGpgCtx *ctx);
50 GGpgKey *g_gpg_ctx_get_signer (GGpgCtx *ctx, guint index);
51 void g_gpg_ctx_clear_signers (GGpgCtx *ctx);
52 ```
53
54 Mark the region, type ```C-c C-g C-g```, and you will see the optimum
55 alignment columns:
56
57 ```
58 identifier-start: 9, arglist-start: 41, arglist-identifier-start: 63
59 ```
60
61 Then, mark the region again, type ```C-c C-g r```, and you will get
62 the code aligned:
63
64 ```c
65 GGpgCtx *g_gpg_ctx_new (GError **error);
66
67 typedef void (*GGpgProgressCallback) (gpointer user_data,
68 const gchar *what,
69 gint type,
70 gint current,
71 gint total);
72
73 void g_gpg_ctx_set_progress_callback (GGpgCtx *ctx,
74 GGpgProgressCallback callback,
75 gpointer user_data,
76 GDestroyNotify destroy_data);
77 void g_gpg_ctx_add_signer (GGpgCtx *ctx,
78 GGpgKey *key);
79 guint g_gpg_ctx_get_n_signers (GGpgCtx *ctx);
80 GGpgKey *g_gpg_ctx_get_signer (GGpgCtx *ctx,
81 guint index);
82 void g_gpg_ctx_clear_signers (GGpgCtx *ctx);
83 ```
84
85 Note that ```typedef``` is skipped as it is not a function declaration.