[anjuta] language-support-cpp-java: Add preference option for modeline support



commit cdd75291c34f3acd6416f3e3f9bf496aabf774f2
Author: Johannes Schmid <jhs gnome org>
Date:   Fri Oct 22 15:46:20 2010 +0200

    language-support-cpp-java: Add preference option for modeline support

 .../anjuta-language-cpp-java.ui                    |   62 ++++++----
 plugins/language-support-cpp-java/plugin.c         |  141 ++++++++++----------
 2 files changed, 111 insertions(+), 92 deletions(-)
---
diff --git a/plugins/language-support-cpp-java/anjuta-language-cpp-java.ui b/plugins/language-support-cpp-java/anjuta-language-cpp-java.ui
index 515828b..41daaf6 100644
--- a/plugins/language-support-cpp-java/anjuta-language-cpp-java.ui
+++ b/plugins/language-support-cpp-java/anjuta-language-cpp-java.ui
@@ -1,21 +1,9 @@
-<?xml version="1.0"?>
+<?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <requires lib="gtk+" version="2.16"/>
   <!-- interface-naming-policy toplevel-contextual -->
-  <object class="GtkAdjustment" id="adjustment1">
-    <property name="upper">100</property>
-    <property name="step_increment">1</property>
-    <property name="page_increment">10</property>
-  </object>
-  <object class="GtkAdjustment" id="adjustment2">
+  <object class="GtkAdjustment" id="adjustment4">
     <property name="upper">100</property>
-    <property name="value">4</property>
-    <property name="step_increment">1</property>
-    <property name="page_increment">10</property>
-  </object>
-  <object class="GtkAdjustment" id="adjustment3">
-    <property name="upper">50</property>
-    <property name="value">10</property>
     <property name="step_increment">1</property>
     <property name="page_increment">10</property>
   </object>
@@ -34,12 +22,12 @@
             <child>
               <object class="GtkVBox" id="vbox1111">
                 <property name="visible">True</property>
-                <property name="orientation">vertical</property>
                 <property name="spacing">5</property>
                 <child>
                   <object class="GtkTable" id="table15">
                     <property name="visible">True</property>
                     <property name="border_width">10</property>
+                    <property name="n_rows">2</property>
                     <property name="column_spacing">5</property>
                     <property name="row_spacing">5</property>
                     <child>
@@ -57,6 +45,24 @@
                         <property name="y_options"></property>
                       </packing>
                     </child>
+                    <child>
+                      <object class="GtkCheckButton" id="preferences_toggle:bool:1:1:cpp-indent-modeline">
+                        <property name="label" translatable="yes">Prefer vim/emacs modelines over indentation settings</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">False</property>
+                        <property name="use_action_appearance">False</property>
+                        <property name="use_underline">True</property>
+                        <property name="xalign">0</property>
+                        <property name="draw_indicator">True</property>
+                      </object>
+                      <packing>
+                        <property name="top_attach">1</property>
+                        <property name="bottom_attach">2</property>
+                        <property name="x_options">GTK_FILL</property>
+                        <property name="y_options"></property>
+                      </packing>
+                    </child>
                   </object>
                   <packing>
                     <property name="expand">False</property>
@@ -76,7 +82,6 @@
                         <child>
                           <object class="GtkVBox" id="vbox2">
                             <property name="visible">True</property>
-                            <property name="orientation">vertical</property>
                             <child>
                               <object class="GtkTable" id="table18">
                                 <property name="visible">True</property>
@@ -88,7 +93,7 @@
                                   <object class="GtkSpinButton" id="preferences_spin:int:0:1:cpp-indent-brace-size">
                                     <property name="visible">True</property>
                                     <property name="can_focus">True</property>
-                                    <property name="invisible_char">&#x2022;</property>
+                                    <property name="invisible_char">â?¢</property>
                                     <property name="adjustment">adjustment1</property>
                                     <property name="climb_rate">1</property>
                                     <property name="numeric">True</property>
@@ -106,7 +111,7 @@
                                   <object class="GtkSpinButton" id="preferences_spin:int:4:1:cpp-indent-statement-size">
                                     <property name="visible">True</property>
                                     <property name="can_focus">True</property>
-                                    <property name="invisible_char">&#x2022;</property>
+                                    <property name="invisible_char">â?¢</property>
                                     <property name="adjustment">adjustment2</property>
                                     <property name="climb_rate">1</property>
                                     <property name="numeric">True</property>
@@ -218,11 +223,11 @@
                               <object class="GtkSpinButton" id="preferences_spin:int:4:1:cpp-indent-paranthese-size">
                                 <property name="visible">True</property>
                                 <property name="can_focus">True</property>
-                                <property name="invisible_char">&#x2022;</property>
+                                <property name="invisible_char">â?¢</property>
                                 <property name="adjustment">adjustment4</property>
                                 <property name="climb_rate">1</property>
                                 <property name="numeric">True</property>
-                                <signal name="value_changed" handler="on_spinbutton1_value_changed"/>
+                                <signal name="value-changed" handler="on_spinbutton1_value_changed" swapped="no"/>
                               </object>
                               <packing>
                                 <property name="left_attach">1</property>
@@ -282,7 +287,6 @@
           <object class="GtkVBox" id="vbox1">
             <property name="visible">True</property>
             <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-            <property name="orientation">vertical</property>
             <child>
               <object class="GtkFrame" id="frame45">
                 <property name="visible">True</property>
@@ -293,7 +297,6 @@
                 <child>
                   <object class="GtkVBox" id="vbox1118">
                     <property name="visible">True</property>
-                    <property name="orientation">vertical</property>
                     <property name="spacing">5</property>
                     <child>
                       <object class="GtkCheckButton" id="preferences_toggle:bool:1:1:cpp-completion-enable">
@@ -323,7 +326,6 @@
                             <child>
                               <object class="GtkVBox" id="vbox3">
                                 <property name="visible">True</property>
-                                <property name="orientation">vertical</property>
                                 <child>
                                   <object class="GtkCheckButton" id="preferences_toggle:bool:1:1:cpp-completion-space-after-func">
                                     <property name="label" translatable="yes">Add a space after function call autocompletion</property>
@@ -470,7 +472,19 @@
       </object>
     </child>
   </object>
-  <object class="GtkAdjustment" id="adjustment4">
+  <object class="GtkAdjustment" id="adjustment3">
+    <property name="upper">50</property>
+    <property name="value">10</property>
+    <property name="step_increment">1</property>
+    <property name="page_increment">10</property>
+  </object>
+  <object class="GtkAdjustment" id="adjustment2">
+    <property name="upper">100</property>
+    <property name="value">4</property>
+    <property name="step_increment">1</property>
+    <property name="page_increment">10</property>
+  </object>
+  <object class="GtkAdjustment" id="adjustment1">
     <property name="upper">100</property>
     <property name="step_increment">1</property>
     <property name="page_increment">10</property>
diff --git a/plugins/language-support-cpp-java/plugin.c b/plugins/language-support-cpp-java/plugin.c
index 64ab118..9d2f755 100644
--- a/plugins/language-support-cpp-java/plugin.c
+++ b/plugins/language-support-cpp-java/plugin.c
@@ -55,6 +55,7 @@
 
 #define PREF_SCHEMA "org.gnome.anjuta.cpp"
 #define PREF_INDENT_AUTOMATIC "cpp-indent-automatic"
+#define PREF_INDENT_MODELINE "cpp-indent-modeline"
 #define PREF_INDENT_STATEMENT_SIZE "cpp-indent-statement-size"
 #define PREF_INDENT_BRACE_SIZE "cpp-indent-brace-size"
 #define PREF_INDENT_PARANTHESE_LINEUP "cpp-indent-paranthese-lineup"
@@ -596,84 +597,88 @@ initialize_indentation_params (CppJavaPlugin *plugin)
 	plugin->param_case_indentation = -1;
 	plugin->param_label_indentation = -1;
 	plugin->param_use_spaces = -1;
-	
-	/* Find the first comment text in the buffer */
-	comment_text = g_string_new (NULL);
-	iter = ianjuta_editor_get_start_position (IANJUTA_EDITOR (plugin->current_editor),
-											  NULL);
-	do
+
+	if (g_settings_get_boolean (plugin->settings,
+	                            PREF_INDENT_MODELINE))
 	{
-		gboolean shift_buffer = TRUE;
-		gint i;
-		gchar ch = ianjuta_editor_cell_get_char (IANJUTA_EDITOR_CELL (iter),
-												 0, NULL);
-		
-		for (i = 0; i < MINI_BUFFER_SIZE - 1; i++)
+		/* Find the first comment text in the buffer */
+		comment_text = g_string_new (NULL);
+		iter = ianjuta_editor_get_start_position (IANJUTA_EDITOR (plugin->current_editor),
+		                                          NULL);
+		do
 		{
-			if (mini_buffer[i] == '\0')
+			gboolean shift_buffer = TRUE;
+			gint i;
+			gchar ch = ianjuta_editor_cell_get_char (IANJUTA_EDITOR_CELL (iter),
+			                                         0, NULL);
+
+			for (i = 0; i < MINI_BUFFER_SIZE - 1; i++)
 			{
+				if (mini_buffer[i] == '\0')
+				{
+					mini_buffer[i] = ch;
+					shift_buffer = FALSE;
+					break;
+				}
+			}
+			if (shift_buffer == TRUE)
+			{
+				/* Shift buffer and add */
+				for (i = 0; i < MINI_BUFFER_SIZE - 1; i++)
+					mini_buffer [i] = mini_buffer[i+1];
 				mini_buffer[i] = ch;
-				shift_buffer = FALSE;
-				break;
 			}
-		}
-		if (shift_buffer == TRUE)
-		{
-			/* Shift buffer and add */
-			for (i = 0; i < MINI_BUFFER_SIZE - 1; i++)
-				mini_buffer [i] = mini_buffer[i+1];
-			mini_buffer[i] = ch;
-		}
-		
-		if (!comment_begun && strncmp (mini_buffer, "/*", 2) == 0)
-		{
-			comment_begun = TRUE;
-			/* Reset buffer */
-			mini_buffer[0] = mini_buffer[1] = '\0';
-		}
-		else if (!comment_begun && strncmp (mini_buffer, "//", 2) == 0)
-		{
-			comment_begun = TRUE;
-			line_comment = TRUE;
-		}
-		else if (!comment_begun && mini_buffer[1] != '\0')
-		{
-			/* The buffer doesn't begin with a comment */
-			break;
-		}
-		else if (comment_begun)
-		{
-			if ((line_comment && ch == '\n') ||
-				(!line_comment && strncmp (mini_buffer, "*/", 2) == 0))
+
+			if (!comment_begun && strncmp (mini_buffer, "/*", 2) == 0)
 			{
-				break;
+				comment_begun = TRUE;
+				/* Reset buffer */
+				mini_buffer[0] = mini_buffer[1] = '\0';
 			}
-		}
-		
-		if (comment_begun)
-			g_string_append_c (comment_text, ch);
-		
-	}
-	while (ianjuta_iterable_next (iter, NULL));
-	
-	/* DEBUG_PRINT ("Comment text: %s", comment_text->str);*/
-	if (comment_text->len > 0)
-	{
-		
-		/* First comment found */
-    gboolean vim;
-		gchar *modeline = extract_mode_line (comment_text->str, &vim);
-		if (modeline)
+			else if (!comment_begun && strncmp (mini_buffer, "//", 2) == 0)
+			                                    {
+													comment_begun = TRUE;
+													line_comment = TRUE;
+												}
+			                                    else if (!comment_begun && mini_buffer[1] != '\0')
+			                                    {
+													/* The buffer doesn't begin with a comment */
+													break;
+												}
+			                                    else if (comment_begun)
+			                                    {
+													if ((line_comment && ch == '\n') ||
+													    (!line_comment && strncmp (mini_buffer, "*/", 2) == 0))
+													{
+														break;
+													}
+												}
+
+			                                    if (comment_begun)
+			                                    g_string_append_c (comment_text, ch);
+
+		                                    }
+		while (ianjuta_iterable_next (iter, NULL));
+
+		/* DEBUG_PRINT ("Comment text: %s", comment_text->str);*/
+		if (comment_text->len > 0)
 		{
-      if (!vim)
-			  parse_mode_line_emacs (plugin, modeline);
-      else
-        parse_mode_line_vim (plugin, modeline);
-			g_free (modeline);
+
+			/* First comment found */
+			gboolean vim;
+			gchar *modeline = extract_mode_line (comment_text->str, &vim);
+			if (modeline)
+			{
+				if (!vim)
+					parse_mode_line_emacs (plugin, modeline);
+				else
+					parse_mode_line_vim (plugin, modeline);
+				g_free (modeline);
+			}
 		}
+		g_string_free (comment_text, TRUE);
+		g_object_unref (iter);
 	}
-	g_string_free (comment_text, TRUE);
-	g_object_unref (iter);
 }
 
 static gint



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]