Bug 571816 – Scintilla no longer highlights typedefs

View: New views
3 Messages — Rating Filter:   Alert me  

Bug 571816 – Scintilla no longer highlights typedefs

by Sandro Dias Pinto Vitenti :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,

I'm trying to solve this bug. I've added the necessary code to get all typedef, local and global.
However when I send them trough:

SendEditorString(SCI_SETKEYWORDS, 3, ...) and
SendEditorString(SCI_SETKEYWORDS, 1, ...)

only the global one works (when the parameter is 1). I have tried other numbers
(which works but not as local keywords) here but
I don't know the scintilla internals enough to understand how to solve this.

Can anyone help? I have attached the patch.

Sandro

[anjuta_scintilla_typdef_hl.diff]

From cbb0479ef05adfaafbed8460f35c76f26583eaf3 Mon Sep 17 00:00:00 2001
From: root <root@laptop.(none)>
Date: Sat, 25 Jul 2009 12:49:03 -0300
Subject: [PATCH 1/2] Added code to highlight typedefs in scintilla text editor

---
 autogen.sh                        |    4 +-
 plugins/scintilla/aneditor-priv.h |    2 +-
 plugins/scintilla/aneditor.cxx    |   15 ++++++++-
 plugins/scintilla/text_editor.c   |   62 +++++++++++++++++++++++++++++++++++-
 plugins/scintilla/text_editor.h   |    5 +++
 5 files changed, 81 insertions(+), 7 deletions(-)

diff --git a/autogen.sh b/autogen.sh
index b9ac147..0a5a7e0 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -5,8 +5,8 @@ CONFIGURE=configure.ac
 
 : ${AUTOCONF=autoconf}
 : ${AUTOHEADER=autoheader}
-: ${AUTOMAKE=automake-1.9}
-: ${ACLOCAL=aclocal-1.9}
+: ${AUTOMAKE=automake}
+: ${ACLOCAL=aclocal}
 : ${INTLTOOLIZE=intltoolize}
 : ${LIBTOOLIZE=libtoolize}
 : ${GTKDOCIZE=gtkdocize}
diff --git a/plugins/scintilla/aneditor-priv.h b/plugins/scintilla/aneditor-priv.h
index 8e24098..cd3ab95 100644
--- a/plugins/scintilla/aneditor-priv.h
+++ b/plugins/scintilla/aneditor-priv.h
@@ -370,7 +370,7 @@ protected:
  SString FindLanguageProperty(const char *pattern,
  const char *defaultValue="");
  void ReadPropertiesInitial();
- void ReadProperties(const char* fileForExt);
+ void ReadProperties(const char* fileForExt, char **typedef_hl);
  long SendEditor(unsigned int msg, unsigned long wParam=0, long lParam=0);
  long SendEditorString(unsigned int msg, unsigned long wParam,
   const char *s);
diff --git a/plugins/scintilla/aneditor.cxx b/plugins/scintilla/aneditor.cxx
index 92a67fe..5f7ae82 100644
--- a/plugins/scintilla/aneditor.cxx
+++ b/plugins/scintilla/aneditor.cxx
@@ -1734,7 +1734,7 @@ long AnEditor::Command(int cmdID, long wParam, long lParam) {
  break;
 
  case ANE_SETHILITE:
- ReadProperties((char*)wParam);
+ ReadProperties((char*)wParam, (char **)lParam);
  SendEditor(SCI_COLOURISE, 0, -1);
  break;
 
@@ -2489,7 +2489,7 @@ SString AnEditor::FindLanguageProperty(const char *pattern, const char *defaultV
  return ret;
 }
 
-void AnEditor::ReadProperties(const char *fileForExt) {
+void AnEditor::ReadProperties(const char *fileForExt, char **typedef_hl) {
  //DWORD dwStart = timeGetTime();
  if (fileForExt)
  strcpy (fileName, fileForExt);
@@ -2520,6 +2520,17 @@ void AnEditor::ReadProperties(const char *fileForExt) {
  SendEditorString(SCI_SETKEYWORDS, 2, kw2.c_str());
  /* For C/C++ projects, get list of typedefs for colorizing */
  /* TODO: Either remove or port to IAnjutaSymbolManager */
+ if (SCLEX_CPP == lexLanguage)
+ {
+ if (typedef_hl != NULL)
+ {
+ if (typedef_hl[0] != NULL)
+ SendEditorString(SCI_SETKEYWORDS, 3, typedef_hl[0]);
+ if (typedef_hl[1] != NULL)
+ SendEditorString(SCI_SETKEYWORDS, 1, typedef_hl[1]);
+ }
+ }
+ else
 #if 0
  if (SCLEX_CPP == lexLanguage)
  {
diff --git a/plugins/scintilla/text_editor.c b/plugins/scintilla/text_editor.c
index 8c00ffa..d51ebd0 100644
--- a/plugins/scintilla/text_editor.c
+++ b/plugins/scintilla/text_editor.c
@@ -60,6 +60,7 @@
 #include <libanjuta/interfaces/ianjuta-indicable.h>
 #include <libanjuta/interfaces/ianjuta-print.h>
 #include <libanjuta/interfaces/ianjuta-document.h>
+#include <libanjuta/interfaces/ianjuta-symbol-manager.h>
 
 #include "properties.h"
 #include "text_editor.h"
@@ -684,9 +685,10 @@ text_editor_hilite_one (TextEditor * te, AnEditorID editor_id,
  }
  else if (te->uri)
  {
- gchar *basename;
+ gchar *basename, *typedef_hl[2];
  basename = g_path_get_basename (te->uri);
- aneditor_command (editor_id, ANE_SETHILITE, (glong) basename, 0);
+ text_editor_get_typedef_hl (te, typedef_hl);
+ aneditor_command (editor_id, ANE_SETHILITE, (glong) basename, (glong) typedef_hl);
  g_free (basename);
  }
  else if (te->filename)
@@ -714,6 +716,62 @@ text_editor_hilite (TextEditor * te, gboolean override_by_pref)
 }
 
 void
+text_editor_get_typedef_hl (TextEditor * te, gchar **typedef_hl)
+{
+        IAnjutaSymbolManager *manager = anjuta_shell_get_interface (te->shell,
+                                                                    IAnjutaSymbolManager, NULL);
+        IAnjutaIterable *iter;
+
+        /* Get global typedefs */
+        iter = ianjuta_symbol_manager_search (manager, IANJUTA_SYMBOL_TYPE_TYPEDEF,
+                                              TRUE, IANJUTA_SYMBOL_FIELD_SIMPLE,  
+                                              NULL, TRUE, TRUE, TRUE, -1, -1, NULL);
+        if (iter)
+        {
+          ianjuta_iterable_first (iter, NULL);
+          if (ianjuta_iterable_get_length (iter, NULL) > 0)
+          {
+            GString *s = g_string_sized_new(ianjuta_iterable_get_length (iter, NULL) * 10);
+            do {
+              IAnjutaSymbol *symbol = IANJUTA_SYMBOL (iter);
+              const gchar *sname = ianjuta_symbol_get_name (symbol, NULL); /* FIXME: MAY BE A LEAK */
+              g_string_append(s, sname);
+              g_string_append_c(s, ' ');
+            } while (ianjuta_iterable_next (iter, NULL));
+            typedef_hl[0] = s->str;
+            g_string_free(s, FALSE); /* MUST FREE BLOCK ANYWHERE */
+          }
+          g_object_unref (iter);
+        }
+        else
+          typedef_hl[0] = NULL;
+        
+        /* Get local typedefs */
+        iter = ianjuta_symbol_manager_search (manager, IANJUTA_SYMBOL_TYPE_TYPEDEF,
+                                              TRUE, IANJUTA_SYMBOL_FIELD_SIMPLE,  
+                                              NULL, TRUE, TRUE, FALSE, -1, -1, NULL);
+        if (iter)
+        {
+          ianjuta_iterable_first (iter, NULL);
+          if (ianjuta_iterable_get_length (iter, NULL) > 0)
+          {
+            GString *s = g_string_sized_new(ianjuta_iterable_get_length (iter, NULL) * 10);
+            do {
+              IAnjutaSymbol *symbol = IANJUTA_SYMBOL (iter);
+              const gchar *sname = ianjuta_symbol_get_name (symbol, NULL); /* FIXME: MAY BE A LEAK */
+              g_string_append(s, sname);
+              g_string_append_c(s, ' ');
+            } while (ianjuta_iterable_next (iter, NULL));
+            typedef_hl[1] = s->str;
+            g_string_free(s, FALSE); /* MUST FREE BLOCK ANYWHERE */
+          }
+          g_object_unref (iter);
+        }
+        else
+          typedef_hl[1] = NULL;
+}
+
+void
 text_editor_set_zoom_factor (TextEditor * te, gint zfac)
 {
  text_editor_command (te, ANE_SETZOOM, zfac,  0);
diff --git a/plugins/scintilla/text_editor.h b/plugins/scintilla/text_editor.h
index 9f199b3..1503e37 100644
--- a/plugins/scintilla/text_editor.h
+++ b/plugins/scintilla/text_editor.h
@@ -150,6 +150,11 @@ void text_editor_set_hilite_type (TextEditor * te, const gchar *file_extension);
 void text_editor_hilite (TextEditor *te, gboolean force);
 
 /*
+ * FIXME: Doc...
+ */
+void text_editor_get_typedef_hl (TextEditor * te, gchar **typedef_hl);
+
+/*
  * Set the zoom factor. Zoom factor basically increases or decreases the
  * text font size by a factor of (2*zfac)
  */
--
1.6.1.3


From 954818d5b72c46b7667da0b163335f373d46417a Mon Sep 17 00:00:00 2001
From: root <root@laptop.(none)>
Date: Sat, 25 Jul 2009 12:53:39 -0300
Subject: [PATCH 2/2] Fixed leak in added code to highlight typedefs in scintilla text editor

---
 plugins/scintilla/text_editor.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/plugins/scintilla/text_editor.c b/plugins/scintilla/text_editor.c
index d51ebd0..2983331 100644
--- a/plugins/scintilla/text_editor.c
+++ b/plugins/scintilla/text_editor.c
@@ -689,6 +689,10 @@ text_editor_hilite_one (TextEditor * te, AnEditorID editor_id,
  basename = g_path_get_basename (te->uri);
  text_editor_get_typedef_hl (te, typedef_hl);
  aneditor_command (editor_id, ANE_SETHILITE, (glong) basename, (glong) typedef_hl);
+ if (typedef_hl[0] != NULL)
+ g_free (typedef_hl[0]);
+ if (typedef_hl[1] != NULL)
+ g_free (typedef_hl[1]);
  g_free (basename);
  }
  else if (te->filename)
--
1.6.1.3



------------------------------------------------------------------------------

_______________________________________________
Anjuta-devel mailing list
Anjuta-devel@...
https://lists.sourceforge.net/lists/listinfo/anjuta-devel

Bug 571816 – Scintilla no longer highlights typedefs

by Sandro Dias Pinto Vitenti :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

(Sorry for sending it again, but the first one was htmled)
Hello,

I'm trying to solve this bug. I've added the necessary code to get all
typedef, local and global.
However when I send them trough:

SendEditorString(SCI_SETKEYWORDS, 3, ...) and
SendEditorString(SCI_SETKEYWORDS, 1, ...)

only the local one works (when the parameter is 1). I have tried other numbers
(which works but not as local keywords) here but
I don't know the scintilla internals enough to understand how to solve this.

Can anyone help? I have attached the patch.

Sandro Vitenti

[anjuta_scintilla_typdef_hl.diff]

From cbb0479ef05adfaafbed8460f35c76f26583eaf3 Mon Sep 17 00:00:00 2001
From: root <root@laptop.(none)>
Date: Sat, 25 Jul 2009 12:49:03 -0300
Subject: [PATCH 1/2] Added code to highlight typedefs in scintilla text editor

---
 autogen.sh                        |    4 +-
 plugins/scintilla/aneditor-priv.h |    2 +-
 plugins/scintilla/aneditor.cxx    |   15 ++++++++-
 plugins/scintilla/text_editor.c   |   62 +++++++++++++++++++++++++++++++++++-
 plugins/scintilla/text_editor.h   |    5 +++
 5 files changed, 81 insertions(+), 7 deletions(-)

diff --git a/autogen.sh b/autogen.sh
index b9ac147..0a5a7e0 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -5,8 +5,8 @@ CONFIGURE=configure.ac
 
 : ${AUTOCONF=autoconf}
 : ${AUTOHEADER=autoheader}
-: ${AUTOMAKE=automake-1.9}
-: ${ACLOCAL=aclocal-1.9}
+: ${AUTOMAKE=automake}
+: ${ACLOCAL=aclocal}
 : ${INTLTOOLIZE=intltoolize}
 : ${LIBTOOLIZE=libtoolize}
 : ${GTKDOCIZE=gtkdocize}
diff --git a/plugins/scintilla/aneditor-priv.h b/plugins/scintilla/aneditor-priv.h
index 8e24098..cd3ab95 100644
--- a/plugins/scintilla/aneditor-priv.h
+++ b/plugins/scintilla/aneditor-priv.h
@@ -370,7 +370,7 @@ protected:
  SString FindLanguageProperty(const char *pattern,
  const char *defaultValue="");
  void ReadPropertiesInitial();
- void ReadProperties(const char* fileForExt);
+ void ReadProperties(const char* fileForExt, char **typedef_hl);
  long SendEditor(unsigned int msg, unsigned long wParam=0, long lParam=0);
  long SendEditorString(unsigned int msg, unsigned long wParam,
   const char *s);
diff --git a/plugins/scintilla/aneditor.cxx b/plugins/scintilla/aneditor.cxx
index 92a67fe..5f7ae82 100644
--- a/plugins/scintilla/aneditor.cxx
+++ b/plugins/scintilla/aneditor.cxx
@@ -1734,7 +1734,7 @@ long AnEditor::Command(int cmdID, long wParam, long lParam) {
  break;
 
  case ANE_SETHILITE:
- ReadProperties((char*)wParam);
+ ReadProperties((char*)wParam, (char **)lParam);
  SendEditor(SCI_COLOURISE, 0, -1);
  break;
 
@@ -2489,7 +2489,7 @@ SString AnEditor::FindLanguageProperty(const char *pattern, const char *defaultV
  return ret;
 }
 
-void AnEditor::ReadProperties(const char *fileForExt) {
+void AnEditor::ReadProperties(const char *fileForExt, char **typedef_hl) {
  //DWORD dwStart = timeGetTime();
  if (fileForExt)
  strcpy (fileName, fileForExt);
@@ -2520,6 +2520,17 @@ void AnEditor::ReadProperties(const char *fileForExt) {
  SendEditorString(SCI_SETKEYWORDS, 2, kw2.c_str());
  /* For C/C++ projects, get list of typedefs for colorizing */
  /* TODO: Either remove or port to IAnjutaSymbolManager */
+ if (SCLEX_CPP == lexLanguage)
+ {
+ if (typedef_hl != NULL)
+ {
+ if (typedef_hl[0] != NULL)
+ SendEditorString(SCI_SETKEYWORDS, 3, typedef_hl[0]);
+ if (typedef_hl[1] != NULL)
+ SendEditorString(SCI_SETKEYWORDS, 1, typedef_hl[1]);
+ }
+ }
+ else
 #if 0
  if (SCLEX_CPP == lexLanguage)
  {
diff --git a/plugins/scintilla/text_editor.c b/plugins/scintilla/text_editor.c
index 8c00ffa..d51ebd0 100644
--- a/plugins/scintilla/text_editor.c
+++ b/plugins/scintilla/text_editor.c
@@ -60,6 +60,7 @@
 #include <libanjuta/interfaces/ianjuta-indicable.h>
 #include <libanjuta/interfaces/ianjuta-print.h>
 #include <libanjuta/interfaces/ianjuta-document.h>
+#include <libanjuta/interfaces/ianjuta-symbol-manager.h>
 
 #include "properties.h"
 #include "text_editor.h"
@@ -684,9 +685,10 @@ text_editor_hilite_one (TextEditor * te, AnEditorID editor_id,
  }
  else if (te->uri)
  {
- gchar *basename;
+ gchar *basename, *typedef_hl[2];
  basename = g_path_get_basename (te->uri);
- aneditor_command (editor_id, ANE_SETHILITE, (glong) basename, 0);
+ text_editor_get_typedef_hl (te, typedef_hl);
+ aneditor_command (editor_id, ANE_SETHILITE, (glong) basename, (glong) typedef_hl);
  g_free (basename);
  }
  else if (te->filename)
@@ -714,6 +716,62 @@ text_editor_hilite (TextEditor * te, gboolean override_by_pref)
 }
 
 void
+text_editor_get_typedef_hl (TextEditor * te, gchar **typedef_hl)
+{
+        IAnjutaSymbolManager *manager = anjuta_shell_get_interface (te->shell,
+                                                                    IAnjutaSymbolManager, NULL);
+        IAnjutaIterable *iter;
+
+        /* Get global typedefs */
+        iter = ianjuta_symbol_manager_search (manager, IANJUTA_SYMBOL_TYPE_TYPEDEF,
+                                              TRUE, IANJUTA_SYMBOL_FIELD_SIMPLE,  
+                                              NULL, TRUE, TRUE, TRUE, -1, -1, NULL);
+        if (iter)
+        {
+          ianjuta_iterable_first (iter, NULL);
+          if (ianjuta_iterable_get_length (iter, NULL) > 0)
+          {
+            GString *s = g_string_sized_new(ianjuta_iterable_get_length (iter, NULL) * 10);
+            do {
+              IAnjutaSymbol *symbol = IANJUTA_SYMBOL (iter);
+              const gchar *sname = ianjuta_symbol_get_name (symbol, NULL); /* FIXME: MAY BE A LEAK */
+              g_string_append(s, sname);
+              g_string_append_c(s, ' ');
+            } while (ianjuta_iterable_next (iter, NULL));
+            typedef_hl[0] = s->str;
+            g_string_free(s, FALSE); /* MUST FREE BLOCK ANYWHERE */
+          }
+          g_object_unref (iter);
+        }
+        else
+          typedef_hl[0] = NULL;
+        
+        /* Get local typedefs */
+        iter = ianjuta_symbol_manager_search (manager, IANJUTA_SYMBOL_TYPE_TYPEDEF,
+                                              TRUE, IANJUTA_SYMBOL_FIELD_SIMPLE,  
+                                              NULL, TRUE, TRUE, FALSE, -1, -1, NULL);
+        if (iter)
+        {
+          ianjuta_iterable_first (iter, NULL);
+          if (ianjuta_iterable_get_length (iter, NULL) > 0)
+          {
+            GString *s = g_string_sized_new(ianjuta_iterable_get_length (iter, NULL) * 10);
+            do {
+              IAnjutaSymbol *symbol = IANJUTA_SYMBOL (iter);
+              const gchar *sname = ianjuta_symbol_get_name (symbol, NULL); /* FIXME: MAY BE A LEAK */
+              g_string_append(s, sname);
+              g_string_append_c(s, ' ');
+            } while (ianjuta_iterable_next (iter, NULL));
+            typedef_hl[1] = s->str;
+            g_string_free(s, FALSE); /* MUST FREE BLOCK ANYWHERE */
+          }
+          g_object_unref (iter);
+        }
+        else
+          typedef_hl[1] = NULL;
+}
+
+void
 text_editor_set_zoom_factor (TextEditor * te, gint zfac)
 {
  text_editor_command (te, ANE_SETZOOM, zfac,  0);
diff --git a/plugins/scintilla/text_editor.h b/plugins/scintilla/text_editor.h
index 9f199b3..1503e37 100644
--- a/plugins/scintilla/text_editor.h
+++ b/plugins/scintilla/text_editor.h
@@ -150,6 +150,11 @@ void text_editor_set_hilite_type (TextEditor * te, const gchar *file_extension);
 void text_editor_hilite (TextEditor *te, gboolean force);
 
 /*
+ * FIXME: Doc...
+ */
+void text_editor_get_typedef_hl (TextEditor * te, gchar **typedef_hl);
+
+/*
  * Set the zoom factor. Zoom factor basically increases or decreases the
  * text font size by a factor of (2*zfac)
  */
--
1.6.1.3


From 954818d5b72c46b7667da0b163335f373d46417a Mon Sep 17 00:00:00 2001
From: root <root@laptop.(none)>
Date: Sat, 25 Jul 2009 12:53:39 -0300
Subject: [PATCH 2/2] Fixed leak in added code to highlight typedefs in scintilla text editor

---
 plugins/scintilla/text_editor.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/plugins/scintilla/text_editor.c b/plugins/scintilla/text_editor.c
index d51ebd0..2983331 100644
--- a/plugins/scintilla/text_editor.c
+++ b/plugins/scintilla/text_editor.c
@@ -689,6 +689,10 @@ text_editor_hilite_one (TextEditor * te, AnEditorID editor_id,
  basename = g_path_get_basename (te->uri);
  text_editor_get_typedef_hl (te, typedef_hl);
  aneditor_command (editor_id, ANE_SETHILITE, (glong) basename, (glong) typedef_hl);
+ if (typedef_hl[0] != NULL)
+ g_free (typedef_hl[0]);
+ if (typedef_hl[1] != NULL)
+ g_free (typedef_hl[1]);
  g_free (basename);
  }
  else if (te->filename)
--
1.6.1.3



------------------------------------------------------------------------------

_______________________________________________
Anjuta-devel mailing list
Anjuta-devel@...
https://lists.sourceforge.net/lists/listinfo/anjuta-devel

Re: Bug 571816 – Scintilla no longer highlights typedefs

by Sébastien Granjoux :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Sandro,

Sandro Vitenti a écrit :

> I'm trying to solve this bug. I've added the necessary code to get all
> typedef, local and global.
> However when I send them trough:
>
> SendEditorString(SCI_SETKEYWORDS, 3, ...) and
> SendEditorString(SCI_SETKEYWORDS, 1, ...)
>
> only the local one works (when the parameter is 1). I have tried other numbers
> (which works but not as local keywords) here but
> I don't know the scintilla internals enough to understand how to solve this.
>
> Can anyone help? I have attached the patch.

Your patch looks fine, I will look at this. Then could you please put it
on bugzilla ? It's the preferred way to send patches for Anjuta.

Regards,

Sébastien

------------------------------------------------------------------------------
_______________________________________________
Anjuta-devel mailing list
Anjuta-devel@...
https://lists.sourceforge.net/lists/listinfo/anjuta-devel