Coder Social home page Coder Social logo

gnome-c-style's Introduction

gnome-c-style

gnome-c-style is an Emacs minor mode for editing C source code in GNOME C coding style. In particular, it is useful to properly line-up function arguments and function declarations in header files.

Install

  • M-x package-install gnome-c-style
  • Add the following line to ~/.emacs.d/init.el:
(add-hook 'c-mode-hook 'gnome-c-style-mode)

Usage

Key Command
C-c C-g a Align argument list at the current point
C-c C-g r Align function declarations in the current region
C-c C-g C-g Compute optimal alignment columns from the current region
C-c C-g g Guess alignment columns from the current region
C-c C-g f Set alignment column to the current point
C-c C-g c Insert module_object
C-c C-g C Insert MODULE_OBJECT
C-c C-g C-c Insert ModuleObject
C-c C-g s Insert custom snippet

Example

If you have the following code in a header file:

GGpgCtx *g_gpg_ctx_new (GError **error);

typedef void (*GGpgProgressCallback) (gpointer user_data,
                                      const gchar *what,
                                      gint type,
                                      gint current,
                                      gint total);

void g_gpg_ctx_set_progress_callback (GGpgCtx *ctx,
                                      GGpgProgressCallback callback,
                                      gpointer user_data,
                                      GDestroyNotify destroy_data);
void g_gpg_ctx_add_signer (GGpgCtx *ctx, GGpgKey *key);
guint g_gpg_ctx_get_n_signers (GGpgCtx *ctx);
GGpgKey *g_gpg_ctx_get_signer (GGpgCtx *ctx, guint index);
void g_gpg_ctx_clear_signers (GGpgCtx *ctx);

Mark the region, type C-c C-g C-g, and you will see the optimum alignment columns:

identifier-start: 9, arglist-start: 41, arglist-identifier-start: 64

Then, mark the region again, type C-c C-g r, and you will get the code aligned:

GGpgCtx *g_gpg_ctx_new                   (GError              **error);

typedef void (*GGpgProgressCallback) (gpointer user_data,
                                      const gchar *what,
                                      gint type,
                                      gint current,
                                      gint total);

void     g_gpg_ctx_set_progress_callback (GGpgCtx              *ctx,
                                          GGpgProgressCallback  callback,
                                          gpointer              user_data,
                                          GDestroyNotify        destroy_data);
void     g_gpg_ctx_add_signer            (GGpgCtx              *ctx,
                                          GGpgKey              *key);
guint    g_gpg_ctx_get_n_signers         (GGpgCtx              *ctx);
GGpgKey *g_gpg_ctx_get_signer            (GGpgCtx              *ctx,
                                          guint                 index);
void     g_gpg_ctx_clear_signers         (GGpgCtx              *ctx);

Note that the typedef statement is skipped as it is not a function declaration.

gnome-c-style's People

Contributors

ueno avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.