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