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