Rename editor_auto_forif() in editor_auto_complete().

Allow using auto completion in PHP files outside of the PHP tags, generally in comments, for news files without filetype and on non-empty lines.


git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@1754 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
Enrico Tröger 2007-07-28 10:27:42 +00:00
parent 2e500fb403
commit 628331a85b
4 changed files with 18 additions and 32 deletions

View File

@ -1,3 +1,12 @@
2007-07-28 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
* src/editor.c, src/editor.h, src/keybindings.c:
Rename editor_auto_forif() in editor_auto_complete().
Allow using auto completion in PHP files outside of the PHP tags,
generally in comments, for news files without filetype and on
non-empty lines.
2007-07-27 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
* plugins/demoplugin.c, plugins/htmlchars.c, plugins/classbuilder.c,

View File

@ -1133,13 +1133,15 @@ static gboolean ac_complete_constructs(gint idx, gint pos, const gchar *word)
gchar *lindent;
gchar *whitespace;
gint step, str_len;
gint ft_id = FILETYPE_ID(doc_list[idx].file_type);
GHashTable *specials;
ScintillaObject *sci = doc_list[idx].sci;
str = g_strdup(word);
g_strstrip(str);
pattern = ac_find_completion_by_name(doc_list[idx].file_type->name, str);
pattern = ac_find_completion_by_name(filetypes[ft_id]->name, str);
geany_debug("-%s- -%s-", word, pattern);
if (pattern == NULL || pattern[0] == '\0')
{
utils_free_pointers(str, pattern, NULL); // free pattern in case it is ""
@ -1201,15 +1203,13 @@ static gboolean at_eol(ScintillaObject *sci, gint pos)
}
gboolean editor_auto_forif(gint idx, gint pos)
gboolean editor_auto_complete(gint idx, gint pos)
{
gboolean result = FALSE;
gchar *word;
gint lexer, style;
gint i;
ScintillaObject *sci;
if (! DOC_IDX_VALID(idx) || doc_list[idx].file_type == NULL)
if (! DOC_IDX_VALID(idx))
return FALSE;
sci = doc_list[idx].sci;
@ -1219,40 +1219,17 @@ gboolean editor_auto_forif(gint idx, gint pos)
lexer = SSM(sci, SCI_GETLEXER, 0, 0);
style = SSM(sci, SCI_GETSTYLEAT, pos - 2, 0);
// return, if we are in a comment
if (is_comment(lexer, style))
return FALSE;
// never auto complete in a PHP file outside of the <? ?> tags
if (lexer == SCLEX_HTML && ! (style >= SCE_HPHP_DEFAULT && style <= SCE_HPHP_OPERATOR))
return FALSE;
// get the current line contents
word = sci_get_line(sci, SSM(sci, SCI_LINEFROMPOSITION, pos, 0));
/* check that the chars before the current word are only whitespace (on this line).
* this prevents completion of '} while ' */
i = strlen(word) - 1;
while (i >= 0 && isspace(word[i])) i--; // skip trailing whitespace
while (i >= 0 && isalpha(word[i])) i--; // find pos before keyword
while (i >= 0 && word[i] != '\n' && word[i] != '\r') // we want to stay in this line('\n' check)
{
if (! isspace(word[i]))
{
g_free(word);
return FALSE;
}
i--;
}
editor_find_current_word(sci, pos, current_word, sizeof current_word, NULL);
// prevent completion of "for "
if (! isspace(sci_get_char_at(sci, pos - 1))) // pos points to the line end char so use pos -1
{
sci_start_undo_action(sci); // needed because we insert a space separately from construct
result = ac_complete_constructs(idx, pos, word);
result = ac_complete_constructs(idx, pos, current_word);
sci_end_undo_action(sci);
}
utils_free_pointers(word, NULL);
return result;
}

View File

@ -104,7 +104,7 @@ gboolean editor_start_auto_complete(gint idx, gint pos, gboolean force);
void editor_close_block(gint idx, gint pos);
gboolean editor_auto_forif(gint idx, gint pos);
gboolean editor_auto_complete(gint idx, gint pos);
void editor_auto_latex(gint idx, gint pos);

View File

@ -632,7 +632,7 @@ static gboolean check_construct_completion(GdkEventKey *event)
gint pos = sci_get_current_position(sci);
if (editor_prefs.auto_complete_constructs)
return editor_auto_forif(idx, pos);
return editor_auto_complete(idx, pos);
}
}
return FALSE;