SF.net SVN: geany: [1669] trunk

eht16 at users.sourceforge.net eht16 at xxxxx
Fri Jul 6 10:16:51 UTC 2007


Revision: 1669
          http://svn.sourceforge.net/geany/?rev=1669&view=rev
Author:   eht16
Date:     2007-07-06 03:16:51 -0700 (Fri, 06 Jul 2007)

Log Message:
-----------
Add keybinding for select current paragraph.

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/doc/geany.docbook
    trunk/src/editor.c
    trunk/src/editor.h
    trunk/src/keybindings.c
    trunk/src/keybindings.h

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2007-07-05 18:19:56 UTC (rev 1668)
+++ trunk/ChangeLog	2007-07-06 10:16:51 UTC (rev 1669)
@@ -1,3 +1,9 @@
+2007-07-06  Enrico Tröger  <enrico.troeger at uvena.de>
+
+ * doc/geany.docbook, src/editor.c, src/editor.h, src/keybindings.c,
+   src/keybindings.h: Add keybinding for select current paragraph.
+
+
 2007-07-05  Enrico Tröger  <enrico.troeger at uvena.de>
 
  * src/search.c: Fix usage of wrong dialog pointer.

Modified: trunk/doc/geany.docbook
===================================================================
--- trunk/doc/geany.docbook	2007-07-05 18:19:56 UTC (rev 1668)
+++ trunk/doc/geany.docbook	2007-07-06 10:16:51 UTC (rev 1669)
@@ -1931,6 +1931,12 @@
 								</entry>
 							</row>
 							<row>
+								<entry>Select current paragraph</entry>
+								<entry>Selects the current paragraph under the cursor which is
+									   defined by two empty lines around it.
+								</entry>
+							</row>
+							<row>
 								<entry>Insert alternative whitespace</entry>
 								<entry>Inserts a tabulator character when spaces should be used for
 									   indentation and inserts space characters of the amount of a

Modified: trunk/src/editor.c
===================================================================
--- trunk/src/editor.c	2007-07-05 18:19:56 UTC (rev 1668)
+++ trunk/src/editor.c	2007-07-06 10:16:51 UTC (rev 1669)
@@ -2351,6 +2351,84 @@
 }
 
 
+/* find the start or end of a paragraph by searching all lines in direction (UP or DOWN)
+ * starting at the given line and return the found line or return -1 if called on an empty line */
+static gint find_paragraph_stop(ScintillaObject *sci, gint line, gint direction)
+{
+	gboolean found_end = FALSE;
+	gint step;
+	gchar *line_buf, *x;
+
+	// first check current line and return -1 if it is empty to skip creating of a selection
+	line_buf = x = sci_get_line(sci, line);
+	while (isspace(*x))
+		x++;
+	if (*x == '\0')
+	{
+		g_free(line_buf);
+		return -1;
+	}
+
+	if (direction == UP)
+		step = -1;
+	else
+		step = 1;
+
+	while (! found_end)
+	{
+		line += step;
+
+		// sci_get_line checks for sanity of the given line, sci_get_line always return a string
+		// containing at least '\0' so no need to check for NULL
+		line_buf = x = sci_get_line(sci, line);
+
+		// check whether after skipping all whitespace we are at end of line and if so, assume
+		// this line as end of paragraph
+		while (isspace(*x))
+			x++;
+		if (*x == '\0')
+		{
+			found_end = TRUE;
+			if (line == -1)
+				// called on the first line but there is no previous line so return line 0
+				line = 0;
+		}
+		g_free(line_buf);
+	}
+	return line;
+}
+
+
+void editor_select_paragraph(ScintillaObject *sci)
+{
+	gint pos_start, pos_end, line_start, line_found;
+
+	g_return_if_fail(sci != NULL);
+
+	line_start = SSM(sci, SCI_LINEFROMPOSITION, SSM(sci, SCI_GETCURRENTPOS, 0, 0), 0);
+
+	line_found = find_paragraph_stop(sci, line_start, UP);
+	if (line_found == -1)
+		return;
+
+	// find_paragraph_stop returns the emtpy line(previous to the real start of the paragraph),
+	// so use the next line for selection start
+	if (line_found > 0)
+		line_found++;
+
+	pos_start = SSM(sci, SCI_POSITIONFROMLINE, line_found, 0);
+
+	line_found = find_paragraph_stop(sci, line_start, DOWN);
+	pos_end = SSM(sci, SCI_POSITIONFROMLINE, line_found, 0);
+
+	// if not on the last line of the document, end the selection on the previous line
+	if (line_found < (SSM(sci, SCI_GETLINECOUNT, 0, 0) -1))
+		pos_end--;
+
+	SSM(sci, SCI_SETSEL, pos_start, pos_end);
+}
+
+
 void editor_finalize()
 {
 	g_hash_table_destroy(editor_prefs.auto_completions);

Modified: trunk/src/editor.h
===================================================================
--- trunk/src/editor.h	2007-07-05 18:19:56 UTC (rev 1668)
+++ trunk/src/editor.h	2007-07-06 10:16:51 UTC (rev 1669)
@@ -136,6 +136,8 @@
 
 void editor_select_word(ScintillaObject *sci);
 
+void editor_select_paragraph(ScintillaObject *sci);
+
 void editor_insert_alternative_whitespace(ScintillaObject *sci);
 
 void editor_finalize();

Modified: trunk/src/keybindings.c
===================================================================
--- trunk/src/keybindings.c	2007-07-05 18:19:56 UTC (rev 1668)
+++ trunk/src/keybindings.c	2007-07-06 10:16:51 UTC (rev 1669)
@@ -289,7 +289,9 @@
 		0, 0, "edit_suppresscompletion", _("Suppress construct completion"));
 
 	keys[GEANY_KEYS_EDIT_SELECTWORD] = fill(cb_func_edit,
-		0, 0, "edit_selectword", _("Select current word"));
+		GDK_w, GDK_SHIFT_MASK | GDK_MOD1_MASK, "edit_selectword", _("Select current word"));
+	keys[GEANY_KEYS_EDIT_SELECTPARAGRAPH] = fill(cb_func_edit,
+		GDK_p, GDK_SHIFT_MASK | GDK_MOD1_MASK, "edit_selectparagraph", _("Select current paragraph"));
 
 	keys[GEANY_KEYS_EDIT_INSERTALTWHITESPACE] = fill(cb_func_edit,
 		0, 0, "edit_insertwhitespace", _("Insert alternative whitespace"));
@@ -1129,6 +1131,9 @@
 		case GEANY_KEYS_EDIT_SELECTWORD:
 			editor_select_word(doc_list[idx].sci);
 			break;
+		case GEANY_KEYS_EDIT_SELECTPARAGRAPH:
+			editor_select_paragraph(doc_list[idx].sci);
+			break;
 		case GEANY_KEYS_EDIT_INSERTALTWHITESPACE:
 			editor_insert_alternative_whitespace(doc_list[idx].sci);
 			break;

Modified: trunk/src/keybindings.h
===================================================================
--- trunk/src/keybindings.h	2007-07-05 18:19:56 UTC (rev 1668)
+++ trunk/src/keybindings.h	2007-07-06 10:16:51 UTC (rev 1669)
@@ -128,6 +128,7 @@
 	GEANY_KEYS_EDIT_GOTONEXTMARKER,
 	GEANY_KEYS_EDIT_GOTOPREVIOUSMARKER,
 	GEANY_KEYS_EDIT_SELECTWORD,
+	GEANY_KEYS_EDIT_SELECTPARAGRAPH,
 	GEANY_KEYS_EDIT_INSERTALTWHITESPACE,
 
 	GEANY_KEYS_EDIT_AUTOCOMPLETE,


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the Commits mailing list