Branch: refs/heads/master Author: Frank Lanitz frank@frank.uvena.de Committer: GitHub noreply@github.com Date: Fri, 12 Jul 2019 07:20:11 UTC Commit: 0cd74f5fcee2adca89b686c342b147e38b3496cc https://github.com/geany/geany-plugins/commit/0cd74f5fcee2adca89b686c342b147...
Log Message: ----------- Merge pull request #860 from LarsGit223/lineops-rm-every-n
lineoperations: remove every n-th line
Modified Paths: -------------- lineoperations/README lineoperations/src/linefunctions.c lineoperations/src/linefunctions.h lineoperations/src/lineoperations.c po/POTFILES.in
Modified: lineoperations/README 25 lines changed, 25 insertions(+), 0 deletions(-) =================================================================== @@ -19,6 +19,7 @@ Features * Keep Unique Lines * Remove Empty Lines * Remove Whitespace Lines +* Remove Every Nth Line * Sort Lines Ascending * Sort Lines Descending
@@ -197,6 +198,30 @@ Removes all lines that have only whitespace characters. Line 1\n Line 2\n
+Remove Every Nth Line +--------------------- + +The user can enter a number N. Every Nth line will be removed then. + + Example: Suppose a file has the following lines and the user enters the + value 2 for N. (#comments added for clarity) + + :: + + Line 1 + Line 2 #removed + Line 3 + Line 4 #removed + Line 5 + + The **Remove Every Nth Line** (N=2) will change the file into this: + + :: + + Line 1 + Line 3 + Line 5 + Sort Lines ----------
Modified: lineoperations/src/linefunctions.c 42 lines changed, 42 insertions(+), 0 deletions(-) =================================================================== @@ -301,3 +301,45 @@ sortlndesc(gchar **lines, gint num_lines, gchar *new_file)
return num_lines; } + + +/* Remove Every Nth Line */ +gint +rmnthln(ScintillaObject *sci, gint line_num, gint end_line_num) +{ + gboolean ok; + gdouble n; + gint count; + gint changed = 0; /* number of lines removed */ + + ok = dialogs_show_input_numeric(_("Remove every Nth line"), + _("Value of N"), &n, 1, 1000, 1); + if (ok == FALSE) + { + return 0; + } + + count = n; + while(line_num <= end_line_num) /* loop through lines */ + { + count--; + + /* check if this is the nth line. */ + if(count == 0) + { + scintilla_send_message(sci, + SCI_DELETERANGE, + sci_get_position_from_line(sci, line_num), + sci_get_line_length(sci, line_num)); + + line_num--; + end_line_num--; + changed++; + count = n; + } + line_num++; + } + + /* return the number of lines deleted */ + return -changed; +}
Modified: lineoperations/src/linefunctions.h 5 lines changed, 5 insertions(+), 0 deletions(-) =================================================================== @@ -69,4 +69,9 @@ sortlnsasc(gchar **lines, gint num_lines, gchar *new_file); gint sortlndesc(gchar **lines, gint num_lines, gchar *new_file);
+ +/* Remove Every Nth Line */ +gint +rmnthln(ScintillaObject *sci, gint line_num, gint end_line_num); + #endif
Modified: lineoperations/src/lineoperations.c 3 lines changed, 3 insertions(+), 0 deletions(-) =================================================================== @@ -264,6 +264,9 @@ lo_init(GeanyPlugin *plugin, gpointer gdata) { N_("Remove _Whitespace Lines"), G_CALLBACK(action_sci_manip_item), (gpointer) rmwhspln }, { NULL }, + { N_("Remove Every _Nth Line"), + G_CALLBACK(action_sci_manip_item), (gpointer) rmnthln }, + { NULL }, { N_("Sort Lines _Ascending"), G_CALLBACK(action_indir_manip_item), (gpointer) sortlnsasc }, { N_("Sort Lines _Descending"),
Modified: po/POTFILES.in 1 lines changed, 1 insertions(+), 0 deletions(-) =================================================================== @@ -220,6 +220,7 @@ keyrecord/src/keyrecord.c
# LineOperations lineoperations/src/lineoperations.c +lineoperations/src/linefunctions.c
# lipsum lipsum/src/lipsum.c
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).
plugins-commits@lists.geany.org