Hey,

attached is a simple patch which enables using the 'wordchars' setting
from the various filetype definition files also for auto-completion,
i.e. to decide whether the entered character should start/continue
auto-completion or not.

Previously, we always used the hard-coded default set of wordchars
(except for LaTeX where we added a backslash in the code).

The patch retains the special LaTeX hack and also the default behaviour
of using Geany's default set of wordchars if not specific in the
filetype definition file of the current filetype.

Using special wordchars for auto-completion might be better for some
languages. I was playing around with some Django template tags and there
I noticed we ignore the wordchars in the filetype definition file for
auto-completion.
This patch might change the auto-completion behaviour if there are
wordchars in a filetype definition file is set for a certain filetype.
I would definitely add a note to the docs that the wordchars setting is
also applied for auto-completion (just forgot it in the attached patch).


Any objections?

Regards,
Enrico

-- 
Get my GPG key from http://www.uvena.de/pub.asc
diff --git a/data/filetypes.latex b/data/filetypes.latex
index 1a465dc..b87e87d 100644
--- a/data/filetypes.latex
+++ b/data/filetypes.latex
@@ -26,7 +26,7 @@ primary=above abovedisplayshortskip abovedisplayskip abovewithdelims accent adjd
 extension=tex

 # the following characters are these which a "word" can contains, see documentation
-#wordchars=_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
+#wordchars=\_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789

 # single comments, like # in this file
 comment_single=%
diff --git a/src/editor.c b/src/editor.c
index ac22e18..495f233 100644
--- a/src/editor.c
+++ b/src/editor.c
@@ -2195,10 +2195,11 @@ gboolean editor_start_auto_complete(GeanyEditor *editor, gint pos, gboolean forc
 	autocomplete_scope(editor);
 	ret = autocomplete_check_html(editor, style, pos);

-	if (ft->id == GEANY_FILETYPES_LATEX)
+	wordchars = highlighting_get_wordchars(ft->id);
+	if (ft->id == GEANY_FILETYPES_LATEX && strchr(wordchars, '\\') == NULL)
+		/* backwards compability: we used to auto-append the backslash for LaTeX however
+		 * this should now be done in data/filetypes.latex */
 		wordchars = GEANY_WORDCHARS"\\"; /* add \ to word chars if we are in a LaTeX file */
-	else
-		wordchars = GEANY_WORDCHARS;

 	read_current_word(editor, pos, cword, sizeof(cword), wordchars, TRUE);
 	root = cword;
diff --git a/src/highlighting.c b/src/highlighting.c
index 29aa081..49d962f 100644
--- a/src/highlighting.c
+++ b/src/highlighting.c
@@ -1184,6 +1184,17 @@ const GeanyLexerStyle *highlighting_get_style(gint ft_id, gint style_id)
 }


+const gchar *highlighting_get_wordchars(gint ft_id)
+{
+	g_return_val_if_fail(ft_id >= 0 && (guint) ft_id < filetypes_array->len, NULL);
+
+	/* ensure filetype loaded */
+	filetypes_load_config((guint) ft_id, FALSE);
+
+	return style_sets[ft_id].wordchars != NULL ? style_sets[ft_id].wordchars : GEANY_WORDCHARS;
+}
+
+
 static GtkWidget *scheme_tree = NULL;

 enum
diff --git a/src/highlighting.h b/src/highlighting.h
index b652f08..7daa7f5 100644
--- a/src/highlighting.h
+++ b/src/highlighting.h
@@ -47,6 +47,8 @@ void highlighting_set_styles(ScintillaObject *sci, GeanyFiletype *ft);

 const GeanyLexerStyle *highlighting_get_style(gint ft_id, gint style_id);

+const gchar *highlighting_get_wordchars(gint ft_id);
+
 void highlighting_free_styles(void);

 gboolean highlighting_is_string_style(gint lexer, gint style);

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
Geany-devel mailing list
Geany-devel@uvena.de
https://lists.uvena.de/cgi-bin/mailman/listinfo/geany-devel

Reply via email to