-
Notifications
You must be signed in to change notification settings - Fork 272
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
Add new "Lineoperations" plugin #324
Conversation
Ca you please rebase your pr against current master and repush it? |
nfposn = 0; | ||
k = 0; | ||
|
||
if(newfile && lines) // verify memory allocation |
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.
g_malloc()
aborts on failure. If you really mean to support allocation failure you need to use g_try_malloc()
instead (no need unless you allocate really large data, as on very low memory situations something in GLib/GTK/Geany will most likely abort anyway).
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.
Thanks, this is now updated. I decided to keep g_malloc and remove the null check since it is unnecessary as "GLib/GTK/Geany will most likely abort anyways.
Signed-off-by: Sylvan Mostert <[email protected]>
bd2293f
to
318f0bd
Compare
Line 1\n #NOT removed (contains non whitespace chars) | ||
Line 2\n | ||
|
||
The **Remove Unique Lines** will change the file into this: |
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.
Here too, reference should probably be "Remove Whitespace Lines"
Added `ensure_final_newline()` to add a newline if it does not exist before operation. If the final line does not have an newline, and it shifts position, the resulting line will be concatenation of two lines. Added null terminating character to new_file string in case of empty file.
d0f4fd2
to
8ff44b7
Compare
|
||
|
||
void | ||
lo_cleanup(void) |
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.
should be static, and signature should be static void lo_cleanup(GeanyPlugin *plugin, gpointer pdata)
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.
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.
Switched `sci_get_line_indentation()` to `SCI_GETLINEINDENTPOSITION`.
Added 'static' keyword for `lo_cleanup`. Added `main_locale_init(LOCALEDIR, GETTEXT_PACKAGE)` for the translation information.
2691a29
to
5cd5c4c
Compare
g_signal_connect(rmdupln_item, "activate", G_CALLBACK(action_rmdupln_item), NULL); | ||
g_signal_connect(rmunqln_item, "activate", G_CALLBACK(action_rmunqln_item), NULL); | ||
g_signal_connect(rmemtyln_item, "activate", G_CALLBACK(action_rmemtyln_item), NULL); | ||
g_signal_connect(rmwhspln_item, "activate", G_CALLBACK(action_rmwhspln_item), NULL); |
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.
you could lower duplication of the wrapper callbacks by having a single callback that calls the appropriate function (either passed as parameter [1] or referenced as an ID or something), as they all have they all behave the same (but the sort ones).
You may or may not want this, it's merely a suggestion. And it's even a bad one if you expect to alter the various functions to receive different parameters in the future.
[1] technically in plain C you're not supposed to convert a function pointer to a data pointer. However, GTK depends on this and it effectively works on all supported platforms (if not all platforms in general).
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.
Done in b4n@f05a05b if you're interested. The patch however depends on the simplified menu building, so you might want to apply it afterward, or just use this as inspiration (or not at all).
|
||
total_num_chars = sci_get_length(doc->editor->sci); | ||
total_num_lines = sci_get_line_count(doc->editor->sci); | ||
lines = g_malloc(sizeof(gchar *) * total_num_lines+1); |
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.
there's a subtle bug here: the +1 is not applied correctly as *
has priority over +
. Wrap in parentheses. (thanks to Valgrind for finding this)
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.
Fix available at b4n@ee35465
An overlooked operator priority lead to underallocating `sizeof(gchar*)-1` bytes, later leading to an invalid memory access.
Removed trailing spaces, and changed all indents to tabs.
plugin->info->name = _("Line Operations"); | ||
plugin->info->description = _("Line Operations provides a handful of functions that can be applied to a document such as, removing duplicate lines, removing empty lines, removing lines with only whitespace, and sorting lines."); | ||
plugin->info->version = "0.1"; | ||
plugin->info->author = _("Sylvan Mostert <[email protected]>"); |
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.
there probably is no need to translate your name :)
LGTM |
LineOperations is a plugin that gives a bunch of simple functions that can be applied to a document.
(remove duplicate lines, empty lines, lines with only whitespace, sort lines...)
It is intended to be a convenient way to use these functions for non-technical users.
I am thinking of adding some more useful functions (e.g. similar to TextFX in Notepad++).
Take a look and let me know what you think, I'm open to suggestions for improvements.