mirror of
https://github.com/MidnightCommander/mc
synced 2025-04-02 13:12:53 +03:00
(edit_buffer_find_word_start): rename from edit_find_word_start
...and move to editbuffer.c. Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
parent
9094cdd1d3
commit
3a8f21166b
@ -31,6 +31,7 @@
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <ctype.h> /* isdigit() */
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
@ -430,6 +431,58 @@ edit_buffer_get_word_from_pos (const edit_buffer_t * buf, off_t start_pos, off_t
|
||||
return match_expr;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Find first character of current word
|
||||
*
|
||||
* @param buf editor buffer
|
||||
* @param word_start position of first character of current word
|
||||
* @param word_len length of current word
|
||||
*
|
||||
* @return TRUE if first character of word is found and this character is not 1) a digit and
|
||||
* 2) a begin of file, FALSE otherwise
|
||||
*/
|
||||
|
||||
gboolean
|
||||
edit_buffer_find_word_start (const edit_buffer_t * buf, off_t * word_start, gsize * word_len)
|
||||
{
|
||||
int c;
|
||||
off_t i;
|
||||
|
||||
/* return if at begin of file */
|
||||
if (buf->curs1 <= 0)
|
||||
return FALSE;
|
||||
|
||||
c = edit_buffer_get_previous_byte (buf);
|
||||
/* return if not at end or in word */
|
||||
if (is_break_char (c))
|
||||
return FALSE;
|
||||
|
||||
/* search start of word */
|
||||
for (i = 1;; i++)
|
||||
{
|
||||
int last;
|
||||
|
||||
last = c;
|
||||
c = edit_buffer_get_byte (buf, buf->curs1 - i - 1);
|
||||
|
||||
if (is_break_char (c))
|
||||
{
|
||||
/* return if word starts with digit */
|
||||
if (isdigit (last))
|
||||
return FALSE;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* success */
|
||||
*word_start = buf->curs1 - i; /* start found */
|
||||
*word_len = (gsize) i;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Basic low level single character buffer alterations and movements at the cursor: insert character
|
||||
|
@ -48,6 +48,8 @@ off_t edit_buffer_get_bol (const edit_buffer_t * buf, off_t current);
|
||||
off_t edit_buffer_get_eol (const edit_buffer_t * buf, off_t current);
|
||||
GString *edit_buffer_get_word_from_pos (const edit_buffer_t * buf, off_t start_pos, off_t * start,
|
||||
gsize * cut);
|
||||
gboolean edit_buffer_find_word_start (const edit_buffer_t * buf, off_t * word_start,
|
||||
gsize * word_len);
|
||||
|
||||
void edit_buffer_insert (edit_buffer_t * buf, int c);
|
||||
void edit_buffer_insert_ahead (edit_buffer_t * buf, int c);
|
||||
|
@ -681,49 +681,6 @@ pipe_mail (const edit_buffer_t * buf, char *to, char *subject, char *cc)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** find first character of current word */
|
||||
|
||||
static gboolean
|
||||
edit_find_word_start (const edit_buffer_t * buf, off_t * word_start, gsize * word_len)
|
||||
{
|
||||
int c;
|
||||
off_t i;
|
||||
|
||||
/* return if at begin of file */
|
||||
if (buf->curs1 <= 0)
|
||||
return FALSE;
|
||||
|
||||
c = edit_buffer_get_previous_byte (buf);
|
||||
/* return if not at end or in word */
|
||||
if (is_break_char (c))
|
||||
return FALSE;
|
||||
|
||||
/* search start of word to be completed */
|
||||
for (i = 1;; i++)
|
||||
{
|
||||
int last;
|
||||
|
||||
last = c;
|
||||
c = edit_buffer_get_byte (buf, buf->curs1 - i - 1);
|
||||
|
||||
if (is_break_char (c))
|
||||
{
|
||||
/* return if word starts with digit */
|
||||
if (isdigit (last))
|
||||
return FALSE;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* success */
|
||||
*word_start = buf->curs1 - i; /* start found */
|
||||
*word_len = (gsize) i;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Get current word under cursor
|
||||
@ -2664,7 +2621,7 @@ edit_complete_word_cmd (WEdit * edit)
|
||||
int max_width;
|
||||
|
||||
/* search start of word to be completed */
|
||||
if (!edit_find_word_start (&edit->buffer, &word_start, &word_len))
|
||||
if (!edit_buffer_find_word_start (&edit->buffer, &word_start, &word_len))
|
||||
return;
|
||||
|
||||
/* prepare match expression */
|
||||
@ -2835,7 +2792,7 @@ edit_get_match_keyword_cmd (WEdit * edit)
|
||||
GPtrArray *def_hash = NULL;
|
||||
|
||||
/* search start of word to be completed */
|
||||
if (!edit_find_word_start (&edit->buffer, &word_start, &word_len))
|
||||
if (!edit_buffer_find_word_start (&edit->buffer, &word_start, &word_len))
|
||||
return;
|
||||
|
||||
/* prepare match expression */
|
||||
|
Loading…
x
Reference in New Issue
Block a user