Skip to content

Conversation

scresto09
Copy link
Contributor

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.

… 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.
@scresto09
Copy link
Contributor Author

This pull request replace previous #1337

Copy link
Member

@eht16 eht16 left a 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.

@scresto09 scresto09 requested a review from eht16 January 24, 2025 14:30
@eht16
Copy link
Member

eht16 commented Feb 1, 2025

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.

@scresto09
Copy link
Contributor Author

OK, thanks !

@scresto31
Copy link

Hi, any update on merging this plugin? Thanks

@b4n b4n added this to the 2.2.0 milestone Jul 7, 2025
Comment on lines +70 to +76
#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 */
Copy link
Member

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like this:

Suggested change
#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

Comment on lines +78 to +81
#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 */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto (although less so)

Comment on lines +83 to +85
#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 */
Copy link
Member

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;
Copy link
Member

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).

Suggested change
ScintillaObject *sci = document_get_current()->editor->sci;
GeanyDocument *doc = document_get_current();
ScintillaObject *sci;
if (! doc)
{
return FALSE;
}
sci = doc->editor->sci;

Comment on lines +347 to +354
if (use_hexa)
{
guessed_number = g_ascii_strtoll(txt, NULL, 16);
}
else
{
guessed_number = atoi(txt);
}
Copy link
Member

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?:

Suggested change
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;
Copy link
Member

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

Comment on lines +372 to +377
#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)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe do this:

Suggested change
#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");
Copy link
Member

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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:"));

Copy link
Member

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"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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."));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants