Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * format_c.c
- *
- * https://www.geany.org/manual/reference/howto.html
- *
- * yum install intltool geany-devel
- * yum install indent
- *
- * gcc -c format_c.c -fPIC `pkg-config --cflags geany`
- * gcc format_c.o -o format_c.so -shared `pkg-config --libs geany`
- * sudo cp format_c.so /usr/lib/x86_64-linux-gnu/geany
- *
- * Copyright 2018 Nikolay <xeritt(at)gmail.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA 02110-1301, USA.
- */
- #include <geanyplugin.h>
- #include <stdlib.h>
- static void item_activate_cb(GtkMenuItem * menuitem, gpointer user_data)
- {
- GeanyDocument *doc;
- doc = document_get_current();
- char command[1024];
- sprintf(command, "indent -kr -i8 -ts8 -sob -l80 -ss -bs -linux \"%s\"",
- doc->file_name);
- gint error_nr = system(command);
- if (error_nr == 0) {
- ui_set_statusbar(TRUE,
- ("Document '%s' successfully format. Reload document!"),
- doc->file_name);
- gboolean res = document_reload_force(doc, NULL);
- } else
- ui_set_statusbar(TRUE, _("File '%s' could not be format (%s)."),
- doc->file_name, g_strerror(error_nr));
- }
- static void on_activate_cb(G_GNUC_UNUSED guint key_id)
- {
- item_activate_cb(NULL, NULL);
- }
- static gboolean save_init(GeanyPlugin * plugin, gpointer pdata)
- {
- GtkWidget *main_menu_item;
- // Create a new menu item and show it
- main_menu_item = gtk_menu_item_new_with_mnemonic("Format C/Linux");
- gtk_widget_show(main_menu_item);
- gtk_container_add(GTK_CONTAINER
- (plugin->geany_data->main_widgets->tools_menu),
- main_menu_item);
- g_signal_connect(main_menu_item, "activate",
- G_CALLBACK(item_activate_cb), NULL);
- GeanyKeyGroup *group;
- group = plugin_set_key_group(plugin, "Format code", 1, NULL);
- keybindings_set_item(group, 0, on_activate_cb,
- 0, 0, "format c", _("Format code C linux style"),
- main_menu_item);
- geany_plugin_set_data(plugin, main_menu_item, NULL);
- return TRUE;
- }
- static void save_cleanup(GeanyPlugin * plugin, gpointer pdata)
- {
- GtkWidget *main_menu_item = (GtkWidget *) pdata;
- gtk_widget_destroy(main_menu_item);
- }
- G_MODULE_EXPORT void geany_load_module(GeanyPlugin * plugin)
- {
- /* Step 1: Set metadata */
- plugin->info->name = "Format C/Linux";
- plugin->info->description = "Format document by C linux kernel style";
- plugin->info->version = "1.0";
- plugin->info->author = "Nikolay <xeritt@gmail.com>";
- /* Step 2: Set functions */
- plugin->funcs->init = save_init;
- plugin->funcs->cleanup = save_cleanup;
- /* Step 3: Register! */
- GEANY_PLUGIN_REGISTER(plugin, 225);
- /* alternatively:
- GEANY_PLUGIN_REGISTER_FULL(plugin, 225, data, free_func); */
- }
Add Comment
Please, Sign In to add comment