[geany/geany-plugins] 2833d9: lineoperations: remove every n-th line

LarsGit223 git-noreply at xxxxx
Fri Jul 12 07:20:48 UTC 2019


Branch:      refs/heads/master
Author:      LarsGit223 <lars_paulsen at web.de>
Committer:   LarsGit223 <lars_paulsen at web.de>
Date:        Tue, 14 May 2019 16:41:47 UTC
Commit:      2833d96aa868fe6f370fdeeac1871c4734d270f4
             https://github.com/geany/geany-plugins/commit/2833d96aa868fe6f370fdeeac1871c4734d270f4

Log Message:
-----------
lineoperations: remove every n-th line

Imlements a new feature which allows to remove every n-th line.
The user can enter the value of 'n' in a dialog. Implements #772.


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(-)
===================================================================
@@ -265,6 +265,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).


More information about the Plugins-Commits mailing list