mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-23 04:46:55 +03:00
(edit_complete_word_cmd): don't get bytes directly from editor buffer.
(edit_get_match_keyword_cmd): likewise. Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
parent
fa9c933ce0
commit
4b9e5f50b1
@ -3292,8 +3292,7 @@ edit_complete_word_cmd (WEdit * edit)
|
|||||||
{
|
{
|
||||||
gsize i, max_len, word_len = 0, num_compl = 0;
|
gsize i, max_len, word_len = 0, num_compl = 0;
|
||||||
off_t word_start = 0;
|
off_t word_start = 0;
|
||||||
unsigned char *bufpos;
|
GString *match_expr;
|
||||||
char *match_expr;
|
|
||||||
GString *compl[MAX_WORD_COMPLETIONS]; /* completions */
|
GString *compl[MAX_WORD_COMPLETIONS]; /* completions */
|
||||||
|
|
||||||
/* search start of word to be completed */
|
/* search start of word to be completed */
|
||||||
@ -3301,18 +3300,16 @@ edit_complete_word_cmd (WEdit * edit)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
/* prepare match expression */
|
/* prepare match expression */
|
||||||
bufpos = &edit->buffers1[word_start >> S_EDIT_BUF_SIZE][word_start & M_EDIT_BUF_SIZE];
|
|
||||||
|
|
||||||
/* match_expr = g_strdup_printf ("\\b%.*s[a-zA-Z_0-9]+", word_len, bufpos); */
|
/* match_expr = g_strdup_printf ("\\b%.*s[a-zA-Z_0-9]+", word_len, bufpos); */
|
||||||
match_expr =
|
match_expr = g_string_new ("(^|\\s+|\\b)");
|
||||||
g_strdup_printf
|
for (i = 0; i < word_len; i++)
|
||||||
("(^|\\s+|\\b)%.*s[^\\s\\.=\\+\\[\\]\\(\\)\\,\\;\\:\\\"\\'\\-\\?\\/\\|\\\\\\{\\}\\*\\&\\^\\%%\\$#@\\!]+",
|
g_string_append_c (match_expr, edit_get_byte (edit, word_start + i));
|
||||||
(int) word_len, bufpos);
|
g_string_append (match_expr, "[^\\s\\.=\\+\\[\\]\\(\\)\\,\\;\\:\\\"\\'\\-\\?\\/\\|\\\\\\{\\}\\*\\&\\^\\%%\\$#@\\!]+");
|
||||||
|
|
||||||
/* collect the possible completions */
|
/* collect the possible completions */
|
||||||
/* start search from begin to end of file */
|
/* start search from begin to end of file */
|
||||||
max_len =
|
max_len =
|
||||||
edit_collect_completions (edit, word_start, word_len, match_expr, (GString **) & compl,
|
edit_collect_completions (edit, word_start, word_len, match_expr->str, (GString **) & compl,
|
||||||
&num_compl);
|
&num_compl);
|
||||||
|
|
||||||
if (num_compl > 0)
|
if (num_compl > 0)
|
||||||
@ -3342,7 +3339,7 @@ edit_complete_word_cmd (WEdit * edit)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free (match_expr);
|
g_string_free (match_expr, TRUE);
|
||||||
/* release memory before return */
|
/* release memory before return */
|
||||||
for (i = 0; i < num_compl; i++)
|
for (i = 0; i < num_compl; i++)
|
||||||
g_string_free (compl[i], TRUE);
|
g_string_free (compl[i], TRUE);
|
||||||
@ -3463,10 +3460,9 @@ edit_get_match_keyword_cmd (WEdit * edit)
|
|||||||
{
|
{
|
||||||
gsize word_len = 0, max_len = 0;
|
gsize word_len = 0, max_len = 0;
|
||||||
int num_def = 0;
|
int num_def = 0;
|
||||||
int i;
|
gsize i;
|
||||||
off_t word_start = 0;
|
off_t word_start = 0;
|
||||||
unsigned char *bufpos;
|
GString *match_expr;
|
||||||
char *match_expr;
|
|
||||||
char *path = NULL;
|
char *path = NULL;
|
||||||
char *ptr = NULL;
|
char *ptr = NULL;
|
||||||
char *tagfile = NULL;
|
char *tagfile = NULL;
|
||||||
@ -3483,8 +3479,9 @@ edit_get_match_keyword_cmd (WEdit * edit)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
/* prepare match expression */
|
/* prepare match expression */
|
||||||
bufpos = &edit->buffers1[word_start >> S_EDIT_BUF_SIZE][word_start & M_EDIT_BUF_SIZE];
|
match_expr = g_string_sized_new (word_len);
|
||||||
match_expr = g_strdup_printf ("%.*s", (int) word_len, bufpos);
|
for (i = 0; i < word_len; i++)
|
||||||
|
g_string_append_c (match_expr, edit_get_byte (edit, word_start + i));
|
||||||
|
|
||||||
ptr = g_get_current_dir ();
|
ptr = g_get_current_dir ();
|
||||||
path = g_strconcat (ptr, G_DIR_SEPARATOR_S, (char *) NULL);
|
path = g_strconcat (ptr, G_DIR_SEPARATOR_S, (char *) NULL);
|
||||||
@ -3506,7 +3503,7 @@ edit_get_match_keyword_cmd (WEdit * edit)
|
|||||||
if (tagfile)
|
if (tagfile)
|
||||||
{
|
{
|
||||||
num_def =
|
num_def =
|
||||||
etags_set_definition_hash (tagfile, path, match_expr, (etags_hash_t *) & def_hash);
|
etags_set_definition_hash (tagfile, path, match_expr->str, (etags_hash_t *) & def_hash);
|
||||||
g_free (tagfile);
|
g_free (tagfile);
|
||||||
}
|
}
|
||||||
g_free (path);
|
g_free (path);
|
||||||
@ -3515,10 +3512,10 @@ edit_get_match_keyword_cmd (WEdit * edit)
|
|||||||
word_len = 0;
|
word_len = 0;
|
||||||
if (num_def > 0)
|
if (num_def > 0)
|
||||||
{
|
{
|
||||||
editcmd_dialog_select_definition_show (edit, match_expr, max_len, word_len,
|
editcmd_dialog_select_definition_show (edit, match_expr->str, max_len, word_len,
|
||||||
(etags_hash_t *) & def_hash, num_def);
|
(etags_hash_t *) & def_hash, num_def);
|
||||||
}
|
}
|
||||||
g_free (match_expr);
|
g_string_free (match_expr, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
Loading…
Reference in New Issue
Block a user