Branch: refs/heads/master Author: Sylvan Mostert smostert.dev@gmail.com Committer: Sylvan Mostert smostert.dev@gmail.com Date: Fri, 09 Sep 2016 05:47:12 UTC Commit: 9b690f10775776fac556d33af705fd1bb580c7bf https://github.com/geany/geany-plugins/commit/9b690f10775776fac556d33af705fd...
Log Message: ----------- lineoperations: removed unnecessary parameters
Most functions did not need GeanyDocument* passed in so it was removed.
For functions that did need GeanyDocument*, it was reduced to either GeanyEditor* or ScintillaObject*.
Modified Paths: -------------- lineoperations/src/linefunctions.c lineoperations/src/linefunctions.h lineoperations/src/lineoperations.c
Modified: lineoperations/src/linefunctions.c 35 lines changed, 22 insertions(+), 13 deletions(-) =================================================================== @@ -1,5 +1,6 @@ /* - * linefunctions.c - Line operations, remove duplicate lines, empty lines, lines with only whitespace, sort lines. + * linefunctions.c - Line operations, remove duplicate lines, empty lines, + * lines with only whitespace, sort lines. * * Copyright 2015 Sylvan Mostert smostert.dev@gmail.com * @@ -23,14 +24,16 @@
/* comparison function to be used in qsort */ -static gint compare_asc(const void * a, const void * b) +static gint +compare_asc(const void * a, const void * b) { return strcmp(*(const gchar **) a, *(const gchar **) b); }
/* comparison function to be used in qsort */ -static gint compare_desc(const void * a, const void * b) +static gint +compare_desc(const void * a, const void * b) { return strcmp(*(const gchar **) b, *(const gchar **) a); } @@ -85,12 +88,12 @@ rmdupln(GeanyDocument *doc, gchar **lines, gint num_lines, gchar *new_file) for(j = (i+1); j < num_lines; j++) { if(!to_remove[j] && strcmp(lines[i], lines[j]) == 0) - to_remove[j] = TRUE; /* line is duplicate, mark to remove */ + to_remove[j] = TRUE; /* line is duplicate, mark to remove */ } } }
- /* copy **lines into 'new_file' if it is not FALSE(not duplicate) */ + /* copy **lines into 'new_file' if it is not FALSE (not duplicate) */ for(i = 0; i < num_lines; i++) if(!to_remove[i]) nf_end = g_stpcpy(nf_end, lines[i]); @@ -145,8 +148,8 @@ rmemtyln(GeanyDocument *doc, gint line_num, gint end_line_num) while(line_num <= end_line_num) /* loop through lines */ { /* check if the first posn of the line is also the end of line posn */ - if(sci_get_position_from_line(doc->editor->sci, i) == - sci_get_line_end_position(doc->editor->sci, i)) + if(sci_get_position_from_line(sci, line_num) == + sci_get_line_end_position (sci, line_num)) { scintilla_send_message(doc->editor->sci, SCI_DELETERANGE, @@ -155,6 +158,7 @@ rmemtyln(GeanyDocument *doc, gint line_num, gint end_line_num) line_num--; end_line_num--; } + line_num++; } }
@@ -169,13 +173,13 @@ rmwhspln(GeanyDocument *doc, gint line_num, gint end_line_num) { indent = scintilla_send_message(doc->editor->sci, SCI_GETLINEINDENTPOSITION, - i, 0); + line_num, 0);
/* check if the posn of indentation is also the end of line posn */ if(indent - - sci_get_position_from_line(doc->editor->sci, i) == - sci_get_line_end_position(doc->editor->sci, i)- - sci_get_position_from_line(doc->editor->sci, i)) + sci_get_position_from_line(doc->editor->sci, line_num) == + sci_get_line_end_position (doc->editor->sci, line_num)- + sci_get_position_from_line(doc->editor->sci, line_num)) { scintilla_send_message(doc->editor->sci, SCI_DELETERANGE, @@ -184,13 +188,16 @@ rmwhspln(GeanyDocument *doc, gint line_num, gint end_line_num) line_num--; end_line_num--; } + line_num++;
} }
/* Sort Lines Ascending */ -void sortlinesasc(GeanyDocument *doc, gchar **lines, gint num_lines, gchar *new_file) { +void +sortlnsasc(GeanyDocument *doc, gchar **lines, gint num_lines, gchar *new_file) +{ gchar *nf_end = new_file; /* points to last char of new_file */ gint i;
@@ -203,7 +210,9 @@ void sortlinesasc(GeanyDocument *doc, gchar **lines, gint num_lines, gchar *new_
/* Sort Lines Descending */ -void sortlinesdesc(GeanyDocument *doc, gchar **lines, gint num_lines, gchar *new_file) { +void +sortlndesc(GeanyDocument *doc, gchar **lines, gint num_lines, gchar *new_file) +{ gchar *nf_end = new_file; /* points to last char of new_file */ gint i;
Modified: lineoperations/src/linefunctions.h 14 lines changed, 7 insertions(+), 7 deletions(-) =================================================================== @@ -32,36 +32,36 @@
/* Remove Duplicate Lines, sorted */ void -rmdupst(GeanyDocument *doc, gchar **lines, gint num_lines, gchar *new_file); +rmdupst(gchar **lines, gint num_lines, gchar *new_file);
/* Remove Duplicate Lines, ordered */ void -rmdupln(GeanyDocument *doc, gchar **lines, gint num_lines, gchar *new_file); +rmdupln(gchar **lines, gint num_lines, gchar *new_file);
/* Remove Unique Lines */ void -rmunqln(GeanyDocument *doc, gchar **lines, gint num_lines, gchar *new_file); +rmunqln(gchar **lines, gint num_lines, gchar *new_file);
/* Remove Empty Lines */ void -rmemtyln(GeanyDocument *doc, gint line_num, gint end_line_num); +rmemtyln(ScintillaObject *sci, gint line_num, gint end_line_num);
/* Remove Whitespace Lines */ void -rmwhspln(GeanyDocument *doc, gint line_num, gint end_line_num); +rmwhspln(ScintillaObject *sci, gint line_num, gint end_line_num);
/* Sort Lines Ascending */ void -sortlnsasc(GeanyDocument *doc, gchar **lines, gint num_lines, gchar *new_file); +sortlnsasc(gchar **lines, gint num_lines, gchar *new_file);
/* Sort Lines Descending */ void -sortlndesc(GeanyDocument *doc, gchar **lines, gint num_lines, gchar *new_file); +sortlndesc(gchar **lines, gint num_lines, gchar *new_file);
#endif
Modified: lineoperations/src/lineoperations.c 48 lines changed, 23 insertions(+), 25 deletions(-) =================================================================== @@ -39,42 +39,42 @@ struct lo_lines { };
-/* select lines in document based on lo_lines struct parameter */ +/* selects lines in document (based of lo_lines struct parameter) */ static void -select_lines(GeanyDocument *doc, struct lo_lines sel) +select_lines(GeanyEditor *editor, struct lo_lines sel) { /* set the selection to beginning of first line */ - sci_set_selection_start(doc->editor->sci, - sci_get_position_from_line(doc->editor->sci, sel.start_posn_line)); + sci_set_selection_start(editor->sci, + sci_get_position_from_line(editor->sci, sel.start_posn_line));
/* set the selection to end of last line */ - sci_set_selection_end(doc->editor->sci, - sci_get_line_end_position(doc->editor->sci, sel.end_posn_line) + - editor_get_eol_char_len(doc->editor)); + sci_set_selection_end(editor->sci, + sci_get_line_end_position(editor->sci, sel.end_posn_line) + + editor_get_eol_char_len(editor)); }
/* get lo_lines struct based off of document */ static struct lo_lines -get_current_sel_lines(GeanyDocument *doc) +get_current_sel_lines(ScintillaObject *sci) { struct lo_lines sel = { 0, 0 }; gint start_posn = 0; /* position of selection start */ gint end_posn = 0; /* position of selection end */
/* check for selection */ - if(sci_has_selection(doc->editor->sci)) + if(sci_has_selection(sci)) { /* get the start and end positions */ - start_posn = sci_get_selection_start(doc->editor->sci); - end_posn = sci_get_selection_end (doc->editor->sci); + start_posn = sci_get_selection_start(sci); + end_posn = sci_get_selection_end (sci);
/* get the line number of those positions */ - sel.start_posn_line = scintilla_send_message(doc->editor->sci, + sel.start_posn_line = scintilla_send_message(sci, SCI_LINEFROMPOSITION, start_posn, 0);
- sel.end_posn_line = scintilla_send_message(doc->editor->sci, + sel.end_posn_line = scintilla_send_message(sci, SCI_LINEFROMPOSITION, end_posn, 0);
@@ -85,7 +85,7 @@ get_current_sel_lines(GeanyDocument *doc) /* if there is no selection, start at first line */ sel.start_posn_line = 0; /* and end at last one */ - sel.end_posn_line = (sci_get_line_count(doc->editor->sci) - 1); + sel.end_posn_line = (sci_get_line_count(sci) - 1);
sel.is_selection = FALSE; } @@ -118,13 +118,10 @@ static void action_indir_manip_item(GtkMenuItem *menuitem, gpointer gdata) { /* function pointer to gdata -- function to be used */ - void (*func)(GeanyDocument * doc, - gchar **lines, - gint num_lines, - gchar *new_file) = gdata; + void (*func)(gchar **lines, gint num_lines, gchar *new_file) = gdata;
GeanyDocument *doc = document_get_current(); - struct lo_lines sel = get_current_sel_lines(doc); + struct lo_lines sel = get_current_sel_lines(doc->editor->sci); gint num_chars = 0; gint num_lines = (sel.end_posn_line - sel.start_posn_line) + 1; gchar **lines = g_malloc(sizeof(gchar *) * num_lines); @@ -143,7 +140,7 @@ action_indir_manip_item(GtkMenuItem *menuitem, gpointer gdata) new_file[0] = '\0';
/* select lines to indicate to user what lines were altered */ - select_lines(doc, sel); + select_lines(doc->editor, sel);
sci_start_undo_action(doc->editor->sci);
@@ -154,7 +151,7 @@ action_indir_manip_item(GtkMenuItem *menuitem, gpointer gdata) ensure_final_newline(doc->editor, num_lines); }
- if(doc) func(doc, lines, num_lines, new_file); + if(doc) func(lines, num_lines, new_file);
/* set new document */ if(sci_has_selection(doc->editor->sci)) @@ -181,16 +178,17 @@ static void action_sci_manip_item(GtkMenuItem *menuitem, gpointer gdata) { /* function pointer to gdata -- function to be used */ - void (*func)(GeanyDocument *, gint, gint) = gdata; + void (*func)(ScintillaObject *, gint, gint) = gdata; GeanyDocument *doc = document_get_current(); - struct lo_lines sel = get_current_sel_lines(doc); + struct lo_lines sel = get_current_sel_lines(doc->editor->sci);
/* select lines to indicate to user what lines were altered */ - select_lines(doc, sel); + if(sel.is_selection) + select_lines(doc->editor, sel);
sci_start_undo_action(doc->editor->sci);
- if(doc) func(doc, sel.start_posn_line, sel.end_posn_line); + if(doc) func(doc->editor->sci, sel.start_posn_line, sel.end_posn_line);
sci_end_undo_action(doc->editor->sci); }
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).