IncDec is a plugin for Geany that provides shortcuts to increment an decrement number at the cursor, or to the right of the cursor (on the same line).
By default, typing **Shift-+** will increment the next number, and typing **Shift--** will decrement the next number. You can also increment and decrement number many times by typing **Shift-***. The number can be at the cursor, or to the right of the cursor (on the same line). Numbers can be negative and positive, and can be in decimal or hexadecimal format (hexadecimal number start with **0x**). You can customize those defaults keys on the preferences, under the Keybindings tab by setting the _IncDec_ keybinding. An item _Increment or Decrement number_ is also added in the Editor Popup Menu, it can be hidden by changing the Plugins Preferences.
You can view, comment on, or merge this pull request online at:
https://github.com/geany/geany-plugins/pull/1351
-- Commit Summary --
* IncDec is a plugin for Geany that provides shortcuts to increment and decrement
-- File Changes --
M Makefile.am (4) M README (1) M build/geany-plugins.nsi (1) A build/incdec.m4 (11) M configure.ac (1) A incdec/AUTHORS (1) A incdec/COPYING (674) A incdec/ChangeLog (0) A incdec/Makefile.am (4) A incdec/NEWS (0) A incdec/README (50) A incdec/src/Makefile.am (16) A incdec/src/incdec-plugin.c (592)
-- Patch Links --
https://github.com/geany/geany-plugins/pull/1351.patch https://github.com/geany/geany-plugins/pull/1351.diff
This pull request replace previous #1337
@scresto09 pushed 1 commit.
5889910191ed1fa066bd7e188a9032b41ab6e859 incdec: fix POTFILES.in
@eht16 requested changes on this pull request.
Nice, thanks!
I added a few minor remarks. Additionally, could you please update the `MAINTAINERS` file in the root directory?
Thanks.
@@ -72,6 +72,7 @@ GP_CHECK_VIMODE
GP_CHECK_WEBHELPER GP_CHECK_WORKBENCH GP_CHECK_XMLSNIPPETS +GP_CHECK_INCDEC
As the rest of the list is sorted alphabetically, could you move your plugin after `GP_CHECK_GITCHANGEBAR`?
- gtk_container_add(GTK_CONTAINER(geany->main_widgets->editor_menu), plugin_data._menu_item_sep);
+ + plugin_data._menu_item_change_number = gtk_menu_item_new_with_mnemonic(_("_Increment or Decrement number")); + gtk_container_add(GTK_CONTAINER(geany->main_widgets->editor_menu), plugin_data._menu_item_change_number); + + configuration_apply(); + + g_signal_connect(plugin_data._menu_item_change_number, "activate", G_CALLBACK(on_change_number_x), NULL); +} + + +void plugin_cleanup (void) +{ + if (plugin_data._dialog) + { + gtk_widget_destroy (GTK_WIDGET (plugin_data._dialog));
Here and in some other places you use a space between identifier and opening braces, in other places not. I suggest to use a consistent style.
- keybindings_set_item (key_group, KB_DECREMENT_NUMBER, NULL, GDK_KEY_KP_Subtract, GDK_SHIFT_MASK,
+ "decrement_number", + _("Decrement Number By 1"), NULL); + keybindings_set_item (key_group, KB_INCREMENT_DECREMENT_NUMBER_X, NULL, GDK_KEY_KP_Multiply, GDK_SHIFT_MASK, + "increment_decrement_number_x", + _("Increment or Decrement Number X times"), NULL); + + plugin_data._menu_item_sep = gtk_separator_menu_item_new(); + gtk_container_add(GTK_CONTAINER(geany->main_widgets->editor_menu), plugin_data._menu_item_sep); + + plugin_data._menu_item_change_number = gtk_menu_item_new_with_mnemonic(_("_Increment or Decrement number")); + gtk_container_add(GTK_CONTAINER(geany->main_widgets->editor_menu), plugin_data._menu_item_change_number); + + configuration_apply(); + + g_signal_connect(plugin_data._menu_item_change_number, "activate", G_CALLBACK(on_change_number_x), NULL);
Here and in some other places, there is mixed indentation, sometimes spaces sometimes tabs. I suggest to use a consistent style.
+ /* when the number changes sign, the format is reset to avoid a display shift */ + if ((positive == FALSE && guessed_number >= 0) || (positive == TRUE && guessed_number < 0)) + { + format_length = 0; + } + else + { + format_length = digit_end - digit_start; + if (format_length > 12) + format_length = 0; + } + + g_snprintf(format_buf, sizeof(format_buf)-1, "%%0%d%c", format_length, use_hexa ? ( hexaCase == HEXA_CASE_UPPER ? 'X' : 'x' ) : 'd'); + + if ((buf = g_strdup_printf(format_buf, guessed_number)))
gcc warns here: ``` incdec-plugin.c: In function 'on_change_number': incdec-plugin.c:374:44: warning: format not a string literal, argument types not checked [-Wformat-nonliteral] 374 | if ((buf = g_strdup_printf(format_buf, guessed_number))) | ^~~~~~~~~~ ``` Maybe this can be fixed.
@eht16 commented on this pull request.
+ gtk_widget_show_all(vbox); + g_signal_connect(dialog, "response", G_CALLBACK(on_configure_response), NULL); + + return vbox; +} + + +void plugin_init (GeanyData *data) +{ + GeanyKeyGroup *key_group; + + load_config(); + + key_group = plugin_set_key_group (geany_plugin, "incdec", KB_COUNT, on_change_number_callback); + keybindings_set_item (key_group, KB_INCREMENT_NUMBER, NULL, GDK_KEY_KP_Add, GDK_SHIFT_MASK,
GDK_KEY_KP_Add is specific for the + key on the numpad, I think.
The ReadMe mentions Shift-+ and this does not work on my system (German keyboard). I think this won't work on most keyboard layouts where +, - and * are interpreted with Shift to another key. So, maybe just make the README (and possibly other references) more explicit.
@scresto09 pushed 1 commit.
abd29d31089188029e481fbb0d2da63b376c4c0a Merge branch 'geany:master' into incdec-plugin-geany
@scresto09 pushed 1 commit.
e5dcca34175b0ae1cea7566bfc2c0c7912133e50 incdec: Cosmetic changes in the code and key binding updates
@scresto09 commented on this pull request.
@@ -72,6 +72,7 @@ GP_CHECK_VIMODE
GP_CHECK_WEBHELPER GP_CHECK_WORKBENCH GP_CHECK_XMLSNIPPETS +GP_CHECK_INCDEC
Ok I did it
@scresto09 commented on this pull request.
- gtk_container_add(GTK_CONTAINER(geany->main_widgets->editor_menu), plugin_data._menu_item_sep);
+ + plugin_data._menu_item_change_number = gtk_menu_item_new_with_mnemonic(_("_Increment or Decrement number")); + gtk_container_add(GTK_CONTAINER(geany->main_widgets->editor_menu), plugin_data._menu_item_change_number); + + configuration_apply(); + + g_signal_connect(plugin_data._menu_item_change_number, "activate", G_CALLBACK(on_change_number_x), NULL); +} + + +void plugin_cleanup (void) +{ + if (plugin_data._dialog) + { + gtk_widget_destroy (GTK_WIDGET (plugin_data._dialog));
Ok I did it
@scresto09 commented on this pull request.
+ gtk_widget_show_all(vbox); + g_signal_connect(dialog, "response", G_CALLBACK(on_configure_response), NULL); + + return vbox; +} + + +void plugin_init (GeanyData *data) +{ + GeanyKeyGroup *key_group; + + load_config(); + + key_group = plugin_set_key_group (geany_plugin, "incdec", KB_COUNT, on_change_number_callback); + keybindings_set_item (key_group, KB_INCREMENT_NUMBER, NULL, GDK_KEY_KP_Add, GDK_SHIFT_MASK,
Yes, you're right, these are not the best keyboard shortcuts.
I have modified the default keyboard shortcuts and updated the files. Now we have to use Shift+A, Shift+X, and Shift+M.
@scresto09 commented on this pull request.
+ /* when the number changes sign, the format is reset to avoid a display shift */ + if ((positive == FALSE && guessed_number >= 0) || (positive == TRUE && guessed_number < 0)) + { + format_length = 0; + } + else + { + format_length = digit_end - digit_start; + if (format_length > 12) + format_length = 0; + } + + g_snprintf(format_buf, sizeof(format_buf)-1, "%%0%d%c", format_length, use_hexa ? ( hexaCase == HEXA_CASE_UPPER ? 'X' : 'x' ) : 'd'); + + if ((buf = g_strdup_printf(format_buf, guessed_number)))
Hum, the code seems correct to me, and it’s really useful for me to use a format that isn’t a "string literal". I don’t think this is a problem. If you'd like, maybe I could add a DEFINE or a CFLAGS to disable this warning ?
@eht16 commented on this pull request.
+ /* when the number changes sign, the format is reset to avoid a display shift */ + if ((positive == FALSE && guessed_number >= 0) || (positive == TRUE && guessed_number < 0)) + { + format_length = 0; + } + else + { + format_length = digit_end - digit_start; + if (format_length > 12) + format_length = 0; + } + + g_snprintf(format_buf, sizeof(format_buf)-1, "%%0%d%c", format_length, use_hexa ? ( hexaCase == HEXA_CASE_UPPER ? 'X' : 'x' ) : 'd'); + + if ((buf = g_strdup_printf(format_buf, guessed_number)))
The best I found is: ```c #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wformat-nonliteral" if ((buf = g_strdup_printf(format_buf, guessed_number))) #pragma GCC diagnostic pop ```
@eht16 commented on this pull request.
@@ -72,6 +72,7 @@ GP_CHECK_VIMODE
GP_CHECK_WEBHELPER GP_CHECK_WORKBENCH GP_CHECK_XMLSNIPPETS +GP_CHECK_INCDEC
Are you sure you pushed all changes?
The order in `configure.ac` is still wrong, also the inconsistent spaces between function name and opening braces.
@scresto09 pushed 1 commit.
6f27cdddaad23626b0776f52d5d4b0e3642cef0d incdec: Cosmetic changes in the code
@scresto09 commented on this pull request.
+ /* when the number changes sign, the format is reset to avoid a display shift */ + if ((positive == FALSE && guessed_number >= 0) || (positive == TRUE && guessed_number < 0)) + { + format_length = 0; + } + else + { + format_length = digit_end - digit_start; + if (format_length > 12) + format_length = 0; + } + + g_snprintf(format_buf, sizeof(format_buf)-1, "%%0%d%c", format_length, use_hexa ? ( hexaCase == HEXA_CASE_UPPER ? 'X' : 'x' ) : 'd'); + + if ((buf = g_strdup_printf(format_buf, guessed_number)))
OK I used it
@scresto09 commented on this pull request.
@@ -72,6 +72,7 @@ GP_CHECK_VIMODE
GP_CHECK_WEBHELPER GP_CHECK_WORKBENCH GP_CHECK_XMLSNIPPETS +GP_CHECK_INCDEC
My bad, it should be better now
Thanks. I think it's ok to merge.
@scresto09 if you change the code the next time, I suggest to remove the mixed indentation (spaces and tabs). It's not utterly important but makes the code a bit nicer and easier to read.
@eht16 approved this pull request.
OK, thanks !
github-comments@lists.geany.org