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