-
Notifications
You must be signed in to change notification settings - Fork 276
New IncDec plugin for Geany #1351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
… 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.
This pull request replace previous #1337 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, thanks!
I added a few minor remarks.
Additionally, could you please update the MAINTAINERS
file in the root directory?
Thanks.
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. |
OK, thanks ! |
Hi, any update on merging this plugin? Thanks |
#define HEXA_NONE -1 /* hexadecimal number not found */ | ||
#define HEXA_MAYBE 0 /* in progress, need scan more characters */ | ||
#define HEXA_REQUIRE_x 1 /* need character x/X */ | ||
#define HEXA_REQUIRE_0 2 /* need character 0 */ | ||
#define HEXA_REQUIRE_xnumber 3 /* need at least one number */ | ||
#define HEXA_ACCEPT_xnumber 4 /* there may be more numbers */ | ||
#define HEXA_FOUND 5 /* ok, hexadecimal number found */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds like good candidates for an enum
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like this:
#define HEXA_NONE -1 /* hexadecimal number not found */ | |
#define HEXA_MAYBE 0 /* in progress, need scan more characters */ | |
#define HEXA_REQUIRE_x 1 /* need character x/X */ | |
#define HEXA_REQUIRE_0 2 /* need character 0 */ | |
#define HEXA_REQUIRE_xnumber 3 /* need at least one number */ | |
#define HEXA_ACCEPT_xnumber 4 /* there may be more numbers */ | |
#define HEXA_FOUND 5 /* ok, hexadecimal number found */ | |
enum { | |
HEXA_NONE = -1, /* hexadecimal number not found */ | |
HEXA_MAYBE, /* in progress, need scan more characters */ | |
HEXA_REQUIRE_x, /* need character x/X */ | |
HEXA_REQUIRE_0, /* need character 0 */ | |
HEXA_REQUIRE_xnumber, /* need at least one number */ | |
HEXA_ACCEPT_xnumber, /* there may be more numbers */ | |
HEXA_FOUND /* ok, hexadecimal number found */ | |
}; |
Just a suggestion though, current code isn't a problem
#define DECIMAL_NONE -1 /* decimal number not found */ | ||
#define DECIMAL_MAYBE 0 /* in progress, need scan more characters */ | ||
#define DECIMAL_REQUIRE_number 1 /* need at least one number */ | ||
#define DECIMAL_FOUND 5 /* ok, decimal number found */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto (although less so)
#define HEXA_CASE_UNKNOWN -1 /* hexadicmal case not yey known */ | ||
#define HEXA_CASE_UPPER 1 /* upper case detected */ | ||
#define HEXA_CASE_LOWER 0 /* lower case detected */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And ditto
|
||
static gboolean on_change_number(gint step) | ||
{ | ||
ScintillaObject *sci = document_get_current()->editor->sci; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
document_get_current()
can return NULL
, you need to guard this against that case. E.g. I believe you'll get a crash if you hit one of the keybindings when no document is open (which is a possibility).
ScintillaObject *sci = document_get_current()->editor->sci; | |
GeanyDocument *doc = document_get_current(); | |
ScintillaObject *sci; | |
if (! doc) | |
{ | |
return FALSE; | |
} | |
sci = doc->editor->sci; |
if (use_hexa) | ||
{ | ||
guessed_number = g_ascii_strtoll(txt, NULL, 16); | ||
} | ||
else | ||
{ | ||
guessed_number = atoi(txt); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any reason not to do this?:
if (use_hexa) | |
{ | |
guessed_number = g_ascii_strtoll(txt, NULL, 16); | |
} | |
else | |
{ | |
guessed_number = atoi(txt); | |
} | |
guessed_number = g_ascii_strtoll(txt, NULL, use_hexa ? 16 : 10); |
|
||
gint hexa_state = 0; | ||
gint decimal_sate = 0; | ||
gint hexaCase = HEXA_CASE_UNKNOWN; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another one that probably should use snake_case hexa_case
#pragma GCC diagnostic push | ||
#pragma GCC diagnostic ignored "-Wformat-nonliteral" | ||
g_snprintf(format_buf, sizeof(format_buf)-1, "%%0%d%c", format_length, use_hexa ? (hexaCase == HEXA_CASE_UPPER ? 'X' : 'x') : 'd'); | ||
#pragma GCC diagnostic pop | ||
|
||
if ((buf = g_strdup_printf(format_buf, guessed_number))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe do this:
#pragma GCC diagnostic push | |
#pragma GCC diagnostic ignored "-Wformat-nonliteral" | |
g_snprintf(format_buf, sizeof(format_buf)-1, "%%0%d%c", format_length, use_hexa ? (hexaCase == HEXA_CASE_UPPER ? 'X' : 'x') : 'd'); | |
#pragma GCC diagnostic pop | |
if ((buf = g_strdup_printf(format_buf, guessed_number))) | |
if (use_hexa) | |
{ | |
buf = g_strdup_printf(hexaCase == HEXA_CASE_UPPER | |
? "%0*" G_GINT64_MODIFIER "X" | |
: "%0*" G_GINT64_MODIFIER "x", | |
format_length, (guint64) guessed_number); | |
} | |
else | |
{ | |
buf = g_strdup_printf("%0*" G_GINT64_FORMAT, format_length, guessed_number); | |
} | |
if (buf) |
|
||
GtkWidget *content_area = gtk_dialog_get_content_area(GTK_DIALOG(plugin_data._dialog)); | ||
|
||
GtkWidget *label = gtk_label_new("Enter the number of positive or negative increments to apply.\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This string isn't marked as translatable. Also, no need for the \n
at the end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GtkWidget *label = gtk_label_new("Enter the number of positive or negative increments to apply.\n"); | |
GtkWidget *label = gtk_label_new(_("Enter the number of positive or negative increments to apply:")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, you should make the entry as the "mnemonic widget" for this label somewhere below, which allows a semantic relation between the two, which in turn allows e.g. a screen reader to properly announce the widgets:
gtk_label_set_mnemonic_widget(GTK_LABEL(label), plugin_data._entry);
|
||
plugin_data._entry = gtk_spin_button_new_with_range(-64000, 64000,1); | ||
gtk_spin_button_set_value(GTK_SPIN_BUTTON(plugin_data._entry), 1); | ||
gtk_widget_set_tooltip_text(plugin_data._entry, _("Enter the number of positive or negative increments to apply then press Enter key.\n")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gtk_widget_set_tooltip_text(plugin_data._entry, _("Enter the number of positive or negative increments to apply then press Enter key.\n")); | |
gtk_widget_set_tooltip_text(plugin_data._entry, _("Enter the number of positive or negative increments to apply then press Enter key.")); |
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.