mirror of
https://github.com/tmux/tmux.git
synced 2025-01-07 16:28:48 +00:00
Use the existing code in format.c to add foramts for word and line at
cursor position in copy mode, from Anindya Mukherjee.
This commit is contained in:
parent
56e5067c46
commit
f7fb5df543
75
format.c
75
format.c
@ -703,30 +703,19 @@ format_cb_cursor_character(struct format_tree *ft, struct format_entry *fe)
|
|||||||
xasprintf(&fe->value, "%.*s", (int)gc.data.size, gc.data.data);
|
xasprintf(&fe->value, "%.*s", (int)gc.data.size, gc.data.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Callback for mouse_word. */
|
/* Return word at given coordinates. Caller frees. */
|
||||||
static void
|
char *
|
||||||
format_cb_mouse_word(struct format_tree *ft, struct format_entry *fe)
|
format_grid_word(struct grid *gd, u_int x, u_int y)
|
||||||
{
|
{
|
||||||
struct window_pane *wp;
|
|
||||||
u_int x, y, end;
|
|
||||||
struct grid *gd;
|
|
||||||
struct grid_line *gl;
|
struct grid_line *gl;
|
||||||
struct grid_cell gc;
|
struct grid_cell gc;
|
||||||
const char *ws;
|
const char *ws;
|
||||||
struct utf8_data *ud = NULL;
|
struct utf8_data *ud = NULL;
|
||||||
|
u_int end;
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
int found = 0;
|
int found = 0;
|
||||||
|
char *s = NULL;
|
||||||
|
|
||||||
if (!ft->m.valid)
|
|
||||||
return;
|
|
||||||
wp = cmd_mouse_pane(&ft->m, NULL, NULL);
|
|
||||||
if (wp == NULL)
|
|
||||||
return;
|
|
||||||
if (!TAILQ_EMPTY (&wp->modes))
|
|
||||||
return;
|
|
||||||
if (cmd_mouse_at(wp, &ft->m, &x, &y, 0) != 0)
|
|
||||||
return;
|
|
||||||
gd = wp->base.grid;
|
|
||||||
ws = options_get_string(global_s_options, "word-separators");
|
ws = options_get_string(global_s_options, "word-separators");
|
||||||
|
|
||||||
y = gd->hsize + y;
|
y = gd->hsize + y;
|
||||||
@ -779,21 +768,19 @@ format_cb_mouse_word(struct format_tree *ft, struct format_entry *fe)
|
|||||||
}
|
}
|
||||||
if (size != 0) {
|
if (size != 0) {
|
||||||
ud[size].size = 0;
|
ud[size].size = 0;
|
||||||
fe->value = utf8_tocstr(ud);
|
s = utf8_tocstr(ud);
|
||||||
free(ud);
|
free(ud);
|
||||||
}
|
}
|
||||||
|
return (s);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Callback for mouse_line. */
|
/* Callback for mouse_word. */
|
||||||
static void
|
static void
|
||||||
format_cb_mouse_line(struct format_tree *ft, struct format_entry *fe)
|
format_cb_mouse_word(struct format_tree *ft, struct format_entry *fe)
|
||||||
{
|
{
|
||||||
struct window_pane *wp;
|
struct window_pane *wp;
|
||||||
u_int x, y;
|
u_int x, y;
|
||||||
struct grid *gd;
|
char *s;
|
||||||
struct grid_cell gc;
|
|
||||||
struct utf8_data *ud = NULL;
|
|
||||||
size_t size = 0;
|
|
||||||
|
|
||||||
if (!ft->m.valid)
|
if (!ft->m.valid)
|
||||||
return;
|
return;
|
||||||
@ -804,7 +791,21 @@ format_cb_mouse_line(struct format_tree *ft, struct format_entry *fe)
|
|||||||
return;
|
return;
|
||||||
if (cmd_mouse_at(wp, &ft->m, &x, &y, 0) != 0)
|
if (cmd_mouse_at(wp, &ft->m, &x, &y, 0) != 0)
|
||||||
return;
|
return;
|
||||||
gd = wp->base.grid;
|
|
||||||
|
s = format_grid_word(wp->base.grid, x, y);
|
||||||
|
if (s != NULL)
|
||||||
|
fe->value = s;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Return line at given coordinates. Caller frees. */
|
||||||
|
char *
|
||||||
|
format_grid_line(struct grid *gd, u_int y)
|
||||||
|
{
|
||||||
|
struct grid_cell gc;
|
||||||
|
struct utf8_data *ud = NULL;
|
||||||
|
u_int x;
|
||||||
|
size_t size = 0;
|
||||||
|
char *s = NULL;
|
||||||
|
|
||||||
y = gd->hsize + y;
|
y = gd->hsize + y;
|
||||||
for (x = 0; x < grid_line_length(gd, y); x++) {
|
for (x = 0; x < grid_line_length(gd, y); x++) {
|
||||||
@ -817,9 +818,33 @@ format_cb_mouse_line(struct format_tree *ft, struct format_entry *fe)
|
|||||||
}
|
}
|
||||||
if (size != 0) {
|
if (size != 0) {
|
||||||
ud[size].size = 0;
|
ud[size].size = 0;
|
||||||
fe->value = utf8_tocstr(ud);
|
s = utf8_tocstr(ud);
|
||||||
free(ud);
|
free(ud);
|
||||||
}
|
}
|
||||||
|
return (s);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Callback for mouse_line. */
|
||||||
|
static void
|
||||||
|
format_cb_mouse_line(struct format_tree *ft, struct format_entry *fe)
|
||||||
|
{
|
||||||
|
struct window_pane *wp;
|
||||||
|
u_int x, y;
|
||||||
|
char *s;
|
||||||
|
|
||||||
|
if (!ft->m.valid)
|
||||||
|
return;
|
||||||
|
wp = cmd_mouse_pane(&ft->m, NULL, NULL);
|
||||||
|
if (wp == NULL)
|
||||||
|
return;
|
||||||
|
if (!TAILQ_EMPTY (&wp->modes))
|
||||||
|
return;
|
||||||
|
if (cmd_mouse_at(wp, &ft->m, &x, &y, 0) != 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
s = format_grid_line(wp->base.grid, y);
|
||||||
|
if (s != NULL)
|
||||||
|
fe->value = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Merge a format tree. */
|
/* Merge a format tree. */
|
||||||
|
2
tmux.1
2
tmux.1
@ -4214,6 +4214,8 @@ The following variables are available, where appropriate:
|
|||||||
.It Li "command_list_alias" Ta "" Ta "Command alias if listing commands"
|
.It Li "command_list_alias" Ta "" Ta "Command alias if listing commands"
|
||||||
.It Li "command_list_name" Ta "" Ta "Command name if listing commands"
|
.It Li "command_list_name" Ta "" Ta "Command name if listing commands"
|
||||||
.It Li "command_list_usage" Ta "" Ta "Command usage if listing commands"
|
.It Li "command_list_usage" Ta "" Ta "Command usage if listing commands"
|
||||||
|
.It Li "copy_cursor_line" Ta "" Ta "Line the cursor is on in copy mode"
|
||||||
|
.It Li "copy_cursor_word" Ta "" Ta "Word under cursor in copy mode"
|
||||||
.It Li "copy_cursor_x" Ta "" Ta "Cursor X position in copy mode"
|
.It Li "copy_cursor_x" Ta "" Ta "Cursor X position in copy mode"
|
||||||
.It Li "copy_cursor_y" Ta "" Ta "Cursor Y position in copy mode"
|
.It Li "copy_cursor_y" Ta "" Ta "Cursor Y position in copy mode"
|
||||||
.It Li "cursor_character" Ta "" Ta "Character at cursor in pane"
|
.It Li "cursor_character" Ta "" Ta "Character at cursor in pane"
|
||||||
|
2
tmux.h
2
tmux.h
@ -1787,6 +1787,8 @@ void format_defaults_pane(struct format_tree *,
|
|||||||
void format_defaults_paste_buffer(struct format_tree *,
|
void format_defaults_paste_buffer(struct format_tree *,
|
||||||
struct paste_buffer *);
|
struct paste_buffer *);
|
||||||
void format_lost_client(struct client *);
|
void format_lost_client(struct client *);
|
||||||
|
char *format_grid_word(struct grid *, u_int, u_int);
|
||||||
|
char *format_grid_line(struct grid *, u_int);
|
||||||
|
|
||||||
/* format-draw.c */
|
/* format-draw.c */
|
||||||
void format_draw(struct screen_write_ctx *,
|
void format_draw(struct screen_write_ctx *,
|
||||||
|
@ -564,6 +564,7 @@ static void
|
|||||||
window_copy_formats(struct window_mode_entry *wme, struct format_tree *ft)
|
window_copy_formats(struct window_mode_entry *wme, struct format_tree *ft)
|
||||||
{
|
{
|
||||||
struct window_copy_mode_data *data = wme->data;
|
struct window_copy_mode_data *data = wme->data;
|
||||||
|
char *s;
|
||||||
|
|
||||||
format_add(ft, "scroll_position", "%d", data->oy);
|
format_add(ft, "scroll_position", "%d", data->oy);
|
||||||
format_add(ft, "rectangle_toggle", "%d", data->rectflag);
|
format_add(ft, "rectangle_toggle", "%d", data->rectflag);
|
||||||
@ -578,6 +579,18 @@ window_copy_formats(struct window_mode_entry *wme, struct format_tree *ft)
|
|||||||
format_add(ft, "selection_end_x", "%d", data->endselx);
|
format_add(ft, "selection_end_x", "%d", data->endselx);
|
||||||
format_add(ft, "selection_end_y", "%d", data->endsely);
|
format_add(ft, "selection_end_y", "%d", data->endsely);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s = format_grid_word(data->screen.grid, data->cx, data->cy);
|
||||||
|
if (s != NULL) {
|
||||||
|
format_add(ft, "copy_cursor_word", "%s", s);
|
||||||
|
free(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
s = format_grid_line(data->screen.grid, data->cy);
|
||||||
|
if (s != NULL) {
|
||||||
|
format_add(ft, "copy_cursor_line", "%s", s);
|
||||||
|
free(s);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
Loading…
Reference in New Issue
Block a user