From c426e485e527a03aa3b4bdbb3203f621e006cbd5 Mon Sep 17 00:00:00 2001 From: nicm Date: Mon, 10 Oct 2016 21:29:23 +0000 Subject: Loads more static, except for cmd-*.c and window-*.c. --- cfg.c | 4 +- environ.c | 7 ++-- format.c | 123 +++++++++++++++++++++++++++++--------------------------- grid.c | 35 ++++++++-------- hooks.c | 3 +- job.c | 8 ++-- key-string.c | 2 +- layout-set.c | 18 ++++----- mode-key.c | 18 ++++----- names.c | 8 ++-- notify.c | 15 +++---- options.c | 3 +- procname.c | 6 +-- screen-redraw.c | 54 +++++++++++++------------ screen.c | 12 +++--- server-client.c | 58 +++++++++++++------------- server-fn.c | 8 ++-- server.c | 39 +++++++++--------- session.c | 22 +++++----- signal.c | 12 +++--- status.c | 68 +++++++++++++++---------------- tmux.c | 6 +-- tty-keys.c | 4 +- tty-term.c | 10 ++--- tty.c | 69 +++++++++++++++---------------- 25 files changed, 309 insertions(+), 303 deletions(-) diff --git a/cfg.c b/cfg.c index ccc93df1..0a931a81 100644 --- a/cfg.c +++ b/cfg.c @@ -36,7 +36,7 @@ char **cfg_causes; u_int cfg_ncauses; struct client *cfg_client; -void cfg_default_done(struct cmd_q *); +static void cfg_default_done(struct cmd_q *); void set_cfg_file(const char *path) @@ -126,7 +126,7 @@ load_cfg(const char *path, struct cmd_q *cmdq, int quiet) return (found); } -void +static void cfg_default_done(__unused struct cmd_q *cmdq) { if (--cfg_references != 0) diff --git a/environ.c b/environ.c index 5d06afbf..016d256a 100644 --- a/environ.c +++ b/environ.c @@ -28,11 +28,10 @@ */ RB_HEAD(environ, environ_entry); -int environ_cmp(struct environ_entry *, struct environ_entry *); -RB_PROTOTYPE(environ, environ_entry, entry, environ_cmp); -RB_GENERATE(environ, environ_entry, entry, environ_cmp); +static int environ_cmp(struct environ_entry *, struct environ_entry *); +RB_GENERATE_STATIC(environ, environ_entry, entry, environ_cmp); -int +static int environ_cmp(struct environ_entry *envent1, struct environ_entry *envent2) { return (strcmp(envent1->name, envent2->name)); diff --git a/format.c b/format.c index a32db538..acf37850 100644 --- a/format.c +++ b/format.c @@ -39,34 +39,41 @@ struct format_entry; typedef void (*format_cb)(struct format_tree *, struct format_entry *); -void format_job_callback(struct job *); -char *format_job_get(struct format_tree *, const char *); -void format_job_timer(int, short, void *); - -void format_cb_host(struct format_tree *, struct format_entry *); -void format_cb_host_short(struct format_tree *, struct format_entry *); -void format_cb_pid(struct format_tree *, struct format_entry *); -void format_cb_session_alerts(struct format_tree *, struct format_entry *); -void format_cb_window_layout(struct format_tree *, struct format_entry *); -void format_cb_window_visible_layout(struct format_tree *, - struct format_entry *); -void format_cb_start_command(struct format_tree *, struct format_entry *); -void format_cb_current_command(struct format_tree *, struct format_entry *); -void format_cb_history_bytes(struct format_tree *, struct format_entry *); -void format_cb_pane_tabs(struct format_tree *, struct format_entry *); - -char *format_find(struct format_tree *, const char *, int); -void format_add_cb(struct format_tree *, const char *, format_cb); -void format_add_tv(struct format_tree *, const char *, struct timeval *); -int format_replace(struct format_tree *, const char *, size_t, char **, - size_t *, size_t *); -char *format_time_string(time_t); - -void format_defaults_pane_tabs(struct format_tree *, struct window_pane *); -void format_defaults_session(struct format_tree *, struct session *); -void format_defaults_client(struct format_tree *, struct client *); -void format_defaults_winlink(struct format_tree *, struct session *, - struct winlink *); +static void format_job_callback(struct job *); +static char *format_job_get(struct format_tree *, const char *); +static void format_job_timer(int, short, void *); + +static void format_cb_host(struct format_tree *, struct format_entry *); +static void format_cb_host_short(struct format_tree *, + struct format_entry *); +static void format_cb_pid(struct format_tree *, struct format_entry *); +static void format_cb_session_alerts(struct format_tree *, + struct format_entry *); +static void format_cb_window_layout(struct format_tree *, + struct format_entry *); +static void format_cb_window_visible_layout(struct format_tree *, + struct format_entry *); +static void format_cb_start_command(struct format_tree *, + struct format_entry *); +static void format_cb_current_command(struct format_tree *, + struct format_entry *); +static void format_cb_history_bytes(struct format_tree *, + struct format_entry *); +static void format_cb_pane_tabs(struct format_tree *, + struct format_entry *); + +static char *format_find(struct format_tree *, const char *, int); +static void format_add_cb(struct format_tree *, const char *, format_cb); +static void format_add_tv(struct format_tree *, const char *, + struct timeval *); +static int format_replace(struct format_tree *, const char *, size_t, + char **, size_t *, size_t *); + +static void format_defaults_session(struct format_tree *, + struct session *); +static void format_defaults_client(struct format_tree *, struct client *); +static void format_defaults_winlink(struct format_tree *, struct session *, + struct winlink *); /* Entry in format job tree. */ struct format_job { @@ -82,14 +89,13 @@ struct format_job { }; /* Format job tree. */ -struct event format_job_event; -int format_job_cmp(struct format_job *, struct format_job *); +static struct event format_job_event; +static int format_job_cmp(struct format_job *, struct format_job *); RB_HEAD(format_job_tree, format_job) format_jobs = RB_INITIALIZER(); -RB_PROTOTYPE(format_job_tree, format_job, entry, format_job_cmp); -RB_GENERATE(format_job_tree, format_job, entry, format_job_cmp); +RB_GENERATE_STATIC(format_job_tree, format_job, entry, format_job_cmp); /* Format job tree comparison function. */ -int +static int format_job_cmp(struct format_job *fj1, struct format_job *fj2) { return (strcmp(fj1->cmd, fj2->cmd)); @@ -120,19 +126,18 @@ struct format_tree { RB_HEAD(format_entry_tree, format_entry) tree; }; -int format_entry_cmp(struct format_entry *, struct format_entry *); -RB_PROTOTYPE(format_entry_tree, format_entry, entry, format_entry_cmp); -RB_GENERATE(format_entry_tree, format_entry, entry, format_entry_cmp); +static int format_entry_cmp(struct format_entry *, struct format_entry *); +RB_GENERATE_STATIC(format_entry_tree, format_entry, entry, format_entry_cmp); /* Format entry tree comparison function. */ -int +static int format_entry_cmp(struct format_entry *fe1, struct format_entry *fe2) { return (strcmp(fe1->key, fe2->key)); } /* Single-character uppercase aliases. */ -const char *format_upper[] = { +static const char *format_upper[] = { NULL, /* A */ NULL, /* B */ NULL, /* C */ @@ -162,7 +167,7 @@ const char *format_upper[] = { }; /* Single-character lowercase aliases. */ -const char *format_lower[] = { +static const char *format_lower[] = { NULL, /* a */ NULL, /* b */ NULL, /* c */ @@ -192,7 +197,7 @@ const char *format_lower[] = { }; /* Format job callback. */ -void +static void format_job_callback(struct job *job) { struct format_job *fj = job->data; @@ -224,7 +229,7 @@ format_job_callback(struct job *job) } /* Find a job. */ -char * +static char * format_job_get(struct format_tree *ft, const char *cmd) { struct format_job fj0, *fj; @@ -258,7 +263,7 @@ format_job_get(struct format_tree *ft, const char *cmd) } /* Remove old jobs. */ -void +static void format_job_timer(__unused int fd, __unused short events, __unused void *arg) { struct format_job *fj, *fj1; @@ -287,7 +292,7 @@ format_job_timer(__unused int fd, __unused short events, __unused void *arg) } /* Callback for host. */ -void +static void format_cb_host(__unused struct format_tree *ft, struct format_entry *fe) { char host[HOST_NAME_MAX + 1]; @@ -299,7 +304,7 @@ format_cb_host(__unused struct format_tree *ft, struct format_entry *fe) } /* Callback for host_short. */ -void +static void format_cb_host_short(__unused struct format_tree *ft, struct format_entry *fe) { char host[HOST_NAME_MAX + 1], *cp; @@ -314,14 +319,14 @@ format_cb_host_short(__unused struct format_tree *ft, struct format_entry *fe) } /* Callback for pid. */ -void +static void format_cb_pid(__unused struct format_tree *ft, struct format_entry *fe) { xasprintf(&fe->value, "%ld", (long)getpid()); } /* Callback for session_alerts. */ -void +static void format_cb_session_alerts(struct format_tree *ft, struct format_entry *fe) { struct session *s = ft->s; @@ -351,7 +356,7 @@ format_cb_session_alerts(struct format_tree *ft, struct format_entry *fe) } /* Callback for window_layout. */ -void +static void format_cb_window_layout(struct format_tree *ft, struct format_entry *fe) { struct window *w = ft->w; @@ -366,7 +371,7 @@ format_cb_window_layout(struct format_tree *ft, struct format_entry *fe) } /* Callback for window_visible_layout. */ -void +static void format_cb_window_visible_layout(struct format_tree *ft, struct format_entry *fe) { struct window *w = ft->w; @@ -378,7 +383,7 @@ format_cb_window_visible_layout(struct format_tree *ft, struct format_entry *fe) } /* Callback for pane_start_command. */ -void +static void format_cb_start_command(struct format_tree *ft, struct format_entry *fe) { struct window_pane *wp = ft->wp; @@ -390,7 +395,7 @@ format_cb_start_command(struct format_tree *ft, struct format_entry *fe) } /* Callback for pane_current_command. */ -void +static void format_cb_current_command(struct format_tree *ft, struct format_entry *fe) { struct window_pane *wp = ft->wp; @@ -413,7 +418,7 @@ format_cb_current_command(struct format_tree *ft, struct format_entry *fe) } /* Callback for history_bytes. */ -void +static void format_cb_history_bytes(struct format_tree *ft, struct format_entry *fe) { struct window_pane *wp = ft->wp; @@ -438,7 +443,7 @@ format_cb_history_bytes(struct format_tree *ft, struct format_entry *fe) } /* Callback for pane_tabs. */ -void +static void format_cb_pane_tabs(struct format_tree *ft, struct format_entry *fe) { struct window_pane *wp = ft->wp; @@ -539,7 +544,7 @@ format_add(struct format_tree *ft, const char *key, const char *fmt, ...) } /* Add a key and time. */ -void +static void format_add_tv(struct format_tree *ft, const char *key, struct timeval *tv) { struct format_entry *fe; @@ -563,7 +568,7 @@ format_add_tv(struct format_tree *ft, const char *key, struct timeval *tv) } /* Add a key and function. */ -void +static void format_add_cb(struct format_tree *ft, const char *key, format_cb cb) { struct format_entry *fe; @@ -587,7 +592,7 @@ format_add_cb(struct format_tree *ft, const char *key, format_cb cb) } /* Find a format entry. */ -char * +static char * format_find(struct format_tree *ft, const char *key, int modifiers) { struct format_entry *fe, fe_find; @@ -682,7 +687,7 @@ found: * Replace a key/value pair in buffer. #{blah} is expanded directly, * #{?blah,a,b} is replace with a if blah exists and is nonzero else b. */ -int +static int format_replace(struct format_tree *ft, const char *key, size_t keylen, char **buf, size_t *len, size_t *off) { @@ -1002,7 +1007,7 @@ format_defaults(struct format_tree *ft, struct client *c, struct session *s, } /* Set default format keys for a session. */ -void +static void format_defaults_session(struct format_tree *ft, struct session *s) { struct session_group *sg; @@ -1031,7 +1036,7 @@ format_defaults_session(struct format_tree *ft, struct session *s) } /* Set default format keys for a client. */ -void +static void format_defaults_client(struct format_tree *ft, struct client *c) { struct session *s; @@ -1098,7 +1103,7 @@ format_defaults_window(struct format_tree *ft, struct window *w) } /* Set default format keys for a winlink. */ -void +static void format_defaults_winlink(struct format_tree *ft, struct session *s, struct winlink *wl) { diff --git a/grid.c b/grid.c index 50766a88..73097983 100644 --- a/grid.c +++ b/grid.c @@ -43,16 +43,17 @@ const struct grid_cell_entry grid_default_entry = { 0, { .data = { 0, 8, 8, ' ' } } }; -void grid_reflow_copy(struct grid_line *, u_int, struct grid_line *l, - u_int, u_int); -void grid_reflow_join(struct grid *, u_int *, struct grid_line *, u_int); -void grid_reflow_split(struct grid *, u_int *, struct grid_line *, u_int, - u_int); -void grid_reflow_move(struct grid *, u_int *, struct grid_line *); -size_t grid_string_cells_fg(const struct grid_cell *, int *); -size_t grid_string_cells_bg(const struct grid_cell *, int *); -void grid_string_cells_code(const struct grid_cell *, - const struct grid_cell *, char *, size_t, int); +static void grid_reflow_copy(struct grid_line *, u_int, struct grid_line *, + u_int, u_int); +static void grid_reflow_join(struct grid *, u_int *, struct grid_line *, + u_int); +static void grid_reflow_split(struct grid *, u_int *, struct grid_line *, + u_int, u_int); +static void grid_reflow_move(struct grid *, u_int *, struct grid_line *); +static size_t grid_string_cells_fg(const struct grid_cell *, int *); +static size_t grid_string_cells_bg(const struct grid_cell *, int *); +static void grid_string_cells_code(const struct grid_cell *, + const struct grid_cell *, char *, size_t, int); /* Copy default into a cell. */ static void @@ -473,7 +474,7 @@ grid_move_cells(struct grid *gd, u_int dx, u_int px, u_int py, u_int nx) } /* Get ANSI foreground sequence. */ -size_t +static size_t grid_string_cells_fg(const struct grid_cell *gc, int *values) { size_t n; @@ -522,7 +523,7 @@ grid_string_cells_fg(const struct grid_cell *gc, int *values) } /* Get ANSI background sequence. */ -size_t +static size_t grid_string_cells_bg(const struct grid_cell *gc, int *values) { size_t n; @@ -575,7 +576,7 @@ grid_string_cells_bg(const struct grid_cell *gc, int *values) * given a current state. The output buffer must be able to hold at least 57 * bytes. */ -void +static void grid_string_cells_code(const struct grid_cell *lastgc, const struct grid_cell *gc, char *buf, size_t len, int escape_c0) { @@ -773,7 +774,7 @@ grid_duplicate_lines(struct grid *dst, u_int dy, struct grid *src, u_int sy, } /* Copy a section of a line. */ -void +static void grid_reflow_copy(struct grid_line *dst_gl, u_int to, struct grid_line *src_gl, u_int from, u_int to_copy) { @@ -798,7 +799,7 @@ grid_reflow_copy(struct grid_line *dst_gl, u_int to, struct grid_line *src_gl, } /* Join line data. */ -void +static void grid_reflow_join(struct grid *dst, u_int *py, struct grid_line *src_gl, u_int new_x) { @@ -833,7 +834,7 @@ grid_reflow_join(struct grid *dst, u_int *py, struct grid_line *src_gl, } /* Split line data. */ -void +static void grid_reflow_split(struct grid *dst, u_int *py, struct grid_line *src_gl, u_int new_x, u_int offset) { @@ -873,7 +874,7 @@ grid_reflow_split(struct grid *dst, u_int *py, struct grid_line *src_gl, } /* Move line data. */ -void +static void grid_reflow_move(struct grid *dst, u_int *py, struct grid_line *src_gl) { struct grid_line *dst_gl; diff --git a/hooks.c b/hooks.c index c1a016ae..62ea05d1 100644 --- a/hooks.c +++ b/hooks.c @@ -29,8 +29,7 @@ struct hooks { }; static int hooks_cmp(struct hook *, struct hook *); -RB_PROTOTYPE(hooks_tree, hook, entry, hooks_cmp); -RB_GENERATE(hooks_tree, hook, entry, hooks_cmp); +RB_GENERATE_STATIC(hooks_tree, hook, entry, hooks_cmp); static struct hook *hooks_find1(struct hooks *, const char *); static void hooks_free1(struct hooks *, struct hook *); diff --git a/job.c b/job.c index d6541709..8310c376 100644 --- a/job.c +++ b/job.c @@ -33,8 +33,8 @@ * output. */ -void job_callback(struct bufferevent *, short, void *); -void job_write_callback(struct bufferevent *, void *); +static void job_callback(struct bufferevent *, short, void *); +static void job_write_callback(struct bufferevent *, void *); /* All jobs list. */ struct joblist all_jobs = LIST_HEAD_INITIALIZER(all_jobs); @@ -149,7 +149,7 @@ job_free(struct job *job) } /* Called when output buffer falls below low watermark (default is 0). */ -void +static void job_write_callback(__unused struct bufferevent *bufev, void *data) { struct job *job = data; @@ -165,7 +165,7 @@ job_write_callback(__unused struct bufferevent *bufev, void *data) } /* Job buffer error callback. */ -void +static void job_callback(__unused struct bufferevent *bufev, __unused short events, void *data) { diff --git a/key-string.c b/key-string.c index ef5cf17c..00ebb386 100644 --- a/key-string.c +++ b/key-string.c @@ -25,7 +25,7 @@ static key_code key_string_search_table(const char *); static key_code key_string_get_modifiers(const char **); -const struct { +static const struct { const char *string; key_code key; } key_string_table[] = { diff --git a/layout-set.c b/layout-set.c index 4d2b8ca7..1da7037a 100644 --- a/layout-set.c +++ b/layout-set.c @@ -27,11 +27,11 @@ * one-off and generate a layout tree. */ -void layout_set_even_h(struct window *); -void layout_set_even_v(struct window *); -void layout_set_main_h(struct window *); -void layout_set_main_v(struct window *); -void layout_set_tiled(struct window *); +static void layout_set_even_h(struct window *); +static void layout_set_even_v(struct window *); +static void layout_set_main_h(struct window *); +static void layout_set_main_v(struct window *); +static void layout_set_tiled(struct window *); const struct { const char *name; @@ -114,7 +114,7 @@ layout_set_previous(struct window *w) return (layout); } -void +static void layout_set_even_h(struct window *w) { struct window_pane *wp; @@ -168,7 +168,7 @@ layout_set_even_h(struct window *w) server_redraw_window(w); } -void +static void layout_set_even_v(struct window *w) { struct window_pane *wp; @@ -222,7 +222,7 @@ layout_set_even_v(struct window *w) server_redraw_window(w); } -void +static void layout_set_main_h(struct window *w) { struct window_pane *wp; @@ -345,7 +345,7 @@ layout_set_main_h(struct window *w) server_redraw_window(w); } -void +static void layout_set_main_v(struct window *w) { struct window_pane *wp; diff --git a/mode-key.c b/mode-key.c index db728fd1..26c7c478 100644 --- a/mode-key.c +++ b/mode-key.c @@ -54,7 +54,7 @@ struct mode_key_entry { }; /* Edit keys command strings. */ -const struct mode_key_cmdstr mode_key_cmdstr_edit[] = { +static const struct mode_key_cmdstr mode_key_cmdstr_edit[] = { { MODEKEYEDIT_BACKSPACE, "backspace" }, { MODEKEYEDIT_CANCEL, "cancel" }, { MODEKEYEDIT_COMPLETE, "complete" }, @@ -89,7 +89,7 @@ const struct mode_key_cmdstr mode_key_cmdstr_edit[] = { }; /* Choice keys command strings. */ -const struct mode_key_cmdstr mode_key_cmdstr_choice[] = { +static const struct mode_key_cmdstr mode_key_cmdstr_choice[] = { { MODEKEYCHOICE_BACKSPACE, "backspace" }, { MODEKEYCHOICE_BOTTOMLINE, "bottom-line"}, { MODEKEYCHOICE_CANCEL, "cancel" }, @@ -114,7 +114,7 @@ const struct mode_key_cmdstr mode_key_cmdstr_choice[] = { }; /* Copy keys command strings. */ -const struct mode_key_cmdstr mode_key_cmdstr_copy[] = { +static const struct mode_key_cmdstr mode_key_cmdstr_copy[] = { { MODEKEYCOPY_APPENDSELECTION, "append-selection" }, { MODEKEYCOPY_BACKTOINDENTATION, "back-to-indentation" }, { MODEKEYCOPY_BOTTOMLINE, "bottom-line" }, @@ -170,7 +170,7 @@ const struct mode_key_cmdstr mode_key_cmdstr_copy[] = { }; /* vi editing keys. */ -const struct mode_key_entry mode_key_vi_edit[] = { +static const struct mode_key_entry mode_key_vi_edit[] = { { '\003' /* C-c */, 0, MODEKEYEDIT_CANCEL, 1 }, { '\010' /* C-h */, 0, MODEKEYEDIT_BACKSPACE, 1 }, { '\011' /* Tab */, 0, MODEKEYEDIT_COMPLETE, 1 }, @@ -229,7 +229,7 @@ const struct mode_key_entry mode_key_vi_edit[] = { struct mode_key_tree mode_key_tree_vi_edit; /* vi choice selection keys. */ -const struct mode_key_entry mode_key_vi_choice[] = { +static const struct mode_key_entry mode_key_vi_choice[] = { { '0' | KEYC_ESCAPE, 0, MODEKEYCHOICE_STARTNUMBERPREFIX, 1 }, { '1' | KEYC_ESCAPE, 0, MODEKEYCHOICE_STARTNUMBERPREFIX, 1 }, { '2' | KEYC_ESCAPE, 0, MODEKEYCHOICE_STARTNUMBERPREFIX, 1 }, @@ -278,7 +278,7 @@ const struct mode_key_entry mode_key_vi_choice[] = { struct mode_key_tree mode_key_tree_vi_choice; /* vi copy mode keys. */ -const struct mode_key_entry mode_key_vi_copy[] = { +static const struct mode_key_entry mode_key_vi_copy[] = { { ' ', 0, MODEKEYCOPY_STARTSELECTION, 1 }, { '"', 0, MODEKEYCOPY_STARTNAMEDBUFFER, 1 }, { '$', 0, MODEKEYCOPY_ENDOFLINE, 1 }, @@ -359,7 +359,7 @@ const struct mode_key_entry mode_key_vi_copy[] = { struct mode_key_tree mode_key_tree_vi_copy; /* emacs editing keys. */ -const struct mode_key_entry mode_key_emacs_edit[] = { +static const struct mode_key_entry mode_key_emacs_edit[] = { { '\001' /* C-a */, 0, MODEKEYEDIT_STARTOFLINE, 1 }, { '\002' /* C-b */, 0, MODEKEYEDIT_CURSORLEFT, 1 }, { '\003' /* C-c */, 0, MODEKEYEDIT_CANCEL, 1 }, @@ -395,7 +395,7 @@ const struct mode_key_entry mode_key_emacs_edit[] = { struct mode_key_tree mode_key_tree_emacs_edit; /* emacs choice selection keys. */ -const struct mode_key_entry mode_key_emacs_choice[] = { +static const struct mode_key_entry mode_key_emacs_choice[] = { { '0' | KEYC_ESCAPE, 0, MODEKEYCHOICE_STARTNUMBERPREFIX, 1 }, { '1' | KEYC_ESCAPE, 0, MODEKEYCHOICE_STARTNUMBERPREFIX, 1 }, { '2' | KEYC_ESCAPE, 0, MODEKEYCHOICE_STARTNUMBERPREFIX, 1 }, @@ -442,7 +442,7 @@ const struct mode_key_entry mode_key_emacs_choice[] = { struct mode_key_tree mode_key_tree_emacs_choice; /* emacs copy mode keys. */ -const struct mode_key_entry mode_key_emacs_copy[] = { +static const struct mode_key_entry mode_key_emacs_copy[] = { { ' ', 0, MODEKEYCOPY_NEXTPAGE, 1 }, { ',', 0, MODEKEYCOPY_JUMPREVERSE, 1 }, { ';', 0, MODEKEYCOPY_JUMPAGAIN, 1 }, diff --git a/names.c b/names.c index 485155ff..b83a0cb7 100644 --- a/names.c +++ b/names.c @@ -25,10 +25,10 @@ #include "tmux.h" -void name_time_callback(int, short, void *); -int name_time_expired(struct window *, struct timeval *); +static void name_time_callback(int, short, void *); +static int name_time_expired(struct window *, struct timeval *); -void +static void name_time_callback(__unused int fd, __unused short events, void *arg) { struct window *w = arg; @@ -37,7 +37,7 @@ name_time_callback(__unused int fd, __unused short events, void *arg) log_debug("@%u name timer expired", w->id); } -int +static int name_time_expired(struct window *w, struct timeval *tv) { struct timeval offset; diff --git a/notify.c b/notify.c index b51a5e59..a1f69240 100644 --- a/notify.c +++ b/notify.c @@ -43,12 +43,13 @@ struct notify_entry { TAILQ_ENTRY(notify_entry) entry; }; -TAILQ_HEAD(, notify_entry) notify_queue = TAILQ_HEAD_INITIALIZER(notify_queue); -int notify_enabled = 1; +TAILQ_HEAD(notify_queue, notify_entry); +static struct notify_queue notify_queue = TAILQ_HEAD_INITIALIZER(notify_queue); +static int notify_enabled = 1; -void notify_drain(void); -void notify_add(enum notify_type, struct client *, struct session *, - struct window *); +static void notify_drain(void); +static void notify_add(enum notify_type, struct client *, struct session *, + struct window *); void notify_enable(void) @@ -63,7 +64,7 @@ notify_disable(void) notify_enabled = 0; } -void +static void notify_add(enum notify_type type, struct client *c, struct session *s, struct window *w) { @@ -84,7 +85,7 @@ notify_add(enum notify_type type, struct client *c, struct session *s, w->references++; } -void +static void notify_drain(void) { struct notify_entry *ne, *ne1; diff --git a/options.c b/options.c index cd3bd8ec..845bd7d5 100644 --- a/options.c +++ b/options.c @@ -35,8 +35,7 @@ struct options { }; static int options_cmp(struct options_entry *, struct options_entry *); -RB_PROTOTYPE(options_tree, options_entry, entry, options_cmp); -RB_GENERATE(options_tree, options_entry, entry, options_cmp); +RB_GENERATE_STATIC(options_tree, options_entry, entry, options_cmp); static void options_free1(struct options *, struct options_entry *); diff --git a/procname.c b/procname.c index 42f5f473..07a8a56c 100644 --- a/procname.c +++ b/procname.c @@ -36,10 +36,10 @@ #define is_stopped(p) \ ((p)->p_stat == SSTOP || (p)->p_stat == SDEAD) -struct kinfo_proc *cmp_procs(struct kinfo_proc *, struct kinfo_proc *); -char *get_proc_name(int, char *); +static struct kinfo_proc *cmp_procs(struct kinfo_proc *, struct kinfo_proc *); +char *get_proc_name(int, char *); -struct kinfo_proc * +static struct kinfo_proc * cmp_procs(struct kinfo_proc *p1, struct kinfo_proc *p2) { if (is_runnable(p1) && !is_runnable(p2)) diff --git a/screen-redraw.c b/screen-redraw.c index 5e4b0848..00e94d61 100644 --- a/screen-redraw.c +++ b/screen-redraw.c @@ -22,21 +22,22 @@ #include "tmux.h" -int screen_redraw_cell_border1(struct window_pane *, u_int, u_int); -int screen_redraw_cell_border(struct client *, u_int, u_int); -int screen_redraw_check_cell(struct client *, u_int, u_int, int, - struct window_pane **); -int screen_redraw_check_is(u_int, u_int, int, int, struct window *, - struct window_pane *, struct window_pane *); - -int screen_redraw_make_pane_status(struct client *, struct window *, - struct window_pane *); -void screen_redraw_draw_pane_status(struct client *, int); - -void screen_redraw_draw_borders(struct client *, int, int, u_int); -void screen_redraw_draw_panes(struct client *, u_int); -void screen_redraw_draw_status(struct client *, u_int); -void screen_redraw_draw_number(struct client *, struct window_pane *, u_int); +static int screen_redraw_cell_border1(struct window_pane *, u_int, u_int); +static int screen_redraw_cell_border(struct client *, u_int, u_int); +static int screen_redraw_check_cell(struct client *, u_int, u_int, int, + struct window_pane **); +static int screen_redraw_check_is(u_int, u_int, int, int, struct window *, + struct window_pane *, struct window_pane *); + +static int screen_redraw_make_pane_status(struct client *, struct window *, + struct window_pane *); +static void screen_redraw_draw_pane_status(struct client *, int); + +static void screen_redraw_draw_borders(struct client *, int, int, u_int); +static void screen_redraw_draw_panes(struct client *, u_int); +static void screen_redraw_draw_status(struct client *, u_int); +static void screen_redraw_draw_number(struct client *, struct window_pane *, + u_int); #define CELL_INSIDE 0 #define CELL_LEFTRIGHT 1 @@ -59,7 +60,7 @@ void screen_redraw_draw_number(struct client *, struct window_pane *, u_int); #define CELL_STATUS_BOTTOM 2 /* Check if cell is on the border of a particular pane. */ -int +static int screen_redraw_cell_border1(struct window_pane *wp, u_int px, u_int py) { /* Inside pane. */ @@ -88,7 +89,7 @@ screen_redraw_cell_border1(struct window_pane *wp, u_int px, u_int py) } /* Check if a cell is on the pane border. */ -int +static int screen_redraw_cell_border(struct client *c, u_int px, u_int py) { struct window *w = c->session->curw->window; @@ -107,7 +108,7 @@ screen_redraw_cell_border(struct client *c, u_int px, u_int py) } /* Check if cell inside a pane. */ -int +static int screen_redraw_check_cell(struct client *c, u_int px, u_int py, int pane_status, struct window_pane **wpp) { @@ -116,6 +117,8 @@ screen_redraw_check_cell(struct client *c, u_int px, u_int py, int pane_status, int borders; u_int right, line; + *wpp = NULL; + if (px > w->sx || py > w->sy) return (CELL_OUTSIDE); @@ -201,12 +204,11 @@ screen_redraw_check_cell(struct client *c, u_int px, u_int py, int pane_status, } } - *wpp = NULL; return (CELL_OUTSIDE); } /* Check if the border of a particular pane. */ -int +static int screen_redraw_check_is(u_int px, u_int py, int type, int pane_status, struct window *w, struct window_pane *wantwp, struct window_pane *wp) { @@ -259,7 +261,7 @@ screen_redraw_check_is(u_int px, u_int py, int type, int pane_status, } /* Update pane status. */ -int +static int screen_redraw_make_pane_status(struct client *c, struct window *w, struct window_pane *wp) { @@ -303,7 +305,7 @@ screen_redraw_make_pane_status(struct client *c, struct window *w, } /* Draw pane status. */ -void +static void screen_redraw_draw_pane_status(struct client *c, int pane_status) { struct window *w = c->session->curw->window; @@ -418,7 +420,7 @@ screen_redraw_pane(struct client *c, struct window_pane *wp) } /* Draw the borders. */ -void +static void screen_redraw_draw_borders(struct client *c, int status, int pane_status, u_int top) { @@ -505,7 +507,7 @@ screen_redraw_draw_borders(struct client *c, int status, int pane_status, } /* Draw the panes. */ -void +static void screen_redraw_draw_panes(struct client *c, u_int top) { struct window *w = c->session->curw->window; @@ -524,7 +526,7 @@ screen_redraw_draw_panes(struct client *c, u_int top) } /* Draw the status line. */ -void +static void screen_redraw_draw_status(struct client *c, u_int top) { struct tty *tty = &c->tty; @@ -536,7 +538,7 @@ screen_redraw_draw_status(struct client *c, u_int top) } /* Draw number on a pane. */ -void +static void screen_redraw_draw_number(struct client *c, struct window_pane *wp, u_int top) { struct tty *tty = &c->tty; diff --git a/screen.c b/screen.c index 8e4f8a65..b0ba216a 100644 --- a/screen.c +++ b/screen.c @@ -24,8 +24,8 @@ #include "tmux.h" -void screen_resize_x(struct screen *, u_int); -void screen_resize_y(struct screen *, u_int); +static void screen_resize_x(struct screen *, u_int); +static void screen_resize_y(struct screen *, u_int); /* Create a new screen. */ void @@ -139,7 +139,7 @@ screen_resize(struct screen *s, u_int sx, u_int sy, int reflow) screen_reflow(s, sx); } -void +static void screen_resize_x(struct screen *s, u_int sx) { struct grid *gd = s->grid; @@ -161,7 +161,7 @@ screen_resize_x(struct screen *s, u_int sx) gd->sx = sx; } -void +static void screen_resize_y(struct screen *s, u_int sy) { struct grid *gd = s->grid; @@ -221,8 +221,8 @@ screen_resize_y(struct screen *s, u_int sy) needed = sy - oldy; /* - * Try to pull as much as possible out of scrolled history, if is - * is enabled. + * Try to pull as much as possible out of scrolled history, if + * is is enabled. */ available = gd->hscrolled; if (gd->flags & GRID_HISTORY && available > 0) { diff --git a/server-client.c b/server-client.c index e87f9d0b..859a451e 100644 --- a/server-client.c +++ b/server-client.c @@ -32,21 +32,21 @@ #include "tmux.h" -void server_client_free(int, short, void *); -void server_client_check_focus(struct window_pane *); -void server_client_check_resize(struct window_pane *); -key_code server_client_check_mouse(struct client *); -void server_client_repeat_timer(int, short, void *); -void server_client_check_exit(struct client *); -void server_client_check_redraw(struct client *); -void server_client_set_title(struct client *); -void server_client_reset_state(struct client *); -int server_client_assume_paste(struct session *); - -void server_client_dispatch(struct imsg *, void *); -void server_client_dispatch_command(struct client *, struct imsg *); -void server_client_dispatch_identify(struct client *, struct imsg *); -void server_client_dispatch_shell(struct client *); +static void server_client_free(int, short, void *); +static void server_client_check_focus(struct window_pane *); +static void server_client_check_resize(struct window_pane *); +static key_code server_client_check_mouse(struct client *); +static void server_client_repeat_timer(int, short, void *); +static void server_client_check_exit(struct client *); +static void server_client_check_redraw(struct client *); +static void server_client_set_title(struct client *); +static void server_client_reset_state(struct client *); +static int server_client_assume_paste(struct session *); + +static void server_client_dispatch(struct imsg *, void *); +static void server_client_dispatch_command(struct client *, struct imsg *); +static void server_client_dispatch_identify(struct client *, struct imsg *); +static void server_client_dispatch_shell(struct client *); /* Check if this client is inside this server. */ int @@ -264,7 +264,7 @@ server_client_unref(struct client *c) } /* Free dead client. */ -void +static void server_client_free(__unused int fd, __unused short events, void *arg) { struct client *c = arg; @@ -289,7 +289,7 @@ server_client_detach(struct client *c, enum msgtype msgtype) } /* Check for mouse keys. */ -key_code +static key_code server_client_check_mouse(struct client *c) { struct session *s = c->session; @@ -555,7 +555,7 @@ server_client_check_mouse(struct client *c) } /* Is this fast enough to probably be a paste? */ -int +static int server_client_assume_paste(struct session *s) { struct timeval tv; @@ -787,7 +787,7 @@ server_client_resize_event(__unused int fd, __unused short events, void *data) } /* Check if pane should be resized. */ -void +static void server_client_check_resize(struct window_pane *wp) { struct timeval tv = { .tv_usec = 250000 }; @@ -817,7 +817,7 @@ server_client_check_resize(struct window_pane *wp) } /* Check whether pane should be focused. */ -void +static void server_client_check_focus(struct window_pane *wp) { struct client *c; @@ -878,7 +878,7 @@ focused: * tty_region/tty_reset/tty_update_mode already take care of not resetting * things that are already in their default state. */ -void +static void server_client_reset_state(struct client *c) { struct window *w = c->session->curw->window; @@ -914,7 +914,7 @@ server_client_reset_state(struct client *c) } /* Repeat time callback. */ -void +static void server_client_repeat_timer(__unused int fd, __unused short events, void *data) { struct client *c = data; @@ -927,7 +927,7 @@ server_client_repeat_timer(__unused int fd, __unused short events, void *data) } /* Check if client should be exited. */ -void +static void server_client_check_exit(struct client *c) { if (!(c->flags & CLIENT_EXIT)) @@ -945,7 +945,7 @@ server_client_check_exit(struct client *c) } /* Check for client redraws. */ -void +static void server_client_check_redraw(struct client *c) { struct session *s = c->session; @@ -1001,7 +1001,7 @@ server_client_check_redraw(struct client *c) } /* Set client title. */ -void +static void server_client_set_title(struct client *c) { struct session *s = c->session; @@ -1026,7 +1026,7 @@ server_client_set_title(struct client *c) } /* Dispatch message from client. */ -void +static void server_client_dispatch(struct imsg *imsg, void *arg) { struct client *c = arg; @@ -1130,7 +1130,7 @@ server_client_dispatch(struct imsg *imsg, void *arg) } /* Handle command message. */ -void +static void server_client_dispatch_command(struct client *c, struct imsg *imsg) { struct msg_command_data data; @@ -1183,7 +1183,7 @@ error: } /* Handle identify message. */ -void +static void server_client_dispatch_identify(struct client *c, struct imsg *imsg) { const char *data, *home; @@ -1291,7 +1291,7 @@ server_client_dispatch_identify(struct client *c, struct imsg *imsg) } /* Handle shell message. */ -void +static void server_client_dispatch_shell(struct client *c) { const char *shell; diff --git a/server-fn.c b/server-fn.c index 89398523..bcb05ddb 100644 --- a/server-fn.c +++ b/server-fn.c @@ -28,8 +28,8 @@ #include "tmux.h" -struct session *server_next_session(struct session *); -void server_callback_identify(int, short, void *); +static struct session *server_next_session(struct session *); +static void server_callback_identify(int, short, void *); void server_fill_environ(struct session *s, struct environ *env) @@ -355,7 +355,7 @@ server_destroy_session_group(struct session *s) } } -struct session * +static struct session * server_next_session(struct session *s) { struct session *s_loop, *s_out; @@ -454,7 +454,7 @@ server_clear_identify(struct client *c, struct window_pane *wp) server_redraw_client(c); } -void +static void server_callback_identify(__unused int fd, __unused short events, void *data) { server_clear_identify(data, NULL); diff --git a/server.c b/server.c index 051e2dec..bcb596b8 100644 --- a/server.c +++ b/server.c @@ -44,21 +44,20 @@ struct clients clients; struct tmuxproc *server_proc; -int server_fd; -int server_exit; -struct event server_ev_accept; +static int server_fd; +static int server_exit; +static struct event server_ev_accept; struct cmd_find_state marked_pane; -int server_create_socket(void); -int server_loop(void); -int server_should_exit(void); -void server_send_exit(void); -void server_accept(int, short, void *); -void server_signal(int); -void server_child_signal(void); -void server_child_exited(pid_t, int); -void server_child_stopped(pid_t, int); +static int server_create_socket(void); +static int server_loop(void); +static void server_send_exit(void); +static void server_accept(int, short, void *); +static void server_signal(int); +static void server_child_signal(void); +static void server_child_exited(pid_t, int); +static void server_child_stopped(pid_t, int); /* Set marked pane. */ void @@ -99,7 +98,7 @@ server_check_marked(void) } /* Create server socket. */ -int +static int server_create_socket(void) { struct sockaddr_un sa; @@ -187,7 +186,7 @@ server_start(struct event_base *base, int lockfd, char *lockfile) } /* Server loop callback. */ -int +static int server_loop(void) { struct client *c; @@ -216,7 +215,7 @@ server_loop(void) } /* Exit the server by killing all clients and windows. */ -void +static void server_send_exit(void) { struct client *c, *c1; @@ -273,7 +272,7 @@ server_update_socket(void) } /* Callback for server socket. */ -void +static void server_accept(int fd, short events, __unused void *data) { struct sockaddr_storage sa; @@ -326,7 +325,7 @@ server_add_accept(int timeout) } /* Signal handler. */ -void +static void server_signal(int sig) { int fd; @@ -353,7 +352,7 @@ server_signal(int sig) } /* Handle SIGCHLD. */ -void +static void server_child_signal(void) { int status; @@ -376,7 +375,7 @@ server_child_signal(void) } /* Handle exited children. */ -void +static void server_child_exited(pid_t pid, int status) { struct window *w, *w1; @@ -402,7 +401,7 @@ server_child_exited(pid_t pid, int status) } /* Handle stopped children. */ -void +static void server_child_stopped(pid_t pid, int status) { struct window *w; diff --git a/session.c b/session.c index 7f2c3d97..e2114023 100644 --- a/session.c +++ b/session.c @@ -27,16 +27,16 @@ #include "tmux.h" -struct sessions sessions; -u_int next_session_id; -struct session_groups session_groups; +struct sessions sessions; +static u_int next_session_id; +struct session_groups session_groups; -void session_free(int, short, void *); +static void session_free(int, short, void *); -void session_lock_timer(int, short, void *); +static void session_lock_timer(int, short, void *); -struct winlink *session_next_alert(struct winlink *); -struct winlink *session_previous_alert(struct winlink *); +static struct winlink *session_next_alert(struct winlink *); +static struct winlink *session_previous_alert(struct winlink *); RB_GENERATE(sessions, session, entry, session_cmp); @@ -182,7 +182,7 @@ session_unref(struct session *s) } /* Free session. */ -void +static void session_free(__unused int fd, __unused short events, void *arg) { struct session *s = arg; @@ -239,7 +239,7 @@ session_check_name(const char *name) } /* Lock session if it has timed out. */ -void +static void session_lock_timer(__unused int fd, __unused short events, void *arg) { struct session *s = arg; @@ -426,7 +426,7 @@ session_is_linked(struct session *s, struct window *w) return (w->references != 1); } -struct winlink * +static struct winlink * session_next_alert(struct winlink *wl) { while (wl != NULL) { @@ -457,7 +457,7 @@ session_next(struct session *s, int alert) return (session_set_current(s, wl)); } -struct winlink * +static struct winlink * session_previous_alert(struct winlink *wl) { while (wl != NULL) { diff --git a/signal.c b/signal.c index 19938638..79d23af0 100644 --- a/signal.c +++ b/signal.c @@ -24,12 +24,12 @@ #include "tmux.h" -struct event ev_sighup; -struct event ev_sigchld; -struct event ev_sigcont; -struct event ev_sigterm; -struct event ev_sigusr1; -struct event ev_sigwinch; +static struct event ev_sighup; +static struct event ev_sigchld; +static struct event ev_sigcont; +static struct event ev_sigterm; +static struct event ev_sigusr1; +static struct event ev_sigwinch; void set_signals(void (*handler)(int, short, void *), void *arg) diff --git a/status.c b/status.c index cc86cb02..62c01344 100644 --- a/status.c +++ b/status.c @@ -29,33 +29,33 @@ #include "tmux.h" -char *status_redraw_get_left(struct client *, time_t, struct grid_cell *, - size_t *); -char *status_redraw_get_right(struct client *, time_t, struct grid_cell *, - size_t *); -char *status_print(struct client *, struct winlink *, time_t, - struct grid_cell *); -char *status_replace(struct client *, struct winlink *, const char *, time_t); -void status_message_callback(int, short, void *); -void status_timer_callback(int, short, void *); - -const char *status_prompt_up_history(u_int *); -const char *status_prompt_down_history(u_int *); -void status_prompt_add_history(const char *); - -const char **status_prompt_complete_list(u_int *, const char *); -char *status_prompt_complete_prefix(const char **, u_int); -char *status_prompt_complete(struct session *, const char *); - -char *status_prompt_find_history_file(void); +static char *status_redraw_get_left(struct client *, time_t, + struct grid_cell *, size_t *); +static char *status_redraw_get_right(struct client *, time_t, + struct grid_cell *, size_t *); +static char *status_print(struct client *, struct winlink *, time_t, + struct grid_cell *); +static char *status_replace(struct client *, struct winlink *, const char *, + time_t); +static void status_message_callback(int, short, void *); +static void status_timer_callback(int, short, void *); + +static char *status_prompt_find_history_file(void); +static const char *status_prompt_up_history(u_int *); +static const char *status_prompt_down_history(u_int *); +static void status_prompt_add_history(const char *); + +static const char **status_prompt_complete_list(u_int *, const char *); +static char *status_prompt_complete_prefix(const char **, u_int); +static char *status_prompt_complete(struct session *, const char *); /* Status prompt history. */ #define PROMPT_HISTORY 100 -char **status_prompt_hlist; -u_int status_prompt_hsize; +static char **status_prompt_hlist; +static u_int status_prompt_hsize; /* Find the history file to load/save from/to. */ -char * +static char * status_prompt_find_history_file(void) { const char *home, *history_file; @@ -144,7 +144,7 @@ status_prompt_save_history(void) } /* Status timer callback. */ -void +static void status_timer_callback(__unused int fd, __unused short events, void *arg) { struct client *c = arg; @@ -207,7 +207,7 @@ status_at_line(struct client *c) } /* Retrieve options for left string. */ -char * +static char * status_redraw_get_left(struct client *c, time_t t, struct grid_cell *gc, size_t *size) { @@ -229,7 +229,7 @@ status_redraw_get_left(struct client *c, time_t t, struct grid_cell *gc, } /* Retrieve options for right string. */ -char * +static char * status_redraw_get_right(struct client *c, time_t t, struct grid_cell *gc, size_t *size) { @@ -493,7 +493,7 @@ out: } /* Replace special sequences in fmt. */ -char * +static char * status_replace(struct client *c, struct winlink *wl, const char *fmt, time_t t) { struct format_tree *ft; @@ -515,7 +515,7 @@ status_replace(struct client *c, struct winlink *wl, const char *fmt, time_t t) } /* Return winlink status line entry and adjust gc as necessary. */ -char * +static char * status_print(struct client *c, struct winlink *wl, time_t t, struct grid_cell *gc) { @@ -607,7 +607,7 @@ status_message_clear(struct client *c) } /* Clear status line message after timer expires. */ -void +static void status_message_callback(__unused int fd, __unused short event, void *data) { struct client *c = data; @@ -1139,7 +1139,7 @@ status_prompt_key(struct client *c, key_code key) } /* Get previous line from the history. */ -const char * +static const char * status_prompt_up_history(u_int *idx) { /* @@ -1154,7 +1154,7 @@ status_prompt_up_history(u_int *idx) } /* Get next line from the history. */ -const char * +static const char * status_prompt_down_history(u_int *idx) { if (status_prompt_hsize == 0 || *idx == 0) @@ -1166,7 +1166,7 @@ status_prompt_down_history(u_int *idx) } /* Add line to the history. */ -void +static void status_prompt_add_history(const char *line) { size_t size; @@ -1191,7 +1191,7 @@ status_prompt_add_history(const char *line) } /* Build completion list. */ -const char ** +static const char ** status_prompt_complete_list(u_int *size, const char *s) { const char **list = NULL, **layout; @@ -1225,7 +1225,7 @@ status_prompt_complete_list(u_int *size, const char *s) } /* Find longest prefix. */ -char * +static char * status_prompt_complete_prefix(const char **list, u_int size) { char *out; @@ -1246,7 +1246,7 @@ status_prompt_complete_prefix(const char **list, u_int size) } /* Complete word. */ -char * +static char * status_prompt_complete(struct session *sess, const char *s) { const char **list = NULL, *colon; diff --git a/tmux.c b/tmux.c index abe2c672..413fea3a 100644 --- a/tmux.c +++ b/tmux.c @@ -44,10 +44,10 @@ struct hooks *global_hooks; struct timeval start_time; const char *socket_path; -__dead void usage(void); -static char *make_label(const char *); +static __dead void usage(void); +static char *make_label(const char *); -__dead void +static __dead void usage(void) { fprintf(stderr, diff --git a/tty-keys.c b/tty-keys.c index 81d541a5..174b008e 100644 --- a/tty-keys.c +++ b/tty-keys.c @@ -50,7 +50,7 @@ struct tty_default_key_raw { const char *string; key_code key; }; -const struct tty_default_key_raw tty_default_raw_keys[] = { +static const struct tty_default_key_raw tty_default_raw_keys[] = { /* * Numeric keypad. Just use the vt100 escape sequences here and always * put the terminal into keypad_xmit mode. Translation of numbers @@ -170,7 +170,7 @@ struct tty_default_key_code { enum tty_code_code code; key_code key; }; -const struct tty_default_key_code tty_default_code_keys[] = { +static const struct tty_default_key_code tty_default_code_keys[] = { /* Function keys. */ { TTYC_KF1, KEYC_F1 }, { TTYC_KF2, KEYC_F2 }, diff --git a/tty-term.c b/tty-term.c index 05ef01e7..2da8a8f5 100644 --- a/tty-term.c +++ b/tty-term.c @@ -27,8 +27,8 @@ #include "tmux.h" -void tty_term_override(struct tty_term *, const char *); -char *tty_term_strip(const char *); +static void tty_term_override(struct tty_term *, const char *); +static char *tty_term_strip(const char *); struct tty_terms tty_terms = LIST_HEAD_INITIALIZER(tty_terms); @@ -53,7 +53,7 @@ struct tty_term_code_entry { const char *name; }; -const struct tty_term_code_entry tty_term_codes[] = { +static const struct tty_term_code_entry tty_term_codes[] = { [TTYC_ACSC] = { TTYCODE_STRING, "acsc" }, [TTYC_AX] = { TTYCODE_FLAG, "AX" }, [TTYC_BCE] = { TTYCODE_FLAG, "bce" }, @@ -264,7 +264,7 @@ tty_term_ncodes(void) return (nitems(tty_term_codes)); } -char * +static char * tty_term_strip(const char *s) { const char *ptr; @@ -293,7 +293,7 @@ tty_term_strip(const char *s) return (xstrdup(buf)); } -void +static void tty_term_override(struct tty_term *term, const char *overrides) { const struct tty_term_code_entry *ent; diff --git a/tty.c b/tty.c index 6cb0ef67..f9b5c89d 100644 --- a/tty.c +++ b/tty.c @@ -31,31 +31,32 @@ #include "tmux.h" -static int tty_log_fd = -1; +static int tty_log_fd = -1; -void tty_read_callback(struct bufferevent *, void *); -void tty_error_callback(struct bufferevent *, short, void *); +static void tty_read_callback(struct bufferevent *, void *); +static void tty_error_callback(struct bufferevent *, short, void *); -static int tty_client_ready(struct client *, struct window_pane *); +static int tty_client_ready(struct client *, struct window_pane *); -void tty_set_italics(struct tty *); -int tty_try_colour(struct tty *, int, const char *); +static void tty_set_italics(struct tty *); +static int tty_try_colour(struct tty *, int, const char *); -void tty_colours(struct tty *, const struct grid_cell *); -void tty_check_fg(struct tty *, struct grid_cell *); -void tty_check_bg(struct tty *, struct grid_cell *); -void tty_colours_fg(struct tty *, const struct grid_cell *); -void tty_colours_bg(struct tty *, const struct grid_cell *); +static void tty_colours(struct tty *, const struct grid_cell *); +static void tty_check_fg(struct tty *, struct grid_cell *); +static void tty_check_bg(struct tty *, struct grid_cell *); +static void tty_colours_fg(struct tty *, const struct grid_cell *); +static void tty_colours_bg(struct tty *, const struct grid_cell *); -int tty_large_region(struct tty *, const struct tty_ctx *); -int tty_fake_bce(const struct tty *, const struct window_pane *); -void tty_redraw_region(struct tty *, const struct tty_ctx *); -void tty_emulate_repeat(struct tty *, enum tty_code_code, enum tty_code_code, - u_int); -void tty_repeat_space(struct tty *, u_int); -void tty_cell(struct tty *, const struct grid_cell *, - const struct window_pane *); -void tty_default_colours(struct grid_cell *, const struct window_pane *); +static int tty_large_region(struct tty *, const struct tty_ctx *); +static int tty_fake_bce(const struct tty *, const struct window_pane *); +static void tty_redraw_region(struct tty *, const struct tty_ctx *); +static void tty_emulate_repeat(struct tty *, enum tty_code_code, + enum tty_code_code, u_int); +static void tty_repeat_space(struct tty *, u_int); +static void tty_cell(struct tty *, const struct grid_cell *, + const struct window_pane *); +static void tty_default_colours(struct grid_cell *, + const struct window_pane *); #define tty_use_acs(tty) \ (tty_term_has((tty)->term, TTYC_ACSC) && !((tty)->flags & TTY_UTF8)) @@ -173,7 +174,7 @@ tty_open(struct tty *tty, char **cause) return (0); } -void +static void tty_read_callback(__unused struct bufferevent *bufev, void *data) { struct tty *tty = data; @@ -182,7 +183,7 @@ tty_read_callback(__unused struct bufferevent *bufev, void *data) ; } -void +static void tty_error_callback(__unused struct bufferevent *bufev, __unused short what, __unused void *data) { @@ -450,7 +451,7 @@ tty_putn(struct tty *tty, const void *buf, size_t len, u_int width) tty->cx += width; } -void +static void tty_set_italics(struct tty *tty) { const char *s; @@ -559,7 +560,7 @@ tty_update_mode(struct tty *tty, int mode, struct screen *s) tty->mode = mode; } -void +static void tty_emulate_repeat(struct tty *tty, enum tty_code_code code, enum tty_code_code code1, u_int n) { @@ -571,7 +572,7 @@ tty_emulate_repeat(struct tty *tty, enum tty_code_code code, } } -void +static void tty_repeat_space(struct tty *tty, u_int n) { while (n-- > 0) @@ -583,7 +584,7 @@ tty_repeat_space(struct tty *tty, u_int n) * probably several times now? Currently yes if it is more than 50% of the * pane. */ -int +static int tty_large_region(__unused struct tty *tty, const struct tty_ctx *ctx) { struct window_pane *wp = ctx->wp; @@ -595,7 +596,7 @@ tty_large_region(__unused struct tty *tty, const struct tty_ctx *ctx) * Return if BCE is needed but the terminal doesn't have it - it'll need to be * emulated. */ -int +static int tty_fake_bce(const struct tty *tty, const struct window_pane *wp) { struct grid_cell gc; @@ -614,7 +615,7 @@ tty_fake_bce(const struct tty *tty, const struct window_pane *wp) * CSR not supported, or window is a pane that doesn't take up the full * width of the terminal. */ -void +static void tty_redraw_region(struct tty *tty, const struct tty_ctx *ctx) { struct window_pane *wp = ctx->wp; @@ -1129,7 +1130,7 @@ tty_cmd_rawstring(struct tty *tty, const struct tty_ctx *ctx) tty_cursor(tty, 0, 0); } -void +static void tty_cell(struct tty *tty, const struct grid_cell *gc, const struct window_pane *wp) { @@ -1419,7 +1420,7 @@ tty_attributes(struct tty *tty, const struct grid_cell *gc, tty_putcode(tty, TTYC_SMACS); } -void +static void tty_colours(struct tty *tty, const struct grid_cell *gc) { struct grid_cell *tc = &tty->cell; @@ -1559,7 +1560,7 @@ tty_check_bg(struct tty *tty, struct grid_cell *gc) gc->bg -= 90; } -void +static void tty_colours_fg(struct tty *tty, const struct grid_cell *gc) { struct grid_cell *tc = &tty->cell; @@ -1589,7 +1590,7 @@ save_fg: tc->fg = gc->fg; } -void +static void tty_colours_bg(struct tty *tty, const struct grid_cell *gc) { struct grid_cell *tc = &tty->cell; @@ -1619,7 +1620,7 @@ save_bg: tc->bg = gc->bg; } -int +static int tty_try_colour(struct tty *tty, int colour, const char *type) { u_char r, g, b; @@ -1672,7 +1673,7 @@ fallback_256: return (0); } -void +static void tty_default_colours(struct grid_cell *gc, const struct window_pane *wp) { struct window *w = wp->window; -- cgit From a81685bfac9d4eac3a7cfd8f8ce13033a46fe01c Mon Sep 17 00:00:00 2001 From: nicm Date: Mon, 10 Oct 2016 21:51:39 +0000 Subject: Add static in cmd-* and fix a few other nits. --- cmd-attach-session.c | 4 +-- cmd-bind-key.c | 10 +++--- cmd-break-pane.c | 4 +-- cmd-capture-pane.c | 21 +++++------ cmd-choose-buffer.c | 4 +-- cmd-choose-client.c | 8 ++--- cmd-choose-tree.c | 4 +-- cmd-clear-history.c | 4 +-- cmd-command-prompt.c | 12 +++---- cmd-confirm-before.c | 12 +++---- cmd-copy-mode.c | 4 +-- cmd-detach-client.c | 4 +-- cmd-display-message.c | 4 +-- cmd-find-window.c | 18 +++++----- cmd-find.c | 98 +++++++++++++++++++++++--------------------------- cmd-if-shell.c | 16 ++++----- cmd-join-pane.c | 18 +++++----- cmd-kill-pane.c | 4 +-- cmd-kill-server.c | 4 +-- cmd-kill-session.c | 4 +-- cmd-kill-window.c | 4 +-- cmd-list-buffers.c | 4 +-- cmd-list-clients.c | 4 +-- cmd-list-panes.c | 20 +++++------ cmd-list-sessions.c | 4 +-- cmd-list-windows.c | 14 ++++---- cmd-load-buffer.c | 9 ++--- cmd-lock-server.c | 4 +-- cmd-move-window.c | 4 +-- cmd-new-session.c | 4 +-- cmd-new-window.c | 4 +-- cmd-paste-buffer.c | 7 ++-- cmd-pipe-pane.c | 8 ++--- cmd-refresh-client.c | 4 +-- cmd-rename-session.c | 4 +-- cmd-rename-window.c | 4 +-- cmd-resize-pane.c | 15 ++++---- cmd-respawn-pane.c | 4 +-- cmd-respawn-window.c | 4 +-- cmd-rotate-window.c | 4 +-- cmd-run-shell.c | 16 ++++----- cmd-save-buffer.c | 4 +-- cmd-select-layout.c | 4 +-- cmd-select-pane.c | 4 +-- cmd-select-window.c | 4 +-- cmd-send-keys.c | 4 +-- cmd-set-buffer.c | 4 +-- cmd-set-environment.c | 4 +-- cmd-set-hook.c | 4 +-- cmd-set-option.c | 60 +++++++++++++++---------------- cmd-show-environment.c | 14 ++++---- cmd-show-messages.c | 12 +++---- cmd-show-options.c | 16 ++++----- cmd-source-file.c | 8 ++--- cmd-split-window.c | 4 +-- cmd-string.c | 31 ++++++++-------- cmd-swap-pane.c | 4 +-- cmd-swap-window.c | 4 +-- cmd-switch-client.c | 4 +-- cmd-unbind-key.c | 10 +++--- cmd-wait-for.c | 45 ++++++++++++----------- window-clock.c | 26 +++++++------- 62 files changed, 333 insertions(+), 339 deletions(-) diff --git a/cmd-attach-session.c b/cmd-attach-session.c index 53c1df31..daab428f 100644 --- a/cmd-attach-session.c +++ b/cmd-attach-session.c @@ -30,7 +30,7 @@ * Attach existing session to the current terminal. */ -enum cmd_retval cmd_attach_session_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_attach_session_exec(struct cmd *, struct cmd_q *); const struct cmd_entry cmd_attach_session_entry = { .name = "attach-session", @@ -154,7 +154,7 @@ cmd_attach_session(struct cmd_q *cmdq, int dflag, int rflag, const char *cflag, return (CMD_RETURN_NORMAL); } -enum cmd_retval +static enum cmd_retval cmd_attach_session_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; diff --git a/cmd-bind-key.c b/cmd-bind-key.c index 88767245..bcc179c3 100644 --- a/cmd-bind-key.c +++ b/cmd-bind-key.c @@ -27,10 +27,10 @@ * Bind a key to a command, this recurses through cmd_*. */ -enum cmd_retval cmd_bind_key_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_bind_key_exec(struct cmd *, struct cmd_q *); -enum cmd_retval cmd_bind_key_mode_table(struct cmd *, struct cmd_q *, - key_code); +static enum cmd_retval cmd_bind_key_mode_table(struct cmd *, struct cmd_q *, + key_code); const struct cmd_entry cmd_bind_key_entry = { .name = "bind-key", @@ -44,7 +44,7 @@ const struct cmd_entry cmd_bind_key_entry = { .exec = cmd_bind_key_exec }; -enum cmd_retval +static enum cmd_retval cmd_bind_key_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; @@ -93,7 +93,7 @@ cmd_bind_key_exec(struct cmd *self, struct cmd_q *cmdq) return (CMD_RETURN_NORMAL); } -enum cmd_retval +static enum cmd_retval cmd_bind_key_mode_table(struct cmd *self, struct cmd_q *cmdq, key_code key) { struct args *args = self->args; diff --git a/cmd-break-pane.c b/cmd-break-pane.c index 85873227..b57542aa 100644 --- a/cmd-break-pane.c +++ b/cmd-break-pane.c @@ -28,7 +28,7 @@ #define BREAK_PANE_TEMPLATE "#{session_name}:#{window_index}.#{pane_index}" -enum cmd_retval cmd_break_pane_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_break_pane_exec(struct cmd *, struct cmd_q *); const struct cmd_entry cmd_break_pane_entry = { .name = "break-pane", @@ -44,7 +44,7 @@ const struct cmd_entry cmd_break_pane_entry = { .exec = cmd_break_pane_exec }; -enum cmd_retval +static enum cmd_retval cmd_break_pane_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; diff --git a/cmd-capture-pane.c b/cmd-capture-pane.c index 33f6cf08..e468674d 100644 --- a/cmd-capture-pane.c +++ b/cmd-capture-pane.c @@ -27,13 +27,14 @@ * Write the entire contents of a pane to a buffer or stdout. */ -enum cmd_retval cmd_capture_pane_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_capture_pane_exec(struct cmd *, struct cmd_q *); -char *cmd_capture_pane_append(char *, size_t *, char *, size_t); -char *cmd_capture_pane_pending(struct args *, struct window_pane *, - size_t *); -char *cmd_capture_pane_history(struct args *, struct cmd_q *, - struct window_pane *, size_t *); +static char *cmd_capture_pane_append(char *, size_t *, char *, + size_t); +static char *cmd_capture_pane_pending(struct args *, + struct window_pane *, size_t *); +static char *cmd_capture_pane_history(struct args *, struct cmd_q *, + struct window_pane *, size_t *); const struct cmd_entry cmd_capture_pane_entry = { .name = "capture-pane", @@ -49,7 +50,7 @@ const struct cmd_entry cmd_capture_pane_entry = { .exec = cmd_capture_pane_exec }; -char * +static char * cmd_capture_pane_append(char *buf, size_t *len, char *line, size_t linelen) { buf = xrealloc(buf, *len + linelen + 1); @@ -58,7 +59,7 @@ cmd_capture_pane_append(char *buf, size_t *len, char *line, size_t linelen) return (buf); } -char * +static char * cmd_capture_pane_pending(struct args *args, struct window_pane *wp, size_t *len) { @@ -90,7 +91,7 @@ cmd_capture_pane_pending(struct args *args, struct window_pane *wp, return (buf); } -char * +static char * cmd_capture_pane_history(struct args *args, struct cmd_q *cmdq, struct window_pane *wp, size_t *len) { @@ -175,7 +176,7 @@ cmd_capture_pane_history(struct args *args, struct cmd_q *cmdq, return (buf); } -enum cmd_retval +static enum cmd_retval cmd_capture_pane_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; diff --git a/cmd-choose-buffer.c b/cmd-choose-buffer.c index 90872e90..fee4958a 100644 --- a/cmd-choose-buffer.c +++ b/cmd-choose-buffer.c @@ -30,7 +30,7 @@ #define CHOOSE_BUFFER_TEMPLATE \ "#{buffer_name}: #{buffer_size} bytes: #{buffer_sample}" -enum cmd_retval cmd_choose_buffer_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_choose_buffer_exec(struct cmd *, struct cmd_q *); const struct cmd_entry cmd_choose_buffer_entry = { .name = "choose-buffer", @@ -45,7 +45,7 @@ const struct cmd_entry cmd_choose_buffer_entry = { .exec = cmd_choose_buffer_exec }; -enum cmd_retval +static enum cmd_retval cmd_choose_buffer_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; diff --git a/cmd-choose-client.c b/cmd-choose-client.c index b9a24be6..67d184b3 100644 --- a/cmd-choose-client.c +++ b/cmd-choose-client.c @@ -33,9 +33,9 @@ "#{?client_utf8, (utf8),}#{?client_readonly, (ro),} " \ "(last used #{t:client_activity})" -enum cmd_retval cmd_choose_client_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_choose_client_exec(struct cmd *, struct cmd_q *); -void cmd_choose_client_callback(struct window_choose_data *); +static void cmd_choose_client_callback(struct window_choose_data *); const struct cmd_entry cmd_choose_client_entry = { .name = "choose-client", @@ -54,7 +54,7 @@ struct cmd_choose_client_data { struct client *client; }; -enum cmd_retval +static enum cmd_retval cmd_choose_client_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; @@ -110,7 +110,7 @@ cmd_choose_client_exec(struct cmd *self, struct cmd_q *cmdq) return (CMD_RETURN_NORMAL); } -void +static void cmd_choose_client_callback(struct window_choose_data *cdata) { struct client *c; diff --git a/cmd-choose-tree.c b/cmd-choose-tree.c index db9222ba..13bbe2a7 100644 --- a/cmd-choose-tree.c +++ b/cmd-choose-tree.c @@ -41,7 +41,7 @@ "#{window_index}: #{window_name}#{window_flags} " \ "\"#{pane_title}\"" -enum cmd_retval cmd_choose_tree_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_choose_tree_exec(struct cmd *, struct cmd_q *); const struct cmd_entry cmd_choose_tree_entry = { .name = "choose-tree", @@ -83,7 +83,7 @@ const struct cmd_entry cmd_choose_window_entry = { .exec = cmd_choose_tree_exec }; -enum cmd_retval +static enum cmd_retval cmd_choose_tree_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; diff --git a/cmd-clear-history.c b/cmd-clear-history.c index 62683ff6..a1da256d 100644 --- a/cmd-clear-history.c +++ b/cmd-clear-history.c @@ -24,7 +24,7 @@ * Clear pane history. */ -enum cmd_retval cmd_clear_history_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_clear_history_exec(struct cmd *, struct cmd_q *); const struct cmd_entry cmd_clear_history_entry = { .name = "clear-history", @@ -39,7 +39,7 @@ const struct cmd_entry cmd_clear_history_entry = { .exec = cmd_clear_history_exec }; -enum cmd_retval +static enum cmd_retval cmd_clear_history_exec(__unused struct cmd *self, struct cmd_q *cmdq) { struct window_pane *wp = cmdq->state.tflag.wp; diff --git a/cmd-command-prompt.c b/cmd-command-prompt.c index 3ec22865..a2fc1278 100644 --- a/cmd-command-prompt.c +++ b/cmd-command-prompt.c @@ -29,10 +29,10 @@ * Prompt for command in client. */ -enum cmd_retval cmd_command_prompt_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_command_prompt_exec(struct cmd *, struct cmd_q *); -int cmd_command_prompt_callback(void *, const char *); -void cmd_command_prompt_free(void *); +static int cmd_command_prompt_callback(void *, const char *); +static void cmd_command_prompt_free(void *); const struct cmd_entry cmd_command_prompt_entry = { .name = "command-prompt", @@ -58,7 +58,7 @@ struct cmd_command_prompt_cdata { int idx; }; -enum cmd_retval +static enum cmd_retval cmd_command_prompt_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; @@ -115,7 +115,7 @@ cmd_command_prompt_exec(struct cmd *self, struct cmd_q *cmdq) return (CMD_RETURN_NORMAL); } -int +static int cmd_command_prompt_callback(void *data, const char *s) { struct cmd_command_prompt_cdata *cdata = data; @@ -162,7 +162,7 @@ cmd_command_prompt_callback(void *data, const char *s) return (0); } -void +static void cmd_command_prompt_free(void *data) { struct cmd_command_prompt_cdata *cdata = data; diff --git a/cmd-confirm-before.c b/cmd-confirm-before.c index b5a12821..4241aefb 100644 --- a/cmd-confirm-before.c +++ b/cmd-confirm-before.c @@ -28,10 +28,10 @@ * Asks for confirmation before executing a command. */ -enum cmd_retval cmd_confirm_before_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_confirm_before_exec(struct cmd *, struct cmd_q *); -int cmd_confirm_before_callback(void *, const char *); -void cmd_confirm_before_free(void *); +static int cmd_confirm_before_callback(void *, const char *); +static void cmd_confirm_before_free(void *); const struct cmd_entry cmd_confirm_before_entry = { .name = "confirm-before", @@ -51,7 +51,7 @@ struct cmd_confirm_before_data { struct client *client; }; -enum cmd_retval +static enum cmd_retval cmd_confirm_before_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; @@ -83,7 +83,7 @@ cmd_confirm_before_exec(struct cmd *self, struct cmd_q *cmdq) return (CMD_RETURN_NORMAL); } -int +static int cmd_confirm_before_callback(void *data, const char *s) { struct cmd_confirm_before_data *cdata = data; @@ -113,7 +113,7 @@ cmd_confirm_before_callback(void *data, const char *s) return (0); } -void +static void cmd_confirm_before_free(void *data) { struct cmd_confirm_before_data *cdata = data; diff --git a/cmd-copy-mode.c b/cmd-copy-mode.c index d785e893..6b99c347 100644 --- a/cmd-copy-mode.c +++ b/cmd-copy-mode.c @@ -24,7 +24,7 @@ * Enter copy or clock mode. */ -enum cmd_retval cmd_copy_mode_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_copy_mode_exec(struct cmd *, struct cmd_q *); const struct cmd_entry cmd_copy_mode_entry = { .name = "copy-mode", @@ -52,7 +52,7 @@ const struct cmd_entry cmd_clock_mode_entry = { .exec = cmd_copy_mode_exec }; -enum cmd_retval +static enum cmd_retval cmd_copy_mode_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; diff --git a/cmd-detach-client.c b/cmd-detach-client.c index 80c6555f..814ba091 100644 --- a/cmd-detach-client.c +++ b/cmd-detach-client.c @@ -26,7 +26,7 @@ * Detach a client. */ -enum cmd_retval cmd_detach_client_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_detach_client_exec(struct cmd *, struct cmd_q *); const struct cmd_entry cmd_detach_client_entry = { .name = "detach-client", @@ -55,7 +55,7 @@ const struct cmd_entry cmd_suspend_client_entry = { .exec = cmd_detach_client_exec }; -enum cmd_retval +static enum cmd_retval cmd_detach_client_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; diff --git a/cmd-display-message.c b/cmd-display-message.c index 217d164a..05e84561 100644 --- a/cmd-display-message.c +++ b/cmd-display-message.c @@ -32,7 +32,7 @@ "#{window_name}, current pane #{pane_index} " \ "- (%H:%M %d-%b-%y)" -enum cmd_retval cmd_display_message_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_display_message_exec(struct cmd *, struct cmd_q *); const struct cmd_entry cmd_display_message_entry = { .name = "display-message", @@ -49,7 +49,7 @@ const struct cmd_entry cmd_display_message_entry = { .exec = cmd_display_message_exec }; -enum cmd_retval +static enum cmd_retval cmd_display_message_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; diff --git a/cmd-find-window.c b/cmd-find-window.c index 6324f26a..6ab6fbcf 100644 --- a/cmd-find-window.c +++ b/cmd-find-window.c @@ -33,9 +33,9 @@ "[#{window_width}x#{window_height}] " \ "(#{window_panes} panes) #{window_find_matches}" -enum cmd_retval cmd_find_window_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_find_window_exec(struct cmd *, struct cmd_q *); -void cmd_find_window_callback(struct window_choose_data *); +static void cmd_find_window_callback(struct window_choose_data *); /* Flags for determining matching behavior. */ #define CMD_FIND_WINDOW_BY_TITLE 0x1 @@ -68,11 +68,11 @@ struct cmd_find_window_data { }; TAILQ_HEAD(cmd_find_window_list, cmd_find_window_data); -u_int cmd_find_window_match_flags(struct args *); -void cmd_find_window_match(struct cmd_find_window_list *, int, - struct winlink *, const char *, const char *); +static u_int cmd_find_window_match_flags(struct args *); +static void cmd_find_window_match(struct cmd_find_window_list *, int, + struct winlink *, const char *, const char *); -u_int +static u_int cmd_find_window_match_flags(struct args *args) { u_int match_flags = 0; @@ -92,7 +92,7 @@ cmd_find_window_match_flags(struct args *args) return (match_flags); } -void +static void cmd_find_window_match(struct cmd_find_window_list *find_list, int match_flags, struct winlink *wl, const char *str, const char *searchstr) @@ -138,7 +138,7 @@ cmd_find_window_match(struct cmd_find_window_list *find_list, free(find_data); } -enum cmd_retval +static enum cmd_retval cmd_find_window_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; @@ -216,7 +216,7 @@ out: return (CMD_RETURN_NORMAL); } -void +static void cmd_find_window_callback(struct window_choose_data *cdata) { struct session *s; diff --git a/cmd-find.c b/cmd-find.c index 22511201..dec386ac 100644 --- a/cmd-find.c +++ b/cmd-find.c @@ -27,33 +27,35 @@ #include "tmux.h" -struct session *cmd_find_try_TMUX(struct client *, struct window *); -int cmd_find_client_better(struct client *, struct client *); -struct client *cmd_find_best_client(struct client **, u_int); -int cmd_find_session_better(struct session *, struct session *, - int); -struct session *cmd_find_best_session(struct session **, u_int, int); -int cmd_find_best_session_with_window(struct cmd_find_state *); -int cmd_find_best_winlink_with_window(struct cmd_find_state *); - -int cmd_find_current_session_with_client(struct cmd_find_state *); -int cmd_find_current_session(struct cmd_find_state *); -struct client *cmd_find_current_client(struct cmd_q *); - -const char *cmd_find_map_table(const char *[][2], const char *); - -int cmd_find_get_session(struct cmd_find_state *, const char *); -int cmd_find_get_window(struct cmd_find_state *, const char *); -int cmd_find_get_window_with_session(struct cmd_find_state *, const char *); -int cmd_find_get_window_with_pane(struct cmd_find_state *); -int cmd_find_get_pane(struct cmd_find_state *, const char *); -int cmd_find_get_pane_with_session(struct cmd_find_state *, const char *); -int cmd_find_get_pane_with_window(struct cmd_find_state *, const char *); - -const char *cmd_find_session_table[][2] = { +static struct session *cmd_find_try_TMUX(struct client *, struct window *); +static int cmd_find_client_better(struct client *, struct client *); +static struct client *cmd_find_best_client(struct client **, u_int); +static int cmd_find_session_better(struct session *, struct session *, + int); +static struct session *cmd_find_best_session(struct session **, u_int, int); +static int cmd_find_best_session_with_window(struct cmd_find_state *); +static int cmd_find_best_winlink_with_window(struct cmd_find_state *); + +static int cmd_find_current_session_with_client(struct cmd_find_state *); +static int cmd_find_current_session(struct cmd_find_state *); +static struct client *cmd_find_current_client(struct cmd_q *); + +static const char *cmd_find_map_table(const char *[][2], const char *); + +static int cmd_find_get_session(struct cmd_find_state *, const char *); +static int cmd_find_get_window(struct cmd_find_state *, const char *); +static int cmd_find_get_window_with_session(struct cmd_find_state *, + const char *); +static int cmd_find_get_pane(struct cmd_find_state *, const char *); +static int cmd_find_get_pane_with_session(struct cmd_find_state *, + const char *); +static int cmd_find_get_pane_with_window(struct cmd_find_state *, + const char *); + +static const char *cmd_find_session_table[][2] = { { NULL, NULL } }; -const char *cmd_find_window_table[][2] = { +static const char *cmd_find_window_table[][2] = { { "{start}", "^" }, { "{last}", "!" }, { "{end}", "$" }, @@ -61,7 +63,7 @@ const char *cmd_find_window_table[][2] = { { "{previous}", "-" }, { NULL, NULL } }; -const char *cmd_find_pane_table[][2] = { +static const char *cmd_find_pane_table[][2] = { { "{last}", "!" }, { "{next}", "+" }, { "{previous}", "-" }, @@ -81,7 +83,7 @@ const char *cmd_find_pane_table[][2] = { }; /* Get session from TMUX if present. */ -struct session * +static struct session * cmd_find_try_TMUX(struct client *c, struct window *w) { struct environ_entry *envent; @@ -108,7 +110,7 @@ cmd_find_try_TMUX(struct client *c, struct window *w) } /* Is this client better? */ -int +static int cmd_find_client_better(struct client *c, struct client *than) { if (than == NULL) @@ -117,7 +119,7 @@ cmd_find_client_better(struct client *c, struct client *than) } /* Find best client from a list, or all if list is NULL. */ -struct client * +static struct client * cmd_find_best_client(struct client **clist, u_int csize) { struct client *c_loop, *c; @@ -143,7 +145,7 @@ cmd_find_best_client(struct client **clist, u_int csize) } /* Is this session better? */ -int +static int cmd_find_session_better(struct session *s, struct session *than, int flags) { int attached; @@ -161,7 +163,7 @@ cmd_find_session_better(struct session *s, struct session *than, int flags) } /* Find best session from a list, or all if list is NULL. */ -struct session * +static struct session * cmd_find_best_session(struct session **slist, u_int ssize, int flags) { struct session *s_loop, *s; @@ -183,7 +185,7 @@ cmd_find_best_session(struct session **slist, u_int ssize, int flags) } /* Find best session and winlink for window. */ -int +static int cmd_find_best_session_with_window(struct cmd_find_state *fs) { struct session **slist = NULL; @@ -220,7 +222,7 @@ fail: * Find the best winlink for a window (the current if it contains the pane, * otherwise the first). */ -int +static int cmd_find_best_winlink_with_window(struct cmd_find_state *fs) { struct winlink *wl, *wl_loop; @@ -244,7 +246,7 @@ cmd_find_best_winlink_with_window(struct cmd_find_state *fs) } /* Find current session when we have an unattached client. */ -int +static int cmd_find_current_session_with_client(struct cmd_find_state *fs) { struct window_pane *wp; @@ -308,7 +310,7 @@ unknown_pane: * Work out the best current state. If this function succeeds, the state is * guaranteed to be completely filled in. */ -int +static int cmd_find_current_session(struct cmd_find_state *fs) { /* If we know the current client, use it. */ @@ -338,7 +340,7 @@ cmd_find_current_session(struct cmd_find_state *fs) } /* Work out the best current client. */ -struct client * +static struct client * cmd_find_current_client(struct cmd_q *cmdq) { struct cmd_find_state current; @@ -384,7 +386,7 @@ cmd_find_current_client(struct cmd_q *cmdq) } /* Maps string in table. */ -const char * +static const char * cmd_find_map_table(const char *table[][2], const char *s) { u_int i; @@ -397,7 +399,7 @@ cmd_find_map_table(const char *table[][2], const char *s) } /* Find session from string. Fills in s. */ -int +static int cmd_find_get_session(struct cmd_find_state *fs, const char *session) { struct session *s, *s_loop; @@ -461,7 +463,7 @@ cmd_find_get_session(struct cmd_find_state *fs, const char *session) } /* Find window from string. Fills in s, wl, w. */ -int +static int cmd_find_get_window(struct cmd_find_state *fs, const char *window) { log_debug("%s: %s", __func__, window); @@ -497,7 +499,7 @@ cmd_find_get_window(struct cmd_find_state *fs, const char *window) * Find window from string, assuming it is in given session. Needs s, fills in * wl and w. */ -int +static int cmd_find_get_window_with_session(struct cmd_find_state *fs, const char *window) { struct winlink *wl; @@ -647,18 +649,8 @@ cmd_find_get_window_with_session(struct cmd_find_state *fs, const char *window) return (-1); } -/* Find window from given pane. Needs wp, fills in s and wl and w. */ -int -cmd_find_get_window_with_pane(struct cmd_find_state *fs) -{ - log_debug("%s", __func__); - - fs->w = fs->wp->window; - return (cmd_find_best_session_with_window(fs)); -} - /* Find pane from string. Fills in s, wl, w, wp. */ -int +static int cmd_find_get_pane(struct cmd_find_state *fs, const char *pane) { log_debug("%s: %s", __func__, pane); @@ -695,7 +687,7 @@ cmd_find_get_pane(struct cmd_find_state *fs, const char *pane) * Find pane from string, assuming it is in given session. Needs s, fills in wl * and w and wp. */ -int +static int cmd_find_get_pane_with_session(struct cmd_find_state *fs, const char *pane) { log_debug("%s: %s", __func__, pane); @@ -722,7 +714,7 @@ cmd_find_get_pane_with_session(struct cmd_find_state *fs, const char *pane) * Find pane from string, assuming it is in the given window. Needs w, fills in * wp. */ -int +static int cmd_find_get_pane_with_window(struct cmd_find_state *fs, const char *pane) { const char *errstr; diff --git a/cmd-if-shell.c b/cmd-if-shell.c index 3dc20cd1..615da2b6 100644 --- a/cmd-if-shell.c +++ b/cmd-if-shell.c @@ -29,11 +29,11 @@ * Executes a tmux command if a shell command returns true or false. */ -enum cmd_retval cmd_if_shell_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_if_shell_exec(struct cmd *, struct cmd_q *); -void cmd_if_shell_callback(struct job *); -void cmd_if_shell_done(struct cmd_q *); -void cmd_if_shell_free(void *); +static void cmd_if_shell_callback(struct job *); +static void cmd_if_shell_done(struct cmd_q *); +static void cmd_if_shell_free(void *); const struct cmd_entry cmd_if_shell_entry = { .name = "if-shell", @@ -63,7 +63,7 @@ struct cmd_if_shell_data { int references; }; -enum cmd_retval +static enum cmd_retval cmd_if_shell_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; @@ -137,7 +137,7 @@ cmd_if_shell_exec(struct cmd *self, struct cmd_q *cmdq) return (CMD_RETURN_WAIT); } -void +static void cmd_if_shell_callback(struct job *job) { struct cmd_if_shell_data *cdata = job->data; @@ -174,7 +174,7 @@ cmd_if_shell_callback(struct job *job) cmd_list_free(cmdlist); } -void +static void cmd_if_shell_done(struct cmd_q *cmdq1) { struct cmd_if_shell_data *cdata = cmdq1->data; @@ -197,7 +197,7 @@ cmd_if_shell_done(struct cmd_q *cmdq1) free(cdata); } -void +static void cmd_if_shell_free(void *data) { struct cmd_if_shell_data *cdata = data; diff --git a/cmd-join-pane.c b/cmd-join-pane.c index 263e7dfc..3ff8f08e 100644 --- a/cmd-join-pane.c +++ b/cmd-join-pane.c @@ -29,9 +29,7 @@ * Join or move a pane into another (like split/swap/kill). */ -enum cmd_retval cmd_join_pane_exec(struct cmd *, struct cmd_q *); - -enum cmd_retval join_pane(struct cmd *, struct cmd_q *, int); +static enum cmd_retval cmd_join_pane_exec(struct cmd *, struct cmd_q *); const struct cmd_entry cmd_join_pane_entry = { .name = "join-pane", @@ -61,14 +59,8 @@ const struct cmd_entry cmd_move_pane_entry = { .exec = cmd_join_pane_exec }; -enum cmd_retval +static enum cmd_retval cmd_join_pane_exec(struct cmd *self, struct cmd_q *cmdq) -{ - return (join_pane(self, cmdq, self->entry == &cmd_join_pane_entry)); -} - -enum cmd_retval -join_pane(struct cmd *self, struct cmd_q *cmdq, int not_same_window) { struct args *args = self->args; struct session *dst_s; @@ -79,6 +71,12 @@ join_pane(struct cmd *self, struct cmd_q *cmdq, int not_same_window) int size, percentage, dst_idx; enum layout_type type; struct layout_cell *lc; + int not_same_window; + + if (self->entry == &cmd_join_pane_entry) + not_same_window = 1; + else + not_same_window = 0; dst_s = cmdq->state.tflag.s; dst_wl = cmdq->state.tflag.wl; diff --git a/cmd-kill-pane.c b/cmd-kill-pane.c index ebb2b8d6..76829aa3 100644 --- a/cmd-kill-pane.c +++ b/cmd-kill-pane.c @@ -26,7 +26,7 @@ * Kill pane. */ -enum cmd_retval cmd_kill_pane_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_kill_pane_exec(struct cmd *, struct cmd_q *); const struct cmd_entry cmd_kill_pane_entry = { .name = "kill-pane", @@ -41,7 +41,7 @@ const struct cmd_entry cmd_kill_pane_entry = { .exec = cmd_kill_pane_exec }; -enum cmd_retval +static enum cmd_retval cmd_kill_pane_exec(struct cmd *self, struct cmd_q *cmdq) { struct winlink *wl = cmdq->state.tflag.wl; diff --git a/cmd-kill-server.c b/cmd-kill-server.c index d1940c33..bbb4e8a0 100644 --- a/cmd-kill-server.c +++ b/cmd-kill-server.c @@ -27,7 +27,7 @@ * Kill the server and do nothing else. */ -enum cmd_retval cmd_kill_server_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_kill_server_exec(struct cmd *, struct cmd_q *); const struct cmd_entry cmd_kill_server_entry = { .name = "kill-server", @@ -51,7 +51,7 @@ const struct cmd_entry cmd_start_server_entry = { .exec = cmd_kill_server_exec }; -enum cmd_retval +static enum cmd_retval cmd_kill_server_exec(struct cmd *self, __unused struct cmd_q *cmdq) { if (self->entry == &cmd_kill_server_entry) diff --git a/cmd-kill-session.c b/cmd-kill-session.c index c77e45bb..ec7d5fb2 100644 --- a/cmd-kill-session.c +++ b/cmd-kill-session.c @@ -27,7 +27,7 @@ * Note this deliberately has no alias to make it hard to hit by accident. */ -enum cmd_retval cmd_kill_session_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_kill_session_exec(struct cmd *, struct cmd_q *); const struct cmd_entry cmd_kill_session_entry = { .name = "kill-session", @@ -42,7 +42,7 @@ const struct cmd_entry cmd_kill_session_entry = { .exec = cmd_kill_session_exec }; -enum cmd_retval +static enum cmd_retval cmd_kill_session_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; diff --git a/cmd-kill-window.c b/cmd-kill-window.c index 9d388ce5..c7534d5c 100644 --- a/cmd-kill-window.c +++ b/cmd-kill-window.c @@ -24,7 +24,7 @@ * Destroy window. */ -enum cmd_retval cmd_kill_window_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_kill_window_exec(struct cmd *, struct cmd_q *); const struct cmd_entry cmd_kill_window_entry = { .name = "kill-window", @@ -52,7 +52,7 @@ const struct cmd_entry cmd_unlink_window_entry = { .exec = cmd_kill_window_exec }; -enum cmd_retval +static enum cmd_retval cmd_kill_window_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; diff --git a/cmd-list-buffers.c b/cmd-list-buffers.c index 238b2776..41ad865b 100644 --- a/cmd-list-buffers.c +++ b/cmd-list-buffers.c @@ -30,7 +30,7 @@ #define LIST_BUFFERS_TEMPLATE \ "#{buffer_name}: #{buffer_size} bytes: \"#{buffer_sample}\"" -enum cmd_retval cmd_list_buffers_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_list_buffers_exec(struct cmd *, struct cmd_q *); const struct cmd_entry cmd_list_buffers_entry = { .name = "list-buffers", @@ -43,7 +43,7 @@ const struct cmd_entry cmd_list_buffers_entry = { .exec = cmd_list_buffers_exec }; -enum cmd_retval +static enum cmd_retval cmd_list_buffers_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; diff --git a/cmd-list-clients.c b/cmd-list-clients.c index f318ac18..efe19652 100644 --- a/cmd-list-clients.c +++ b/cmd-list-clients.c @@ -33,7 +33,7 @@ "[#{client_width}x#{client_height} #{client_termname}]" \ "#{?client_utf8, (utf8),} #{?client_readonly, (ro),}" -enum cmd_retval cmd_list_clients_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_list_clients_exec(struct cmd *, struct cmd_q *); const struct cmd_entry cmd_list_clients_entry = { .name = "list-clients", @@ -48,7 +48,7 @@ const struct cmd_entry cmd_list_clients_entry = { .exec = cmd_list_clients_exec }; -enum cmd_retval +static enum cmd_retval cmd_list_clients_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; diff --git a/cmd-list-panes.c b/cmd-list-panes.c index 76e06a71..9d78589a 100644 --- a/cmd-list-panes.c +++ b/cmd-list-panes.c @@ -26,13 +26,13 @@ * List panes on given window. */ -enum cmd_retval cmd_list_panes_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_list_panes_exec(struct cmd *, struct cmd_q *); -void cmd_list_panes_server(struct cmd *, struct cmd_q *); -void cmd_list_panes_session(struct cmd *, struct session *, struct cmd_q *, - int); -void cmd_list_panes_window(struct cmd *, struct session *, struct winlink *, - struct cmd_q *, int); +static void cmd_list_panes_server(struct cmd *, struct cmd_q *); +static void cmd_list_panes_session(struct cmd *, struct session *, + struct cmd_q *, int); +static void cmd_list_panes_window(struct cmd *, struct session *, + struct winlink *, struct cmd_q *, int); const struct cmd_entry cmd_list_panes_entry = { .name = "list-panes", @@ -47,7 +47,7 @@ const struct cmd_entry cmd_list_panes_entry = { .exec = cmd_list_panes_exec }; -enum cmd_retval +static enum cmd_retval cmd_list_panes_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; @@ -64,7 +64,7 @@ cmd_list_panes_exec(struct cmd *self, struct cmd_q *cmdq) return (CMD_RETURN_NORMAL); } -void +static void cmd_list_panes_server(struct cmd *self, struct cmd_q *cmdq) { struct session *s; @@ -73,7 +73,7 @@ cmd_list_panes_server(struct cmd *self, struct cmd_q *cmdq) cmd_list_panes_session(self, s, cmdq, 2); } -void +static void cmd_list_panes_session(struct cmd *self, struct session *s, struct cmd_q *cmdq, int type) { @@ -83,7 +83,7 @@ cmd_list_panes_session(struct cmd *self, struct session *s, struct cmd_q *cmdq, cmd_list_panes_window(self, s, wl, cmdq, type); } -void +static void cmd_list_panes_window(struct cmd *self, struct session *s, struct winlink *wl, struct cmd_q *cmdq, int type) { diff --git a/cmd-list-sessions.c b/cmd-list-sessions.c index 27e80dbc..30a1f586 100644 --- a/cmd-list-sessions.c +++ b/cmd-list-sessions.c @@ -36,7 +36,7 @@ "#{session_group}#{?session_grouped,),}" \ "#{?session_attached, (attached),}" -enum cmd_retval cmd_list_sessions_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_list_sessions_exec(struct cmd *, struct cmd_q *); const struct cmd_entry cmd_list_sessions_entry = { .name = "list-sessions", @@ -49,7 +49,7 @@ const struct cmd_entry cmd_list_sessions_entry = { .exec = cmd_list_sessions_exec }; -enum cmd_retval +static enum cmd_retval cmd_list_sessions_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; diff --git a/cmd-list-windows.c b/cmd-list-windows.c index 11a5fddf..7ca49b3e 100644 --- a/cmd-list-windows.c +++ b/cmd-list-windows.c @@ -39,11 +39,11 @@ "(#{window_panes} panes) " \ "[#{window_width}x#{window_height}] " -enum cmd_retval cmd_list_windows_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_list_windows_exec(struct cmd *, struct cmd_q *); -void cmd_list_windows_server(struct cmd *, struct cmd_q *); -void cmd_list_windows_session(struct cmd *, struct session *, - struct cmd_q *, int); +static void cmd_list_windows_server(struct cmd *, struct cmd_q *); +static void cmd_list_windows_session(struct cmd *, struct session *, + struct cmd_q *, int); const struct cmd_entry cmd_list_windows_entry = { .name = "list-windows", @@ -58,7 +58,7 @@ const struct cmd_entry cmd_list_windows_entry = { .exec = cmd_list_windows_exec }; -enum cmd_retval +static enum cmd_retval cmd_list_windows_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; @@ -71,7 +71,7 @@ cmd_list_windows_exec(struct cmd *self, struct cmd_q *cmdq) return (CMD_RETURN_NORMAL); } -void +static void cmd_list_windows_server(struct cmd *self, struct cmd_q *cmdq) { struct session *s; @@ -80,7 +80,7 @@ cmd_list_windows_server(struct cmd *self, struct cmd_q *cmdq) cmd_list_windows_session(self, s, cmdq, 1); } -void +static void cmd_list_windows_session(struct cmd *self, struct session *s, struct cmd_q *cmdq, int type) { diff --git a/cmd-load-buffer.c b/cmd-load-buffer.c index de76b855..d97d139c 100644 --- a/cmd-load-buffer.c +++ b/cmd-load-buffer.c @@ -31,8 +31,9 @@ * Loads a paste buffer from a file. */ -enum cmd_retval cmd_load_buffer_exec(struct cmd *, struct cmd_q *); -void cmd_load_buffer_callback(struct client *, int, void *); +static enum cmd_retval cmd_load_buffer_exec(struct cmd *, struct cmd_q *); + +static void cmd_load_buffer_callback(struct client *, int, void *); const struct cmd_entry cmd_load_buffer_entry = { .name = "load-buffer", @@ -45,7 +46,7 @@ const struct cmd_entry cmd_load_buffer_entry = { .exec = cmd_load_buffer_exec }; -enum cmd_retval +static enum cmd_retval cmd_load_buffer_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; @@ -132,7 +133,7 @@ error: return (CMD_RETURN_ERROR); } -void +static void cmd_load_buffer_callback(struct client *c, int closed, void *data) { const char *bufname = data; diff --git a/cmd-lock-server.c b/cmd-lock-server.c index 01597169..2eef9952 100644 --- a/cmd-lock-server.c +++ b/cmd-lock-server.c @@ -24,7 +24,7 @@ * Lock commands. */ -enum cmd_retval cmd_lock_server_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_lock_server_exec(struct cmd *, struct cmd_q *); const struct cmd_entry cmd_lock_server_entry = { .name = "lock-server", @@ -63,7 +63,7 @@ const struct cmd_entry cmd_lock_client_entry = { .exec = cmd_lock_server_exec }; -enum cmd_retval +static enum cmd_retval cmd_lock_server_exec(struct cmd *self, __unused struct cmd_q *cmdq) { if (self->entry == &cmd_lock_server_entry) diff --git a/cmd-move-window.c b/cmd-move-window.c index aa683b83..1d423646 100644 --- a/cmd-move-window.c +++ b/cmd-move-window.c @@ -26,7 +26,7 @@ * Move a window. */ -enum cmd_retval cmd_move_window_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_move_window_exec(struct cmd *, struct cmd_q *); const struct cmd_entry cmd_move_window_entry = { .name = "move-window", @@ -56,7 +56,7 @@ const struct cmd_entry cmd_link_window_entry = { .exec = cmd_move_window_exec }; -enum cmd_retval +static enum cmd_retval cmd_move_window_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; diff --git a/cmd-new-session.c b/cmd-new-session.c index 357ffed1..f48872fc 100644 --- a/cmd-new-session.c +++ b/cmd-new-session.c @@ -33,7 +33,7 @@ #define NEW_SESSION_TEMPLATE "#{session_name}:" -enum cmd_retval cmd_new_session_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_new_session_exec(struct cmd *, struct cmd_q *); const struct cmd_entry cmd_new_session_entry = { .name = "new-session", @@ -63,7 +63,7 @@ const struct cmd_entry cmd_has_session_entry = { .exec = cmd_new_session_exec }; -enum cmd_retval +static enum cmd_retval cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; diff --git a/cmd-new-window.c b/cmd-new-window.c index 2a647b9f..edd44150 100644 --- a/cmd-new-window.c +++ b/cmd-new-window.c @@ -32,7 +32,7 @@ #define NEW_WINDOW_TEMPLATE "#{session_name}:#{window_index}.#{pane_index}" -enum cmd_retval cmd_new_window_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_new_window_exec(struct cmd *, struct cmd_q *); const struct cmd_entry cmd_new_window_entry = { .name = "new-window", @@ -48,7 +48,7 @@ const struct cmd_entry cmd_new_window_entry = { .exec = cmd_new_window_exec }; -enum cmd_retval +static enum cmd_retval cmd_new_window_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; diff --git a/cmd-paste-buffer.c b/cmd-paste-buffer.c index 8025975f..5f8b46c4 100644 --- a/cmd-paste-buffer.c +++ b/cmd-paste-buffer.c @@ -28,10 +28,7 @@ * Paste paste buffer if present. */ -enum cmd_retval cmd_paste_buffer_exec(struct cmd *, struct cmd_q *); - -void cmd_paste_buffer_filter(struct window_pane *, - const char *, size_t, const char *, int); +static enum cmd_retval cmd_paste_buffer_exec(struct cmd *, struct cmd_q *); const struct cmd_entry cmd_paste_buffer_entry = { .name = "paste-buffer", @@ -47,7 +44,7 @@ const struct cmd_entry cmd_paste_buffer_entry = { .exec = cmd_paste_buffer_exec }; -enum cmd_retval +static enum cmd_retval cmd_paste_buffer_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; diff --git a/cmd-pipe-pane.c b/cmd-pipe-pane.c index e59fc586..ea8ec527 100644 --- a/cmd-pipe-pane.c +++ b/cmd-pipe-pane.c @@ -33,9 +33,9 @@ * Open pipe to redirect pane output. If already open, close first. */ -enum cmd_retval cmd_pipe_pane_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_pipe_pane_exec(struct cmd *, struct cmd_q *); -void cmd_pipe_pane_error_callback(struct bufferevent *, short, void *); +static void cmd_pipe_pane_error_callback(struct bufferevent *, short, void *); const struct cmd_entry cmd_pipe_pane_entry = { .name = "pipe-pane", @@ -50,7 +50,7 @@ const struct cmd_entry cmd_pipe_pane_entry = { .exec = cmd_pipe_pane_exec }; -enum cmd_retval +static enum cmd_retval cmd_pipe_pane_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; @@ -142,7 +142,7 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmd_q *cmdq) } } -void +static void cmd_pipe_pane_error_callback(__unused struct bufferevent *bufev, __unused short what, void *data) { diff --git a/cmd-refresh-client.c b/cmd-refresh-client.c index 79e5aad0..79747f2c 100644 --- a/cmd-refresh-client.c +++ b/cmd-refresh-client.c @@ -24,7 +24,7 @@ * Refresh client. */ -enum cmd_retval cmd_refresh_client_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_refresh_client_exec(struct cmd *, struct cmd_q *); const struct cmd_entry cmd_refresh_client_entry = { .name = "refresh-client", @@ -39,7 +39,7 @@ const struct cmd_entry cmd_refresh_client_entry = { .exec = cmd_refresh_client_exec }; -enum cmd_retval +static enum cmd_retval cmd_refresh_client_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; diff --git a/cmd-rename-session.c b/cmd-rename-session.c index b40f44f7..7e9fd015 100644 --- a/cmd-rename-session.c +++ b/cmd-rename-session.c @@ -26,7 +26,7 @@ * Change session name. */ -enum cmd_retval cmd_rename_session_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_rename_session_exec(struct cmd *, struct cmd_q *); const struct cmd_entry cmd_rename_session_entry = { .name = "rename-session", @@ -41,7 +41,7 @@ const struct cmd_entry cmd_rename_session_entry = { .exec = cmd_rename_session_exec }; -enum cmd_retval +static enum cmd_retval cmd_rename_session_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; diff --git a/cmd-rename-window.c b/cmd-rename-window.c index a1f15eef..ee53fcb3 100644 --- a/cmd-rename-window.c +++ b/cmd-rename-window.c @@ -26,7 +26,7 @@ * Rename a window. */ -enum cmd_retval cmd_rename_window_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_rename_window_exec(struct cmd *, struct cmd_q *); const struct cmd_entry cmd_rename_window_entry = { .name = "rename-window", @@ -41,7 +41,7 @@ const struct cmd_entry cmd_rename_window_entry = { .exec = cmd_rename_window_exec }; -enum cmd_retval +static enum cmd_retval cmd_rename_window_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; diff --git a/cmd-resize-pane.c b/cmd-resize-pane.c index fa52ab14..36726688 100644 --- a/cmd-resize-pane.c +++ b/cmd-resize-pane.c @@ -26,9 +26,10 @@ * Increase or decrease pane size. */ -enum cmd_retval cmd_resize_pane_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_resize_pane_exec(struct cmd *, struct cmd_q *); -void cmd_resize_pane_mouse_update(struct client *, struct mouse_event *); +static void cmd_resize_pane_mouse_update(struct client *, + struct mouse_event *); const struct cmd_entry cmd_resize_pane_entry = { .name = "resize-pane", @@ -44,7 +45,7 @@ const struct cmd_entry cmd_resize_pane_entry = { .exec = cmd_resize_pane_exec }; -enum cmd_retval +static enum cmd_retval cmd_resize_pane_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; @@ -123,7 +124,7 @@ cmd_resize_pane_exec(struct cmd *self, struct cmd_q *cmdq) return (CMD_RETURN_NORMAL); } -void +static void cmd_resize_pane_mouse_update(struct client *c, struct mouse_event *m) { struct winlink *wl; @@ -154,12 +155,14 @@ cmd_resize_pane_mouse_update(struct client *c, struct mouse_event *m) continue; if (wp->xoff + wp->sx == m->lx && - wp->yoff <= 1 + ly && wp->yoff + wp->sy >= ly) { + wp->yoff <= 1 + ly && + wp->yoff + wp->sy >= ly) { layout_resize_pane(wp, LAYOUT_LEFTRIGHT, m->x - m->lx, 0); found = 1; } if (wp->yoff + wp->sy == ly && - wp->xoff <= 1 + m->lx && wp->xoff + wp->sx >= m->lx) { + wp->xoff <= 1 + m->lx && + wp->xoff + wp->sx >= m->lx) { layout_resize_pane(wp, LAYOUT_TOPBOTTOM, y - ly, 0); found = 1; } diff --git a/cmd-respawn-pane.c b/cmd-respawn-pane.c index ba2c1cd2..3a7c8090 100644 --- a/cmd-respawn-pane.c +++ b/cmd-respawn-pane.c @@ -28,7 +28,7 @@ * Respawn a pane (restart the command). Kill existing if -k given. */ -enum cmd_retval cmd_respawn_pane_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_respawn_pane_exec(struct cmd *, struct cmd_q *); const struct cmd_entry cmd_respawn_pane_entry = { .name = "respawn-pane", @@ -43,7 +43,7 @@ const struct cmd_entry cmd_respawn_pane_entry = { .exec = cmd_respawn_pane_exec }; -enum cmd_retval +static enum cmd_retval cmd_respawn_pane_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; diff --git a/cmd-respawn-window.c b/cmd-respawn-window.c index 95fc0cb4..42f7db19 100644 --- a/cmd-respawn-window.c +++ b/cmd-respawn-window.c @@ -27,7 +27,7 @@ * Respawn a window (restart the command). Kill existing if -k given. */ -enum cmd_retval cmd_respawn_window_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_respawn_window_exec(struct cmd *, struct cmd_q *); const struct cmd_entry cmd_respawn_window_entry = { .name = "respawn-window", @@ -42,7 +42,7 @@ const struct cmd_entry cmd_respawn_window_entry = { .exec = cmd_respawn_window_exec }; -enum cmd_retval +static enum cmd_retval cmd_respawn_window_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; diff --git a/cmd-rotate-window.c b/cmd-rotate-window.c index 94eca37d..bda810c3 100644 --- a/cmd-rotate-window.c +++ b/cmd-rotate-window.c @@ -24,7 +24,7 @@ * Rotate the panes in a window. */ -enum cmd_retval cmd_rotate_window_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_rotate_window_exec(struct cmd *, struct cmd_q *); const struct cmd_entry cmd_rotate_window_entry = { .name = "rotate-window", @@ -39,7 +39,7 @@ const struct cmd_entry cmd_rotate_window_entry = { .exec = cmd_rotate_window_exec }; -enum cmd_retval +static enum cmd_retval cmd_rotate_window_exec(struct cmd *self, struct cmd_q *cmdq) { struct winlink *wl = cmdq->state.tflag.wl; diff --git a/cmd-run-shell.c b/cmd-run-shell.c index d87a061f..55c98ad3 100644 --- a/cmd-run-shell.c +++ b/cmd-run-shell.c @@ -29,11 +29,11 @@ * Runs a command without a window. */ -enum cmd_retval cmd_run_shell_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_run_shell_exec(struct cmd *, struct cmd_q *); -void cmd_run_shell_callback(struct job *); -void cmd_run_shell_free(void *); -void cmd_run_shell_print(struct job *, const char *); +static void cmd_run_shell_callback(struct job *); +static void cmd_run_shell_free(void *); +static void cmd_run_shell_print(struct job *, const char *); const struct cmd_entry cmd_run_shell_entry = { .name = "run-shell", @@ -55,7 +55,7 @@ struct cmd_run_shell_data { int wp_id; }; -void +static void cmd_run_shell_print(struct job *job, const char *msg) { struct cmd_run_shell_data *cdata = job->data; @@ -74,7 +74,7 @@ cmd_run_shell_print(struct job *job, const char *msg) window_copy_add(wp, "%s", msg); } -enum cmd_retval +static enum cmd_retval cmd_run_shell_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; @@ -113,7 +113,7 @@ cmd_run_shell_exec(struct cmd *self, struct cmd_q *cmdq) return (CMD_RETURN_WAIT); } -void +static void cmd_run_shell_callback(struct job *job) { struct cmd_run_shell_data *cdata = job->data; @@ -161,7 +161,7 @@ cmd_run_shell_callback(struct job *job) free(msg); } -void +static void cmd_run_shell_free(void *data) { struct cmd_run_shell_data *cdata = data; diff --git a/cmd-save-buffer.c b/cmd-save-buffer.c index 3aaf8159..f52061f7 100644 --- a/cmd-save-buffer.c +++ b/cmd-save-buffer.c @@ -32,7 +32,7 @@ * Saves a paste buffer to a file. */ -enum cmd_retval cmd_save_buffer_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_save_buffer_exec(struct cmd *, struct cmd_q *); const struct cmd_entry cmd_save_buffer_entry = { .name = "save-buffer", @@ -56,7 +56,7 @@ const struct cmd_entry cmd_show_buffer_entry = { .exec = cmd_save_buffer_exec }; -enum cmd_retval +static enum cmd_retval cmd_save_buffer_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; diff --git a/cmd-select-layout.c b/cmd-select-layout.c index 44f01bb7..48d2ac30 100644 --- a/cmd-select-layout.c +++ b/cmd-select-layout.c @@ -26,7 +26,7 @@ * Switch window to selected layout. */ -enum cmd_retval cmd_select_layout_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_select_layout_exec(struct cmd *, struct cmd_q *); const struct cmd_entry cmd_select_layout_entry = { .name = "select-layout", @@ -67,7 +67,7 @@ const struct cmd_entry cmd_previous_layout_entry = { .exec = cmd_select_layout_exec }; -enum cmd_retval +static enum cmd_retval cmd_select_layout_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; diff --git a/cmd-select-pane.c b/cmd-select-pane.c index 14d53d48..956d42a8 100644 --- a/cmd-select-pane.c +++ b/cmd-select-pane.c @@ -24,7 +24,7 @@ * Select pane. */ -enum cmd_retval cmd_select_pane_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_select_pane_exec(struct cmd *, struct cmd_q *); const struct cmd_entry cmd_select_pane_entry = { .name = "select-pane", @@ -52,7 +52,7 @@ const struct cmd_entry cmd_last_pane_entry = { .exec = cmd_select_pane_exec }; -enum cmd_retval +static enum cmd_retval cmd_select_pane_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; diff --git a/cmd-select-window.c b/cmd-select-window.c index 78228067..a1413ae0 100644 --- a/cmd-select-window.c +++ b/cmd-select-window.c @@ -26,7 +26,7 @@ * Select window by index. */ -enum cmd_retval cmd_select_window_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_select_window_exec(struct cmd *, struct cmd_q *); const struct cmd_entry cmd_select_window_entry = { .name = "select-window", @@ -80,7 +80,7 @@ const struct cmd_entry cmd_last_window_entry = { .exec = cmd_select_window_exec }; -enum cmd_retval +static enum cmd_retval cmd_select_window_exec(struct cmd *self, struct cmd_q *cmdq) { struct winlink *wl = cmdq->state.tflag.wl; diff --git a/cmd-send-keys.c b/cmd-send-keys.c index 92c75ec3..9d6b41d8 100644 --- a/cmd-send-keys.c +++ b/cmd-send-keys.c @@ -27,7 +27,7 @@ * Send keys to client. */ -enum cmd_retval cmd_send_keys_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_send_keys_exec(struct cmd *, struct cmd_q *); const struct cmd_entry cmd_send_keys_entry = { .name = "send-keys", @@ -55,7 +55,7 @@ const struct cmd_entry cmd_send_prefix_entry = { .exec = cmd_send_keys_exec }; -enum cmd_retval +static enum cmd_retval cmd_send_keys_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; diff --git a/cmd-set-buffer.c b/cmd-set-buffer.c index 1f0cf3d8..41ea73d9 100644 --- a/cmd-set-buffer.c +++ b/cmd-set-buffer.c @@ -27,7 +27,7 @@ * Add, set, append to or delete a paste buffer. */ -enum cmd_retval cmd_set_buffer_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_set_buffer_exec(struct cmd *, struct cmd_q *); const struct cmd_entry cmd_set_buffer_entry = { .name = "set-buffer", @@ -51,7 +51,7 @@ const struct cmd_entry cmd_delete_buffer_entry = { .exec = cmd_set_buffer_exec }; -enum cmd_retval +static enum cmd_retval cmd_set_buffer_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; diff --git a/cmd-set-environment.c b/cmd-set-environment.c index ba295ea6..bfb39a4a 100644 --- a/cmd-set-environment.c +++ b/cmd-set-environment.c @@ -27,7 +27,7 @@ * Set an environment variable. */ -enum cmd_retval cmd_set_environment_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_set_environment_exec(struct cmd *, struct cmd_q *); const struct cmd_entry cmd_set_environment_entry = { .name = "set-environment", @@ -42,7 +42,7 @@ const struct cmd_entry cmd_set_environment_entry = { .exec = cmd_set_environment_exec }; -enum cmd_retval +static enum cmd_retval cmd_set_environment_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; diff --git a/cmd-set-hook.c b/cmd-set-hook.c index 4d7cf908..2e8bcb0f 100644 --- a/cmd-set-hook.c +++ b/cmd-set-hook.c @@ -27,7 +27,7 @@ * Set or show global or session hooks. */ -enum cmd_retval cmd_set_hook_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_set_hook_exec(struct cmd *, struct cmd_q *); const struct cmd_entry cmd_set_hook_entry = { .name = "set-hook", @@ -55,7 +55,7 @@ const struct cmd_entry cmd_show_hooks_entry = { .exec = cmd_set_hook_exec }; -enum cmd_retval +static enum cmd_retval cmd_set_hook_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; diff --git a/cmd-set-option.c b/cmd-set-option.c index 0f116b6f..8f7e469c 100644 --- a/cmd-set-option.c +++ b/cmd-set-option.c @@ -27,40 +27,40 @@ * Set an option. */ -enum cmd_retval cmd_set_option_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_set_option_exec(struct cmd *, struct cmd_q *); -enum cmd_retval cmd_set_option_user(struct cmd *, struct cmd_q *, +static enum cmd_retval cmd_set_option_user(struct cmd *, struct cmd_q *, const char *, const char *); -int cmd_set_option_unset(struct cmd *, struct cmd_q *, - const struct options_table_entry *, struct options *, - const char *); -int cmd_set_option_set(struct cmd *, struct cmd_q *, - const struct options_table_entry *, struct options *, - const char *); +static int cmd_set_option_unset(struct cmd *, struct cmd_q *, + const struct options_table_entry *, struct options *, + const char *); +static int cmd_set_option_set(struct cmd *, struct cmd_q *, + const struct options_table_entry *, struct options *, + const char *); -struct options_entry *cmd_set_option_string(struct cmd *, struct cmd_q *, - const struct options_table_entry *, struct options *, - const char *); -struct options_entry *cmd_set_option_number(struct cmd *, struct cmd_q *, +static struct options_entry *cmd_set_option_string(struct cmd *, struct cmd_q *, const struct options_table_entry *, struct options *, const char *); -struct options_entry *cmd_set_option_key(struct cmd *, struct cmd_q *, +static struct options_entry *cmd_set_option_number(struct cmd *, struct cmd_q *, const struct options_table_entry *, struct options *, const char *); -struct options_entry *cmd_set_option_colour(struct cmd *, struct cmd_q *, +static struct options_entry *cmd_set_option_key(struct cmd *, struct cmd_q *, const struct options_table_entry *, struct options *, const char *); -struct options_entry *cmd_set_option_attributes(struct cmd *, struct cmd_q *, +static struct options_entry *cmd_set_option_colour(struct cmd *, struct cmd_q *, const struct options_table_entry *, struct options *, const char *); -struct options_entry *cmd_set_option_flag(struct cmd *, struct cmd_q *, +static struct options_entry *cmd_set_option_attributes(struct cmd *, + struct cmd_q *, const struct options_table_entry *, + struct options *, const char *); +static struct options_entry *cmd_set_option_flag(struct cmd *, struct cmd_q *, const struct options_table_entry *, struct options *, const char *); -struct options_entry *cmd_set_option_choice(struct cmd *, struct cmd_q *, +static struct options_entry *cmd_set_option_choice(struct cmd *, struct cmd_q *, const struct options_table_entry *, struct options *, const char *); -struct options_entry *cmd_set_option_style(struct cmd *, struct cmd_q *, +static struct options_entry *cmd_set_option_style(struct cmd *, struct cmd_q *, const struct options_table_entry *, struct options *, const char *); @@ -90,7 +90,7 @@ const struct cmd_entry cmd_set_window_option_entry = { .exec = cmd_set_option_exec }; -enum cmd_retval +static enum cmd_retval cmd_set_option_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; @@ -223,7 +223,7 @@ cmd_set_option_exec(struct cmd *self, struct cmd_q *cmdq) } /* Set user option. */ -enum cmd_retval +static enum cmd_retval cmd_set_option_user(struct cmd *self, struct cmd_q *cmdq, const char *optstr, const char *valstr) { @@ -301,7 +301,7 @@ cmd_set_option_user(struct cmd *self, struct cmd_q *cmdq, const char *optstr, } /* Unset an option. */ -int +static int cmd_set_option_unset(struct cmd *self, struct cmd_q *cmdq, const struct options_table_entry *oe, struct options *oo, const char *value) @@ -331,7 +331,7 @@ cmd_set_option_unset(struct cmd *self, struct cmd_q *cmdq, } /* Set an option. */ -int +static int cmd_set_option_set(struct cmd *self, struct cmd_q *cmdq, const struct options_table_entry *oe, struct options *oo, const char *value) @@ -386,7 +386,7 @@ cmd_set_option_set(struct cmd *self, struct cmd_q *cmdq, } /* Set a string option. */ -struct options_entry * +static struct options_entry * cmd_set_option_string(struct cmd *self, __unused struct cmd_q *cmdq, const struct options_table_entry *oe, struct options *oo, const char *value) @@ -408,7 +408,7 @@ cmd_set_option_string(struct cmd *self, __unused struct cmd_q *cmdq, } /* Set a number option. */ -struct options_entry * +static struct options_entry * cmd_set_option_number(__unused struct cmd *self, struct cmd_q *cmdq, const struct options_table_entry *oe, struct options *oo, const char *value) @@ -426,7 +426,7 @@ cmd_set_option_number(__unused struct cmd *self, struct cmd_q *cmdq, } /* Set a key option. */ -struct options_entry * +static struct options_entry * cmd_set_option_key(__unused struct cmd *self, struct cmd_q *cmdq, const struct options_table_entry *oe, struct options *oo, const char *value) @@ -443,7 +443,7 @@ cmd_set_option_key(__unused struct cmd *self, struct cmd_q *cmdq, } /* Set a colour option. */ -struct options_entry * +static struct options_entry * cmd_set_option_colour(__unused struct cmd *self, struct cmd_q *cmdq, const struct options_table_entry *oe, struct options *oo, const char *value) @@ -459,7 +459,7 @@ cmd_set_option_colour(__unused struct cmd *self, struct cmd_q *cmdq, } /* Set an attributes option. */ -struct options_entry * +static struct options_entry * cmd_set_option_attributes(__unused struct cmd *self, struct cmd_q *cmdq, const struct options_table_entry *oe, struct options *oo, const char *value) @@ -475,7 +475,7 @@ cmd_set_option_attributes(__unused struct cmd *self, struct cmd_q *cmdq, } /* Set a flag option. */ -struct options_entry * +static struct options_entry * cmd_set_option_flag(__unused struct cmd *self, struct cmd_q *cmdq, const struct options_table_entry *oe, struct options *oo, const char *value) @@ -503,7 +503,7 @@ cmd_set_option_flag(__unused struct cmd *self, struct cmd_q *cmdq, } /* Set a choice option. */ -struct options_entry * +static struct options_entry * cmd_set_option_choice(__unused struct cmd *self, struct cmd_q *cmdq, const struct options_table_entry *oe, struct options *oo, const char *value) @@ -538,7 +538,7 @@ cmd_set_option_choice(__unused struct cmd *self, struct cmd_q *cmdq, } /* Set a style option. */ -struct options_entry * +static struct options_entry * cmd_set_option_style(struct cmd *self, struct cmd_q *cmdq, const struct options_table_entry *oe, struct options *oo, const char *value) diff --git a/cmd-show-environment.c b/cmd-show-environment.c index 29e89274..5ad0bb8a 100644 --- a/cmd-show-environment.c +++ b/cmd-show-environment.c @@ -27,11 +27,11 @@ * Show environment. */ -enum cmd_retval cmd_show_environment_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_show_environment_exec(struct cmd *, struct cmd_q *); -char *cmd_show_environment_escape(struct environ_entry *); -void cmd_show_environment_print(struct cmd *, struct cmd_q *, - struct environ_entry *); +static char *cmd_show_environment_escape(struct environ_entry *); +static void cmd_show_environment_print(struct cmd *, struct cmd_q *, + struct environ_entry *); const struct cmd_entry cmd_show_environment_entry = { .name = "show-environment", @@ -46,7 +46,7 @@ const struct cmd_entry cmd_show_environment_entry = { .exec = cmd_show_environment_exec }; -char * +static char * cmd_show_environment_escape(struct environ_entry *envent) { const char *value = envent->value; @@ -64,7 +64,7 @@ cmd_show_environment_escape(struct environ_entry *envent) return (ret); } -void +static void cmd_show_environment_print(struct cmd *self, struct cmd_q *cmdq, struct environ_entry *envent) { @@ -87,7 +87,7 @@ cmd_show_environment_print(struct cmd *self, struct cmd_q *cmdq, cmdq_print(cmdq, "unset %s;", envent->name); } -enum cmd_retval +static enum cmd_retval cmd_show_environment_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; diff --git a/cmd-show-messages.c b/cmd-show-messages.c index 3131184d..0f607aa2 100644 --- a/cmd-show-messages.c +++ b/cmd-show-messages.c @@ -29,7 +29,7 @@ * Show client message log. */ -enum cmd_retval cmd_show_messages_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_show_messages_exec(struct cmd *, struct cmd_q *); const struct cmd_entry cmd_show_messages_entry = { .name = "show-messages", @@ -55,10 +55,10 @@ const struct cmd_entry cmd_server_info_entry = { .exec = cmd_show_messages_exec }; -int cmd_show_messages_terminals(struct cmd_q *, int); -int cmd_show_messages_jobs(struct cmd_q *, int); +static int cmd_show_messages_terminals(struct cmd_q *, int); +static int cmd_show_messages_jobs(struct cmd_q *, int); -int +static int cmd_show_messages_terminals(struct cmd_q *cmdq, int blank) { struct tty_term *term; @@ -79,7 +79,7 @@ cmd_show_messages_terminals(struct cmd_q *cmdq, int blank) return (n != 0); } -int +static int cmd_show_messages_jobs(struct cmd_q *cmdq, int blank) { struct job *job; @@ -98,7 +98,7 @@ cmd_show_messages_jobs(struct cmd_q *cmdq, int blank) return (n != 0); } -enum cmd_retval +static enum cmd_retval cmd_show_messages_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; diff --git a/cmd-show-options.c b/cmd-show-options.c index 322f532c..89d8f219 100644 --- a/cmd-show-options.c +++ b/cmd-show-options.c @@ -27,12 +27,12 @@ * Show options. */ -enum cmd_retval cmd_show_options_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_show_options_exec(struct cmd *, struct cmd_q *); -enum cmd_retval cmd_show_options_one(struct cmd *, struct cmd_q *, - struct options *, int); -enum cmd_retval cmd_show_options_all(struct cmd *, struct cmd_q *, - struct options *, enum options_table_scope); +static enum cmd_retval cmd_show_options_one(struct cmd *, struct cmd_q *, + struct options *, int); +static enum cmd_retval cmd_show_options_all(struct cmd *, struct cmd_q *, + struct options *, enum options_table_scope); const struct cmd_entry cmd_show_options_entry = { .name = "show-options", @@ -60,7 +60,7 @@ const struct cmd_entry cmd_show_window_options_entry = { .exec = cmd_show_options_exec }; -enum cmd_retval +static enum cmd_retval cmd_show_options_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; @@ -110,7 +110,7 @@ cmd_show_options_exec(struct cmd *self, struct cmd_q *cmdq) return (cmd_show_options_one(self, cmdq, oo, quiet)); } -enum cmd_retval +static enum cmd_retval cmd_show_options_one(struct cmd *self, struct cmd_q *cmdq, struct options *oo, int quiet) { @@ -160,7 +160,7 @@ retry: return (CMD_RETURN_NORMAL); } -enum cmd_retval +static enum cmd_retval cmd_show_options_all(struct cmd *self, struct cmd_q *cmdq, struct options *oo, enum options_table_scope scope) { diff --git a/cmd-source-file.c b/cmd-source-file.c index ecebbaca..ef3ac7ac 100644 --- a/cmd-source-file.c +++ b/cmd-source-file.c @@ -26,9 +26,9 @@ * Sources a configuration file. */ -enum cmd_retval cmd_source_file_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_source_file_exec(struct cmd *, struct cmd_q *); -void cmd_source_file_done(struct cmd_q *); +static void cmd_source_file_done(struct cmd_q *); const struct cmd_entry cmd_source_file_entry = { .name = "source-file", @@ -41,7 +41,7 @@ const struct cmd_entry cmd_source_file_entry = { .exec = cmd_source_file_exec }; -enum cmd_retval +static enum cmd_retval cmd_source_file_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; @@ -76,7 +76,7 @@ cmd_source_file_exec(struct cmd *self, struct cmd_q *cmdq) return (CMD_RETURN_WAIT); } -void +static void cmd_source_file_done(struct cmd_q *cmdq1) { struct cmd_q *cmdq = cmdq1->data; diff --git a/cmd-split-window.c b/cmd-split-window.c index 8d24c6c5..e3e3d059 100644 --- a/cmd-split-window.c +++ b/cmd-split-window.c @@ -33,7 +33,7 @@ #define SPLIT_WINDOW_TEMPLATE "#{session_name}:#{window_index}.#{pane_index}" -enum cmd_retval cmd_split_window_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_split_window_exec(struct cmd *, struct cmd_q *); const struct cmd_entry cmd_split_window_entry = { .name = "split-window", @@ -49,7 +49,7 @@ const struct cmd_entry cmd_split_window_entry = { .exec = cmd_split_window_exec }; -enum cmd_retval +static enum cmd_retval cmd_split_window_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; diff --git a/cmd-string.c b/cmd-string.c index 757d4cdb..2cf63294 100644 --- a/cmd-string.c +++ b/cmd-string.c @@ -31,14 +31,14 @@ * Parse a command from a string. */ -int cmd_string_getc(const char *, size_t *); -void cmd_string_ungetc(size_t *); -void cmd_string_copy(char **, char *, size_t *); -char *cmd_string_string(const char *, size_t *, char, int); -char *cmd_string_variable(const char *, size_t *); -char *cmd_string_expand_tilde(const char *, size_t *); - -int +static int cmd_string_getc(const char *, size_t *); +static void cmd_string_ungetc(size_t *); +static void cmd_string_copy(char **, char *, size_t *); +static char *cmd_string_string(const char *, size_t *, char, int); +static char *cmd_string_variable(const char *, size_t *); +static char *cmd_string_expand_tilde(const char *, size_t *); + +static int cmd_string_getc(const char *s, size_t *p) { const u_char *ucs = s; @@ -48,7 +48,7 @@ cmd_string_getc(const char *s, size_t *p) return (ucs[(*p)++]); } -void +static void cmd_string_ungetc(size_t *p) { (*p)--; @@ -173,7 +173,7 @@ out: return (rval); } -void +static void cmd_string_copy(char **dst, char *src, size_t *len) { size_t srclen; @@ -187,7 +187,7 @@ cmd_string_copy(char **dst, char *src, size_t *len) free(src); } -char * +static char * cmd_string_string(const char *s, size_t *p, char endch, int esc) { int ch; @@ -245,7 +245,7 @@ error: return (NULL); } -char * +static char * cmd_string_variable(const char *s, size_t *p) { int ch, fch; @@ -314,7 +314,7 @@ error: return (NULL); } -char * +static char * cmd_string_expand_tilde(const char *s, size_t *p) { struct passwd *pw; @@ -337,7 +337,10 @@ cmd_string_expand_tilde(const char *s, size_t *p) cp = user = xmalloc(strlen(s)); for (;;) { last = cmd_string_getc(s, p); - if (last == EOF || last == '/' || last == ' '|| last == '\t') + if (last == EOF || + last == '/' || + last == ' '|| + last == '\t') break; *cp++ = last; } diff --git a/cmd-swap-pane.c b/cmd-swap-pane.c index 13575e0a..e5f5c810 100644 --- a/cmd-swap-pane.c +++ b/cmd-swap-pane.c @@ -26,7 +26,7 @@ * Swap two panes. */ -enum cmd_retval cmd_swap_pane_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_swap_pane_exec(struct cmd *, struct cmd_q *); const struct cmd_entry cmd_swap_pane_entry = { .name = "swap-pane", @@ -42,7 +42,7 @@ const struct cmd_entry cmd_swap_pane_entry = { .exec = cmd_swap_pane_exec }; -enum cmd_retval +static enum cmd_retval cmd_swap_pane_exec(struct cmd *self, struct cmd_q *cmdq) { struct window *src_w, *dst_w; diff --git a/cmd-swap-window.c b/cmd-swap-window.c index 14907d2d..904a974d 100644 --- a/cmd-swap-window.c +++ b/cmd-swap-window.c @@ -26,7 +26,7 @@ * Swap one window with another. */ -enum cmd_retval cmd_swap_window_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_swap_window_exec(struct cmd *, struct cmd_q *); const struct cmd_entry cmd_swap_window_entry = { .name = "swap-window", @@ -42,7 +42,7 @@ const struct cmd_entry cmd_swap_window_entry = { .exec = cmd_swap_window_exec }; -enum cmd_retval +static enum cmd_retval cmd_swap_window_exec(struct cmd *self, struct cmd_q *cmdq) { struct session *src, *dst; diff --git a/cmd-switch-client.c b/cmd-switch-client.c index 6e2ee2a0..cc3212db 100644 --- a/cmd-switch-client.c +++ b/cmd-switch-client.c @@ -27,7 +27,7 @@ * Switch client to a different session. */ -enum cmd_retval cmd_switch_client_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_switch_client_exec(struct cmd *, struct cmd_q *); const struct cmd_entry cmd_switch_client_entry = { .name = "switch-client", @@ -44,7 +44,7 @@ const struct cmd_entry cmd_switch_client_entry = { .exec = cmd_switch_client_exec }; -enum cmd_retval +static enum cmd_retval cmd_switch_client_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; diff --git a/cmd-unbind-key.c b/cmd-unbind-key.c index 7452fd9f..00c7779b 100644 --- a/cmd-unbind-key.c +++ b/cmd-unbind-key.c @@ -26,9 +26,9 @@ * Unbind key from command. */ -enum cmd_retval cmd_unbind_key_exec(struct cmd *, struct cmd_q *); -enum cmd_retval cmd_unbind_key_mode_table(struct cmd *, struct cmd_q *, - key_code); +static enum cmd_retval cmd_unbind_key_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_unbind_key_mode_table(struct cmd *, struct cmd_q *, + key_code); const struct cmd_entry cmd_unbind_key_entry = { .name = "unbind-key", @@ -41,7 +41,7 @@ const struct cmd_entry cmd_unbind_key_entry = { .exec = cmd_unbind_key_exec }; -enum cmd_retval +static enum cmd_retval cmd_unbind_key_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; @@ -98,7 +98,7 @@ cmd_unbind_key_exec(struct cmd *self, struct cmd_q *cmdq) return (CMD_RETURN_NORMAL); } -enum cmd_retval +static enum cmd_retval cmd_unbind_key_mode_table(struct cmd *self, struct cmd_q *cmdq, key_code key) { struct args *args = self->args; diff --git a/cmd-wait-for.c b/cmd-wait-for.c index 81b01627..fb2fb699 100644 --- a/cmd-wait-for.c +++ b/cmd-wait-for.c @@ -28,7 +28,7 @@ * Block or wake a client on a named wait channel. */ -enum cmd_retval cmd_wait_for_exec(struct cmd *, struct cmd_q *); +static enum cmd_retval cmd_wait_for_exec(struct cmd *, struct cmd_q *); const struct cmd_entry cmd_wait_for_entry = { .name = "wait-for", @@ -52,31 +52,30 @@ struct wait_channel { RB_ENTRY(wait_channel) entry; }; RB_HEAD(wait_channels, wait_channel); -struct wait_channels wait_channels = RB_INITIALIZER(wait_channels); +static struct wait_channels wait_channels = RB_INITIALIZER(wait_channels); -int wait_channel_cmp(struct wait_channel *, struct wait_channel *); -RB_PROTOTYPE(wait_channels, wait_channel, entry, wait_channel_cmp); -RB_GENERATE(wait_channels, wait_channel, entry, wait_channel_cmp); +static int wait_channel_cmp(struct wait_channel *, struct wait_channel *); +RB_GENERATE_STATIC(wait_channels, wait_channel, entry, wait_channel_cmp); -int +static int wait_channel_cmp(struct wait_channel *wc1, struct wait_channel *wc2) { return (strcmp(wc1->name, wc2->name)); } -enum cmd_retval cmd_wait_for_signal(struct cmd_q *, const char *, - struct wait_channel *); -enum cmd_retval cmd_wait_for_wait(struct cmd_q *, const char *, - struct wait_channel *); -enum cmd_retval cmd_wait_for_lock(struct cmd_q *, const char *, - struct wait_channel *); -enum cmd_retval cmd_wait_for_unlock(struct cmd_q *, const char *, - struct wait_channel *); +static enum cmd_retval cmd_wait_for_signal(struct cmd_q *, const char *, + struct wait_channel *); +static enum cmd_retval cmd_wait_for_wait(struct cmd_q *, const char *, + struct wait_channel *); +static enum cmd_retval cmd_wait_for_lock(struct cmd_q *, const char *, + struct wait_channel *); +static enum cmd_retval cmd_wait_for_unlock(struct cmd_q *, const char *, + struct wait_channel *); -struct wait_channel *cmd_wait_for_add(const char *); -void cmd_wait_for_remove(struct wait_channel *wc); +static struct wait_channel *cmd_wait_for_add(const char *); +static void cmd_wait_for_remove(struct wait_channel *wc); -struct wait_channel * +static struct wait_channel * cmd_wait_for_add(const char *name) { struct wait_channel *wc; @@ -97,7 +96,7 @@ cmd_wait_for_add(const char *name) return (wc); } -void +static void cmd_wait_for_remove(struct wait_channel *wc) { if (wc->locked) @@ -113,7 +112,7 @@ cmd_wait_for_remove(struct wait_channel *wc) free(wc); } -enum cmd_retval +static enum cmd_retval cmd_wait_for_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; @@ -132,7 +131,7 @@ cmd_wait_for_exec(struct cmd *self, struct cmd_q *cmdq) return (cmd_wait_for_wait(cmdq, name, wc)); } -enum cmd_retval +static enum cmd_retval cmd_wait_for_signal(__unused struct cmd_q *cmdq, const char *name, struct wait_channel *wc) { @@ -158,7 +157,7 @@ cmd_wait_for_signal(__unused struct cmd_q *cmdq, const char *name, return (CMD_RETURN_NORMAL); } -enum cmd_retval +static enum cmd_retval cmd_wait_for_wait(struct cmd_q *cmdq, const char *name, struct wait_channel *wc) { @@ -185,7 +184,7 @@ cmd_wait_for_wait(struct cmd_q *cmdq, const char *name, return (CMD_RETURN_WAIT); } -enum cmd_retval +static enum cmd_retval cmd_wait_for_lock(struct cmd_q *cmdq, const char *name, struct wait_channel *wc) { @@ -207,7 +206,7 @@ cmd_wait_for_lock(struct cmd_q *cmdq, const char *name, return (CMD_RETURN_NORMAL); } -enum cmd_retval +static enum cmd_retval cmd_wait_for_unlock(struct cmd_q *cmdq, const char *name, struct wait_channel *wc) { diff --git a/window-clock.c b/window-clock.c index f6dc85cd..a9bbb75a 100644 --- a/window-clock.c +++ b/window-clock.c @@ -24,14 +24,14 @@ #include "tmux.h" -struct screen *window_clock_init(struct window_pane *); -void window_clock_free(struct window_pane *); -void window_clock_resize(struct window_pane *, u_int, u_int); -void window_clock_key(struct window_pane *, struct client *, - struct session *, key_code, struct mouse_event *); +static struct screen *window_clock_init(struct window_pane *); +static void window_clock_free(struct window_pane *); +static void window_clock_resize(struct window_pane *, u_int, u_int); +static void window_clock_key(struct window_pane *, struct client *, + struct session *, key_code, struct mouse_event *); -void window_clock_timer_callback(int, short, void *); -void window_clock_draw_screen(struct window_pane *); +static void window_clock_timer_callback(int, short, void *); +static void window_clock_draw_screen(struct window_pane *); const struct window_mode window_clock_mode = { window_clock_init, @@ -119,7 +119,7 @@ const char window_clock_table[14][5][5] = { { 1,0,0,0,1 } }, }; -void +static void window_clock_timer_callback(__unused int fd, __unused short events, void *arg) { struct window_pane *wp = arg; @@ -142,7 +142,7 @@ window_clock_timer_callback(__unused int fd, __unused short events, void *arg) server_redraw_window(wp->window); } -struct screen * +static struct screen * window_clock_init(struct window_pane *wp) { struct window_clock_mode_data *data; @@ -164,7 +164,7 @@ window_clock_init(struct window_pane *wp) return (s); } -void +static void window_clock_free(struct window_pane *wp) { struct window_clock_mode_data *data = wp->modedata; @@ -174,7 +174,7 @@ window_clock_free(struct window_pane *wp) free(data); } -void +static void window_clock_resize(struct window_pane *wp, u_int sx, u_int sy) { struct window_clock_mode_data *data = wp->modedata; @@ -184,7 +184,7 @@ window_clock_resize(struct window_pane *wp, u_int sx, u_int sy) window_clock_draw_screen(wp); } -void +static void window_clock_key(struct window_pane *wp, __unused struct client *c, __unused struct session *sess, __unused key_code key, __unused struct mouse_event *m) @@ -192,7 +192,7 @@ window_clock_key(struct window_pane *wp, __unused struct client *c, window_pane_reset_mode(wp); } -void +static void window_clock_draw_screen(struct window_pane *wp) { struct window_clock_mode_data *data = wp->modedata; -- cgit From 8b804fb5894b6717de36c5c9c96f7fd29b14a864 Mon Sep 17 00:00:00 2001 From: nicm Date: Tue, 11 Oct 2016 07:11:40 +0000 Subject: Support UTF-8 entry into the command prompt. --- status.c | 316 ++++++++++++++++++++++++++++++++++++++++----------------------- tmux.h | 4 +- utf8.c | 27 ++++++ 3 files changed, 230 insertions(+), 117 deletions(-) diff --git a/status.c b/status.c index 62c01344..c51a3f34 100644 --- a/status.c +++ b/status.c @@ -662,18 +662,21 @@ status_prompt_set(struct client *c, const char *msg, const char *input, struct format_tree *ft; int keys; time_t t; + char *tmp; ft = format_create(NULL, 0); format_defaults(ft, c, NULL, NULL, NULL); + t = time(NULL); + tmp = format_expand_time(ft, input, t); status_message_clear(c); status_prompt_clear(c); c->prompt_string = format_expand_time(ft, msg, t); - c->prompt_buffer = format_expand_time(ft, input, t); - c->prompt_index = strlen(c->prompt_buffer); + c->prompt_buffer = utf8_fromcstr(tmp); + c->prompt_index = utf8_strlen(c->prompt_buffer); c->prompt_callbackfn = callbackfn; c->prompt_freefn = freefn; @@ -692,6 +695,7 @@ status_prompt_set(struct client *c, const char *msg, const char *input, c->tty.flags |= (TTY_NOCURSOR|TTY_FREEZE); c->flags |= CLIENT_STATUS; + free(tmp); format_free(ft); } @@ -723,22 +727,26 @@ status_prompt_update(struct client *c, const char *msg, const char *input) { struct format_tree *ft; time_t t; + char *tmp; ft = format_create(NULL, 0); format_defaults(ft, c, NULL, NULL, NULL); + t = time(NULL); + tmp = format_expand_time(ft, input, t); free(c->prompt_string); c->prompt_string = format_expand_time(ft, msg, t); free(c->prompt_buffer); - c->prompt_buffer = format_expand_time(ft, input, t); - c->prompt_index = strlen(c->prompt_buffer); + c->prompt_buffer = utf8_fromcstr(tmp); + c->prompt_index = utf8_strlen(c->prompt_buffer); c->prompt_hindex = 0; c->flags |= CLIENT_STATUS; + free(tmp); format_free(ft); } @@ -746,57 +754,80 @@ status_prompt_update(struct client *c, const char *msg, const char *input) int status_prompt_redraw(struct client *c) { - struct screen_write_ctx ctx; - struct session *s = c->session; - struct screen old_status; - size_t i, size, left, len, off; - struct grid_cell gc; + struct screen_write_ctx ctx; + struct session *s = c->session; + struct screen old_status; + u_int i, offset, left, start, pcursor, pwidth, width; + struct grid_cell gc, cursorgc; if (c->tty.sx == 0 || c->tty.sy == 0) return (0); memcpy(&old_status, &c->status, sizeof old_status); screen_init(&c->status, c->tty.sx, 1, 0); - len = screen_write_strlen("%s", c->prompt_string); - if (len > c->tty.sx) - len = c->tty.sx; - off = 0; - - /* Change colours for command mode. */ if (c->prompt_mdata.mode == 1) style_apply(&gc, s->options, "message-command-style"); else style_apply(&gc, s->options, "message-style"); - screen_write_start(&ctx, NULL, &c->status); + memcpy(&cursorgc, &gc, sizeof cursorgc); + cursorgc.attr ^= GRID_ATTR_REVERSE; + start = screen_write_strlen("%s", c->prompt_string); + if (start > c->tty.sx) + start = c->tty.sx; + + screen_write_start(&ctx, NULL, &c->status); screen_write_cursormove(&ctx, 0, 0); - screen_write_nputs(&ctx, len, &gc, "%s", c->prompt_string); + screen_write_nputs(&ctx, start, &gc, "%s", c->prompt_string); + while (c->status.cx < screen_size_x(&c->status)) + screen_write_putc(&ctx, &gc, ' '); + screen_write_cursormove(&ctx, start, 0); - left = c->tty.sx - len; - if (left != 0) { - size = screen_write_strlen("%s", c->prompt_buffer); - if (c->prompt_index >= left) { - off = c->prompt_index - left + 1; - if (c->prompt_index == size) - left--; - size = left; + left = c->tty.sx - start; + if (left == 0) + goto finished; + + pcursor = utf8_strwidth(c->prompt_buffer, c->prompt_index); + pwidth = utf8_strwidth(c->prompt_buffer, -1); + if (pcursor >= left) { + /* + * The cursor would be outside the screen so start drawing + * with it on the right. + */ + offset = (pcursor - left) + 1; + pwidth = left; + } else + offset = 0; + if (pwidth > left) + pwidth = left; + + width = 0; + for (i = 0; c->prompt_buffer[i].size != 0; i++) { + if (width < offset) { + width += c->prompt_buffer[i].width; + continue; } - screen_write_nputs(&ctx, left, &gc, "%s", c->prompt_buffer + - off); + if (width >= offset + pwidth) + break; + width += c->prompt_buffer[i].width; + if (width > offset + pwidth) + break; - for (i = len + size; i < c->tty.sx; i++) - screen_write_putc(&ctx, &gc, ' '); + if (i != c->prompt_index) { + utf8_copy(&gc.data, &c->prompt_buffer[i]); + screen_write_cell(&ctx, &gc); + } else { + utf8_copy(&cursorgc.data, &c->prompt_buffer[i]); + screen_write_cell(&ctx, &cursorgc); + } } + if (c->status.cx < screen_size_x(&c->status) && c->prompt_index >= i) + screen_write_putc(&ctx, &cursorgc, ' '); +finished: screen_write_stop(&ctx); - /* Apply fake cursor. */ - off = len + c->prompt_index - off; - grid_view_get_cell(c->status.grid, off, 0, &gc); - gc.attr ^= GRID_ATTR_REVERSE; - grid_view_set_cell(c->status.grid, off, 0, &gc); - if (grid_compare(c->status.grid, old_status.grid) == 0) { screen_free(&old_status); return (0); @@ -805,19 +836,37 @@ status_prompt_redraw(struct client *c) return (1); } +/* Is this a separator? */ +static int +status_prompt_in_list(const char *ws, const struct utf8_data *ud) +{ + if (ud->size != 1 || ud->width != 1) + return (0); + return (strchr(ws, *ud->data) != NULL); +} + +/* Is this a space? */ +static int +status_prompt_space(const struct utf8_data *ud) +{ + if (ud->size != 1 || ud->width != 1) + return (0); + return (*ud->data == ' '); +} + /* Handle keys in prompt. */ void status_prompt_key(struct client *c, key_code key) { - struct session *sess = c->session; - struct options *oo = sess->options; + struct options *oo = c->session->options; struct paste_buffer *pb; - char *s, *first, *last, word[64], swapc; - const char *histstr, *bufdata, *wsep = NULL; + char *s, word[64]; + const char *histstr, *bufdata, *ws = NULL; u_char ch; - size_t size, n, off, idx, bufsize; + size_t size, n, off, idx, bufsize, used; + struct utf8_data tmp, *first, *last, *ud; - size = strlen(c->prompt_buffer); + size = utf8_strlen(c->prompt_buffer); switch (mode_key_lookup(&c->prompt_mdata, key, NULL, NULL)) { case MODEKEYEDIT_CURSORLEFT: if (c->prompt_index > 0) { @@ -856,7 +905,7 @@ status_prompt_key(struct client *c, key_code key) } break; case MODEKEYEDIT_COMPLETE: - if (*c->prompt_buffer == '\0') + if (c->prompt_buffer[0].size == 0) break; idx = c->prompt_index; @@ -864,40 +913,50 @@ status_prompt_key(struct client *c, key_code key) idx--; /* Find the word we are in. */ - first = c->prompt_buffer + idx; - while (first > c->prompt_buffer && *first != ' ') + first = &c->prompt_buffer[idx]; + while (first > c->prompt_buffer && !status_prompt_space(first)) first--; - while (*first == ' ') + while (first->size != 0 && status_prompt_space(first)) first++; - last = c->prompt_buffer + idx; - while (*last != '\0' && *last != ' ') + last = &c->prompt_buffer[idx]; + while (last->size != 0 && !status_prompt_space(last)) last++; - while (*last == ' ') + while (last > c->prompt_buffer && status_prompt_space(last)) last--; - if (*last != '\0') + if (last->size != 0) last++; - if (last <= first || - ((size_t) (last - first)) > (sizeof word) - 1) + if (last <= first) break; - memcpy(word, first, last - first); - word[last - first] = '\0'; + + used = 0; + for (ud = first; ud < last; ud++) { + if (used + ud->size >= sizeof word) + break; + memcpy(word + used, ud->data, ud->size); + used += ud->size; + } + if (ud != last) + break; + word[used] = '\0'; /* And try to complete it. */ - if ((s = status_prompt_complete(sess, word)) == NULL) + if ((s = status_prompt_complete(c->session, word)) == NULL) break; /* Trim out word. */ n = size - (last - c->prompt_buffer) + 1; /* with \0 */ - memmove(first, last, n); + memmove(first, last, n * sizeof *c->prompt_buffer); size -= last - first; /* Insert the new word. */ size += strlen(s); off = first - c->prompt_buffer; - c->prompt_buffer = xrealloc(c->prompt_buffer, size + 1); + c->prompt_buffer = xreallocarray(c->prompt_buffer, size + 1, + sizeof *c->prompt_buffer); first = c->prompt_buffer + off; - memmove(first + strlen(s), first, n); - memcpy(first, s, strlen(s)); + memmove(first + strlen(s), first, n * sizeof *c->prompt_buffer); + for (idx = 0; idx < strlen(s); idx++) + utf8_set(&first[idx], s[idx]); c->prompt_index = (first - c->prompt_buffer) + strlen(s); free(s); @@ -907,11 +966,12 @@ status_prompt_key(struct client *c, key_code key) case MODEKEYEDIT_BACKSPACE: if (c->prompt_index != 0) { if (c->prompt_index == size) - c->prompt_buffer[--c->prompt_index] = '\0'; + c->prompt_buffer[--c->prompt_index].size = 0; else { memmove(c->prompt_buffer + c->prompt_index - 1, c->prompt_buffer + c->prompt_index, - size + 1 - c->prompt_index); + (size + 1 - c->prompt_index) * + sizeof *c->prompt_buffer); c->prompt_index--; } c->flags |= CLIENT_STATUS; @@ -922,38 +982,39 @@ status_prompt_key(struct client *c, key_code key) if (c->prompt_index != size) { memmove(c->prompt_buffer + c->prompt_index, c->prompt_buffer + c->prompt_index + 1, - size + 1 - c->prompt_index); + (size + 1 - c->prompt_index) * + sizeof *c->prompt_buffer); c->flags |= CLIENT_STATUS; } break; case MODEKEYEDIT_DELETELINE: case MODEKEYEDIT_SWITCHMODESUBSTITUTELINE: - *c->prompt_buffer = '\0'; + c->prompt_buffer[0].size = 0; c->prompt_index = 0; c->flags |= CLIENT_STATUS; break; case MODEKEYEDIT_DELETETOENDOFLINE: case MODEKEYEDIT_SWITCHMODECHANGELINE: if (c->prompt_index < size) { - c->prompt_buffer[c->prompt_index] = '\0'; + c->prompt_buffer[c->prompt_index].size = 0; c->flags |= CLIENT_STATUS; } break; case MODEKEYEDIT_DELETEWORD: - wsep = options_get_string(oo, "word-separators"); + ws = options_get_string(oo, "word-separators"); idx = c->prompt_index; /* Find a non-separator. */ while (idx != 0) { idx--; - if (!strchr(wsep, c->prompt_buffer[idx])) + if (!status_prompt_in_list(ws, &c->prompt_buffer[idx])) break; } /* Find the separator at the beginning of the word. */ while (idx != 0) { idx--; - if (strchr(wsep, c->prompt_buffer[idx])) { + if (status_prompt_in_list(ws, &c->prompt_buffer[idx])) { /* Go back to the word. */ idx++; break; @@ -962,53 +1023,55 @@ status_prompt_key(struct client *c, key_code key) memmove(c->prompt_buffer + idx, c->prompt_buffer + c->prompt_index, - size + 1 - c->prompt_index); + (size + 1 - c->prompt_index) * + sizeof *c->prompt_buffer); memset(c->prompt_buffer + size - (c->prompt_index - idx), - '\0', c->prompt_index - idx); + '\0', (c->prompt_index - idx) * sizeof *c->prompt_buffer); c->prompt_index = idx; + c->flags |= CLIENT_STATUS; break; case MODEKEYEDIT_NEXTSPACE: - wsep = " "; + ws = " "; /* FALLTHROUGH */ case MODEKEYEDIT_NEXTWORD: - if (wsep == NULL) - wsep = options_get_string(oo, "word-separators"); + if (ws == NULL) + ws = options_get_string(oo, "word-separators"); /* Find a separator. */ while (c->prompt_index != size) { - c->prompt_index++; - if (strchr(wsep, c->prompt_buffer[c->prompt_index])) + idx = ++c->prompt_index; + if (status_prompt_in_list(ws, &c->prompt_buffer[idx])) break; } - /* Find the word right after the separation. */ + /* Find the word right after the separator. */ while (c->prompt_index != size) { - c->prompt_index++; - if (!strchr(wsep, c->prompt_buffer[c->prompt_index])) + idx = ++c->prompt_index; + if (!status_prompt_in_list(ws, &c->prompt_buffer[idx])) break; } c->flags |= CLIENT_STATUS; break; case MODEKEYEDIT_NEXTSPACEEND: - wsep = " "; + ws = " "; /* FALLTHROUGH */ case MODEKEYEDIT_NEXTWORDEND: - if (wsep == NULL) - wsep = options_get_string(oo, "word-separators"); + if (ws == NULL) + ws = options_get_string(oo, "word-separators"); /* Find a word. */ while (c->prompt_index != size) { - c->prompt_index++; - if (!strchr(wsep, c->prompt_buffer[c->prompt_index])) + idx = ++c->prompt_index; + if (!status_prompt_in_list(ws, &c->prompt_buffer[idx])) break; } /* Find the separator at the end of the word. */ while (c->prompt_index != size) { - c->prompt_index++; - if (strchr(wsep, c->prompt_buffer[c->prompt_index])) + idx = ++c->prompt_index; + if (status_prompt_in_list(ws, &c->prompt_buffer[idx])) break; } @@ -1020,23 +1083,23 @@ status_prompt_key(struct client *c, key_code key) c->flags |= CLIENT_STATUS; break; case MODEKEYEDIT_PREVIOUSSPACE: - wsep = " "; + ws = " "; /* FALLTHROUGH */ case MODEKEYEDIT_PREVIOUSWORD: - if (wsep == NULL) - wsep = options_get_string(oo, "word-separators"); + if (ws == NULL) + ws = options_get_string(oo, "word-separators"); /* Find a non-separator. */ while (c->prompt_index != 0) { - c->prompt_index--; - if (!strchr(wsep, c->prompt_buffer[c->prompt_index])) + idx = --c->prompt_index; + if (!status_prompt_in_list(ws, &c->prompt_buffer[idx])) break; } /* Find the separator at the beginning of the word. */ while (c->prompt_index != 0) { - c->prompt_index--; - if (strchr(wsep, c->prompt_buffer[c->prompt_index])) { + idx = --c->prompt_index; + if (status_prompt_in_list(ws, &c->prompt_buffer[idx])) { /* Go back to the word. */ c->prompt_index++; break; @@ -1050,8 +1113,8 @@ status_prompt_key(struct client *c, key_code key) if (histstr == NULL) break; free(c->prompt_buffer); - c->prompt_buffer = xstrdup(histstr); - c->prompt_index = strlen(c->prompt_buffer); + c->prompt_buffer = utf8_fromcstr(histstr); + c->prompt_index = utf8_strlen(c->prompt_buffer); c->flags |= CLIENT_STATUS; break; case MODEKEYEDIT_HISTORYDOWN: @@ -1059,8 +1122,8 @@ status_prompt_key(struct client *c, key_code key) if (histstr == NULL) break; free(c->prompt_buffer); - c->prompt_buffer = xstrdup(histstr); - c->prompt_index = strlen(c->prompt_buffer); + c->prompt_buffer = utf8_fromcstr(histstr); + c->prompt_index = utf8_strlen(c->prompt_buffer); c->flags |= CLIENT_STATUS; break; case MODEKEYEDIT_PASTE: @@ -1069,20 +1132,28 @@ status_prompt_key(struct client *c, key_code key) bufdata = paste_buffer_data(pb, &bufsize); for (n = 0; n < bufsize; n++) { ch = (u_char)bufdata[n]; - if (ch < 32 || ch == 127) + if (ch < 32 || ch >= 127) break; } - c->prompt_buffer = xrealloc(c->prompt_buffer, size + n + 1); + c->prompt_buffer = xreallocarray(c->prompt_buffer, size + n + 1, + sizeof *c->prompt_buffer); if (c->prompt_index == size) { - memcpy(c->prompt_buffer + c->prompt_index, bufdata, n); + for (idx = 0; idx < n; idx++) { + ud = &c->prompt_buffer[c->prompt_index + idx]; + utf8_set(ud, bufdata[idx]); + } c->prompt_index += n; - c->prompt_buffer[c->prompt_index] = '\0'; + c->prompt_buffer[c->prompt_index].size = 0; } else { memmove(c->prompt_buffer + c->prompt_index + n, c->prompt_buffer + c->prompt_index, - size + 1 - c->prompt_index); - memcpy(c->prompt_buffer + c->prompt_index, bufdata, n); + (size + 1 - c->prompt_index) * + sizeof *c->prompt_buffer); + for (idx = 0; idx < n; idx++) { + ud = &c->prompt_buffer[c->prompt_index + idx]; + utf8_set(ud, bufdata[idx]); + } c->prompt_index += n; } @@ -1093,42 +1164,55 @@ status_prompt_key(struct client *c, key_code key) if (idx < size) idx++; if (idx >= 2) { - swapc = c->prompt_buffer[idx - 2]; - c->prompt_buffer[idx - 2] = c->prompt_buffer[idx - 1]; - c->prompt_buffer[idx - 1] = swapc; + utf8_copy(&tmp, &c->prompt_buffer[idx - 2]); + utf8_copy(&c->prompt_buffer[idx - 2], + &c->prompt_buffer[idx - 1]); + utf8_copy(&c->prompt_buffer[idx - 1], &tmp); c->prompt_index = idx; c->flags |= CLIENT_STATUS; } break; case MODEKEYEDIT_ENTER: - if (*c->prompt_buffer != '\0') - status_prompt_add_history(c->prompt_buffer); - if (c->prompt_callbackfn(c->prompt_data, c->prompt_buffer) == 0) + s = utf8_tocstr(c->prompt_buffer); + if (*s != '\0') + status_prompt_add_history(s); + if (c->prompt_callbackfn(c->prompt_data, s) == 0) status_prompt_clear(c); + free(s); break; case MODEKEYEDIT_CANCEL: if (c->prompt_callbackfn(c->prompt_data, NULL) == 0) status_prompt_clear(c); break; case MODEKEY_OTHER: - if (key <= 0x1f || key >= 0x7f) + if (key <= 0x1f || key >= KEYC_BASE) + break; + if (utf8_split(key, &tmp) != UTF8_DONE) break; - c->prompt_buffer = xrealloc(c->prompt_buffer, size + 2); + + c->prompt_buffer = xreallocarray(c->prompt_buffer, size + 2, + sizeof *c->prompt_buffer); if (c->prompt_index == size) { - c->prompt_buffer[c->prompt_index++] = key; - c->prompt_buffer[c->prompt_index] = '\0'; + utf8_copy(&c->prompt_buffer[c->prompt_index], &tmp); + c->prompt_index++; + c->prompt_buffer[c->prompt_index].size = 0; } else { memmove(c->prompt_buffer + c->prompt_index + 1, c->prompt_buffer + c->prompt_index, - size + 1 - c->prompt_index); - c->prompt_buffer[c->prompt_index++] = key; + (size + 1 - c->prompt_index) * + sizeof *c->prompt_buffer); + utf8_copy(&c->prompt_buffer[c->prompt_index], &tmp); + c->prompt_index++; } if (c->prompt_flags & PROMPT_SINGLE) { - if (c->prompt_callbackfn(c->prompt_data, - c->prompt_buffer) == 0) + s = utf8_tocstr(c->prompt_buffer); + if (strlen(s) != 1) + status_prompt_clear(c); + else if (c->prompt_callbackfn(c->prompt_data, s) == 0) status_prompt_clear(c); + free(s); } c->flags |= CLIENT_STATUS; @@ -1247,7 +1331,7 @@ status_prompt_complete_prefix(const char **list, u_int size) /* Complete word. */ static char * -status_prompt_complete(struct session *sess, const char *s) +status_prompt_complete(struct session *session, const char *s) { const char **list = NULL, *colon; u_int size = 0, i; @@ -1300,7 +1384,7 @@ status_prompt_complete(struct session *sess, const char *s) colon = ""; if (*s == ':') { - RB_FOREACH(wl, winlinks, &sess->windows) { + RB_FOREACH(wl, winlinks, &session->windows) { xasprintf(&tmp, ":%s", wl->window->name); if (strncmp(tmp, s, strlen(s)) == 0){ list = xreallocarray(list, size + 1, diff --git a/tmux.h b/tmux.h index 21802854..18ef8082 100644 --- a/tmux.h +++ b/tmux.h @@ -1300,7 +1300,7 @@ struct client { TAILQ_HEAD(, message_entry) message_log; char *prompt_string; - char *prompt_buffer; + struct utf8_data *prompt_buffer; size_t prompt_index; int (*prompt_callbackfn)(void *, const char *); void (*prompt_freefn)(void *); @@ -2345,6 +2345,8 @@ enum utf8_state utf8_combine(const struct utf8_data *, wchar_t *); enum utf8_state utf8_split(wchar_t, struct utf8_data *); int utf8_strvis(char *, const char *, size_t, int); char *utf8_sanitize(const char *); +size_t utf8_strlen(const struct utf8_data *); +u_int utf8_strwidth(const struct utf8_data *, ssize_t); struct utf8_data *utf8_fromcstr(const char *); char *utf8_tocstr(struct utf8_data *); u_int utf8_cstrwidth(const char *); diff --git a/utf8.c b/utf8.c index eadefa11..5ab2127a 100644 --- a/utf8.c +++ b/utf8.c @@ -236,6 +236,33 @@ utf8_sanitize(const char *src) return (dst); } +/* Get UTF-8 buffer length. */ +size_t +utf8_strlen(const struct utf8_data *s) +{ + size_t i; + + for (i = 0; s[i].size != 0; i++) + /* nothing */; + return (i); +} + +/* Get UTF-8 string width. */ +u_int +utf8_strwidth(const struct utf8_data *s, ssize_t n) +{ + ssize_t i; + u_int width; + + width = 0; + for (i = 0; s[i].size != 0; i++) { + if (n != -1 && n == i) + break; + width += s[i].width; + } + return (width); +} + /* * Convert a string into a buffer of UTF-8 characters. Terminated by size == 0. * Caller frees. -- cgit From 76d6d3641f271be1756e41494960d96714e7ee58 Mon Sep 17 00:00:00 2001 From: nicm Date: Tue, 11 Oct 2016 07:23:34 +0000 Subject: Fundamental change to how copy mode key bindings work: The vi-copy and emacs-copy mode key tables are gone, and instead copy mode commands are bound in one of two normal key tables ("copy-mode" or "copy-mode-vi"). Keys are bound to "send-keys -X copy-mode-command". So: bind -temacs-copy C-Up scroll-up bind -temacs-copy -R5 WheelUpPane scroll-up Becomes: bind -Tcopy-mode C-Up send -X scroll-up bind -Tcopy-mode WheelUpPane send -N5 -X scroll-up This allows the full command parser and command set to be used - for example, we can use the normal command prompt for searching, jumping, and so on instead of a custom one: bind -Tcopy-mode C-r command-prompt -p'search up' "send -X search-backward '%%'" command-prompt also gets a -1 option to only require on key press, which is needed for jumping. The plan is to get rid of mode keys entirely, so more to come eventually. --- cmd-bind-key.c | 51 +-- cmd-command-prompt.c | 10 +- cmd-list-keys.c | 24 +- cmd-send-keys.c | 36 ++- key-bindings.c | 136 ++++++++ mode-key.c | 561 +++++++++++---------------------- server-client.c | 33 +- status.c | 2 +- tmux.1 | 200 ++++++------ tmux.h | 64 +--- window-choose.c | 16 +- window-clock.c | 8 +- window-copy.c | 854 +++++++++++++++++++-------------------------------- window.c | 1 + 14 files changed, 806 insertions(+), 1190 deletions(-) diff --git a/cmd-bind-key.c b/cmd-bind-key.c index bcc179c3..69314788 100644 --- a/cmd-bind-key.c +++ b/cmd-bind-key.c @@ -36,8 +36,8 @@ const struct cmd_entry cmd_bind_key_entry = { .name = "bind-key", .alias = "bind", - .args = { "cnrR:t:T:", 1, -1 }, - .usage = "[-cnr] [-t mode-table] [-R repeat-count] [-T key-table] key " + .args = { "cnrt:T:", 1, -1 }, + .usage = "[-cnr] [-t mode-table] [-T key-table] key " "command [arguments]", .flags = 0, @@ -97,12 +97,10 @@ static enum cmd_retval cmd_bind_key_mode_table(struct cmd *self, struct cmd_q *cmdq, key_code key) { struct args *args = self->args; - const char *tablename, *arg; + const char *tablename; const struct mode_key_table *mtab; struct mode_key_binding *mbind, mtmp; enum mode_key_cmd cmd; - char *cause; - u_int repeat; tablename = args_get(args, 't'); if ((mtab = mode_key_findtable(tablename)) == NULL) { @@ -116,44 +114,9 @@ cmd_bind_key_mode_table(struct cmd *self, struct cmd_q *cmdq, key_code key) return (CMD_RETURN_ERROR); } - switch (cmd) { - case MODEKEYCOPY_APPENDSELECTION: - case MODEKEYCOPY_COPYSELECTION: - case MODEKEYCOPY_STARTNAMEDBUFFER: - if (args->argc == 2) - arg = NULL; - else { - arg = args->argv[2]; - if (strcmp(arg, "-x") != 0) { - cmdq_error(cmdq, "unknown argument"); - return (CMD_RETURN_ERROR); - } - } - break; - case MODEKEYCOPY_COPYPIPE: - if (args->argc != 3) { - cmdq_error(cmdq, "no argument given"); - return (CMD_RETURN_ERROR); - } - arg = args->argv[2]; - break; - default: - if (args->argc != 2) { - cmdq_error(cmdq, "no argument allowed"); - return (CMD_RETURN_ERROR); - } - arg = NULL; - break; - } - - repeat = 1; - if (args_has(args, 'R')) { - repeat = args_strtonum(args, 'R', 1, SHRT_MAX, &cause); - if (cause != NULL) { - cmdq_error(cmdq, "repeat count %s", cause); - free(cause); - return (CMD_RETURN_ERROR); - } + if (args->argc != 2) { + cmdq_error(cmdq, "no argument allowed"); + return (CMD_RETURN_ERROR); } mtmp.key = key; @@ -164,8 +127,6 @@ cmd_bind_key_mode_table(struct cmd *self, struct cmd_q *cmdq, key_code key) mbind->mode = mtmp.mode; RB_INSERT(mode_key_tree, mtab->tree, mbind); } - mbind->repeat = repeat; mbind->cmd = cmd; - mbind->arg = arg != NULL ? xstrdup(arg) : NULL; return (CMD_RETURN_NORMAL); } diff --git a/cmd-command-prompt.c b/cmd-command-prompt.c index a2fc1278..09ab9813 100644 --- a/cmd-command-prompt.c +++ b/cmd-command-prompt.c @@ -38,8 +38,8 @@ const struct cmd_entry cmd_command_prompt_entry = { .name = "command-prompt", .alias = NULL, - .args = { "I:p:t:", 0, 1 }, - .usage = "[-I inputs] [-p prompts] " CMD_TARGET_CLIENT_USAGE " " + .args = { "1I:p:t:", 0, 1 }, + .usage = "[-1] [-I inputs] [-p prompts] " CMD_TARGET_CLIENT_USAGE " " "[template]", .tflag = CMD_CLIENT, @@ -67,6 +67,7 @@ cmd_command_prompt_exec(struct cmd *self, struct cmd_q *cmdq) struct client *c = cmdq->state.c; char *prompt, *ptr, *input = NULL; size_t n; + int flags; if (c->prompt_string != NULL) return (CMD_RETURN_NORMAL); @@ -108,8 +109,11 @@ cmd_command_prompt_exec(struct cmd *self, struct cmd_q *cmdq) input = strsep(&cdata->next_input, ","); } + flags = 0; + if (args_has(args, '1')) + flags |= PROMPT_SINGLE; status_prompt_set(c, prompt, input, cmd_command_prompt_callback, - cmd_command_prompt_free, cdata, 0); + cmd_command_prompt_free, cdata, flags); free(prompt); return (CMD_RETURN_NORMAL); diff --git a/cmd-list-keys.c b/cmd-list-keys.c index d5f516fa..85cb4744 100644 --- a/cmd-list-keys.c +++ b/cmd-list-keys.c @@ -138,8 +138,7 @@ cmd_list_keys_table(struct cmd *self, struct cmd_q *cmdq) const char *tablename, *key, *cmdstr, *mode; const struct mode_key_table *mtab; struct mode_key_binding *mbind; - char repeat[16]; - int width, keywidth, repeatwidth, any_mode; + int width, keywidth, any_mode; tablename = args_get(args, 't'); if ((mtab = mode_key_findtable(tablename)) == NULL) { @@ -147,7 +146,7 @@ cmd_list_keys_table(struct cmd *self, struct cmd_q *cmdq) return (CMD_RETURN_ERROR); } - keywidth = repeatwidth = 0; + keywidth = 0; any_mode = 0; RB_FOREACH(mbind, mode_key_tree, mtab->tree) { key = key_string_lookup_key(mbind->key); @@ -158,13 +157,6 @@ cmd_list_keys_table(struct cmd *self, struct cmd_q *cmdq) width = strlen(key); if (width > keywidth) keywidth = width; - - if (mbind->repeat != 1) { - snprintf(repeat, sizeof repeat, "%u", mbind->repeat); - width = strlen(repeat); - if (width > repeatwidth) - repeatwidth = width; - } } RB_FOREACH(mbind, mode_key_tree, mtab->tree) { @@ -173,20 +165,12 @@ cmd_list_keys_table(struct cmd *self, struct cmd_q *cmdq) mode = ""; if (mbind->mode != 0) mode = "c"; - snprintf(repeat, sizeof repeat, "%u", mbind->repeat); cmdstr = mode_key_tostring(mtab->cmdstr, mbind->cmd); if (cmdstr != NULL) { - cmdq_print(cmdq, - "bind-key -%st %s%s%s%*s %*s %s%s%s%s", + cmdq_print(cmdq, "bind-key -%st %s%s %*s %s", mode, any_mode && *mode == '\0' ? " " : "", mtab->name, - mbind->repeat != 1 ? " -R " : - (repeatwidth == 0 ? "" : " "), - repeatwidth, mbind->repeat != 1 ? repeat : "", - (int)keywidth, key, cmdstr, - mbind->arg != NULL ? " \"" : "", - mbind->arg != NULL ? mbind->arg : "", - mbind->arg != NULL ? "\"": ""); + (int)keywidth, key, cmdstr); } } diff --git a/cmd-send-keys.c b/cmd-send-keys.c index 9d6b41d8..e3b8d6e4 100644 --- a/cmd-send-keys.c +++ b/cmd-send-keys.c @@ -33,8 +33,8 @@ const struct cmd_entry cmd_send_keys_entry = { .name = "send-keys", .alias = "send", - .args = { "lRMt:", 0, -1 }, - .usage = "[-lRM] " CMD_TARGET_PANE_USAGE " key ...", + .args = { "lXRMN:t:", 0, -1 }, + .usage = "[-lXRM] [-N repeat-count] " CMD_TARGET_PANE_USAGE " key ...", .tflag = CMD_PANE, @@ -59,12 +59,44 @@ static enum cmd_retval cmd_send_keys_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; + struct client *c = cmdq->state.c; struct window_pane *wp = cmdq->state.tflag.wp; struct session *s = cmdq->state.tflag.s; struct mouse_event *m = &cmdq->item->mouse; const u_char *keystr; int i, literal; key_code key; + u_int np; + char *cause = NULL; + + if (args_has(args, 'N')) { + if (wp->mode == NULL || wp->mode->command == NULL) { + cmdq_error(cmdq, "not in a mode"); + return (CMD_RETURN_ERROR); + } + np = args_strtonum(args, 'N', 1, UINT_MAX, &cause); + if (cause != NULL) { + cmdq_error(cmdq, "prefix %s", cause); + free(cause); + return (CMD_RETURN_ERROR); + } + wp->modeprefix = np; + } + + if (args_has(args, 'X')) { + if (wp->mode == NULL || wp->mode->command == NULL) { + cmdq_error(cmdq, "not in a mode"); + return (CMD_RETURN_ERROR); + } + if (!m->valid) + wp->mode->command(wp, c, s, args, NULL); + else + wp->mode->command(wp, c, s, args, m); + return (CMD_RETURN_NORMAL); + } + + if (args_has(args, 'N')) /* only with -X */ + return (CMD_RETURN_NORMAL); if (args_has(args, 'M')) { wp = cmd_mouse_pane(m, &s, NULL); diff --git a/key-bindings.c b/key-bindings.c index 0d13385d..384a9f8f 100644 --- a/key-bindings.c +++ b/key-bindings.c @@ -232,6 +232,142 @@ key_bindings_init(void) "bind -n MouseDrag1Pane if -Ft= '#{mouse_any_flag}' 'if -Ft= \"#{pane_in_mode}\" \"copy-mode -M\" \"send-keys -M\"' 'copy-mode -M'", "bind -n MouseDown3Pane if-shell -Ft= '#{mouse_any_flag}' 'select-pane -t=; send-keys -M' 'select-pane -mt='", "bind -n WheelUpPane if-shell -Ft= '#{mouse_any_flag}' 'send-keys -M' 'if -Ft= \"#{pane_in_mode}\" \"send-keys -M\" \"copy-mode -et=\"'", + + "bind -Tcopy-mode C-Space send -X begin-selection", + "bind -Tcopy-mode C-a send -X start-of-line", + "bind -Tcopy-mode C-c send -X cancel", + "bind -Tcopy-mode C-e send -X end-of-line", + "bind -Tcopy-mode C-f send -X cursor-right", + "bind -Tcopy-mode C-g send -X clear-selection", + "bind -Tcopy-mode C-k send -X copy-end-of-line", + "bind -Tcopy-mode C-n send -X cursor-down", + "bind -Tcopy-mode C-p send -X cursor-up", + "bind -Tcopy-mode C-r command-prompt -p'search up' \"send -X search-backward '%%'\"", + "bind -Tcopy-mode C-s command-prompt -p'search down' \"send -X search-forward '%%'\"", + "bind -Tcopy-mode C-v send -X page-down", + "bind -Tcopy-mode C-w send -X copy-selection-and-cancel", + "bind -Tcopy-mode Escape send -X cancel", + "bind -Tcopy-mode Space send -X page-down", + "bind -Tcopy-mode , send -X jump-reverse", + "bind -Tcopy-mode \\; send -X jump-again", + "bind -Tcopy-mode F command-prompt -1p'jump backward' \"send -X jump-backward '%%'\"", + "bind -Tcopy-mode N send -X search-reverse", + "bind -Tcopy-mode R send -X rectangle-toggle", + "bind -Tcopy-mode T command-prompt -1p'jump to backward' \"send -X jump-to-backward '%%'\"", + "bind -Tcopy-mode f command-prompt -1p'jump forward' \"send -X jump-forward '%%'\"", + "bind -Tcopy-mode g command-prompt -p'goto line' \"send -X goto-line '%%'\"", + "bind -Tcopy-mode n send -X search-again", + "bind -Tcopy-mode q send -X cancel", + "bind -Tcopy-mode t command-prompt -1p'jump to forward' \"send -X jump-to-forward '%%'\"", + "bind -Tcopy-mode MouseDrag1Pane send -X begin-selection", + "bind -Tcopy-mode MouseDragEnd1Pane send -X copy-selection-and-cancel", + "bind -Tcopy-mode WheelUpPane send -N5 -X scroll-up", + "bind -Tcopy-mode WheelDownPane send -N5 -X scroll-down", + "bind -Tcopy-mode NPage send -X page-down", + "bind -Tcopy-mode PPage send -X page-up", + "bind -Tcopy-mode Up send -X cursor-up", + "bind -Tcopy-mode Down send -X cursor-down", + "bind -Tcopy-mode Left send -X cursor-left", + "bind -Tcopy-mode Right send -X cursor-right", + "bind -Tcopy-mode M-1 command-prompt -p'repeat' -I1 \"send -N '%%'\"", + "bind -Tcopy-mode M-2 command-prompt -p'repeat' -I2 \"send -N '%%'\"", + "bind -Tcopy-mode M-3 command-prompt -p'repeat' -I3 \"send -N '%%'\"", + "bind -Tcopy-mode M-4 command-prompt -p'repeat' -I4 \"send -N '%%'\"", + "bind -Tcopy-mode M-5 command-prompt -p'repeat' -I5 \"send -N '%%'\"", + "bind -Tcopy-mode M-6 command-prompt -p'repeat' -I6 \"send -N '%%'\"", + "bind -Tcopy-mode M-7 command-prompt -p'repeat' -I7 \"send -N '%%'\"", + "bind -Tcopy-mode M-8 command-prompt -p'repeat' -I8 \"send -N '%%'\"", + "bind -Tcopy-mode M-9 command-prompt -p'repeat' -I9 \"send -N '%%'\"", + "bind -Tcopy-mode M-< send -X history-top", + "bind -Tcopy-mode M-> send -X history-bottom", + "bind -Tcopy-mode M-R send -X top-line", + "bind -Tcopy-mode M-b send -X previous-word", + "bind -Tcopy-mode M-f send -X next-word-end", + "bind -Tcopy-mode M-m send -X back-to-indentation", + "bind -Tcopy-mode M-r send -X middle-line", + "bind -Tcopy-mode M-v send -X page-up", + "bind -Tcopy-mode M-w send -X copy-selection-and-cancel", + "bind -Tcopy-mode M-{ send -X previous-paragraph", + "bind -Tcopy-mode M-} send -X next-paragraph", + "bind -Tcopy-mode M-Up send -X halfpage-up", + "bind -Tcopy-mode M-Down send -X halfpage-down", + "bind -Tcopy-mode C-Up send -X scroll-up", + "bind -Tcopy-mode C-Down send -X scroll-down", + + "bind -Tcopy-mode-vi C-b send -X page-up", + "bind -Tcopy-mode-vi C-c send -X cancel", + "bind -Tcopy-mode-vi C-d send -X halfpage-down", + "bind -Tcopy-mode-vi C-e send -X scroll-down", + "bind -Tcopy-mode-vi C-f send -X page-down", + "bind -Tcopy-mode-vi C-h send -X cursor-left", + "bind -Tcopy-mode-vi C-j send -X copy-selection-and-cancel", + "bind -Tcopy-mode-vi Enter send -X copy-selection-and-cancel", + "bind -Tcopy-mode-vi C-u send -X halfpage-up", + "bind -Tcopy-mode-vi C-v send -X rectangle-toggle", + "bind -Tcopy-mode-vi C-y send -X scroll-up", + "bind -Tcopy-mode-vi Escape send -X clear-selection", + "bind -Tcopy-mode-vi Space send -X begin-selection", + "bind -Tcopy-mode-vi '$' send -X end-of-line", + "bind -Tcopy-mode-vi , send -X jump-reverse", + "bind -Tcopy-mode-vi / command-prompt -p'search down' \"send -X search-forward '%%'\"", + "bind -Tcopy-mode-vi 0 send -X start-of-line", + "bind -Tcopy-mode-vi 1 command-prompt -p'repeat' -I1 \"send -N '%%'\"", + "bind -Tcopy-mode-vi 2 command-prompt -p'repeat' -I2 \"send -N '%%'\"", + "bind -Tcopy-mode-vi 3 command-prompt -p'repeat' -I3 \"send -N '%%'\"", + "bind -Tcopy-mode-vi 4 command-prompt -p'repeat' -I4 \"send -N '%%'\"", + "bind -Tcopy-mode-vi 5 command-prompt -p'repeat' -I5 \"send -N '%%'\"", + "bind -Tcopy-mode-vi 6 command-prompt -p'repeat' -I6 \"send -N '%%'\"", + "bind -Tcopy-mode-vi 7 command-prompt -p'repeat' -I7 \"send -N '%%'\"", + "bind -Tcopy-mode-vi 8 command-prompt -p'repeat' -I8 \"send -N '%%'\"", + "bind -Tcopy-mode-vi 9 command-prompt -p'repeat' -I9 \"send -N '%%'\"", + "bind -Tcopy-mode-vi : command-prompt -p'goto line' \"send -X goto-line '%%'\"", + "bind -Tcopy-mode-vi \\; send -X jump-again" + "bind -Tcopy-mode-vi ? command-prompt -p'search up' \"send -X search-backward '%%'\"", + "bind -Tcopy-mode-vi A send -X append-selection-and-cancel", + "bind -Tcopy-mode-vi B send -X previous-space", + "bind -Tcopy-mode-vi D send -X copy-end-of-line", + "bind -Tcopy-mode-vi E send -X next-space-end", + "bind -Tcopy-mode-vi F command-prompt -1p'jump backward' \"send -X jump-backward '%%'\"", + "bind -Tcopy-mode-vi G send -X history-bottom", + "bind -Tcopy-mode-vi H send -X top-line", + "bind -Tcopy-mode-vi J send -X scroll-down", + "bind -Tcopy-mode-vi K send -X scroll-up", + "bind -Tcopy-mode-vi L send -X bottom-line", + "bind -Tcopy-mode-vi M send -X middle-line", + "bind -Tcopy-mode-vi N send -X search-reverse", + "bind -Tcopy-mode-vi T command-prompt -1p'jump to backward' \"send -X jump-to-backward '%%'\"", + "bind -Tcopy-mode-vi V send -X select-line", + "bind -Tcopy-mode-vi W send -X next-space", + "bind -Tcopy-mode-vi ^ send -X back-to-indentation", + "bind -Tcopy-mode-vi b send -X previous-word", + "bind -Tcopy-mode-vi e send -X next-word-end", + "bind -Tcopy-mode-vi f command-prompt -1p'jump forward' \"send -X jump-forward '%%'\"", + "bind -Tcopy-mode-vi g send -X history-top", + "bind -Tcopy-mode-vi h send -X cursor-left", + "bind -Tcopy-mode-vi j send -X cursor-down", + "bind -Tcopy-mode-vi k send -X cursor-up", + "bind -Tcopy-mode-vi l send -X cursor-right", + "bind -Tcopy-mode-vi n send -X search-again", + "bind -Tcopy-mode-vi o send -X other-end", + "bind -Tcopy-mode-vi q send -X cancel", + "bind -Tcopy-mode-vi t command-prompt -1p'jump to forward' \"send -X jump-to-forward '%%'\"", + "bind -Tcopy-mode-vi v send -X rectangle-toggle", + "bind -Tcopy-mode-vi w send -X next-word", + "bind -Tcopy-mode-vi { send -X previous-paragraph", + "bind -Tcopy-mode-vi } send -X next-paragraph", + "bind -Tcopy-mode-vi MouseDrag1Pane send -X begin-selection", + "bind -Tcopy-mode-vi MouseDragEnd1Pane send -X copy-selection-and-cancel", + "bind -Tcopy-mode-vi WheelUpPane send -N5 -X scroll-up", + "bind -Tcopy-mode-vi WheelDownPane send -N5 -X scroll-down", + "bind -Tcopy-mode-vi BSpace send -X cursor-left", + "bind -Tcopy-mode-vi NPage send -X page-down", + "bind -Tcopy-mode-vi PPage send -X page-up", + "bind -Tcopy-mode-vi Up send -X cursor-up", + "bind -Tcopy-mode-vi Down send -X cursor-down", + "bind -Tcopy-mode-vi Left send -X cursor-left", + "bind -Tcopy-mode-vi Right send -X cursor-right", + "bind -Tcopy-mode-vi C-Up send -X scroll-up", + "bind -Tcopy-mode-vi C-Down send -X scroll-down", }; u_int i; struct cmd_list *cmdlist; diff --git a/mode-key.c b/mode-key.c index 26c7c478..5c3c7889 100644 --- a/mode-key.c +++ b/mode-key.c @@ -50,7 +50,6 @@ struct mode_key_entry { */ int mode; enum mode_key_cmd cmd; - u_int repeat; }; /* Edit keys command strings. */ @@ -113,416 +112,207 @@ static const struct mode_key_cmdstr mode_key_cmdstr_choice[] = { { 0, NULL } }; -/* Copy keys command strings. */ -static const struct mode_key_cmdstr mode_key_cmdstr_copy[] = { - { MODEKEYCOPY_APPENDSELECTION, "append-selection" }, - { MODEKEYCOPY_BACKTOINDENTATION, "back-to-indentation" }, - { MODEKEYCOPY_BOTTOMLINE, "bottom-line" }, - { MODEKEYCOPY_CANCEL, "cancel" }, - { MODEKEYCOPY_CLEARSELECTION, "clear-selection" }, - { MODEKEYCOPY_COPYPIPE, "copy-pipe" }, - { MODEKEYCOPY_COPYLINE, "copy-line" }, - { MODEKEYCOPY_COPYENDOFLINE, "copy-end-of-line" }, - { MODEKEYCOPY_COPYSELECTION, "copy-selection" }, - { MODEKEYCOPY_DOWN, "cursor-down" }, - { MODEKEYCOPY_ENDOFLINE, "end-of-line" }, - { MODEKEYCOPY_GOTOLINE, "goto-line" }, - { MODEKEYCOPY_HALFPAGEDOWN, "halfpage-down" }, - { MODEKEYCOPY_HALFPAGEUP, "halfpage-up" }, - { MODEKEYCOPY_HISTORYBOTTOM, "history-bottom" }, - { MODEKEYCOPY_HISTORYTOP, "history-top" }, - { MODEKEYCOPY_JUMP, "jump-forward" }, - { MODEKEYCOPY_JUMPAGAIN, "jump-again" }, - { MODEKEYCOPY_JUMPREVERSE, "jump-reverse" }, - { MODEKEYCOPY_JUMPBACK, "jump-backward" }, - { MODEKEYCOPY_JUMPTO, "jump-to-forward" }, - { MODEKEYCOPY_JUMPTOBACK, "jump-to-backward" }, - { MODEKEYCOPY_LEFT, "cursor-left" }, - { MODEKEYCOPY_RECTANGLETOGGLE, "rectangle-toggle" }, - { MODEKEYCOPY_MIDDLELINE, "middle-line" }, - { MODEKEYCOPY_NEXTPAGE, "page-down" }, - { MODEKEYCOPY_NEXTPARAGRAPH, "next-paragraph" }, - { MODEKEYCOPY_NEXTSPACE, "next-space" }, - { MODEKEYCOPY_NEXTSPACEEND, "next-space-end" }, - { MODEKEYCOPY_NEXTWORD, "next-word" }, - { MODEKEYCOPY_NEXTWORDEND, "next-word-end" }, - { MODEKEYCOPY_OTHEREND, "other-end" }, - { MODEKEYCOPY_PREVIOUSPAGE, "page-up" }, - { MODEKEYCOPY_PREVIOUSPARAGRAPH, "previous-paragraph" }, - { MODEKEYCOPY_PREVIOUSSPACE, "previous-space" }, - { MODEKEYCOPY_PREVIOUSWORD, "previous-word" }, - { MODEKEYCOPY_RIGHT, "cursor-right" }, - { MODEKEYCOPY_SCROLLDOWN, "scroll-down" }, - { MODEKEYCOPY_SCROLLUP, "scroll-up" }, - { MODEKEYCOPY_SEARCHAGAIN, "search-again" }, - { MODEKEYCOPY_SEARCHDOWN, "search-forward" }, - { MODEKEYCOPY_SEARCHREVERSE, "search-reverse" }, - { MODEKEYCOPY_SEARCHUP, "search-backward" }, - { MODEKEYCOPY_SELECTLINE, "select-line" }, - { MODEKEYCOPY_STARTNAMEDBUFFER, "start-named-buffer" }, - { MODEKEYCOPY_STARTNUMBERPREFIX, "start-number-prefix" }, - { MODEKEYCOPY_STARTOFLINE, "start-of-line" }, - { MODEKEYCOPY_STARTSELECTION, "begin-selection" }, - { MODEKEYCOPY_TOPLINE, "top-line" }, - { MODEKEYCOPY_UP, "cursor-up" }, - - { 0, NULL } -}; - /* vi editing keys. */ static const struct mode_key_entry mode_key_vi_edit[] = { - { '\003' /* C-c */, 0, MODEKEYEDIT_CANCEL, 1 }, - { '\010' /* C-h */, 0, MODEKEYEDIT_BACKSPACE, 1 }, - { '\011' /* Tab */, 0, MODEKEYEDIT_COMPLETE, 1 }, - { '\025' /* C-u */, 0, MODEKEYEDIT_DELETELINE, 1 }, - { '\027' /* C-w */, 0, MODEKEYEDIT_DELETEWORD, 1 }, - { '\033' /* Escape */, 0, MODEKEYEDIT_SWITCHMODE, 1 }, - { '\n', 0, MODEKEYEDIT_ENTER, 1 }, - { '\r', 0, MODEKEYEDIT_ENTER, 1 }, - { KEYC_BSPACE, 0, MODEKEYEDIT_BACKSPACE, 1 }, - { KEYC_DC, 0, MODEKEYEDIT_DELETE, 1 }, - { KEYC_DOWN, 0, MODEKEYEDIT_HISTORYDOWN, 1 }, - { KEYC_LEFT, 0, MODEKEYEDIT_CURSORLEFT, 1 }, - { KEYC_RIGHT, 0, MODEKEYEDIT_CURSORRIGHT, 1 }, - { KEYC_UP, 0, MODEKEYEDIT_HISTORYUP, 1 }, - { KEYC_HOME, 0, MODEKEYEDIT_STARTOFLINE, 1 }, - { KEYC_END, 0, MODEKEYEDIT_ENDOFLINE, 1 }, - - { '$', 1, MODEKEYEDIT_ENDOFLINE, 1 }, - { '0', 1, MODEKEYEDIT_STARTOFLINE, 1 }, - { 'A', 1, MODEKEYEDIT_SWITCHMODEAPPENDLINE, 1 }, - { 'B', 1, MODEKEYEDIT_PREVIOUSSPACE, 1 }, - { 'C', 1, MODEKEYEDIT_SWITCHMODECHANGELINE, 1 }, - { 'D', 1, MODEKEYEDIT_DELETETOENDOFLINE, 1 }, - { 'E', 1, MODEKEYEDIT_NEXTSPACEEND, 1 }, - { 'I', 1, MODEKEYEDIT_SWITCHMODEBEGINLINE, 1 }, - { 'S', 1, MODEKEYEDIT_SWITCHMODESUBSTITUTELINE, 1 }, - { 'W', 1, MODEKEYEDIT_NEXTSPACE, 1 }, - { 'X', 1, MODEKEYEDIT_BACKSPACE, 1 }, - { '\003' /* C-c */, 1, MODEKEYEDIT_CANCEL, 1 }, - { '\010' /* C-h */, 1, MODEKEYEDIT_BACKSPACE, 1 }, - { '\n', 1, MODEKEYEDIT_ENTER, 1 }, - { '\r', 1, MODEKEYEDIT_ENTER, 1 }, - { '^', 1, MODEKEYEDIT_STARTOFLINE, 1 }, - { 'a', 1, MODEKEYEDIT_SWITCHMODEAPPEND, 1 }, - { 'b', 1, MODEKEYEDIT_PREVIOUSWORD, 1 }, - { 'd', 1, MODEKEYEDIT_DELETELINE, 1 }, - { 'e', 1, MODEKEYEDIT_NEXTWORDEND, 1 }, - { 'h', 1, MODEKEYEDIT_CURSORLEFT, 1 }, - { 'i', 1, MODEKEYEDIT_SWITCHMODE, 1 }, - { 'j', 1, MODEKEYEDIT_HISTORYDOWN, 1 }, - { 'k', 1, MODEKEYEDIT_HISTORYUP, 1 }, - { 'l', 1, MODEKEYEDIT_CURSORRIGHT, 1 }, - { 'p', 1, MODEKEYEDIT_PASTE, 1 }, - { 's', 1, MODEKEYEDIT_SWITCHMODESUBSTITUTE, 1 }, - { 'w', 1, MODEKEYEDIT_NEXTWORD, 1 }, - { 'x', 1, MODEKEYEDIT_DELETE, 1 }, - { KEYC_BSPACE, 1, MODEKEYEDIT_BACKSPACE, 1 }, - { KEYC_DC, 1, MODEKEYEDIT_DELETE, 1 }, - { KEYC_DOWN, 1, MODEKEYEDIT_HISTORYDOWN, 1 }, - { KEYC_LEFT, 1, MODEKEYEDIT_CURSORLEFT, 1 }, - { KEYC_RIGHT, 1, MODEKEYEDIT_CURSORRIGHT, 1 }, - { KEYC_UP, 1, MODEKEYEDIT_HISTORYUP, 1 }, - - { 0, -1, 0, 1 } + { '\003' /* C-c */, 0, MODEKEYEDIT_CANCEL }, + { '\010' /* C-h */, 0, MODEKEYEDIT_BACKSPACE }, + { '\011' /* Tab */, 0, MODEKEYEDIT_COMPLETE }, + { '\025' /* C-u */, 0, MODEKEYEDIT_DELETELINE }, + { '\027' /* C-w */, 0, MODEKEYEDIT_DELETEWORD }, + { '\033' /* Escape */, 0, MODEKEYEDIT_SWITCHMODE }, + { '\n', 0, MODEKEYEDIT_ENTER }, + { '\r', 0, MODEKEYEDIT_ENTER }, + { KEYC_BSPACE, 0, MODEKEYEDIT_BACKSPACE }, + { KEYC_DC, 0, MODEKEYEDIT_DELETE }, + { KEYC_DOWN, 0, MODEKEYEDIT_HISTORYDOWN }, + { KEYC_LEFT, 0, MODEKEYEDIT_CURSORLEFT }, + { KEYC_RIGHT, 0, MODEKEYEDIT_CURSORRIGHT }, + { KEYC_UP, 0, MODEKEYEDIT_HISTORYUP }, + { KEYC_HOME, 0, MODEKEYEDIT_STARTOFLINE }, + { KEYC_END, 0, MODEKEYEDIT_ENDOFLINE }, + + { '$', 1, MODEKEYEDIT_ENDOFLINE }, + { '0', 1, MODEKEYEDIT_STARTOFLINE }, + { 'A', 1, MODEKEYEDIT_SWITCHMODEAPPENDLINE }, + { 'B', 1, MODEKEYEDIT_PREVIOUSSPACE }, + { 'C', 1, MODEKEYEDIT_SWITCHMODECHANGELINE }, + { 'D', 1, MODEKEYEDIT_DELETETOENDOFLINE }, + { 'E', 1, MODEKEYEDIT_NEXTSPACEEND }, + { 'I', 1, MODEKEYEDIT_SWITCHMODEBEGINLINE }, + { 'S', 1, MODEKEYEDIT_SWITCHMODESUBSTITUTELINE }, + { 'W', 1, MODEKEYEDIT_NEXTSPACE }, + { 'X', 1, MODEKEYEDIT_BACKSPACE }, + { '\003' /* C-c */, 1, MODEKEYEDIT_CANCEL }, + { '\010' /* C-h */, 1, MODEKEYEDIT_BACKSPACE }, + { '\n', 1, MODEKEYEDIT_ENTER }, + { '\r', 1, MODEKEYEDIT_ENTER }, + { '^', 1, MODEKEYEDIT_STARTOFLINE }, + { 'a', 1, MODEKEYEDIT_SWITCHMODEAPPEND }, + { 'b', 1, MODEKEYEDIT_PREVIOUSWORD }, + { 'd', 1, MODEKEYEDIT_DELETELINE }, + { 'e', 1, MODEKEYEDIT_NEXTWORDEND }, + { 'h', 1, MODEKEYEDIT_CURSORLEFT }, + { 'i', 1, MODEKEYEDIT_SWITCHMODE }, + { 'j', 1, MODEKEYEDIT_HISTORYDOWN }, + { 'k', 1, MODEKEYEDIT_HISTORYUP }, + { 'l', 1, MODEKEYEDIT_CURSORRIGHT }, + { 'p', 1, MODEKEYEDIT_PASTE }, + { 's', 1, MODEKEYEDIT_SWITCHMODESUBSTITUTE }, + { 'w', 1, MODEKEYEDIT_NEXTWORD }, + { 'x', 1, MODEKEYEDIT_DELETE }, + { KEYC_BSPACE, 1, MODEKEYEDIT_BACKSPACE }, + { KEYC_DC, 1, MODEKEYEDIT_DELETE }, + { KEYC_DOWN, 1, MODEKEYEDIT_HISTORYDOWN }, + { KEYC_LEFT, 1, MODEKEYEDIT_CURSORLEFT }, + { KEYC_RIGHT, 1, MODEKEYEDIT_CURSORRIGHT }, + { KEYC_UP, 1, MODEKEYEDIT_HISTORYUP }, + + { 0, -1, 0 } }; struct mode_key_tree mode_key_tree_vi_edit; /* vi choice selection keys. */ static const struct mode_key_entry mode_key_vi_choice[] = { - { '0' | KEYC_ESCAPE, 0, MODEKEYCHOICE_STARTNUMBERPREFIX, 1 }, - { '1' | KEYC_ESCAPE, 0, MODEKEYCHOICE_STARTNUMBERPREFIX, 1 }, - { '2' | KEYC_ESCAPE, 0, MODEKEYCHOICE_STARTNUMBERPREFIX, 1 }, - { '3' | KEYC_ESCAPE, 0, MODEKEYCHOICE_STARTNUMBERPREFIX, 1 }, - { '4' | KEYC_ESCAPE, 0, MODEKEYCHOICE_STARTNUMBERPREFIX, 1 }, - { '5' | KEYC_ESCAPE, 0, MODEKEYCHOICE_STARTNUMBERPREFIX, 1 }, - { '6' | KEYC_ESCAPE, 0, MODEKEYCHOICE_STARTNUMBERPREFIX, 1 }, - { '7' | KEYC_ESCAPE, 0, MODEKEYCHOICE_STARTNUMBERPREFIX, 1 }, - { '8' | KEYC_ESCAPE, 0, MODEKEYCHOICE_STARTNUMBERPREFIX, 1 }, - { '9' | KEYC_ESCAPE, 0, MODEKEYCHOICE_STARTNUMBERPREFIX, 1 }, - { '\002' /* C-b */, 0, MODEKEYCHOICE_PAGEUP, 1 }, - { '\003' /* C-c */, 0, MODEKEYCHOICE_CANCEL, 1 }, - { '\005' /* C-e */, 0, MODEKEYCHOICE_SCROLLDOWN, 1 }, - { '\006' /* C-f */, 0, MODEKEYCHOICE_PAGEDOWN, 1 }, - { '\031' /* C-y */, 0, MODEKEYCHOICE_SCROLLUP, 1 }, - { '\n', 0, MODEKEYCHOICE_CHOOSE, 1 }, - { '\r', 0, MODEKEYCHOICE_CHOOSE, 1 }, - { 'j', 0, MODEKEYCHOICE_DOWN, 1 }, - { 'k', 0, MODEKEYCHOICE_UP, 1 }, - { 'q', 0, MODEKEYCHOICE_CANCEL, 1 }, - { KEYC_HOME, 0, MODEKEYCHOICE_STARTOFLIST, 1 }, - { 'g', 0, MODEKEYCHOICE_STARTOFLIST, 1 }, - { 'H', 0, MODEKEYCHOICE_TOPLINE, 1 }, - { 'L', 0, MODEKEYCHOICE_BOTTOMLINE, 1 }, - { 'G', 0, MODEKEYCHOICE_ENDOFLIST, 1 }, - { KEYC_END, 0, MODEKEYCHOICE_ENDOFLIST, 1 }, - { KEYC_BSPACE, 0, MODEKEYCHOICE_BACKSPACE, 1 }, - { KEYC_DOWN | KEYC_CTRL, 0, MODEKEYCHOICE_SCROLLDOWN, 1 }, - { KEYC_DOWN, 0, MODEKEYCHOICE_DOWN, 1 }, - { KEYC_NPAGE, 0, MODEKEYCHOICE_PAGEDOWN, 1 }, - { KEYC_PPAGE, 0, MODEKEYCHOICE_PAGEUP, 1 }, - { KEYC_UP | KEYC_CTRL, 0, MODEKEYCHOICE_SCROLLUP, 1 }, - { KEYC_UP, 0, MODEKEYCHOICE_UP, 1 }, - { ' ', 0, MODEKEYCHOICE_TREE_TOGGLE, 1 }, - { KEYC_LEFT, 0, MODEKEYCHOICE_TREE_COLLAPSE, 1 }, - { KEYC_RIGHT, 0, MODEKEYCHOICE_TREE_EXPAND, 1 }, - { KEYC_LEFT | KEYC_CTRL, 0, MODEKEYCHOICE_TREE_COLLAPSE_ALL, 1 }, - { KEYC_RIGHT | KEYC_CTRL, 0, MODEKEYCHOICE_TREE_EXPAND_ALL, 1 }, - { KEYC_MOUSEDOWN1_PANE, 0, MODEKEYCHOICE_CHOOSE, 1 }, - { KEYC_MOUSEDOWN3_PANE, 0, MODEKEYCHOICE_TREE_TOGGLE, 1 }, - { KEYC_WHEELUP_PANE, 0, MODEKEYCHOICE_UP, 1 }, - { KEYC_WHEELDOWN_PANE, 0, MODEKEYCHOICE_DOWN, 1 }, - - { 0, -1, 0, 1 } + { '0' | KEYC_ESCAPE, 0, MODEKEYCHOICE_STARTNUMBERPREFIX }, + { '1' | KEYC_ESCAPE, 0, MODEKEYCHOICE_STARTNUMBERPREFIX }, + { '2' | KEYC_ESCAPE, 0, MODEKEYCHOICE_STARTNUMBERPREFIX }, + { '3' | KEYC_ESCAPE, 0, MODEKEYCHOICE_STARTNUMBERPREFIX }, + { '4' | KEYC_ESCAPE, 0, MODEKEYCHOICE_STARTNUMBERPREFIX }, + { '5' | KEYC_ESCAPE, 0, MODEKEYCHOICE_STARTNUMBERPREFIX }, + { '6' | KEYC_ESCAPE, 0, MODEKEYCHOICE_STARTNUMBERPREFIX }, + { '7' | KEYC_ESCAPE, 0, MODEKEYCHOICE_STARTNUMBERPREFIX }, + { '8' | KEYC_ESCAPE, 0, MODEKEYCHOICE_STARTNUMBERPREFIX }, + { '9' | KEYC_ESCAPE, 0, MODEKEYCHOICE_STARTNUMBERPREFIX }, + { '\002' /* C-b */, 0, MODEKEYCHOICE_PAGEUP }, + { '\003' /* C-c */, 0, MODEKEYCHOICE_CANCEL }, + { '\005' /* C-e */, 0, MODEKEYCHOICE_SCROLLDOWN }, + { '\006' /* C-f */, 0, MODEKEYCHOICE_PAGEDOWN }, + { '\031' /* C-y */, 0, MODEKEYCHOICE_SCROLLUP }, + { '\n', 0, MODEKEYCHOICE_CHOOSE }, + { '\r', 0, MODEKEYCHOICE_CHOOSE }, + { 'j', 0, MODEKEYCHOICE_DOWN }, + { 'k', 0, MODEKEYCHOICE_UP }, + { 'q', 0, MODEKEYCHOICE_CANCEL }, + { KEYC_HOME, 0, MODEKEYCHOICE_STARTOFLIST }, + { 'g', 0, MODEKEYCHOICE_STARTOFLIST }, + { 'H', 0, MODEKEYCHOICE_TOPLINE }, + { 'L', 0, MODEKEYCHOICE_BOTTOMLINE }, + { 'G', 0, MODEKEYCHOICE_ENDOFLIST }, + { KEYC_END, 0, MODEKEYCHOICE_ENDOFLIST }, + { KEYC_BSPACE, 0, MODEKEYCHOICE_BACKSPACE }, + { KEYC_DOWN | KEYC_CTRL, 0, MODEKEYCHOICE_SCROLLDOWN }, + { KEYC_DOWN, 0, MODEKEYCHOICE_DOWN }, + { KEYC_NPAGE, 0, MODEKEYCHOICE_PAGEDOWN }, + { KEYC_PPAGE, 0, MODEKEYCHOICE_PAGEUP }, + { KEYC_UP | KEYC_CTRL, 0, MODEKEYCHOICE_SCROLLUP }, + { KEYC_UP, 0, MODEKEYCHOICE_UP }, + { ' ', 0, MODEKEYCHOICE_TREE_TOGGLE }, + { KEYC_LEFT, 0, MODEKEYCHOICE_TREE_COLLAPSE }, + { KEYC_RIGHT, 0, MODEKEYCHOICE_TREE_EXPAND }, + { KEYC_LEFT | KEYC_CTRL, 0, MODEKEYCHOICE_TREE_COLLAPSE_ALL }, + { KEYC_RIGHT | KEYC_CTRL, 0, MODEKEYCHOICE_TREE_EXPAND_ALL }, + { KEYC_MOUSEDOWN1_PANE, 0, MODEKEYCHOICE_CHOOSE }, + { KEYC_MOUSEDOWN3_PANE, 0, MODEKEYCHOICE_TREE_TOGGLE }, + { KEYC_WHEELUP_PANE, 0, MODEKEYCHOICE_UP }, + { KEYC_WHEELDOWN_PANE, 0, MODEKEYCHOICE_DOWN }, + + { 0, -1, 0 } }; struct mode_key_tree mode_key_tree_vi_choice; -/* vi copy mode keys. */ -static const struct mode_key_entry mode_key_vi_copy[] = { - { ' ', 0, MODEKEYCOPY_STARTSELECTION, 1 }, - { '"', 0, MODEKEYCOPY_STARTNAMEDBUFFER, 1 }, - { '$', 0, MODEKEYCOPY_ENDOFLINE, 1 }, - { ',', 0, MODEKEYCOPY_JUMPREVERSE, 1 }, - { ';', 0, MODEKEYCOPY_JUMPAGAIN, 1 }, - { '/', 0, MODEKEYCOPY_SEARCHDOWN, 1 }, - { '0', 0, MODEKEYCOPY_STARTOFLINE, 1 }, - { '1', 0, MODEKEYCOPY_STARTNUMBERPREFIX, 1 }, - { '2', 0, MODEKEYCOPY_STARTNUMBERPREFIX, 1 }, - { '3', 0, MODEKEYCOPY_STARTNUMBERPREFIX, 1 }, - { '4', 0, MODEKEYCOPY_STARTNUMBERPREFIX, 1 }, - { '5', 0, MODEKEYCOPY_STARTNUMBERPREFIX, 1 }, - { '6', 0, MODEKEYCOPY_STARTNUMBERPREFIX, 1 }, - { '7', 0, MODEKEYCOPY_STARTNUMBERPREFIX, 1 }, - { '8', 0, MODEKEYCOPY_STARTNUMBERPREFIX, 1 }, - { '9', 0, MODEKEYCOPY_STARTNUMBERPREFIX, 1 }, - { ':', 0, MODEKEYCOPY_GOTOLINE, 1 }, - { '?', 0, MODEKEYCOPY_SEARCHUP, 1 }, - { 'A', 0, MODEKEYCOPY_APPENDSELECTION, 1 }, - { 'B', 0, MODEKEYCOPY_PREVIOUSSPACE, 1 }, - { 'D', 0, MODEKEYCOPY_COPYENDOFLINE, 1 }, - { 'E', 0, MODEKEYCOPY_NEXTSPACEEND, 1 }, - { 'F', 0, MODEKEYCOPY_JUMPBACK, 1 }, - { 'G', 0, MODEKEYCOPY_HISTORYBOTTOM, 1 }, - { 'H', 0, MODEKEYCOPY_TOPLINE, 1 }, - { 'J', 0, MODEKEYCOPY_SCROLLDOWN, 1 }, - { 'K', 0, MODEKEYCOPY_SCROLLUP, 1 }, - { 'L', 0, MODEKEYCOPY_BOTTOMLINE, 1 }, - { 'M', 0, MODEKEYCOPY_MIDDLELINE, 1 }, - { 'N', 0, MODEKEYCOPY_SEARCHREVERSE, 1 }, - { 'T', 0, MODEKEYCOPY_JUMPTOBACK, 1 }, - { 'V', 0, MODEKEYCOPY_SELECTLINE, 1 }, - { 'W', 0, MODEKEYCOPY_NEXTSPACE, 1 }, - { '\002' /* C-b */, 0, MODEKEYCOPY_PREVIOUSPAGE, 1 }, - { '\003' /* C-c */, 0, MODEKEYCOPY_CANCEL, 1 }, - { '\004' /* C-d */, 0, MODEKEYCOPY_HALFPAGEDOWN, 1 }, - { '\005' /* C-e */, 0, MODEKEYCOPY_SCROLLDOWN, 1 }, - { '\006' /* C-f */, 0, MODEKEYCOPY_NEXTPAGE, 1 }, - { '\010' /* C-h */, 0, MODEKEYCOPY_LEFT, 1 }, - { '\025' /* C-u */, 0, MODEKEYCOPY_HALFPAGEUP, 1 }, - { '\031' /* C-y */, 0, MODEKEYCOPY_SCROLLUP, 1 }, - { '\033' /* Escape */, 0, MODEKEYCOPY_CLEARSELECTION, 1 }, - { '\n', 0, MODEKEYCOPY_COPYSELECTION, 1 }, - { '\r', 0, MODEKEYCOPY_COPYSELECTION, 1 }, - { '^', 0, MODEKEYCOPY_BACKTOINDENTATION, 1 }, - { 'b', 0, MODEKEYCOPY_PREVIOUSWORD, 1 }, - { 'e', 0, MODEKEYCOPY_NEXTWORDEND, 1 }, - { 'f', 0, MODEKEYCOPY_JUMP, 1 }, - { 'g', 0, MODEKEYCOPY_HISTORYTOP, 1 }, - { 'h', 0, MODEKEYCOPY_LEFT, 1 }, - { 'j', 0, MODEKEYCOPY_DOWN, 1 }, - { 'k', 0, MODEKEYCOPY_UP, 1 }, - { 'l', 0, MODEKEYCOPY_RIGHT, 1 }, - { 'n', 0, MODEKEYCOPY_SEARCHAGAIN, 1 }, - { 'o', 0, MODEKEYCOPY_OTHEREND, 1 }, - { 't', 0, MODEKEYCOPY_JUMPTO, 1 }, - { 'q', 0, MODEKEYCOPY_CANCEL, 1 }, - { 'v', 0, MODEKEYCOPY_RECTANGLETOGGLE, 1 }, - { 'w', 0, MODEKEYCOPY_NEXTWORD, 1 }, - { '{', 0, MODEKEYCOPY_PREVIOUSPARAGRAPH, 1 }, - { '}', 0, MODEKEYCOPY_NEXTPARAGRAPH, 1 }, - { KEYC_BSPACE, 0, MODEKEYCOPY_LEFT, 1 }, - { KEYC_DOWN | KEYC_CTRL, 0, MODEKEYCOPY_SCROLLDOWN, 1 }, - { KEYC_DOWN, 0, MODEKEYCOPY_DOWN, 1 }, - { KEYC_LEFT, 0, MODEKEYCOPY_LEFT, 1 }, - { KEYC_NPAGE, 0, MODEKEYCOPY_NEXTPAGE, 1 }, - { KEYC_PPAGE, 0, MODEKEYCOPY_PREVIOUSPAGE, 1 }, - { KEYC_RIGHT, 0, MODEKEYCOPY_RIGHT, 1 }, - { KEYC_UP | KEYC_CTRL, 0, MODEKEYCOPY_SCROLLUP, 1 }, - { KEYC_UP, 0, MODEKEYCOPY_UP, 1 }, - { KEYC_WHEELUP_PANE, 0, MODEKEYCOPY_SCROLLUP, 1 }, - { KEYC_WHEELDOWN_PANE, 0, MODEKEYCOPY_SCROLLDOWN, 1 }, - { KEYC_MOUSEDRAG1_PANE, 0, MODEKEYCOPY_STARTSELECTION, 1 }, - { KEYC_MOUSEDRAGEND1_PANE, 0, MODEKEYCOPY_COPYSELECTION, 1 }, - - { 0, -1, 0, 1 } -}; -struct mode_key_tree mode_key_tree_vi_copy; - /* emacs editing keys. */ static const struct mode_key_entry mode_key_emacs_edit[] = { - { '\001' /* C-a */, 0, MODEKEYEDIT_STARTOFLINE, 1 }, - { '\002' /* C-b */, 0, MODEKEYEDIT_CURSORLEFT, 1 }, - { '\003' /* C-c */, 0, MODEKEYEDIT_CANCEL, 1 }, - { '\004' /* C-d */, 0, MODEKEYEDIT_DELETE, 1 }, - { '\005' /* C-e */, 0, MODEKEYEDIT_ENDOFLINE, 1 }, - { '\006' /* C-f */, 0, MODEKEYEDIT_CURSORRIGHT, 1 }, - { '\010' /* C-H */, 0, MODEKEYEDIT_BACKSPACE, 1 }, - { '\011' /* Tab */, 0, MODEKEYEDIT_COMPLETE, 1 }, - { '\013' /* C-k */, 0, MODEKEYEDIT_DELETETOENDOFLINE, 1 }, - { '\016' /* C-n */, 0, MODEKEYEDIT_HISTORYDOWN, 1 }, - { '\020' /* C-p */, 0, MODEKEYEDIT_HISTORYUP, 1 }, - { '\024' /* C-t */, 0, MODEKEYEDIT_TRANSPOSECHARS, 1 }, - { '\025' /* C-u */, 0, MODEKEYEDIT_DELETELINE, 1 }, - { '\027' /* C-w */, 0, MODEKEYEDIT_DELETEWORD, 1 }, - { '\031' /* C-y */, 0, MODEKEYEDIT_PASTE, 1 }, - { '\033' /* Escape */, 0, MODEKEYEDIT_CANCEL, 1 }, - { '\n', 0, MODEKEYEDIT_ENTER, 1 }, - { '\r', 0, MODEKEYEDIT_ENTER, 1 }, - { 'b' | KEYC_ESCAPE, 0, MODEKEYEDIT_PREVIOUSWORD, 1 }, - { 'f' | KEYC_ESCAPE, 0, MODEKEYEDIT_NEXTWORDEND, 1 }, - { 'm' | KEYC_ESCAPE, 0, MODEKEYEDIT_STARTOFLINE, 1 }, - { KEYC_BSPACE, 0, MODEKEYEDIT_BACKSPACE, 1 }, - { KEYC_DC, 0, MODEKEYEDIT_DELETE, 1 }, - { KEYC_DOWN, 0, MODEKEYEDIT_HISTORYDOWN, 1 }, - { KEYC_LEFT, 0, MODEKEYEDIT_CURSORLEFT, 1 }, - { KEYC_RIGHT, 0, MODEKEYEDIT_CURSORRIGHT, 1 }, - { KEYC_UP, 0, MODEKEYEDIT_HISTORYUP, 1 }, - { KEYC_HOME, 0, MODEKEYEDIT_STARTOFLINE, 1 }, - { KEYC_END, 0, MODEKEYEDIT_ENDOFLINE, 1 }, - - { 0, -1, 0, 1 } + { '\001' /* C-a */, 0, MODEKEYEDIT_STARTOFLINE }, + { '\002' /* C-b */, 0, MODEKEYEDIT_CURSORLEFT }, + { '\003' /* C-c */, 0, MODEKEYEDIT_CANCEL }, + { '\004' /* C-d */, 0, MODEKEYEDIT_DELETE }, + { '\005' /* C-e */, 0, MODEKEYEDIT_ENDOFLINE }, + { '\006' /* C-f */, 0, MODEKEYEDIT_CURSORRIGHT }, + { '\010' /* C-H */, 0, MODEKEYEDIT_BACKSPACE }, + { '\011' /* Tab */, 0, MODEKEYEDIT_COMPLETE }, + { '\013' /* C-k */, 0, MODEKEYEDIT_DELETETOENDOFLINE }, + { '\016' /* C-n */, 0, MODEKEYEDIT_HISTORYDOWN }, + { '\020' /* C-p */, 0, MODEKEYEDIT_HISTORYUP }, + { '\024' /* C-t */, 0, MODEKEYEDIT_TRANSPOSECHARS }, + { '\025' /* C-u */, 0, MODEKEYEDIT_DELETELINE }, + { '\027' /* C-w */, 0, MODEKEYEDIT_DELETEWORD }, + { '\031' /* C-y */, 0, MODEKEYEDIT_PASTE }, + { '\033' /* Escape */, 0, MODEKEYEDIT_CANCEL }, + { '\n', 0, MODEKEYEDIT_ENTER }, + { '\r', 0, MODEKEYEDIT_ENTER }, + { 'b' | KEYC_ESCAPE, 0, MODEKEYEDIT_PREVIOUSWORD }, + { 'f' | KEYC_ESCAPE, 0, MODEKEYEDIT_NEXTWORDEND }, + { 'm' | KEYC_ESCAPE, 0, MODEKEYEDIT_STARTOFLINE }, + { KEYC_BSPACE, 0, MODEKEYEDIT_BACKSPACE }, + { KEYC_DC, 0, MODEKEYEDIT_DELETE }, + { KEYC_DOWN, 0, MODEKEYEDIT_HISTORYDOWN }, + { KEYC_LEFT, 0, MODEKEYEDIT_CURSORLEFT }, + { KEYC_RIGHT, 0, MODEKEYEDIT_CURSORRIGHT }, + { KEYC_UP, 0, MODEKEYEDIT_HISTORYUP }, + { KEYC_HOME, 0, MODEKEYEDIT_STARTOFLINE }, + { KEYC_END, 0, MODEKEYEDIT_ENDOFLINE }, + + { 0, -1, 0 } }; struct mode_key_tree mode_key_tree_emacs_edit; /* emacs choice selection keys. */ static const struct mode_key_entry mode_key_emacs_choice[] = { - { '0' | KEYC_ESCAPE, 0, MODEKEYCHOICE_STARTNUMBERPREFIX, 1 }, - { '1' | KEYC_ESCAPE, 0, MODEKEYCHOICE_STARTNUMBERPREFIX, 1 }, - { '2' | KEYC_ESCAPE, 0, MODEKEYCHOICE_STARTNUMBERPREFIX, 1 }, - { '3' | KEYC_ESCAPE, 0, MODEKEYCHOICE_STARTNUMBERPREFIX, 1 }, - { '4' | KEYC_ESCAPE, 0, MODEKEYCHOICE_STARTNUMBERPREFIX, 1 }, - { '5' | KEYC_ESCAPE, 0, MODEKEYCHOICE_STARTNUMBERPREFIX, 1 }, - { '6' | KEYC_ESCAPE, 0, MODEKEYCHOICE_STARTNUMBERPREFIX, 1 }, - { '7' | KEYC_ESCAPE, 0, MODEKEYCHOICE_STARTNUMBERPREFIX, 1 }, - { '8' | KEYC_ESCAPE, 0, MODEKEYCHOICE_STARTNUMBERPREFIX, 1 }, - { '9' | KEYC_ESCAPE, 0, MODEKEYCHOICE_STARTNUMBERPREFIX, 1 }, - { '\003' /* C-c */, 0, MODEKEYCHOICE_CANCEL, 1 }, - { '\016' /* C-n */, 0, MODEKEYCHOICE_DOWN, 1 }, - { '\020' /* C-p */, 0, MODEKEYCHOICE_UP, 1 }, - { '\026' /* C-v */, 0, MODEKEYCHOICE_PAGEDOWN, 1 }, - { '\033' /* Escape */, 0, MODEKEYCHOICE_CANCEL, 1 }, - { '\n', 0, MODEKEYCHOICE_CHOOSE, 1 }, - { '\r', 0, MODEKEYCHOICE_CHOOSE, 1 }, - { 'q', 0, MODEKEYCHOICE_CANCEL, 1 }, - { 'v' | KEYC_ESCAPE, 0, MODEKEYCHOICE_PAGEUP, 1 }, - { KEYC_HOME, 0, MODEKEYCHOICE_STARTOFLIST, 1 }, - { '<' | KEYC_ESCAPE, 0, MODEKEYCHOICE_STARTOFLIST, 1 }, - { 'R' | KEYC_ESCAPE, 0, MODEKEYCHOICE_TOPLINE, 1 }, - { '>' | KEYC_ESCAPE, 0, MODEKEYCHOICE_ENDOFLIST, 1 }, - { KEYC_END, 0, MODEKEYCHOICE_ENDOFLIST, 1 }, - { KEYC_BSPACE, 0, MODEKEYCHOICE_BACKSPACE, 1 }, - { KEYC_DOWN | KEYC_CTRL, 0, MODEKEYCHOICE_SCROLLDOWN, 1 }, - { KEYC_DOWN, 0, MODEKEYCHOICE_DOWN, 1 }, - { KEYC_NPAGE, 0, MODEKEYCHOICE_PAGEDOWN, 1 }, - { KEYC_PPAGE, 0, MODEKEYCHOICE_PAGEUP, 1 }, - { KEYC_UP | KEYC_CTRL, 0, MODEKEYCHOICE_SCROLLUP, 1 }, - { KEYC_UP, 0, MODEKEYCHOICE_UP, 1 }, - { ' ', 0, MODEKEYCHOICE_TREE_TOGGLE, 1 }, - { KEYC_LEFT, 0, MODEKEYCHOICE_TREE_COLLAPSE, 1 }, - { KEYC_RIGHT, 0, MODEKEYCHOICE_TREE_EXPAND, 1 }, - { KEYC_LEFT | KEYC_CTRL, 0, MODEKEYCHOICE_TREE_COLLAPSE_ALL, 1 }, - { KEYC_RIGHT | KEYC_CTRL, 0, MODEKEYCHOICE_TREE_EXPAND_ALL, 1 }, - { KEYC_MOUSEDOWN1_PANE, 0, MODEKEYCHOICE_CHOOSE, 1 }, - { KEYC_MOUSEDOWN3_PANE, 0, MODEKEYCHOICE_TREE_TOGGLE, 1 }, - { KEYC_WHEELUP_PANE, 0, MODEKEYCHOICE_UP, 5 }, - { KEYC_WHEELDOWN_PANE, 0, MODEKEYCHOICE_DOWN, 5 }, - - { 0, -1, 0, 1 } + { '0' | KEYC_ESCAPE, 0, MODEKEYCHOICE_STARTNUMBERPREFIX }, + { '1' | KEYC_ESCAPE, 0, MODEKEYCHOICE_STARTNUMBERPREFIX }, + { '2' | KEYC_ESCAPE, 0, MODEKEYCHOICE_STARTNUMBERPREFIX }, + { '3' | KEYC_ESCAPE, 0, MODEKEYCHOICE_STARTNUMBERPREFIX }, + { '4' | KEYC_ESCAPE, 0, MODEKEYCHOICE_STARTNUMBERPREFIX }, + { '5' | KEYC_ESCAPE, 0, MODEKEYCHOICE_STARTNUMBERPREFIX }, + { '6' | KEYC_ESCAPE, 0, MODEKEYCHOICE_STARTNUMBERPREFIX }, + { '7' | KEYC_ESCAPE, 0, MODEKEYCHOICE_STARTNUMBERPREFIX }, + { '8' | KEYC_ESCAPE, 0, MODEKEYCHOICE_STARTNUMBERPREFIX }, + { '9' | KEYC_ESCAPE, 0, MODEKEYCHOICE_STARTNUMBERPREFIX }, + { '\003' /* C-c */, 0, MODEKEYCHOICE_CANCEL }, + { '\016' /* C-n */, 0, MODEKEYCHOICE_DOWN }, + { '\020' /* C-p */, 0, MODEKEYCHOICE_UP }, + { '\026' /* C-v */, 0, MODEKEYCHOICE_PAGEDOWN }, + { '\033' /* Escape */, 0, MODEKEYCHOICE_CANCEL }, + { '\n', 0, MODEKEYCHOICE_CHOOSE }, + { '\r', 0, MODEKEYCHOICE_CHOOSE }, + { 'q', 0, MODEKEYCHOICE_CANCEL }, + { 'v' | KEYC_ESCAPE, 0, MODEKEYCHOICE_PAGEUP }, + { KEYC_HOME, 0, MODEKEYCHOICE_STARTOFLIST }, + { '<' | KEYC_ESCAPE, 0, MODEKEYCHOICE_STARTOFLIST }, + { 'R' | KEYC_ESCAPE, 0, MODEKEYCHOICE_TOPLINE }, + { '>' | KEYC_ESCAPE, 0, MODEKEYCHOICE_ENDOFLIST }, + { KEYC_END, 0, MODEKEYCHOICE_ENDOFLIST }, + { KEYC_BSPACE, 0, MODEKEYCHOICE_BACKSPACE }, + { KEYC_DOWN | KEYC_CTRL, 0, MODEKEYCHOICE_SCROLLDOWN }, + { KEYC_DOWN, 0, MODEKEYCHOICE_DOWN }, + { KEYC_NPAGE, 0, MODEKEYCHOICE_PAGEDOWN }, + { KEYC_PPAGE, 0, MODEKEYCHOICE_PAGEUP }, + { KEYC_UP | KEYC_CTRL, 0, MODEKEYCHOICE_SCROLLUP }, + { KEYC_UP, 0, MODEKEYCHOICE_UP }, + { ' ', 0, MODEKEYCHOICE_TREE_TOGGLE }, + { KEYC_LEFT, 0, MODEKEYCHOICE_TREE_COLLAPSE }, + { KEYC_RIGHT, 0, MODEKEYCHOICE_TREE_EXPAND }, + { KEYC_LEFT | KEYC_CTRL, 0, MODEKEYCHOICE_TREE_COLLAPSE_ALL }, + { KEYC_RIGHT | KEYC_CTRL, 0, MODEKEYCHOICE_TREE_EXPAND_ALL }, + { KEYC_MOUSEDOWN1_PANE, 0, MODEKEYCHOICE_CHOOSE }, + { KEYC_MOUSEDOWN3_PANE, 0, MODEKEYCHOICE_TREE_TOGGLE }, + { KEYC_WHEELUP_PANE, 0, MODEKEYCHOICE_UP }, + { KEYC_WHEELDOWN_PANE, 0, MODEKEYCHOICE_DOWN }, + + { 0, -1, 0 } }; struct mode_key_tree mode_key_tree_emacs_choice; -/* emacs copy mode keys. */ -static const struct mode_key_entry mode_key_emacs_copy[] = { - { ' ', 0, MODEKEYCOPY_NEXTPAGE, 1 }, - { ',', 0, MODEKEYCOPY_JUMPREVERSE, 1 }, - { ';', 0, MODEKEYCOPY_JUMPAGAIN, 1 }, - { '1' | KEYC_ESCAPE, 0, MODEKEYCOPY_STARTNUMBERPREFIX, 1 }, - { '2' | KEYC_ESCAPE, 0, MODEKEYCOPY_STARTNUMBERPREFIX, 1 }, - { '3' | KEYC_ESCAPE, 0, MODEKEYCOPY_STARTNUMBERPREFIX, 1 }, - { '4' | KEYC_ESCAPE, 0, MODEKEYCOPY_STARTNUMBERPREFIX, 1 }, - { '5' | KEYC_ESCAPE, 0, MODEKEYCOPY_STARTNUMBERPREFIX, 1 }, - { '6' | KEYC_ESCAPE, 0, MODEKEYCOPY_STARTNUMBERPREFIX, 1 }, - { '7' | KEYC_ESCAPE, 0, MODEKEYCOPY_STARTNUMBERPREFIX, 1 }, - { '8' | KEYC_ESCAPE, 0, MODEKEYCOPY_STARTNUMBERPREFIX, 1 }, - { '9' | KEYC_ESCAPE, 0, MODEKEYCOPY_STARTNUMBERPREFIX, 1 }, - { '<' | KEYC_ESCAPE, 0, MODEKEYCOPY_HISTORYTOP, 1 }, - { '>' | KEYC_ESCAPE, 0, MODEKEYCOPY_HISTORYBOTTOM, 1 }, - { 'F', 0, MODEKEYCOPY_JUMPBACK, 1 }, - { 'N', 0, MODEKEYCOPY_SEARCHREVERSE, 1 }, - { 'R' | KEYC_ESCAPE, 0, MODEKEYCOPY_TOPLINE, 1 }, - { 'R', 0, MODEKEYCOPY_RECTANGLETOGGLE, 1 }, - { 'T', 0, MODEKEYCOPY_JUMPTOBACK, 1 }, - { '\000' /* C-Space */, 0, MODEKEYCOPY_STARTSELECTION, 1 }, - { '\001' /* C-a */, 0, MODEKEYCOPY_STARTOFLINE, 1 }, - { '\002' /* C-b */, 0, MODEKEYCOPY_LEFT, 1 }, - { '\003' /* C-c */, 0, MODEKEYCOPY_CANCEL, 1 }, - { '\005' /* C-e */, 0, MODEKEYCOPY_ENDOFLINE, 1 }, - { '\006' /* C-f */, 0, MODEKEYCOPY_RIGHT, 1 }, - { '\007' /* C-g */, 0, MODEKEYCOPY_CLEARSELECTION, 1 }, - { '\013' /* C-k */, 0, MODEKEYCOPY_COPYENDOFLINE, 1 }, - { '\016' /* C-n */, 0, MODEKEYCOPY_DOWN, 1 }, - { '\020' /* C-p */, 0, MODEKEYCOPY_UP, 1 }, - { '\022' /* C-r */, 0, MODEKEYCOPY_SEARCHUP, 1 }, - { '\023' /* C-s */, 0, MODEKEYCOPY_SEARCHDOWN, 1 }, - { '\026' /* C-v */, 0, MODEKEYCOPY_NEXTPAGE, 1 }, - { '\027' /* C-w */, 0, MODEKEYCOPY_COPYSELECTION, 1 }, - { '\033' /* Escape */, 0, MODEKEYCOPY_CANCEL, 1 }, - { 'b' | KEYC_ESCAPE, 0, MODEKEYCOPY_PREVIOUSWORD, 1 }, - { 'f', 0, MODEKEYCOPY_JUMP, 1 }, - { 'f' | KEYC_ESCAPE, 0, MODEKEYCOPY_NEXTWORDEND, 1 }, - { 'g', 0, MODEKEYCOPY_GOTOLINE, 1 }, - { 'm' | KEYC_ESCAPE, 0, MODEKEYCOPY_BACKTOINDENTATION, 1 }, - { 'n', 0, MODEKEYCOPY_SEARCHAGAIN, 1 }, - { 'q', 0, MODEKEYCOPY_CANCEL, 1 }, - { 'r' | KEYC_ESCAPE, 0, MODEKEYCOPY_MIDDLELINE, 1 }, - { 't', 0, MODEKEYCOPY_JUMPTO, 1 }, - { 'v' | KEYC_ESCAPE, 0, MODEKEYCOPY_PREVIOUSPAGE, 1 }, - { 'w' | KEYC_ESCAPE, 0, MODEKEYCOPY_COPYSELECTION, 1 }, - { '{' | KEYC_ESCAPE, 0, MODEKEYCOPY_PREVIOUSPARAGRAPH, 1 }, - { '}' | KEYC_ESCAPE, 0, MODEKEYCOPY_NEXTPARAGRAPH, 1 }, - { KEYC_DOWN | KEYC_CTRL, 0, MODEKEYCOPY_SCROLLDOWN, 1 }, - { KEYC_DOWN | KEYC_ESCAPE, 0, MODEKEYCOPY_HALFPAGEDOWN, 1 }, - { KEYC_DOWN, 0, MODEKEYCOPY_DOWN, 1 }, - { KEYC_LEFT, 0, MODEKEYCOPY_LEFT, 1 }, - { KEYC_NPAGE, 0, MODEKEYCOPY_NEXTPAGE, 1 }, - { KEYC_PPAGE, 0, MODEKEYCOPY_PREVIOUSPAGE, 1 }, - { KEYC_RIGHT, 0, MODEKEYCOPY_RIGHT, 1 }, - { KEYC_UP | KEYC_CTRL, 0, MODEKEYCOPY_SCROLLUP, 1 }, - { KEYC_UP | KEYC_ESCAPE, 0, MODEKEYCOPY_HALFPAGEUP, 1 }, - { KEYC_UP, 0, MODEKEYCOPY_UP, 1 }, - { KEYC_WHEELUP_PANE, 0, MODEKEYCOPY_SCROLLUP, 5 }, - { KEYC_WHEELDOWN_PANE, 0, MODEKEYCOPY_SCROLLDOWN, 5 }, - { KEYC_MOUSEDRAG1_PANE, 0, MODEKEYCOPY_STARTSELECTION, 1 }, - { KEYC_MOUSEDRAGEND1_PANE, 0, MODEKEYCOPY_COPYSELECTION, 1 }, - - { 0, -1, 0, 1 } -}; -struct mode_key_tree mode_key_tree_emacs_copy; - /* Table mapping key table names to default settings and trees. */ const struct mode_key_table mode_key_tables[] = { { "vi-edit", mode_key_cmdstr_edit, &mode_key_tree_vi_edit, mode_key_vi_edit }, { "vi-choice", mode_key_cmdstr_choice, &mode_key_tree_vi_choice, mode_key_vi_choice }, - { "vi-copy", mode_key_cmdstr_copy, - &mode_key_tree_vi_copy, mode_key_vi_copy }, { "emacs-edit", mode_key_cmdstr_edit, &mode_key_tree_emacs_edit, mode_key_emacs_edit }, { "emacs-choice", mode_key_cmdstr_choice, &mode_key_tree_emacs_choice, mode_key_emacs_choice }, - { "emacs-copy", mode_key_cmdstr_copy, - &mode_key_tree_emacs_copy, mode_key_emacs_copy }, { NULL, NULL, NULL, NULL } }; @@ -587,10 +377,8 @@ mode_key_init_trees(void) for (ment = mtab->table; ment->mode != -1; ment++) { mbind = xmalloc(sizeof *mbind); mbind->key = ment->key; - mbind->repeat = ment->repeat; mbind->mode = ment->mode; mbind->cmd = ment->cmd; - mbind->arg = NULL; RB_INSERT(mode_key_tree, mtab->tree, mbind); } } @@ -604,8 +392,7 @@ mode_key_init(struct mode_key_data *mdata, struct mode_key_tree *mtree) } enum mode_key_cmd -mode_key_lookup(struct mode_key_data *mdata, key_code key, const char **arg, - u_int *repeat) +mode_key_lookup(struct mode_key_data *mdata, key_code key) { struct mode_key_binding *mbind, mtmp; @@ -616,8 +403,6 @@ mode_key_lookup(struct mode_key_data *mdata, key_code key, const char **arg, return (MODEKEY_NONE); return (MODEKEY_OTHER); } - if (repeat != NULL) - *repeat = mbind->repeat; switch (mbind->cmd) { case MODEKEYEDIT_SWITCHMODE: @@ -630,8 +415,6 @@ mode_key_lookup(struct mode_key_data *mdata, key_code key, const char **arg, mdata->mode = 1 - mdata->mode; /* FALLTHROUGH */ default: - if (arg != NULL) - *arg = mbind->arg; return (mbind->cmd); } } diff --git a/server-client.c b/server-client.c index 859a451e..70fdd51a 100644 --- a/server-client.c +++ b/server-client.c @@ -97,6 +97,13 @@ server_client_get_key_table(struct client *c) return (name); } +/* Is this client using the default key table? */ +int +server_client_is_default_key_table(struct client *c) +{ + return (strcmp(c->keytable->name, server_client_get_key_table(c)) == 0); +} + /* Create a new client. */ void server_client_create(int fd) @@ -587,6 +594,7 @@ server_client_handle_key(struct client *c, key_code key) struct window *w; struct window_pane *wp; struct timeval tv; + const char *name; struct key_table *table; struct key_binding bd_find, *bd; int xtimeout; @@ -595,6 +603,10 @@ server_client_handle_key(struct client *c, key_code key) if (s == NULL || (c->flags & (CLIENT_DEAD|CLIENT_SUSPENDED)) != 0) return; w = s->curw->window; + if (KEYC_IS_MOUSE(key)) + wp = cmd_mouse_pane(m, NULL, NULL); + else + wp = w->active; /* Update the activity timer. */ if (gettimeofday(&c->activity_time, NULL) != 0) @@ -645,9 +657,21 @@ server_client_handle_key(struct client *c, key_code key) goto forward; retry: + /* + * Work out the current key table. If the pane is in a mode, use + * the mode table instead of the default key table. + */ + name = NULL; + if (wp != NULL && wp->mode != NULL && wp->mode->key_table != NULL) + name = wp->mode->key_table(wp); + if (name == NULL || !server_client_is_default_key_table(c)) + table = c->keytable; + else + table = key_bindings_get_table(name, 1); + /* Try to see if there is a key binding in the current table. */ bd_find.key = key; - bd = RB_FIND(key_bindings, &c->keytable->key_bindings, &bd_find); + bd = RB_FIND(key_bindings, &table->key_bindings, &bd_find); if (bd != NULL) { /* * Key was matched in this table. If currently repeating but a @@ -665,7 +689,6 @@ retry: * Take a reference to this table to make sure the key binding * doesn't disappear. */ - table = c->keytable; table->references++; /* @@ -704,7 +727,7 @@ retry: } /* If no match and we're not in the root table, that's it. */ - if (strcmp(c->keytable->name, server_client_get_key_table(c)) != 0) { + if (name == NULL && !server_client_is_default_key_table(c)) { server_client_set_key_table(c, NULL); server_status_client(c); return; @@ -724,10 +747,6 @@ retry: forward: if (c->flags & CLIENT_READONLY) return; - if (KEYC_IS_MOUSE(key)) - wp = cmd_mouse_pane(m, NULL, NULL); - else - wp = w->active; if (wp != NULL) window_pane_key(wp, c, s, key, m); } diff --git a/status.c b/status.c index c51a3f34..6ea8c6c3 100644 --- a/status.c +++ b/status.c @@ -867,7 +867,7 @@ status_prompt_key(struct client *c, key_code key) struct utf8_data tmp, *first, *last, *ud; size = utf8_strlen(c->prompt_buffer); - switch (mode_key_lookup(&c->prompt_mdata, key, NULL, NULL)) { + switch (mode_key_lookup(&c->prompt_mdata, key)) { case MODEKEYEDIT_CURSORLEFT: if (c->prompt_index > 0) { c->prompt_index--; diff --git a/tmux.1 b/tmux.1 index 650a7469..ec6b02cd 100644 --- a/tmux.1 +++ b/tmux.1 @@ -1002,63 +1002,76 @@ It is also entered when a command that produces output, such as .Ic list-keys , is executed from a key binding. .Pp -The keys available depend on whether emacs or vi mode is selected -(see the +Commands are sent to copy mode using the +.Fl X +flag to the +.Ic send-keys +command. +When a key is pressed, copy mode automatically uses one of two key tables, +depending on the .Ic mode-keys -option). -The following keys are supported as appropriate for the mode: -.Bl -column "FunctionXXXXXXXXXXXXXXXXX" "viXXXXXXXXXX" "emacs" -offset indent -.It Sy "Function" Ta Sy "vi" Ta Sy "emacs" -.It Li "Append selection" Ta "A" Ta "" -.It Li "Back to indentation" Ta "^" Ta "M-m" -.It Li "Bottom of history" Ta "G" Ta "M-<" -.It Li "Clear selection" Ta "Escape" Ta "C-g" -.It Li "Copy selection" Ta "Enter" Ta "M-w" -.It Li "Copy to named buffer" Ta \&" Ta "" -.It Li "Cursor down" Ta "j" Ta "Down" -.It Li "Cursor left" Ta "h" Ta "Left" -.It Li "Cursor right" Ta "l" Ta "Right" -.It Li "Cursor to bottom line" Ta "L" Ta "" -.It Li "Cursor to middle line" Ta "M" Ta "M-r" -.It Li "Cursor to top line" Ta "H" Ta "M-R" -.It Li "Cursor up" Ta "k" Ta "Up" -.It Li "Delete entire line" Ta "d" Ta "C-u" -.It Li "Delete/Copy to end of line" Ta "D" Ta "C-k" -.It Li "End of line" Ta "$" Ta "C-e" -.It Li "Go to line" Ta ":" Ta "g" -.It Li "Half page down" Ta "C-d" Ta "M-Down" -.It Li "Half page up" Ta "C-u" Ta "M-Up" -.It Li "Jump again" Ta ";" Ta ";" -.It Li "Jump again in reverse" Ta "," Ta "," -.It Li "Jump backward" Ta "F" Ta "F" -.It Li "Jump forward" Ta "f" Ta "f" -.It Li "Jump to backward" Ta "T" Ta "" -.It Li "Jump to forward" Ta "t" Ta "" -.It Li "Next page" Ta "C-f" Ta "Page down" -.It Li "Next paragraph" Ta "}" Ta "M-}" -.It Li "Next space" Ta "W" Ta "" -.It Li "Next space, end of word" Ta "E" Ta "" -.It Li "Next word" Ta "w" Ta "" -.It Li "Next word end" Ta "e" Ta "M-f" -.It Li "Other end of selection" Ta "o" Ta "" -.It Li "Paste buffer" Ta "p" Ta "C-y" -.It Li "Previous page" Ta "C-b" Ta "Page up" -.It Li "Previous paragraph" Ta "{" Ta "M-{" -.It Li "Previous space" Ta "B" Ta "" -.It Li "Previous word" Ta "b" Ta "M-b" -.It Li "Quit mode" Ta "q" Ta "Escape" -.It Li "Rectangle toggle" Ta "v" Ta "R" -.It Li "Scroll down" Ta "C-Down or C-e" Ta "C-Down" -.It Li "Scroll up" Ta "C-Up or C-y" Ta "C-Up" -.It Li "Search again" Ta "n" Ta "n" -.It Li "Search again in reverse" Ta "N" Ta "N" -.It Li "Search backward" Ta "?" Ta "C-r" -.It Li "Search forward" Ta "/" Ta "C-s" -.It Li "Select line" Ta "V" Ta "" -.It Li "Start of line" Ta "0" Ta "C-a" -.It Li "Start selection" Ta "Space" Ta "C-Space" -.It Li "Top of history" Ta "g" Ta "M->" -.It Li "Transpose characters" Ta "" Ta "C-t" +option: +.Ic copy-mode +for emacs, or +.Ic copy-mode-vi +for vi. +Key tables may be viewed with the +.Ic list-keys +command. +.Pp +The following commands are supported in copy mode: +.Bl -column "CommandXXXXXXXXXXXXXXXXX" "viXXXXXXXXXX" "emacs" -offset indent +.It Sy "Command" Ta Sy "vi" Ta Sy "emacs" +.It Li "append-selection" Ta "" Ta "" +.It Li "append-selection-and-cancel" Ta "A" Ta "" +.It Li "back-to-indentation" Ta "^" Ta "M-m" +.It Li "begin-selection" Ta "Space" Ta "C-Space" +.It Li "bottom-line" Ta "L" Ta "" +.It Li "cancel" Ta "q" Ta "Escape" +.It Li "clear-selection" Ta "Escape" Ta "C-g" +.It Li "copy-end-of-line" Ta "D" Ta "C-k" +.It Li "copy-line" Ta "" Ta "" +.It Li "copy-pipe " Ta "" Ta "" +.It Li "copy-selection" Ta "" Ta "" +.It Li "copy-selection-and-cancel" Ta "Enter" Ta "M-w" +.It Li "cursor-down" Ta "j" Ta "Down" +.It Li "cursor-left" Ta "h" Ta "Left" +.It Li "cursor-right" Ta "l" Ta "Right" +.It Li "cursor-up" Ta "k" Ta "Up" +.It Li "end-of-line" Ta "$" Ta "C-e" +.It Li "goto-line " Ta ":" Ta "g" +.It Li "halfpage-down" Ta "C-d" Ta "M-Down" +.It Li "halfpage-up" Ta "C-u" Ta "M-Up" +.It Li "history-bottom" Ta "G" Ta "M-<" +.It Li "history-top" Ta "g" Ta "M->" +.It Li "jump-again" Ta ";" Ta ";" +.It Li "jump-backward " Ta "F" Ta "F" +.It Li "jump-forward " Ta "f" Ta "f" +.It Li "jump-reverse" Ta "," Ta "," +.It Li "jump-to-backward " Ta "T" Ta "" +.It Li "jump-to-forward " Ta "t" Ta "" +.It Li "middle-line" Ta "M" Ta "M-r" +.It Li "next-paragraph" Ta "}" Ta "M-}" +.It Li "next-space" Ta "W" Ta "" +.It Li "next-space-end" Ta "E" Ta "" +.It Li "next-word" Ta "w" Ta "" +.It Li "next-word-end" Ta "e" Ta "M-f" +.It Li "other-end" Ta "o" Ta "" +.It Li "page-down" Ta "C-f" Ta "PageDown" +.It Li "page-up" Ta "C-b" Ta "PageUp" +.It Li "previous-paragraph" Ta "{" Ta "M-{" +.It Li "previous-space" Ta "B" Ta "" +.It Li "previous-word" Ta "b" Ta "M-b" +.It Li "rectangle-toggle" Ta "v" Ta "R" +.It Li "scroll-down" Ta "C-e" Ta "C-Down" +.It Li "scroll-up" Ta "C-y" Ta "C-Up" +.It Li "search-again" Ta "n" Ta "n" +.It Li "search-backward " Ta "?" Ta "C-r" +.It Li "search-forward " Ta "/" Ta "C-s" +.It Li "search-reverse" Ta "N" Ta "N" +.It Li "select-line" Ta "V" Ta "" +.It Li "start-of-line" Ta "0" Ta "C-a" +.It Li "top-line" Ta "H" Ta "M-R" .El .Pp The next and previous word keys use space and the @@ -1090,59 +1103,18 @@ will then jump to the next occurrence. Commands in copy mode may be prefaced by an optional repeat count. With vi key bindings, a prefix is entered using the number keys; with emacs, the Alt (meta) key and a number begins prefix entry. -For example, to move the cursor forward by ten words, use -.Ql M-1 0 M-f -in emacs mode, and -.Ql 10w -in vi. .Pp Mode key bindings are defined in a set of named tables: .Em vi-edit and .Em emacs-edit -for keys used when line editing at the command prompt; +for keys used when line editing at the command prompt; and .Em vi-choice and .Em emacs-choice for keys used when choosing from lists (such as produced by the .Ic choose-window -command); and -.Em vi-copy -and -.Em emacs-copy -used in copy mode. -The tables may be viewed with the -.Ic list-keys -command and keys modified or removed with -.Ic bind-key -and -.Ic unbind-key . -If -.Ic append-selection , -.Ic copy-selection , -or -.Ic start-named-buffer -are given the -.Fl x -flag, -.Nm -will not exit copy mode after copying. -.Ic copy-pipe -copies the selection and pipes it to a command. -For example the following will bind -.Ql C-w -not to exit after copying and -.Ql C-q -to copy the selection into -.Pa /tmp -as well as the paste buffer: -.Bd -literal -offset indent -bind-key -temacs-copy C-w copy-selection -x -bind-key -temacs-copy C-q copy-pipe "cat >/tmp/out" -.Ed -.Pp -The paste buffer key pastes the first line from the top paste buffer on the -stack. +command). .Pp The synopsis for the .Ic copy-mode @@ -2133,7 +2105,6 @@ Commands related to key bindings are as follows: .Bl -tag -width Ds .It Xo Ic bind-key .Op Fl cnr -.Op Fl R Ar repeat-count .Op Fl t Ar mode-table .Op Fl T Ar key-table .Ar key Ar command Op Ar arguments @@ -2192,19 +2163,6 @@ is bound in the binding for command mode with .Fl c or for normal mode without. -For keys in the -.Em vi-copy -or -.Em emacs-copy -tables, -.Fl R -specifies how many times the command should be repeated. -.Pp -See the -.Sx WINDOWS AND PANES -section and the -.Ic list-keys -command for information on mode key bindings. .Pp To view the default bindings and possible commands, see the .Ic list-keys @@ -2236,7 +2194,8 @@ are listed; this may be one of: or .Em emacs-copy . .It Xo Ic send-keys -.Op Fl lMR +.Op Fl lMRX +.Op Fl N Ar repeat-count .Op Fl t Ar target-pane .Ar key Ar ... .Xc @@ -2261,6 +2220,14 @@ flag causes the terminal state to be reset. .Fl M passes through a mouse event (only valid if bound to a mouse key binding, see .Sx MOUSE SUPPORT ) . +.Pp +.Fl X +is used to send a command into copy mode - see +the +.Sx WINDOWS AND PANES +section. +.Fl N +specifies a repeat count to a copy mode command. .It Xo Ic send-prefix .Op Fl 2 .Op Fl t Ar target-pane @@ -3779,6 +3746,7 @@ session option. Commands related to the status line are as follows: .Bl -tag -width Ds .It Xo Ic command-prompt +.Op Fl 1 .Op Fl I Ar inputs .Op Fl p Ar prompts .Op Fl t Ar target-client @@ -3828,6 +3796,10 @@ Up to nine prompt responses may be replaced to .Ql %9 .Pc . +.Pp +.Fl 1 +makes the prompt only accept one key press, in this case the resulting input +is a single character. .It Xo Ic confirm-before .Op Fl p Ar prompt .Op Fl t Ar target-client diff --git a/tmux.h b/tmux.h index 18ef8082..2a020c33 100644 --- a/tmux.h +++ b/tmux.h @@ -38,6 +38,7 @@ extern char **environ; +struct args; struct client; struct environ; struct input_ctx; @@ -511,58 +512,6 @@ enum mode_key_cmd { MODEKEYCHOICE_TREE_EXPAND_ALL, MODEKEYCHOICE_TREE_TOGGLE, MODEKEYCHOICE_UP, - - /* Copy keys. */ - MODEKEYCOPY_APPENDSELECTION, - MODEKEYCOPY_BACKTOINDENTATION, - MODEKEYCOPY_BOTTOMLINE, - MODEKEYCOPY_CANCEL, - MODEKEYCOPY_CLEARSELECTION, - MODEKEYCOPY_COPYPIPE, - MODEKEYCOPY_COPYLINE, - MODEKEYCOPY_COPYENDOFLINE, - MODEKEYCOPY_COPYSELECTION, - MODEKEYCOPY_DOWN, - MODEKEYCOPY_ENDOFLINE, - MODEKEYCOPY_GOTOLINE, - MODEKEYCOPY_HALFPAGEDOWN, - MODEKEYCOPY_HALFPAGEUP, - MODEKEYCOPY_HISTORYBOTTOM, - MODEKEYCOPY_HISTORYTOP, - MODEKEYCOPY_JUMP, - MODEKEYCOPY_JUMPAGAIN, - MODEKEYCOPY_JUMPREVERSE, - MODEKEYCOPY_JUMPBACK, - MODEKEYCOPY_JUMPTO, - MODEKEYCOPY_JUMPTOBACK, - MODEKEYCOPY_LEFT, - MODEKEYCOPY_MIDDLELINE, - MODEKEYCOPY_NEXTPAGE, - MODEKEYCOPY_NEXTPARAGRAPH, - MODEKEYCOPY_NEXTSPACE, - MODEKEYCOPY_NEXTSPACEEND, - MODEKEYCOPY_NEXTWORD, - MODEKEYCOPY_NEXTWORDEND, - MODEKEYCOPY_OTHEREND, - MODEKEYCOPY_PREVIOUSPAGE, - MODEKEYCOPY_PREVIOUSPARAGRAPH, - MODEKEYCOPY_PREVIOUSSPACE, - MODEKEYCOPY_PREVIOUSWORD, - MODEKEYCOPY_RECTANGLETOGGLE, - MODEKEYCOPY_RIGHT, - MODEKEYCOPY_SCROLLDOWN, - MODEKEYCOPY_SCROLLUP, - MODEKEYCOPY_SEARCHAGAIN, - MODEKEYCOPY_SEARCHDOWN, - MODEKEYCOPY_SEARCHREVERSE, - MODEKEYCOPY_SEARCHUP, - MODEKEYCOPY_SELECTLINE, - MODEKEYCOPY_STARTNAMEDBUFFER, - MODEKEYCOPY_STARTNUMBERPREFIX, - MODEKEYCOPY_STARTOFLINE, - MODEKEYCOPY_STARTSELECTION, - MODEKEYCOPY_TOPLINE, - MODEKEYCOPY_UP, }; /* Data required while mode keys are in use. */ @@ -576,11 +525,9 @@ struct mode_key_data { /* Binding between a key and a command. */ struct mode_key_binding { key_code key; - u_int repeat; int mode; enum mode_key_cmd cmd; - const char *arg; RB_ENTRY(mode_key_binding) entry; }; @@ -832,6 +779,10 @@ struct window_mode { void (*resize)(struct window_pane *, u_int, u_int); void (*key)(struct window_pane *, struct client *, struct session *, key_code, struct mouse_event *); + + const char *(*key_table)(struct window_pane *); + void (*command)(struct window_pane *, struct client *, + struct session *, struct args *, struct mouse_event *); }; #define WINDOW_MODE_TIMEOUT 180 @@ -923,6 +874,7 @@ struct window_pane { void *modedata; struct event modetimer; time_t modelast; + u_int modeprefix; TAILQ_ENTRY(window_pane) entry; RB_ENTRY(window_pane) tree_entry; @@ -1650,8 +1602,7 @@ enum mode_key_cmd mode_key_fromstring(const struct mode_key_cmdstr *, const struct mode_key_table *mode_key_findtable(const char *); void mode_key_init_trees(void); void mode_key_init(struct mode_key_data *, struct mode_key_tree *); -enum mode_key_cmd mode_key_lookup(struct mode_key_data *, key_code, - const char **, u_int *); +enum mode_key_cmd mode_key_lookup(struct mode_key_data *, key_code); /* notify.c */ void notify_enable(void); @@ -1920,6 +1871,7 @@ void server_add_accept(int); /* server-client.c */ void server_client_set_key_table(struct client *, const char *); const char *server_client_get_key_table(struct client *); +int server_client_is_default_key_table(struct client *); int server_client_check_nested(struct client *); void server_client_handle_key(struct client *, key_code); void server_client_create(int); diff --git a/window-choose.c b/window-choose.c index 715915b6..19677c86 100644 --- a/window-choose.c +++ b/window-choose.c @@ -52,10 +52,10 @@ enum window_choose_input_type { }; const struct window_mode window_choose_mode = { - window_choose_init, - window_choose_free, - window_choose_resize, - window_choose_key, + .init = window_choose_init, + .free = window_choose_free, + .resize = window_choose_resize, + .key = window_choose_key, }; struct window_choose_mode_item { @@ -552,7 +552,7 @@ window_choose_key(struct window_pane *wp, __unused struct client *c, items = data->list_size; if (data->input_type == WINDOW_CHOOSE_GOTO_ITEM) { - switch (mode_key_lookup(&data->mdata, key, NULL, NULL)) { + switch (mode_key_lookup(&data->mdata, key)) { case MODEKEYCHOICE_CANCEL: data->input_type = WINDOW_CHOOSE_NORMAL; window_choose_redraw_screen(wp); @@ -582,7 +582,7 @@ window_choose_key(struct window_pane *wp, __unused struct client *c, return; } - switch (mode_key_lookup(&data->mdata, key, NULL, NULL)) { + switch (mode_key_lookup(&data->mdata, key)) { case MODEKEYCHOICE_CANCEL: window_choose_fire_callback(wp, NULL); break; @@ -837,7 +837,7 @@ window_choose_key_index(struct window_choose_mode_data *data, u_int idx) int mkey; for (ptr = keys; *ptr != '\0'; ptr++) { - mkey = mode_key_lookup(&data->mdata, *ptr, NULL, NULL); + mkey = mode_key_lookup(&data->mdata, *ptr); if (mkey != MODEKEY_NONE && mkey != MODEKEY_OTHER) continue; if (idx-- == 0) @@ -857,7 +857,7 @@ window_choose_index_key(struct window_choose_mode_data *data, key_code key) u_int idx = 0; for (ptr = keys; *ptr != '\0'; ptr++) { - mkey = mode_key_lookup(&data->mdata, *ptr, NULL, NULL); + mkey = mode_key_lookup(&data->mdata, *ptr); if (mkey != MODEKEY_NONE && mkey != MODEKEY_OTHER) continue; if (key == (key_code)*ptr) diff --git a/window-clock.c b/window-clock.c index a9bbb75a..c80e9af7 100644 --- a/window-clock.c +++ b/window-clock.c @@ -34,10 +34,10 @@ static void window_clock_timer_callback(int, short, void *); static void window_clock_draw_screen(struct window_pane *); const struct window_mode window_clock_mode = { - window_clock_init, - window_clock_free, - window_clock_resize, - window_clock_key, + .init = window_clock_init, + .free = window_clock_free, + .resize = window_clock_resize, + .key = window_clock_key, }; struct window_clock_mode_data { diff --git a/window-copy.c b/window-copy.c index f1379604..d5140fc7 100644 --- a/window-copy.c +++ b/window-copy.c @@ -24,16 +24,15 @@ #include "tmux.h" +const char *window_copy_key_table(struct window_pane *); +void window_copy_command(struct window_pane *, struct client *, + struct session *, struct args *, struct mouse_event *); struct screen *window_copy_init(struct window_pane *); void window_copy_free(struct window_pane *); void window_copy_pagedown(struct window_pane *, int); void window_copy_next_paragraph(struct window_pane *); void window_copy_previous_paragraph(struct window_pane *); void window_copy_resize(struct window_pane *, u_int, u_int); -void window_copy_key(struct window_pane *, struct client *, struct session *, - key_code, struct mouse_event *); -int window_copy_key_input(struct window_pane *, key_code); -int window_copy_key_numeric_prefix(struct window_pane *, key_code); void window_copy_redraw_selection(struct window_pane *, u_int); void window_copy_redraw_lines(struct window_pane *, u_int, u_int); @@ -96,23 +95,21 @@ void window_copy_drag_update(struct client *, struct mouse_event *); void window_copy_drag_release(struct client *, struct mouse_event *); const struct window_mode window_copy_mode = { - window_copy_init, - window_copy_free, - window_copy_resize, - window_copy_key, + .init = window_copy_init, + .free = window_copy_free, + .resize = window_copy_resize, + .key_table = window_copy_key_table, + .command = window_copy_command, }; -enum window_copy_input_type { +enum { WINDOW_COPY_OFF, - WINDOW_COPY_NAMEDBUFFER, - WINDOW_COPY_NUMERICPREFIX, WINDOW_COPY_SEARCHUP, WINDOW_COPY_SEARCHDOWN, WINDOW_COPY_JUMPFORWARD, - WINDOW_COPY_JUMPBACK, + WINDOW_COPY_JUMPBACKWARD, WINDOW_COPY_JUMPTOFORWARD, - WINDOW_COPY_JUMPTOBACK, - WINDOW_COPY_GOTOLINE, + WINDOW_COPY_JUMPTOBACKWARD, }; /* @@ -132,39 +129,30 @@ enum window_copy_input_type { * mode ends). */ struct window_copy_mode_data { - struct screen screen; + struct screen screen; - struct screen *backing; - int backing_written; /* backing display started */ + struct screen *backing; + int backing_written; /* backing display started */ - struct mode_key_data mdata; + u_int oy; - u_int oy; + u_int selx; + u_int sely; - u_int selx; - u_int sely; + int rectflag; /* in rectangle copy mode? */ + int scroll_exit; /* exit on scroll to end? */ - int rectflag; /* in rectangle copy mode? */ - int scroll_exit; /* exit on scroll to end? */ + u_int cx; + u_int cy; - u_int cx; - u_int cy; + u_int lastcx; /* position in last line w/ content */ + u_int lastsx; /* size of last line w/ content */ - u_int lastcx; /* position in last line w/ content */ - u_int lastsx; /* size of last line w/ content */ + int searchtype; + char *searchstr; - enum window_copy_input_type inputtype; - const char *inputprompt; - char *inputstr; - int inputexit; - - int numprefix; - - enum window_copy_input_type searchtype; - char *searchstr; - - enum window_copy_input_type jumptype; - char jumpchar; + int jumptype; + char jumpchar; }; struct screen * @@ -172,7 +160,6 @@ window_copy_init(struct window_pane *wp) { struct window_copy_mode_data *data; struct screen *s; - int keys; wp->modedata = data = xmalloc(sizeof *data); data->oy = 0; @@ -187,11 +174,6 @@ window_copy_init(struct window_pane *wp) data->rectflag = 0; data->scroll_exit = 0; - data->inputtype = WINDOW_COPY_OFF; - data->inputprompt = NULL; - data->inputstr = xstrdup(""); - data->numprefix = -1; - data->searchtype = WINDOW_COPY_OFF; data->searchstr = NULL; @@ -203,13 +185,7 @@ window_copy_init(struct window_pane *wp) s = &data->screen; screen_init(s, screen_size_x(&wp->base), screen_size_y(&wp->base), 0); - - keys = options_get_number(wp->window->options, "mode-keys"); - if (keys == MODEKEY_EMACS) - mode_key_init(&data->mdata, &mode_key_tree_emacs_copy); - else - mode_key_init(&data->mdata, &mode_key_tree_vi_copy); - s->sel.modekeys = keys; + s->sel.modekeys = options_get_number(wp->window->options, "mode-keys"); data->backing = NULL; @@ -261,7 +237,6 @@ window_copy_free(struct window_pane *wp) bufferevent_enable(wp->event, EV_READ|EV_WRITE); free(data->searchstr); - free(data->inputstr); if (data->backing != &wp->base) { screen_free(data->backing); @@ -483,529 +458,337 @@ window_copy_resize(struct window_pane *wp, u_int sx, u_int sy) window_copy_redraw_screen(wp); } +const char * +window_copy_key_table(struct window_pane *wp) +{ + if (options_get_number(wp->window->options, "mode-keys") == MODEKEY_VI) + return ("copy-mode-vi"); + return ("copy-mode"); +} + void -window_copy_key(struct window_pane *wp, struct client *c, struct session *sess, - key_code key, struct mouse_event *m) +window_copy_command(struct window_pane *wp, struct client *c, struct session *s, + struct args *args, struct mouse_event *m) { - const char *word_separators; struct window_copy_mode_data *data = wp->modedata; - struct screen *s = &data->screen; - u_int np; - int keys; - enum mode_key_cmd cmd; - const char *arg, *ss; - - np = 1; - if (data->numprefix > 0) - np = data->numprefix; - - if (data->inputtype == WINDOW_COPY_JUMPFORWARD || - data->inputtype == WINDOW_COPY_JUMPBACK || - data->inputtype == WINDOW_COPY_JUMPTOFORWARD || - data->inputtype == WINDOW_COPY_JUMPTOBACK) { - /* Ignore keys with modifiers. */ - if ((key & KEYC_MASK_MOD) == 0) { - data->jumpchar = key; - if (data->inputtype == WINDOW_COPY_JUMPFORWARD) { - for (; np != 0; np--) - window_copy_cursor_jump(wp); - } - if (data->inputtype == WINDOW_COPY_JUMPBACK) { - for (; np != 0; np--) - window_copy_cursor_jump_back(wp); - } - if (data->inputtype == WINDOW_COPY_JUMPTOFORWARD) { - for (; np != 0; np--) - window_copy_cursor_jump_to(wp, 0); - } - if (data->inputtype == WINDOW_COPY_JUMPTOBACK) { - for (; np != 0; np--) - window_copy_cursor_jump_to_back(wp, 0); - } - } - data->jumptype = data->inputtype; - data->inputtype = WINDOW_COPY_OFF; - window_copy_redraw_lines(wp, screen_size_y(s) - 1, 1); - return; - } else if (data->inputtype == WINDOW_COPY_NUMERICPREFIX) { - if (window_copy_key_numeric_prefix(wp, key) == 0) - return; - data->inputtype = WINDOW_COPY_OFF; - window_copy_redraw_lines(wp, screen_size_y(s) - 1, 1); - } else if (data->inputtype != WINDOW_COPY_OFF) { - if (window_copy_key_input(wp, key) != 0) - goto input_off; + struct screen *sn = &data->screen; + const char *command, *argument, *ws, *ss; + u_int np = wp->modeprefix; + + if (args->argc == 0) return; - } + command = args->argv[0]; - cmd = mode_key_lookup(&data->mdata, key, &arg, &np); - if (data->numprefix > 0) - np = data->numprefix; - if (cmd != MODEKEYCOPY_PREVIOUSPAGE && - cmd != MODEKEYCOPY_NEXTPAGE && - cmd != MODEKEYCOPY_SCROLLUP && - cmd != MODEKEYCOPY_SCROLLDOWN && - cmd != MODEKEYCOPY_HALFPAGEUP && - cmd != MODEKEYCOPY_HALFPAGEDOWN) - data->scroll_exit = 0; - switch (cmd) { - case MODEKEYCOPY_APPENDSELECTION: - if (sess != NULL) { - window_copy_append_selection(wp, NULL); - if (arg == NULL) { - window_pane_reset_mode(wp); - return; - } + if (args->argc == 1) { + if (strcmp(command, "append-selection") == 0) { + if (s != NULL) + window_copy_append_selection(wp, NULL); window_copy_clear_selection(wp); window_copy_redraw_screen(wp); } - break; - case MODEKEYCOPY_CANCEL: - window_pane_reset_mode(wp); - return; - case MODEKEYCOPY_OTHEREND: - if (np % 2) - window_copy_other_end(wp); - break; - case MODEKEYCOPY_LEFT: - for (; np != 0; np--) - window_copy_cursor_left(wp); - break; - case MODEKEYCOPY_RIGHT: - for (; np != 0; np--) - window_copy_cursor_right(wp); - break; - case MODEKEYCOPY_UP: - for (; np != 0; np--) - window_copy_cursor_up(wp, 0); - break; - case MODEKEYCOPY_DOWN: - for (; np != 0; np--) - window_copy_cursor_down(wp, 0); - break; - case MODEKEYCOPY_SCROLLUP: - for (; np != 0; np--) - window_copy_cursor_up(wp, 1); - break; - case MODEKEYCOPY_SCROLLDOWN: - for (; np != 0; np--) - window_copy_cursor_down(wp, 1); - if (data->scroll_exit && data->oy == 0) { + if (strcmp(command, "append-selection-and-cancel") == 0) { + if (s != NULL) + window_copy_append_selection(wp, NULL); + window_copy_clear_selection(wp); + window_copy_redraw_screen(wp); window_pane_reset_mode(wp); - return; } - break; - case MODEKEYCOPY_PREVIOUSPAGE: - for (; np != 0; np--) - window_copy_pageup(wp, 0); - break; - case MODEKEYCOPY_NEXTPAGE: - for (; np != 0; np--) - window_copy_pagedown(wp, 0); - break; - case MODEKEYCOPY_PREVIOUSPARAGRAPH: - for (; np != 0; np--) - window_copy_previous_paragraph(wp); - break; - case MODEKEYCOPY_NEXTPARAGRAPH: - for (; np != 0; np--) - window_copy_next_paragraph(wp); - break; - case MODEKEYCOPY_HALFPAGEUP: - for (; np != 0; np--) - window_copy_pageup(wp, 1); - break; - case MODEKEYCOPY_HALFPAGEDOWN: - for (; np != 0; np--) - window_copy_pagedown(wp, 1); - break; - case MODEKEYCOPY_TOPLINE: - data->cx = 0; - data->cy = 0; - window_copy_update_selection(wp, 1); - window_copy_redraw_screen(wp); - break; - case MODEKEYCOPY_MIDDLELINE: - data->cx = 0; - data->cy = (screen_size_y(s) - 1) / 2; - window_copy_update_selection(wp, 1); - window_copy_redraw_screen(wp); - break; - case MODEKEYCOPY_BOTTOMLINE: - data->cx = 0; - data->cy = screen_size_y(s) - 1; - window_copy_update_selection(wp, 1); - window_copy_redraw_screen(wp); - break; - case MODEKEYCOPY_HISTORYTOP: - data->cx = 0; - data->cy = 0; - data->oy = screen_hsize(data->backing); - window_copy_update_selection(wp, 1); - window_copy_redraw_screen(wp); - break; - case MODEKEYCOPY_HISTORYBOTTOM: - data->cx = 0; - data->cy = screen_size_y(s) - 1; - data->oy = 0; - window_copy_update_selection(wp, 1); - window_copy_redraw_screen(wp); - break; - case MODEKEYCOPY_STARTSELECTION: - if (KEYC_IS_MOUSE(key)) { - if (c != NULL) + if (strcmp(command, "back-to-indentation") == 0) + window_copy_cursor_back_to_indentation(wp); + if (strcmp(command, "begin-selection") == 0) { + if (m != NULL) window_copy_start_drag(c, m); - } else { - s->sel.lineflag = LINE_SEL_NONE; - window_copy_start_selection(wp); + else { + sn->sel.lineflag = LINE_SEL_NONE; + window_copy_start_selection(wp); + window_copy_redraw_screen(wp); + } + } + if (strcmp(command, "bottom-line") == 0) { + data->cx = 0; + data->cy = screen_size_y(sn) - 1; + window_copy_update_selection(wp, 1); window_copy_redraw_screen(wp); } - break; - case MODEKEYCOPY_SELECTLINE: - s->sel.lineflag = LINE_SEL_LEFT_RIGHT; - data->rectflag = 0; - /* FALLTHROUGH */ - case MODEKEYCOPY_COPYLINE: - window_copy_cursor_start_of_line(wp); - /* FALLTHROUGH */ - case MODEKEYCOPY_COPYENDOFLINE: - window_copy_start_selection(wp); - for (; np > 1; np--) - window_copy_cursor_down(wp, 0); - window_copy_cursor_end_of_line(wp); - window_copy_redraw_screen(wp); - - /* If a copy command then copy the selection and exit. */ - if (sess != NULL && - (cmd == MODEKEYCOPY_COPYLINE || - cmd == MODEKEYCOPY_COPYENDOFLINE)) { - window_copy_copy_selection(wp, NULL); + if (strcmp(command, "cancel") == 0) window_pane_reset_mode(wp); - return; + if (strcmp(command, "clear-selection") == 0) { + window_copy_clear_selection(wp); + window_copy_redraw_screen(wp); } - break; - case MODEKEYCOPY_CLEARSELECTION: - window_copy_clear_selection(wp); - window_copy_redraw_screen(wp); - break; - case MODEKEYCOPY_COPYPIPE: - if (sess != NULL) { - window_copy_copy_pipe(wp, sess, NULL, arg); - window_pane_reset_mode(wp); - return; + if (strcmp(command, "copy-end-of-line") == 0) { + window_copy_start_selection(wp); + for (; np > 1; np--) + window_copy_cursor_down(wp, 0); + window_copy_cursor_end_of_line(wp); + window_copy_redraw_screen(wp); + + if (s != NULL) { + window_copy_copy_selection(wp, NULL); + window_pane_reset_mode(wp); + } } - break; - case MODEKEYCOPY_COPYSELECTION: - if (sess != NULL) { - window_copy_copy_selection(wp, NULL); - if (arg == NULL) { + if (strcmp(command, "copy-line") == 0) { + window_copy_cursor_start_of_line(wp); + window_copy_start_selection(wp); + for (; np > 1; np--) + window_copy_cursor_down(wp, 0); + window_copy_cursor_end_of_line(wp); + window_copy_redraw_screen(wp); + + if (s != NULL) { + window_copy_copy_selection(wp, NULL); window_pane_reset_mode(wp); - return; } + } + if (strcmp(command, "copy-selection") == 0) { + if (s != NULL) + window_copy_copy_selection(wp, NULL); window_copy_clear_selection(wp); window_copy_redraw_screen(wp); } - break; - case MODEKEYCOPY_STARTOFLINE: - window_copy_cursor_start_of_line(wp); - break; - case MODEKEYCOPY_BACKTOINDENTATION: - window_copy_cursor_back_to_indentation(wp); - break; - case MODEKEYCOPY_ENDOFLINE: - window_copy_cursor_end_of_line(wp); - break; - case MODEKEYCOPY_NEXTSPACE: - for (; np != 0; np--) - window_copy_cursor_next_word(wp, " "); - break; - case MODEKEYCOPY_NEXTSPACEEND: - for (; np != 0; np--) - window_copy_cursor_next_word_end(wp, " "); - break; - case MODEKEYCOPY_NEXTWORD: - word_separators = - options_get_string(sess->options, "word-separators"); - for (; np != 0; np--) - window_copy_cursor_next_word(wp, word_separators); - break; - case MODEKEYCOPY_NEXTWORDEND: - word_separators = - options_get_string(sess->options, "word-separators"); - for (; np != 0; np--) - window_copy_cursor_next_word_end(wp, word_separators); - break; - case MODEKEYCOPY_PREVIOUSSPACE: - for (; np != 0; np--) - window_copy_cursor_previous_word(wp, " "); - break; - case MODEKEYCOPY_PREVIOUSWORD: - word_separators = - options_get_string(sess->options, "word-separators"); - for (; np != 0; np--) - window_copy_cursor_previous_word(wp, word_separators); - break; - case MODEKEYCOPY_JUMP: - data->inputtype = WINDOW_COPY_JUMPFORWARD; - data->inputprompt = "Jump Forward"; - *data->inputstr = '\0'; - window_copy_redraw_lines(wp, screen_size_y(s) - 1, 1); - return; /* skip numprefix reset */ - case MODEKEYCOPY_JUMPAGAIN: - if (data->jumptype == WINDOW_COPY_JUMPFORWARD) { + if (strcmp(command, "copy-selection-and-cancel") == 0) { + if (s != NULL) + window_copy_copy_selection(wp, NULL); + window_copy_clear_selection(wp); + window_copy_redraw_screen(wp); + window_pane_reset_mode(wp); + } + if (strcmp(command, "cursor-down") == 0) { for (; np != 0; np--) - window_copy_cursor_jump(wp); - } else if (data->jumptype == WINDOW_COPY_JUMPBACK) { + window_copy_cursor_down(wp, 0); + } + if (strcmp(command, "cursor-left") == 0) { for (; np != 0; np--) - window_copy_cursor_jump_back(wp); - } else if (data->jumptype == WINDOW_COPY_JUMPTOFORWARD) { + window_copy_cursor_left(wp); + } + if (strcmp(command, "cursor-right") == 0) { for (; np != 0; np--) - window_copy_cursor_jump_to(wp, 1); - } else if (data->jumptype == WINDOW_COPY_JUMPTOBACK) { + window_copy_cursor_right(wp); + } + if (strcmp(command, "cursor-up") == 0) { for (; np != 0; np--) - window_copy_cursor_jump_to_back(wp, 1); + window_copy_cursor_up(wp, 0); } - break; - case MODEKEYCOPY_JUMPREVERSE: - if (data->jumptype == WINDOW_COPY_JUMPFORWARD) { + if (strcmp(command, "end-of-line") == 0) + window_copy_cursor_end_of_line(wp); + if (strcmp(command, "halfpage-down") == 0) { for (; np != 0; np--) - window_copy_cursor_jump_back(wp); - } else if (data->jumptype == WINDOW_COPY_JUMPBACK) { + window_copy_pagedown(wp, 1); + } + if (strcmp(command, "halfpage-up") == 0) { for (; np != 0; np--) - window_copy_cursor_jump(wp); - } else if (data->jumptype == WINDOW_COPY_JUMPTOFORWARD) { + window_copy_pageup(wp, 1); + } + if (strcmp(command, "history-bottom") == 0) { + data->cx = 0; + data->cy = screen_size_y(sn) - 1; + data->oy = 0; + window_copy_update_selection(wp, 1); + window_copy_redraw_screen(wp); + } + if (strcmp(command, "history-top") == 0) { + data->cx = 0; + data->cy = 0; + data->oy = screen_hsize(data->backing); + window_copy_update_selection(wp, 1); + window_copy_redraw_screen(wp); + } + if (strcmp(command, "jump-again") == 0) { + switch (data->jumptype) { + case WINDOW_COPY_JUMPFORWARD: + for (; np != 0; np--) + window_copy_cursor_jump(wp); + break; + case WINDOW_COPY_JUMPBACKWARD: + for (; np != 0; np--) + window_copy_cursor_jump_back(wp); + break; + case WINDOW_COPY_JUMPTOFORWARD: + for (; np != 0; np--) + window_copy_cursor_jump_to(wp, 1); + break; + case WINDOW_COPY_JUMPTOBACKWARD: + for (; np != 0; np--) + window_copy_cursor_jump_to_back(wp, 1); + break; + } + } + if (strcmp(command, "jump-reverse") == 0) { + switch (data->jumptype) { + case WINDOW_COPY_JUMPFORWARD: + for (; np != 0; np--) + window_copy_cursor_jump_back(wp); + break; + case WINDOW_COPY_JUMPBACKWARD: + for (; np != 0; np--) + window_copy_cursor_jump(wp); + break; + case WINDOW_COPY_JUMPTOFORWARD: + for (; np != 0; np--) + window_copy_cursor_jump_to_back(wp, 1); + break; + case WINDOW_COPY_JUMPTOBACKWARD: + for (; np != 0; np--) + window_copy_cursor_jump_to(wp, 1); + break; + } + } + if (strcmp(command, "middle-line") == 0) { + data->cx = 0; + data->cy = (screen_size_y(sn) - 1) / 2; + window_copy_update_selection(wp, 1); + window_copy_redraw_screen(wp); + } + if (strcmp(command, "next-paragraph") == 0) { for (; np != 0; np--) - window_copy_cursor_jump_to_back(wp, 1); - } else if (data->jumptype == WINDOW_COPY_JUMPTOBACK) { + window_copy_next_paragraph(wp); + } + if (strcmp(command, "next-space") == 0) { for (; np != 0; np--) - window_copy_cursor_jump_to(wp, 1); + window_copy_cursor_next_word(wp, " "); } - break; - case MODEKEYCOPY_JUMPBACK: - data->inputtype = WINDOW_COPY_JUMPBACK; - data->inputprompt = "Jump Back"; - *data->inputstr = '\0'; - window_copy_redraw_lines(wp, screen_size_y(s) - 1, 1); - return; /* skip numprefix reset */ - case MODEKEYCOPY_JUMPTO: - data->inputtype = WINDOW_COPY_JUMPTOFORWARD; - data->inputprompt = "Jump To"; - *data->inputstr = '\0'; - window_copy_redraw_lines(wp, screen_size_y(s) - 1, 1); - return; /* skip numprefix reset */ - case MODEKEYCOPY_JUMPTOBACK: - data->inputtype = WINDOW_COPY_JUMPTOBACK; - data->inputprompt = "Jump To Back"; - *data->inputstr = '\0'; - window_copy_redraw_lines(wp, screen_size_y(s) - 1, 1); - return; /* skip numprefix reset */ - case MODEKEYCOPY_SEARCHUP: - data->inputtype = WINDOW_COPY_SEARCHUP; - data->inputprompt = "Search Up"; - goto input_on; - case MODEKEYCOPY_SEARCHDOWN: - data->inputtype = WINDOW_COPY_SEARCHDOWN; - data->inputprompt = "Search Down"; - goto input_on; - case MODEKEYCOPY_SEARCHAGAIN: - case MODEKEYCOPY_SEARCHREVERSE: - switch (data->searchtype) { - case WINDOW_COPY_OFF: - case WINDOW_COPY_GOTOLINE: - case WINDOW_COPY_JUMPFORWARD: - case WINDOW_COPY_JUMPBACK: - case WINDOW_COPY_JUMPTOFORWARD: - case WINDOW_COPY_JUMPTOBACK: - case WINDOW_COPY_NAMEDBUFFER: - case WINDOW_COPY_NUMERICPREFIX: - break; - case WINDOW_COPY_SEARCHUP: + if (strcmp(command, "next-space-end") == 0) { + for (; np != 0; np--) + window_copy_cursor_next_word_end(wp, " "); + } + if (strcmp(command, "next-word") == 0) { + ws = options_get_string(s->options, "word-separators"); + for (; np != 0; np--) + window_copy_cursor_next_word(wp, ws); + } + if (strcmp(command, "next-word-end") == 0) { + ws = options_get_string(s->options, "word-separators"); + for (; np != 0; np--) + window_copy_cursor_next_word_end(wp, ws); + } + if (strcmp(command, "other-end") == 0) { + if ((np % 2) != 0) + window_copy_other_end(wp); + } + if (strcmp(command, "page-down") == 0) { + for (; np != 0; np--) + window_copy_pagedown(wp, 0); + } + if (strcmp(command, "page-up") == 0) { + for (; np != 0; np--) + window_copy_pageup(wp, 0); + } + if (strcmp(command, "previous-paragraph") == 0) { + for (; np != 0; np--) + window_copy_previous_paragraph(wp); + } + if (strcmp(command, "previous-space") == 0) { + for (; np != 0; np--) + window_copy_cursor_previous_word(wp, " "); + } + if (strcmp(command, "previous-word") == 0) { + ws = options_get_string(s->options, "word-separators"); + for (; np != 0; np--) + window_copy_cursor_previous_word(wp, ws); + } + if (strcmp(command, "rectangle-toggle") == 0) { + sn->sel.lineflag = LINE_SEL_NONE; + window_copy_rectangle_toggle(wp); + } + if (strcmp(command, "scroll-down") == 0) { + for (; np != 0; np--) + window_copy_cursor_down(wp, 1); + if (data->scroll_exit && data->oy == 0) + window_pane_reset_mode(wp); + } + if (strcmp(command, "scroll-up") == 0) { + for (; np != 0; np--) + window_copy_cursor_up(wp, 1); + } + if (strcmp(command, "search-again") == 0) { ss = data->searchstr; - if (cmd == MODEKEYCOPY_SEARCHAGAIN) { + if (data->searchtype == WINDOW_COPY_SEARCHUP) { for (; np != 0; np--) window_copy_search_up(wp, ss, 1); - } else { + } else if (data->searchtype == WINDOW_COPY_SEARCHDOWN) { for (; np != 0; np--) window_copy_search_down(wp, ss, 1); } - break; - case WINDOW_COPY_SEARCHDOWN: + } + if (strcmp(command, "search-reverse") == 0) { ss = data->searchstr; - if (cmd == MODEKEYCOPY_SEARCHAGAIN) { + if (data->searchtype == WINDOW_COPY_SEARCHUP) { for (; np != 0; np--) window_copy_search_down(wp, ss, 1); - } else { + } else if (data->searchtype == WINDOW_COPY_SEARCHDOWN) { for (; np != 0; np--) window_copy_search_up(wp, ss, 1); } - break; } - break; - case MODEKEYCOPY_GOTOLINE: - data->inputtype = WINDOW_COPY_GOTOLINE; - data->inputprompt = "Goto Line"; - *data->inputstr = '\0'; - goto input_on; - case MODEKEYCOPY_STARTNAMEDBUFFER: - data->inputtype = WINDOW_COPY_NAMEDBUFFER; - data->inputexit = (arg == NULL); - data->inputprompt = "Buffer"; - *data->inputstr = '\0'; - goto input_on; - case MODEKEYCOPY_STARTNUMBERPREFIX: - key &= KEYC_MASK_KEY; - if (key >= '0' && key <= '9') { - data->inputtype = WINDOW_COPY_NUMERICPREFIX; - data->numprefix = 0; - window_copy_key_numeric_prefix(wp, key); - return; + if (strcmp(command, "select-line") == 0) { + sn->sel.lineflag = LINE_SEL_LEFT_RIGHT; + data->rectflag = 0; + window_copy_cursor_start_of_line(wp); + window_copy_start_selection(wp); + for (; np > 1; np--) + window_copy_cursor_down(wp, 0); + window_copy_cursor_end_of_line(wp); + window_copy_redraw_screen(wp); } - break; - case MODEKEYCOPY_RECTANGLETOGGLE: - s->sel.lineflag = LINE_SEL_NONE; - window_copy_rectangle_toggle(wp); - break; - default: - break; - } - - data->numprefix = -1; - return; - -input_on: - keys = options_get_number(wp->window->options, "mode-keys"); - if (keys == MODEKEY_EMACS) - mode_key_init(&data->mdata, &mode_key_tree_emacs_edit); - else - mode_key_init(&data->mdata, &mode_key_tree_vi_edit); - - window_copy_redraw_lines(wp, screen_size_y(s) - 1, 1); - return; - -input_off: - keys = options_get_number(wp->window->options, "mode-keys"); - if (keys == MODEKEY_EMACS) - mode_key_init(&data->mdata, &mode_key_tree_emacs_copy); - else - mode_key_init(&data->mdata, &mode_key_tree_vi_copy); - - data->inputtype = WINDOW_COPY_OFF; - data->inputprompt = NULL; - - window_copy_redraw_lines(wp, screen_size_y(s) - 1, 1); -} - -int -window_copy_key_input(struct window_pane *wp, key_code key) -{ - struct window_copy_mode_data *data = wp->modedata; - struct screen *s = &data->screen; - const char *bufdata; - size_t inputlen, n, bufsize; - u_int np; - struct paste_buffer *pb; - u_char ch; - - switch (mode_key_lookup(&data->mdata, key, NULL, &np)) { - case MODEKEYEDIT_CANCEL: - data->numprefix = -1; - return (-1); - case MODEKEYEDIT_BACKSPACE: - inputlen = strlen(data->inputstr); - if (inputlen > 0) - data->inputstr[inputlen - 1] = '\0'; - break; - case MODEKEYEDIT_DELETELINE: - *data->inputstr = '\0'; - break; - case MODEKEYEDIT_PASTE: - if ((pb = paste_get_top(NULL)) == NULL) - break; - bufdata = paste_buffer_data(pb, &bufsize); - for (n = 0; n < bufsize; n++) { - ch = (u_char)bufdata[n]; - if (ch < 32 || ch == 127) - break; + if (strcmp(command, "start-of-line") == 0) { + window_copy_cursor_start_of_line(wp); } - inputlen = strlen(data->inputstr); - - data->inputstr = xrealloc(data->inputstr, inputlen + n + 1); - memcpy(data->inputstr + inputlen, bufdata, n); - data->inputstr[inputlen + n] = '\0'; - break; - case MODEKEYEDIT_ENTER: - if (data->numprefix > 0) - np = data->numprefix; - switch (data->inputtype) { - case WINDOW_COPY_OFF: - case WINDOW_COPY_JUMPFORWARD: - case WINDOW_COPY_JUMPBACK: - case WINDOW_COPY_JUMPTOFORWARD: - case WINDOW_COPY_JUMPTOBACK: - case WINDOW_COPY_NUMERICPREFIX: - break; - case WINDOW_COPY_SEARCHUP: - data->searchtype = data->inputtype; - data->searchstr = xstrdup(data->inputstr); - for (; np != 0; np--) - window_copy_search_up(wp, data->inputstr, 1); - break; - case WINDOW_COPY_SEARCHDOWN: - data->searchtype = data->inputtype; - data->searchstr = xstrdup(data->inputstr); - for (; np != 0; np--) - window_copy_search_down(wp, data->inputstr, 1); - break; - case WINDOW_COPY_NAMEDBUFFER: - window_copy_copy_selection(wp, data->inputstr); - *data->inputstr = '\0'; - if (data->inputexit) { + if (strcmp(command, "top-line") == 0) { + data->cx = 0; + data->cy = 0; + window_copy_update_selection(wp, 1); + window_copy_redraw_screen(wp); + } + } else if (args->argc == 2 && *args->argv[1] != '\0') { + argument = args->argv[1]; + if (strcmp(command, "copy-pipe") == 0) { + if (s != NULL) { + window_copy_copy_pipe(wp, s, NULL, argument); window_pane_reset_mode(wp); - return (0); } - window_copy_clear_selection(wp); - window_copy_redraw_screen(wp); - break; - case WINDOW_COPY_GOTOLINE: - window_copy_goto_line(wp, data->inputstr); - *data->inputstr = '\0'; - break; } - data->numprefix = -1; - return (1); - case MODEKEY_OTHER: - if (key < 32 || key > 126) - break; - inputlen = strlen(data->inputstr) + 2; - - data->inputstr = xrealloc(data->inputstr, inputlen); - data->inputstr[inputlen - 2] = key; - data->inputstr[inputlen - 1] = '\0'; - break; - default: - break; + if (strcmp(command, "goto-line") == 0) + window_copy_goto_line(wp, argument); + if (strcmp(command, "jump-backward") == 0) { + data->jumptype = WINDOW_COPY_JUMPBACKWARD; + data->jumpchar = *argument; + for (; np != 0; np--) + window_copy_cursor_jump_back(wp); + } + if (strcmp(command, "jump-forward") == 0) { + data->jumptype = WINDOW_COPY_JUMPFORWARD; + data->jumpchar = *argument; + for (; np != 0; np--) + window_copy_cursor_jump(wp); + } + if (strcmp(command, "jump-to-backward") == 0) { + data->jumptype = WINDOW_COPY_JUMPTOBACKWARD; + data->jumpchar = *argument; + for (; np != 0; np--) + window_copy_cursor_jump_to_back(wp, 1); + } + if (strcmp(command, "jump-to-forward") == 0) { + data->jumptype = WINDOW_COPY_JUMPTOFORWARD; + data->jumpchar = *argument; + for (; np != 0; np--) + window_copy_cursor_jump_to(wp, 1); + } + if (strcmp(command, "search-backward") == 0) { + data->searchtype = WINDOW_COPY_SEARCHUP; + data->searchstr = xstrdup(argument); + for (; np != 0; np--) + window_copy_search_up(wp, data->searchstr, 1); + } + if (strcmp(command, "search-forward") == 0) { + data->searchtype = WINDOW_COPY_SEARCHDOWN; + data->searchstr = xstrdup(argument); + for (; np != 0; np--) + window_copy_search_down(wp, data->searchstr, 1); + } } - window_copy_redraw_lines(wp, screen_size_y(s) - 1, 1); - return (0); -} - -int -window_copy_key_numeric_prefix(struct window_pane *wp, key_code key) -{ - struct window_copy_mode_data *data = wp->modedata; - struct screen *s = &data->screen; - - key &= KEYC_MASK_KEY; - if (key < '0' || key > '9') - return (1); - - if (data->numprefix >= 100) /* no more than three digits */ - return (0); - data->numprefix = data->numprefix * 10 + key - '0'; - - window_copy_redraw_lines(wp, screen_size_y(s) - 1, 1); - return (0); + wp->modeprefix = 1; } void @@ -1268,7 +1051,7 @@ window_copy_write_line(struct window_pane *wp, struct screen_write_ctx *ctx, struct options *oo = wp->window->options; struct grid_cell gc; char hdr[512]; - size_t last, xoff = 0, size = 0, limit; + size_t last, xoff = 0, size = 0; style_apply(&gc, oo, "mode-style"); @@ -1280,20 +1063,6 @@ window_copy_write_line(struct window_pane *wp, struct screen_write_ctx *ctx, size = screen_size_x(s); screen_write_cursormove(ctx, screen_size_x(s) - size, 0); screen_write_puts(ctx, &gc, "%s", hdr); - } else if (py == last && data->inputtype != WINDOW_COPY_OFF) { - limit = sizeof hdr; - if (limit > screen_size_x(s) + 1) - limit = screen_size_x(s) + 1; - if (data->inputtype == WINDOW_COPY_NUMERICPREFIX) { - xoff = size = xsnprintf(hdr, limit, - "Repeat: %d", data->numprefix); - } else { - /* We don't care about truncation. */ - xoff = size = snprintf(hdr, limit, - "%s: %s", data->inputprompt, data->inputstr); - } - screen_write_cursormove(ctx, 0, last); - screen_write_puts(ctx, &gc, "%s", hdr); } else size = 0; @@ -2342,6 +2111,9 @@ window_copy_start_drag(struct client *c, struct mouse_event *m) struct window_pane *wp; u_int x, y; + if (c == NULL) + return; + wp = cmd_mouse_pane(m, NULL, NULL); if (wp == NULL || wp->mode != &window_copy_mode) return; @@ -2350,7 +2122,7 @@ window_copy_start_drag(struct client *c, struct mouse_event *m) return; c->tty.mouse_drag_update = window_copy_drag_update; - c->tty.mouse_drag_release = NULL; /* will fire MouseUp key */ + c->tty.mouse_drag_release = NULL; /* will fire MouseDragEnd key */ window_copy_update_cursor(wp, x, y); window_copy_start_selection(wp); diff --git a/window.c b/window.c index 84b6cc5a..2dd8f78f 100644 --- a/window.c +++ b/window.c @@ -1124,6 +1124,7 @@ window_pane_reset_mode(struct window_pane *wp) wp->mode->free(wp); wp->mode = NULL; + wp->modeprefix = 1; wp->screen = &wp->base; wp->flags |= (PANE_REDRAW|PANE_CHANGED); -- cgit From 85d7afaefc1e2cf8008575a776ec70f51d24e1a6 Mon Sep 17 00:00:00 2001 From: nicm Date: Tue, 11 Oct 2016 09:30:36 +0000 Subject: Support double and triple clicks (they are cumulative, so double is fired then triple), and use for select-word and select-line in copy mode. Inspired by a different solution from Omar Sandoval. --- key-bindings.c | 4 ++ key-string.c | 6 +++ server-client.c | 121 ++++++++++++++++++++++++++++++++++++++++++++++++++++---- tmux.1 | 4 +- tmux.h | 14 +++++++ window-copy.c | 32 ++++++++++++++- 6 files changed, 170 insertions(+), 11 deletions(-) diff --git a/key-bindings.c b/key-bindings.c index 384a9f8f..f6b17c3c 100644 --- a/key-bindings.c +++ b/key-bindings.c @@ -263,6 +263,8 @@ key_bindings_init(void) "bind -Tcopy-mode MouseDragEnd1Pane send -X copy-selection-and-cancel", "bind -Tcopy-mode WheelUpPane send -N5 -X scroll-up", "bind -Tcopy-mode WheelDownPane send -N5 -X scroll-down", + "bind -Tcopy-mode DoubleClick1Pane send -X select-word", + "bind -Tcopy-mode TripleClick1Pane send -X select-line", "bind -Tcopy-mode NPage send -X page-down", "bind -Tcopy-mode PPage send -X page-up", "bind -Tcopy-mode Up send -X cursor-up", @@ -359,6 +361,8 @@ key_bindings_init(void) "bind -Tcopy-mode-vi MouseDragEnd1Pane send -X copy-selection-and-cancel", "bind -Tcopy-mode-vi WheelUpPane send -N5 -X scroll-up", "bind -Tcopy-mode-vi WheelDownPane send -N5 -X scroll-down", + "bind -Tcopy-mode-vi DoubleClick1Pane send -X select-word", + "bind -Tcopy-mode-vi TripleClick1Pane send -X select-line", "bind -Tcopy-mode-vi BSpace send -X cursor-left", "bind -Tcopy-mode-vi NPage send -X page-down", "bind -Tcopy-mode-vi PPage send -X page-up", diff --git a/key-string.c b/key-string.c index 00ebb386..d513ec6f 100644 --- a/key-string.c +++ b/key-string.c @@ -98,6 +98,12 @@ static const struct { KEYC_MOUSE_STRING(MOUSEDRAGEND3, MouseDragEnd3), KEYC_MOUSE_STRING(WHEELUP, WheelUp), KEYC_MOUSE_STRING(WHEELDOWN, WheelDown), + KEYC_MOUSE_STRING(DOUBLECLICK1, DoubleClick1), + KEYC_MOUSE_STRING(DOUBLECLICK2, DoubleClick2), + KEYC_MOUSE_STRING(DOUBLECLICK3, DoubleClick3), + KEYC_MOUSE_STRING(TRIPLECLICK1, TripleClick1), + KEYC_MOUSE_STRING(TRIPLECLICK2, TripleClick2), + KEYC_MOUSE_STRING(TRIPLECLICK3, TripleClick3), }; /* Find key string in table. */ diff --git a/server-client.c b/server-client.c index 70fdd51a..d5c0cf23 100644 --- a/server-client.c +++ b/server-client.c @@ -37,6 +37,7 @@ static void server_client_check_focus(struct window_pane *); static void server_client_check_resize(struct window_pane *); static key_code server_client_check_mouse(struct client *); static void server_client_repeat_timer(int, short, void *); +static void server_client_click_timer(int, short, void *); static void server_client_check_exit(struct client *); static void server_client_check_redraw(struct client *); static void server_client_set_title(struct client *); @@ -155,6 +156,7 @@ server_client_create(int fd) c->keytable->references++; evtimer_set(&c->repeat_timer, server_client_repeat_timer, c); + evtimer_set(&c->click_timer, server_client_click_timer, c); TAILQ_INSERT_TAIL(&clients, c, entry); log_debug("new client %p", c); @@ -223,6 +225,7 @@ server_client_lost(struct client *c) free((void *)c->cwd); evtimer_del(&c->repeat_timer); + evtimer_del(&c->click_timer); key_bindings_unref_table(c->keytable); @@ -299,14 +302,16 @@ server_client_detach(struct client *c, enum msgtype msgtype) static key_code server_client_check_mouse(struct client *c) { - struct session *s = c->session; - struct mouse_event *m = &c->tty.mouse; - struct window *w; - struct window_pane *wp; - enum { NOTYPE, DOWN, UP, DRAG, WHEEL } type = NOTYPE; - enum { NOWHERE, PANE, STATUS, BORDER } where = NOWHERE; - u_int x, y, b; - key_code key; + struct session *s = c->session; + struct mouse_event *m = &c->tty.mouse; + struct window *w; + struct window_pane *wp; + u_int x, y, b; + int flag; + key_code key; + struct timeval tv; + enum { NOTYPE, DOWN, UP, DRAG, WHEEL, DOUBLE, TRIPLE } type = NOTYPE; + enum { NOWHERE, PANE, STATUS, BORDER } where = NOWHERE; log_debug("mouse %02x at %u,%u (last %u,%u) (%d)", m->b, m->x, m->y, m->lx, m->ly, c->tty.mouse_drag_flag); @@ -330,10 +335,45 @@ server_client_check_mouse(struct client *c) x = m->x, y = m->y, b = m->lb; log_debug("up at %u,%u", x, y); } else { + if (c->flags & CLIENT_DOUBLECLICK) { + evtimer_del(&c->click_timer); + c->flags &= ~CLIENT_DOUBLECLICK; + if (m->b == c->click_button) { + type = DOUBLE; + x = m->x, y = m->y, b = m->b; + log_debug("double-click at %u,%u", x, y); + flag = CLIENT_TRIPLECLICK; + goto add_timer; + } + } else if (c->flags & CLIENT_TRIPLECLICK) { + evtimer_del(&c->click_timer); + c->flags &= ~CLIENT_TRIPLECLICK; + if (m->b == c->click_button) { + type = TRIPLE; + x = m->x, y = m->y, b = m->b; + log_debug("triple-click at %u,%u", x, y); + goto have_event; + } + } + type = DOWN; x = m->x, y = m->y, b = m->b; log_debug("down at %u,%u", x, y); + flag = CLIENT_DOUBLECLICK; + + add_timer: + if (KEYC_CLICK_TIMEOUT != 0) { + c->flags |= flag; + c->click_button = m->b; + + tv.tv_sec = KEYC_CLICK_TIMEOUT / 1000; + tv.tv_usec = (KEYC_CLICK_TIMEOUT % 1000) * 1000L; + evtimer_del(&c->click_timer); + evtimer_add(&c->click_timer, &tv); + } } + +have_event: if (type == NOTYPE) return (KEYC_UNKNOWN); @@ -546,6 +586,62 @@ server_client_check_mouse(struct client *c) break; } break; + case DOUBLE: + switch (MOUSE_BUTTONS(b)) { + case 0: + if (where == PANE) + key = KEYC_DOUBLECLICK1_PANE; + if (where == STATUS) + key = KEYC_DOUBLECLICK1_STATUS; + if (where == BORDER) + key = KEYC_DOUBLECLICK1_BORDER; + break; + case 1: + if (where == PANE) + key = KEYC_DOUBLECLICK2_PANE; + if (where == STATUS) + key = KEYC_DOUBLECLICK2_STATUS; + if (where == BORDER) + key = KEYC_DOUBLECLICK2_BORDER; + break; + case 2: + if (where == PANE) + key = KEYC_DOUBLECLICK3_PANE; + if (where == STATUS) + key = KEYC_DOUBLECLICK3_STATUS; + if (where == BORDER) + key = KEYC_DOUBLECLICK3_BORDER; + break; + } + break; + case TRIPLE: + switch (MOUSE_BUTTONS(b)) { + case 0: + if (where == PANE) + key = KEYC_TRIPLECLICK1_PANE; + if (where == STATUS) + key = KEYC_TRIPLECLICK1_STATUS; + if (where == BORDER) + key = KEYC_TRIPLECLICK1_BORDER; + break; + case 1: + if (where == PANE) + key = KEYC_TRIPLECLICK2_PANE; + if (where == STATUS) + key = KEYC_TRIPLECLICK2_STATUS; + if (where == BORDER) + key = KEYC_TRIPLECLICK2_BORDER; + break; + case 2: + if (where == PANE) + key = KEYC_TRIPLECLICK3_PANE; + if (where == STATUS) + key = KEYC_TRIPLECLICK3_STATUS; + if (where == BORDER) + key = KEYC_TRIPLECLICK3_BORDER; + break; + } + break; } if (key == KEYC_UNKNOWN) return (KEYC_UNKNOWN); @@ -945,6 +1041,15 @@ server_client_repeat_timer(__unused int fd, __unused short events, void *data) } } +/* Double-click callback. */ +static void +server_client_click_timer(__unused int fd, __unused short events, void *data) +{ + struct client *c = data; + + c->flags &= ~(CLIENT_DOUBLECLICK|CLIENT_TRIPLECLICK); +} + /* Check if client should be exited. */ static void server_client_check_exit(struct client *c) diff --git a/tmux.1 b/tmux.1 index ec6b02cd..f375a215 100644 --- a/tmux.1 +++ b/tmux.1 @@ -3334,10 +3334,12 @@ for a pane border or for the status line). The following mouse events are available: .Bl -column "MouseDown1" "MouseDrag1" "WheelDown" -offset indent +.It Li "WheelUp" Ta "WheelDown" Ta "" .It Li "MouseDown1" Ta "MouseUp1" Ta "MouseDrag1" Ta "MouseDragEnd1" .It Li "MouseDown2" Ta "MouseUp2" Ta "MouseDrag2" Ta "MouseDragEnd2" .It Li "MouseDown3" Ta "MouseUp3" Ta "MouseDrag3" Ta "MouseDragEnd3" -.It Li "WheelUp" Ta "WheelDown" Ta "" Ta "" +.It Li "DoubleClick1" Ta "DoubleClick2" Ta "DoubleClick3" Ta "WheelUp" +.It Li "TripleClick1" Ta "TripleClick2" Ta "TripleClick3" Ta "WheelDown" .El .Pp Each should be suffixed with a location, for example diff --git a/tmux.h b/tmux.h index 2a020c33..f18276c5 100644 --- a/tmux.h +++ b/tmux.h @@ -105,6 +105,9 @@ struct tmuxproc; #define KEYC_IS_MOUSE(key) (((key) & KEYC_MASK_KEY) >= KEYC_MOUSE && \ ((key) & KEYC_MASK_KEY) < KEYC_BSPACE) +/* Multiple click timeout. */ +#define KEYC_CLICK_TIMEOUT 300 + /* Mouse key codes. */ #define KEYC_MOUSE_KEY(name) \ KEYC_ ## name ## _PANE, \ @@ -143,6 +146,12 @@ enum { KEYC_MOUSE_KEY(MOUSEDRAGEND3), KEYC_MOUSE_KEY(WHEELUP), KEYC_MOUSE_KEY(WHEELDOWN), + KEYC_MOUSE_KEY(DOUBLECLICK1), + KEYC_MOUSE_KEY(DOUBLECLICK2), + KEYC_MOUSE_KEY(DOUBLECLICK3), + KEYC_MOUSE_KEY(TRIPLECLICK1), + KEYC_MOUSE_KEY(TRIPLECLICK2), + KEYC_MOUSE_KEY(TRIPLECLICK3), /* Backspace key. */ KEYC_BSPACE, @@ -1216,6 +1225,9 @@ struct client { struct event repeat_timer; + struct event click_timer; + u_int click_button; + struct event status_timer; struct screen status; @@ -1239,6 +1251,8 @@ struct client { #define CLIENT_256COLOURS 0x20000 #define CLIENT_IDENTIFIED 0x40000 #define CLIENT_STATUSFORCE 0x80000 +#define CLIENT_DOUBLECLICK 0x100000 +#define CLIENT_TRIPLECLICK 0x200000 int flags; struct key_table *keytable; diff --git a/window-copy.c b/window-copy.c index d5140fc7..5c1f5f81 100644 --- a/window-copy.c +++ b/window-copy.c @@ -91,6 +91,7 @@ void window_copy_cursor_previous_word(struct window_pane *, const char *); void window_copy_scroll_up(struct window_pane *, u_int); void window_copy_scroll_down(struct window_pane *, u_int); void window_copy_rectangle_toggle(struct window_pane *); +void window_copy_move_mouse(struct mouse_event *); void window_copy_drag_update(struct client *, struct mouse_event *); void window_copy_drag_release(struct client *, struct mouse_event *); @@ -479,6 +480,9 @@ window_copy_command(struct window_pane *wp, struct client *c, struct session *s, return; command = args->argv[0]; + if (m != NULL && m->valid) + window_copy_move_mouse(m); + if (args->argc == 1) { if (strcmp(command, "append-selection") == 0) { if (s != NULL) @@ -731,9 +735,17 @@ window_copy_command(struct window_pane *wp, struct client *c, struct session *s, window_copy_cursor_end_of_line(wp); window_copy_redraw_screen(wp); } - if (strcmp(command, "start-of-line") == 0) { - window_copy_cursor_start_of_line(wp); + if (strcmp(command, "select-word") == 0) { + sn->sel.lineflag = LINE_SEL_LEFT_RIGHT; + data->rectflag = 0; + ws = options_get_string(s->options, "word-separators"); + window_copy_cursor_previous_word(wp, ws); + window_copy_start_selection(wp); + window_copy_cursor_next_word_end(wp, ws); + window_copy_redraw_screen(wp); } + if (strcmp(command, "start-of-line") == 0) + window_copy_cursor_start_of_line(wp); if (strcmp(command, "top-line") == 0) { data->cx = 0; data->cy = 0; @@ -2105,6 +2117,22 @@ window_copy_rectangle_toggle(struct window_pane *wp) window_copy_redraw_screen(wp); } +void +window_copy_move_mouse(struct mouse_event *m) +{ + struct window_pane *wp; + u_int x, y; + + wp = cmd_mouse_pane(m, NULL, NULL); + if (wp == NULL || wp->mode != &window_copy_mode) + return; + + if (cmd_mouse_at(wp, m, &x, &y, 1) != 0) + return; + + window_copy_update_cursor(wp, x, y); +} + void window_copy_start_drag(struct client *c, struct mouse_event *m) { -- cgit From e45401846f0a423bb90ebd3943041a28b2657631 Mon Sep 17 00:00:00 2001 From: nicm Date: Tue, 11 Oct 2016 13:21:59 +0000 Subject: Add static in window-*.c and move some internal functions out of tmux.h. --- arguments.c | 27 +----- cmd-queue.c | 3 +- grid.c | 5 +- names.c | 8 +- screen.c | 4 +- server-fn.c | 3 +- session.c | 10 ++- tmux.c | 7 +- tmux.h | 21 ----- tty.c | 15 +++- window-choose.c | 93 ++++++++++---------- window-copy.c | 260 +++++++++++++++++++++++++++++--------------------------- window.c | 18 ++-- 13 files changed, 235 insertions(+), 239 deletions(-) diff --git a/arguments.c b/arguments.c index 3dbfbfb7..2aedd7ce 100644 --- a/arguments.c +++ b/arguments.c @@ -35,6 +35,7 @@ struct args_entry { RB_ENTRY(args_entry) entry; }; +static void args_set(struct args *, u_char, const char *); static struct args_entry *args_find(struct args *, u_char); static int args_cmp(struct args_entry *, struct args_entry *); @@ -47,30 +48,6 @@ args_cmp(struct args_entry *a1, struct args_entry *a2) return (a1->flag - a2->flag); } -/* Create an arguments set with no flags. */ -struct args * -args_create(int argc, ...) -{ - struct args *args; - va_list ap; - int i; - - args = xcalloc(1, sizeof *args); - - args->argc = argc; - if (argc == 0) - args->argv = NULL; - else - args->argv = xcalloc(argc, sizeof *args->argv); - - va_start(ap, argc); - for (i = 0; i < argc; i++) - args->argv[i] = xstrdup(va_arg(ap, char *)); - va_end(ap); - - return (args); -} - /* Find a flag in the arguments tree. */ static struct args_entry * args_find(struct args *args, u_char ch) @@ -206,7 +183,7 @@ args_has(struct args *args, u_char ch) } /* Set argument value in the arguments tree. */ -void +static void args_set(struct args *args, u_char ch, const char *value) { struct args_entry *entry; diff --git a/cmd-queue.c b/cmd-queue.c index e9073c92..5a81f88e 100644 --- a/cmd-queue.c +++ b/cmd-queue.c @@ -26,6 +26,7 @@ #include "tmux.h" static enum cmd_retval cmdq_continue_one(struct cmd_q *); +static void cmdq_flush(struct cmd_q *); /* Create new command queue. */ struct cmd_q * @@ -319,7 +320,7 @@ out: } /* Flush command queue. */ -void +static void cmdq_flush(struct cmd_q *cmdq) { struct cmd_q_item *item, *item1; diff --git a/grid.c b/grid.c index 73097983..35de2aef 100644 --- a/grid.c +++ b/grid.c @@ -43,6 +43,8 @@ const struct grid_cell_entry grid_default_entry = { 0, { .data = { 0, 8, 8, ' ' } } }; +static void grid_expand_line(struct grid *, u_int, u_int); + static void grid_reflow_copy(struct grid_line *, u_int, struct grid_line *, u_int, u_int); static void grid_reflow_join(struct grid *, u_int *, struct grid_line *, @@ -50,6 +52,7 @@ static void grid_reflow_join(struct grid *, u_int *, struct grid_line *, static void grid_reflow_split(struct grid *, u_int *, struct grid_line *, u_int, u_int); static void grid_reflow_move(struct grid *, u_int *, struct grid_line *); + static size_t grid_string_cells_fg(const struct grid_cell *, int *); static size_t grid_string_cells_bg(const struct grid_cell *, int *); static void grid_string_cells_code(const struct grid_cell *, @@ -243,7 +246,7 @@ grid_scroll_history_region(struct grid *gd, u_int upper, u_int lower) } /* Expand line to fit to cell. */ -void +static void grid_expand_line(struct grid *gd, u_int py, u_int sx) { struct grid_line *gl; diff --git a/names.c b/names.c index b83a0cb7..6a368825 100644 --- a/names.c +++ b/names.c @@ -25,8 +25,10 @@ #include "tmux.h" -static void name_time_callback(int, short, void *); -static int name_time_expired(struct window *, struct timeval *); +static void name_time_callback(int, short, void *); +static int name_time_expired(struct window *, struct timeval *); + +static char *format_window_name(struct window *); static void name_time_callback(__unused int fd, __unused short events, void *arg) @@ -115,7 +117,7 @@ default_window_name(struct window *w) return (s); } -char * +static char * format_window_name(struct window *w) { struct format_tree *ft; diff --git a/screen.c b/screen.c index b0ba216a..7bde6f9b 100644 --- a/screen.c +++ b/screen.c @@ -27,6 +27,8 @@ static void screen_resize_x(struct screen *, u_int); static void screen_resize_y(struct screen *, u_int); +static void screen_reflow(struct screen *, u_int); + /* Create a new screen. */ void screen_init(struct screen *s, u_int sx, u_int sy, u_int hlimit) @@ -370,7 +372,7 @@ screen_check_selection(struct screen *s, u_int px, u_int py) } /* Reflow wrapped lines. */ -void +static void screen_reflow(struct screen *s, u_int new_x) { struct grid *old = s->grid; diff --git a/server-fn.c b/server-fn.c index bcb05ddb..72750321 100644 --- a/server-fn.c +++ b/server-fn.c @@ -30,6 +30,7 @@ static struct session *server_next_session(struct session *); static void server_callback_identify(int, short, void *); +static void server_destroy_session_group(struct session *); void server_fill_environ(struct session *s, struct environ *env) @@ -339,7 +340,7 @@ server_destroy_pane(struct window_pane *wp, int hooks) server_redraw_window(w); } -void +static void server_destroy_session_group(struct session *s) { struct session_group *sg; diff --git a/session.c b/session.c index e2114023..dcd37bb1 100644 --- a/session.c +++ b/session.c @@ -38,6 +38,10 @@ static void session_lock_timer(int, short, void *); static struct winlink *session_next_alert(struct winlink *); static struct winlink *session_previous_alert(struct winlink *); +static void session_group_remove(struct session *); +static u_int session_group_count(struct session_group *); +static void session_group_synchronize1(struct session *, struct session *); + RB_GENERATE(sessions, session, entry, session_cmp); int @@ -582,7 +586,7 @@ session_group_add(struct session *target, struct session *s) } /* Remove a session from its group and destroy the group if empty. */ -void +static void session_group_remove(struct session *s) { struct session_group *sg; @@ -599,7 +603,7 @@ session_group_remove(struct session *s) } /* Count number of sessions in session group. */ -u_int +static u_int session_group_count(struct session_group *sg) { struct session *s; @@ -650,7 +654,7 @@ session_group_synchronize_from(struct session *target) * winlinks then recreating them, then updating the current window, last window * stack and alerts. */ -void +static void session_group_synchronize1(struct session *target, struct session *s) { struct winlinks old_windows, *ww; diff --git a/tmux.c b/tmux.c index 413fea3a..dbd91e2b 100644 --- a/tmux.c +++ b/tmux.c @@ -47,6 +47,9 @@ const char *socket_path; static __dead void usage(void); static char *make_label(const char *); +static const char *getshell(void); +static int checkshell(const char *); + static __dead void usage(void) { @@ -57,7 +60,7 @@ usage(void) exit(1); } -const char * +static const char * getshell(void) { struct passwd *pw; @@ -74,7 +77,7 @@ getshell(void) return (_PATH_BSHELL); } -int +static int checkshell(const char *shell) { if (shell == NULL || *shell == '\0' || *shell != '/') diff --git a/tmux.h b/tmux.h index f18276c5..e2c1514c 100644 --- a/tmux.h +++ b/tmux.h @@ -1520,8 +1520,6 @@ extern struct options *global_w_options; extern struct environ *global_environ; extern struct timeval start_time; extern const char *socket_path; -const char *getshell(void); -int checkshell(const char *); int areshell(const char *); void setblocking(int, int); const char *find_home(void); @@ -1681,14 +1679,11 @@ void environ_log(struct environ *, const char *); /* tty.c */ void tty_create_log(void); -void tty_init_termios(int, struct termios *, struct bufferevent *); void tty_raw(struct tty *, const char *); void tty_attributes(struct tty *, const struct grid_cell *, const struct window_pane *); void tty_reset(struct tty *); -void tty_region_pane(struct tty *, const struct tty_ctx *, u_int, u_int); void tty_region(struct tty *, u_int, u_int); -void tty_cursor_pane(struct tty *, const struct tty_ctx *, u_int, u_int); void tty_cursor(struct tty *, u_int, u_int); void tty_putcode(struct tty *, enum tty_code_code); void tty_putcode1(struct tty *, enum tty_code_code, int); @@ -1706,7 +1701,6 @@ void tty_start_tty(struct tty *); void tty_stop_tty(struct tty *); void tty_set_title(struct tty *, const char *); void tty_update_mode(struct tty *, int, struct screen *); -void tty_force_cursor_colour(struct tty *, const char *); void tty_draw_pane(struct tty *, const struct window_pane *, u_int, u_int, u_int); void tty_draw_line(struct tty *, const struct window_pane *, struct screen *, @@ -1763,12 +1757,10 @@ void tty_keys_free(struct tty *); key_code tty_keys_next(struct tty *); /* arguments.c */ -struct args *args_create(int, ...); struct args *args_parse(const char *, int, char **); void args_free(struct args *); char *args_print(struct args *); int args_has(struct args *, u_char); -void args_set(struct args *, u_char, const char *); const char *args_get(struct args *, u_char); long long args_strtonum(struct args *, u_char, long long, long long, char **); @@ -1832,7 +1824,6 @@ void cmdq_run(struct cmd_q *, struct cmd_list *, void cmdq_append(struct cmd_q *, struct cmd_list *, struct mouse_event *); int cmdq_continue(struct cmd_q *); -void cmdq_flush(struct cmd_q *); /* cmd-string.c */ int cmd_string_parse(const char *, struct cmd_list **, const char *, @@ -1916,7 +1907,6 @@ int server_link_window(struct session *, struct winlink *, struct session *, int, int, int, char **); void server_unlink_window(struct session *, struct winlink *); void server_destroy_pane(struct window_pane *, int); -void server_destroy_session_group(struct session *); void server_destroy_session(struct session *); void server_check_unattached(void); void server_set_identify(struct client *); @@ -1982,7 +1972,6 @@ void grid_collect_history(struct grid *); void grid_scroll_history(struct grid *); void grid_scroll_history_region(struct grid *, u_int, u_int); void grid_clear_history(struct grid *); -void grid_expand_line(struct grid *, u_int, u_int); const struct grid_line *grid_peek_line(struct grid *, u_int); void grid_get_cell(struct grid *, u_int, u_int, struct grid_cell *); void grid_set_cell(struct grid *, u_int, u_int, const struct grid_cell *); @@ -2078,7 +2067,6 @@ void screen_set_selection(struct screen *, u_int, u_int, u_int, u_int, u_int, struct grid_cell *); void screen_clear_selection(struct screen *); int screen_check_selection(struct screen *, u_int, u_int); -void screen_reflow(struct screen *, u_int); /* window.c */ extern struct windows windows; @@ -2092,7 +2080,6 @@ RB_PROTOTYPE(window_pane_tree, window_pane, tree_entry, window_pane_cmp); struct winlink *winlink_find_by_index(struct winlinks *, int); struct winlink *winlink_find_by_window(struct winlinks *, struct window *); struct winlink *winlink_find_by_window_id(struct winlinks *, u_int); -int winlink_next_index(struct winlinks *, int); u_int winlink_count(struct winlinks *); struct winlink *winlink_add(struct winlinks *, int); void winlink_set_window(struct winlink *, struct window *); @@ -2136,8 +2123,6 @@ u_int window_count_panes(struct window *); void window_destroy_panes(struct window *); struct window_pane *window_pane_find_by_id_str(const char *); struct window_pane *window_pane_find_by_id(u_int); -struct window_pane *window_pane_create(struct window *, u_int, u_int, u_int); -void window_pane_destroy(struct window_pane *); int window_pane_spawn(struct window_pane *, int, char **, const char *, const char *, const char *, struct environ *, struct termios *, char **); @@ -2223,7 +2208,6 @@ void window_choose_ready(struct window_pane *, u_int, void (*)(struct window_choose_data *)); struct window_choose_data *window_choose_data_create (int, struct client *, struct session *); -void window_choose_data_free(struct window_choose_data *); void window_choose_data_run(struct window_choose_data *); struct window_choose_data *window_choose_add_window(struct window_pane *, struct client *, struct session *, struct winlink *, @@ -2232,13 +2216,11 @@ struct window_choose_data *window_choose_add_session(struct window_pane *, struct client *, struct session *, const char *, const char *, u_int); void window_choose_expand_all(struct window_pane *); -void window_choose_collapse_all(struct window_pane *); void window_choose_set_current(struct window_pane *, u_int); /* names.c */ void check_window_name(struct window *); char *default_window_name(struct window *); -char *format_window_name(struct window *); char *parse_window_name(const char *); /* signal.c */ @@ -2295,11 +2277,8 @@ int session_set_current(struct session *, struct winlink *); struct session_group *session_group_find(struct session *); u_int session_group_index(struct session_group *); void session_group_add(struct session *, struct session *); -void session_group_remove(struct session *); -u_int session_group_count(struct session_group *); void session_group_synchronize_to(struct session *); void session_group_synchronize_from(struct session *); -void session_group_synchronize1(struct session *, struct session *); void session_renumber_windows(struct session *); /* utf8.c */ diff --git a/tty.c b/tty.c index f9b5c89d..d8702a2f 100644 --- a/tty.c +++ b/tty.c @@ -33,6 +33,8 @@ static int tty_log_fd = -1; +static void tty_init_termios(int, struct termios *, struct bufferevent *); + static void tty_read_callback(struct bufferevent *, void *); static void tty_error_callback(struct bufferevent *, short, void *); @@ -40,6 +42,9 @@ static int tty_client_ready(struct client *, struct window_pane *); static void tty_set_italics(struct tty *); static int tty_try_colour(struct tty *, int, const char *); +static void tty_force_cursor_colour(struct tty *, const char *); +static void tty_cursor_pane(struct tty *, const struct tty_ctx *, u_int, + u_int); static void tty_colours(struct tty *, const struct grid_cell *); static void tty_check_fg(struct tty *, struct grid_cell *); @@ -47,6 +52,8 @@ static void tty_check_bg(struct tty *, struct grid_cell *); static void tty_colours_fg(struct tty *, const struct grid_cell *); static void tty_colours_bg(struct tty *, const struct grid_cell *); +static void tty_region_pane(struct tty *, const struct tty_ctx *, u_int, + u_int); static int tty_large_region(struct tty *, const struct tty_ctx *); static int tty_fake_bce(const struct tty *, const struct window_pane *); static void tty_redraw_region(struct tty *, const struct tty_ctx *); @@ -189,7 +196,7 @@ tty_error_callback(__unused struct bufferevent *bufev, __unused short what, { } -void +static void tty_init_termios(int fd, struct termios *orig_tio, struct bufferevent *bufev) { struct termios tio; @@ -478,7 +485,7 @@ tty_set_title(struct tty *tty, const char *title) tty_putcode(tty, TTYC_FSL); } -void +static void tty_force_cursor_colour(struct tty *tty, const char *ccolour) { if (*ccolour == '\0') @@ -1182,7 +1189,7 @@ tty_reset(struct tty *tty) } /* Set region inside pane. */ -void +static void tty_region_pane(struct tty *tty, const struct tty_ctx *ctx, u_int rupper, u_int rlower) { @@ -1215,7 +1222,7 @@ tty_region(struct tty *tty, u_int rupper, u_int rlower) } /* Move cursor inside pane. */ -void +static void tty_cursor_pane(struct tty *tty, const struct tty_ctx *ctx, u_int cx, u_int cy) { tty_cursor(tty, ctx->xoff + cx, ctx->yoff + cy); diff --git a/window-choose.c b/window-choose.c index 19677c86..02c10257 100644 --- a/window-choose.c +++ b/window-choose.c @@ -24,27 +24,32 @@ #include "tmux.h" -struct screen *window_choose_init(struct window_pane *); -void window_choose_free(struct window_pane *); -void window_choose_resize(struct window_pane *, u_int, u_int); -void window_choose_key(struct window_pane *, struct client *, - struct session *, key_code, struct mouse_event *); +static struct screen *window_choose_init(struct window_pane *); +static void window_choose_free(struct window_pane *); +static void window_choose_resize(struct window_pane *, u_int, u_int); +static void window_choose_key(struct window_pane *, struct client *, + struct session *, key_code, struct mouse_event *); -void window_choose_default_callback(struct window_choose_data *); -struct window_choose_mode_item *window_choose_get_item(struct window_pane *, - key_code, struct mouse_event *); +static void window_choose_default_callback(struct window_choose_data *); +static struct window_choose_mode_item *window_choose_get_item( + struct window_pane *, key_code, struct mouse_event *); -void window_choose_fire_callback(struct window_pane *, - struct window_choose_data *); -void window_choose_redraw_screen(struct window_pane *); -void window_choose_write_line(struct window_pane *, - struct screen_write_ctx *, u_int); +static void window_choose_fire_callback(struct window_pane *, + struct window_choose_data *); +static void window_choose_redraw_screen(struct window_pane *); +static void window_choose_write_line(struct window_pane *, + struct screen_write_ctx *, u_int); -void window_choose_scroll_up(struct window_pane *); -void window_choose_scroll_down(struct window_pane *); +static void window_choose_scroll_up(struct window_pane *); +static void window_choose_scroll_down(struct window_pane *); -void window_choose_collapse(struct window_pane *, struct session *, u_int); -void window_choose_expand(struct window_pane *, struct session *, u_int); +static void window_choose_collapse(struct window_pane *, struct session *, + u_int); +static void window_choose_expand(struct window_pane *, struct session *, + u_int); +static void window_choose_collapse_all(struct window_pane *); + +static void window_choose_data_free(struct window_choose_data *); enum window_choose_input_type { WINDOW_CHOOSE_NORMAL = -1, @@ -86,12 +91,14 @@ struct window_choose_mode_data { void (*callbackfn)(struct window_choose_data *); }; -void window_choose_free1(struct window_choose_mode_data *); -int window_choose_key_index(struct window_choose_mode_data *, u_int); -int window_choose_index_key(struct window_choose_mode_data *, key_code); -void window_choose_prompt_input(enum window_choose_input_type, - const char *, struct window_pane *, key_code); -void window_choose_reset_top(struct window_pane *, u_int); +static void window_choose_free1(struct window_choose_mode_data *); +static int window_choose_key_index(struct window_choose_mode_data *, + u_int); +static int window_choose_index_key(struct window_choose_mode_data *, + key_code); +static void window_choose_prompt_input(enum window_choose_input_type, + const char *, struct window_pane *, key_code); +static void window_choose_reset_top(struct window_pane *, u_int); void window_choose_add(struct window_pane *wp, struct window_choose_data *wcd) @@ -122,7 +129,7 @@ window_choose_set_current(struct window_pane *wp, u_int cur) window_choose_reset_top(wp, screen_size_y(s)); } -void +static void window_choose_reset_top(struct window_pane *wp, u_int sy) { struct window_choose_mode_data *data = wp->modedata; @@ -156,7 +163,7 @@ window_choose_ready(struct window_pane *wp, u_int cur, window_choose_collapse_all(wp); } -struct screen * +static struct screen * window_choose_init(struct window_pane *wp) { struct window_choose_mode_data *data; @@ -218,7 +225,7 @@ window_choose_data_create(int type, struct client *c, struct session *s) return (wcd); } -void +static void window_choose_data_free(struct window_choose_data *wcd) { server_client_unref(wcd->start_client); @@ -260,7 +267,7 @@ window_choose_data_run(struct window_choose_data *cdata) cmd_list_free(cmdlist); } -void +static void window_choose_default_callback(struct window_choose_data *wcd) { if (wcd == NULL) @@ -271,14 +278,14 @@ window_choose_default_callback(struct window_choose_data *wcd) window_choose_data_run(wcd); } -void +static void window_choose_free(struct window_pane *wp) { if (wp->modedata != NULL) window_choose_free1(wp->modedata); } -void +static void window_choose_free1(struct window_choose_mode_data *data) { struct window_choose_mode_item *item; @@ -301,7 +308,7 @@ window_choose_free1(struct window_choose_mode_data *data) free(data); } -void +static void window_choose_resize(struct window_pane *wp, u_int sx, u_int sy) { struct window_choose_mode_data *data = wp->modedata; @@ -312,7 +319,7 @@ window_choose_resize(struct window_pane *wp, u_int sx, u_int sy) window_choose_redraw_screen(wp); } -void +static void window_choose_fire_callback(struct window_pane *wp, struct window_choose_data *wcd) { @@ -326,7 +333,7 @@ window_choose_fire_callback(struct window_pane *wp, window_choose_free1(data); } -void +static void window_choose_prompt_input(enum window_choose_input_type input_type, const char *prompt, struct window_pane *wp, key_code key) { @@ -344,7 +351,7 @@ window_choose_prompt_input(enum window_choose_input_type input_type, window_choose_redraw_screen(wp); } -void +static void window_choose_collapse(struct window_pane *wp, struct session *s, u_int pos) { struct window_choose_mode_data *data = wp->modedata; @@ -395,7 +402,7 @@ window_choose_collapse(struct window_pane *wp, struct session *s, u_int pos) } } -void +static void window_choose_collapse_all(struct window_pane *wp) { struct window_choose_mode_data *data = wp->modedata; @@ -446,7 +453,7 @@ window_choose_expand_all(struct window_pane *wp) window_choose_reset_top(wp, screen_size_y(scr)); } -void +static void window_choose_expand(struct window_pane *wp, struct session *s, u_int pos) { struct window_choose_mode_data *data = wp->modedata; @@ -518,7 +525,7 @@ window_choose_expand(struct window_pane *wp, struct session *s, u_int pos) } } -struct window_choose_mode_item * +static struct window_choose_mode_item * window_choose_get_item(struct window_pane *wp, key_code key, struct mouse_event *m) { @@ -537,7 +544,7 @@ window_choose_get_item(struct window_pane *wp, key_code key, return (&data->list[idx]); } -void +static void window_choose_key(struct window_pane *wp, __unused struct client *c, __unused struct session *sess, key_code key, struct mouse_event *m) { @@ -769,7 +776,7 @@ window_choose_key(struct window_pane *wp, __unused struct client *c, } } -void +static void window_choose_write_line(struct window_pane *wp, struct screen_write_ctx *ctx, u_int py) { @@ -827,7 +834,7 @@ window_choose_write_line(struct window_pane *wp, struct screen_write_ctx *ctx, } -int +static int window_choose_key_index(struct window_choose_mode_data *data, u_int idx) { static const char keys[] = "0123456789" @@ -846,7 +853,7 @@ window_choose_key_index(struct window_choose_mode_data *data, u_int idx) return (-1); } -int +static int window_choose_index_key(struct window_choose_mode_data *data, key_code key) { static const char keys[] = "0123456789" @@ -867,7 +874,7 @@ window_choose_index_key(struct window_choose_mode_data *data, key_code key) return (-1); } -void +static void window_choose_redraw_screen(struct window_pane *wp) { struct window_choose_mode_data *data = wp->modedata; @@ -881,7 +888,7 @@ window_choose_redraw_screen(struct window_pane *wp) screen_write_stop(&ctx); } -void +static void window_choose_scroll_up(struct window_pane *wp) { struct window_choose_mode_data *data = wp->modedata; @@ -900,7 +907,7 @@ window_choose_scroll_up(struct window_pane *wp) screen_write_stop(&ctx); } -void +static void window_choose_scroll_down(struct window_pane *wp) { struct window_choose_mode_data *data = wp->modedata; diff --git a/window-copy.c b/window-copy.c index 5c1f5f81..d282e25e 100644 --- a/window-copy.c +++ b/window-copy.c @@ -24,76 +24,82 @@ #include "tmux.h" -const char *window_copy_key_table(struct window_pane *); -void window_copy_command(struct window_pane *, struct client *, - struct session *, struct args *, struct mouse_event *); -struct screen *window_copy_init(struct window_pane *); -void window_copy_free(struct window_pane *); -void window_copy_pagedown(struct window_pane *, int); -void window_copy_next_paragraph(struct window_pane *); -void window_copy_previous_paragraph(struct window_pane *); -void window_copy_resize(struct window_pane *, u_int, u_int); - -void window_copy_redraw_selection(struct window_pane *, u_int); -void window_copy_redraw_lines(struct window_pane *, u_int, u_int); -void window_copy_redraw_screen(struct window_pane *); -void window_copy_write_line(struct window_pane *, struct screen_write_ctx *, - u_int); -void window_copy_write_lines(struct window_pane *, - struct screen_write_ctx *, u_int, u_int); - -void window_copy_scroll_to(struct window_pane *, u_int, u_int); -int window_copy_search_compare(struct grid *, u_int, u_int, struct grid *, - u_int, int); -int window_copy_search_lr(struct grid *, struct grid *, u_int *, u_int, - u_int, u_int, int); -int window_copy_search_rl(struct grid *, struct grid *, u_int *, u_int, - u_int, u_int, int); -void window_copy_move_left(struct screen *, u_int *, u_int *); -void window_copy_move_right(struct screen *, u_int *, u_int *); -int window_copy_is_lowercase(const char *); -void window_copy_search_jump(struct window_pane *, struct grid *, - struct grid *, u_int, u_int, u_int, int, int, int); -void window_copy_search(struct window_pane *, const char *, int, int); -void window_copy_search_up(struct window_pane *, const char *, int); -void window_copy_search_down(struct window_pane *, const char *, int); -void window_copy_goto_line(struct window_pane *, const char *); -void window_copy_update_cursor(struct window_pane *, u_int, u_int); -void window_copy_start_selection(struct window_pane *); -int window_copy_update_selection(struct window_pane *, int); -void *window_copy_get_selection(struct window_pane *, size_t *); -void window_copy_copy_buffer(struct window_pane *, const char *, void *, - size_t); -void window_copy_copy_pipe(struct window_pane *, struct session *, - const char *, const char *); -void window_copy_copy_selection(struct window_pane *, const char *); -void window_copy_append_selection(struct window_pane *, const char *); -void window_copy_clear_selection(struct window_pane *); -void window_copy_copy_line(struct window_pane *, char **, size_t *, u_int, - u_int, u_int); -int window_copy_in_set(struct window_pane *, u_int, u_int, const char *); -u_int window_copy_find_length(struct window_pane *, u_int); -void window_copy_cursor_start_of_line(struct window_pane *); -void window_copy_cursor_back_to_indentation(struct window_pane *); -void window_copy_cursor_end_of_line(struct window_pane *); -void window_copy_other_end(struct window_pane *); -void window_copy_cursor_left(struct window_pane *); -void window_copy_cursor_right(struct window_pane *); -void window_copy_cursor_up(struct window_pane *, int); -void window_copy_cursor_down(struct window_pane *, int); -void window_copy_cursor_jump(struct window_pane *); -void window_copy_cursor_jump_back(struct window_pane *); -void window_copy_cursor_jump_to(struct window_pane *, int); -void window_copy_cursor_jump_to_back(struct window_pane *, int); -void window_copy_cursor_next_word(struct window_pane *, const char *); -void window_copy_cursor_next_word_end(struct window_pane *, const char *); -void window_copy_cursor_previous_word(struct window_pane *, const char *); -void window_copy_scroll_up(struct window_pane *, u_int); -void window_copy_scroll_down(struct window_pane *, u_int); -void window_copy_rectangle_toggle(struct window_pane *); -void window_copy_move_mouse(struct mouse_event *); -void window_copy_drag_update(struct client *, struct mouse_event *); -void window_copy_drag_release(struct client *, struct mouse_event *); +static const char *window_copy_key_table(struct window_pane *); +static void window_copy_command(struct window_pane *, struct client *, + struct session *, struct args *, struct mouse_event *); +static struct screen *window_copy_init(struct window_pane *); +static void window_copy_free(struct window_pane *); +static void window_copy_pagedown(struct window_pane *, int); +static void window_copy_next_paragraph(struct window_pane *); +static void window_copy_previous_paragraph(struct window_pane *); +static void window_copy_resize(struct window_pane *, u_int, u_int); + +static void window_copy_redraw_selection(struct window_pane *, u_int); +static void window_copy_redraw_lines(struct window_pane *, u_int, u_int); +static void window_copy_redraw_screen(struct window_pane *); +static void window_copy_write_line(struct window_pane *, + struct screen_write_ctx *, u_int); +static void window_copy_write_lines(struct window_pane *, + struct screen_write_ctx *, u_int, u_int); + +static void window_copy_scroll_to(struct window_pane *, u_int, u_int); +static int window_copy_search_compare(struct grid *, u_int, u_int, + struct grid *, u_int, int); +static int window_copy_search_lr(struct grid *, struct grid *, u_int *, + u_int, u_int, u_int, int); +static int window_copy_search_rl(struct grid *, struct grid *, u_int *, + u_int, u_int, u_int, int); +static void window_copy_move_left(struct screen *, u_int *, u_int *); +static void window_copy_move_right(struct screen *, u_int *, u_int *); +static int window_copy_is_lowercase(const char *); +static void window_copy_search_jump(struct window_pane *, struct grid *, + struct grid *, u_int, u_int, u_int, int, int, int); +static void window_copy_search(struct window_pane *, const char *, int, + int); +static void window_copy_search_up(struct window_pane *, const char *, int); +static void window_copy_search_down(struct window_pane *, const char *, + int); +static void window_copy_goto_line(struct window_pane *, const char *); +static void window_copy_update_cursor(struct window_pane *, u_int, u_int); +static void window_copy_start_selection(struct window_pane *); +static int window_copy_update_selection(struct window_pane *, int); +static void *window_copy_get_selection(struct window_pane *, size_t *); +static void window_copy_copy_buffer(struct window_pane *, const char *, + void *, size_t); +static void window_copy_copy_pipe(struct window_pane *, struct session *, + const char *, const char *); +static void window_copy_copy_selection(struct window_pane *, const char *); +static void window_copy_append_selection(struct window_pane *, + const char *); +static void window_copy_clear_selection(struct window_pane *); +static void window_copy_copy_line(struct window_pane *, char **, size_t *, + u_int, u_int, u_int); +static int window_copy_in_set(struct window_pane *, u_int, u_int, + const char *); +static u_int window_copy_find_length(struct window_pane *, u_int); +static void window_copy_cursor_start_of_line(struct window_pane *); +static void window_copy_cursor_back_to_indentation(struct window_pane *); +static void window_copy_cursor_end_of_line(struct window_pane *); +static void window_copy_other_end(struct window_pane *); +static void window_copy_cursor_left(struct window_pane *); +static void window_copy_cursor_right(struct window_pane *); +static void window_copy_cursor_up(struct window_pane *, int); +static void window_copy_cursor_down(struct window_pane *, int); +static void window_copy_cursor_jump(struct window_pane *); +static void window_copy_cursor_jump_back(struct window_pane *); +static void window_copy_cursor_jump_to(struct window_pane *, int); +static void window_copy_cursor_jump_to_back(struct window_pane *, int); +static void window_copy_cursor_next_word(struct window_pane *, + const char *); +static void window_copy_cursor_next_word_end(struct window_pane *, + const char *); +static void window_copy_cursor_previous_word(struct window_pane *, + const char *); +static void window_copy_scroll_up(struct window_pane *, u_int); +static void window_copy_scroll_down(struct window_pane *, u_int); +static void window_copy_rectangle_toggle(struct window_pane *); +static void window_copy_move_mouse(struct mouse_event *); +static void window_copy_drag_update(struct client *, struct mouse_event *); const struct window_mode window_copy_mode = { .init = window_copy_init, @@ -156,7 +162,7 @@ struct window_copy_mode_data { char jumpchar; }; -struct screen * +static struct screen * window_copy_init(struct window_pane *wp) { struct window_copy_mode_data *data; @@ -229,7 +235,7 @@ window_copy_init_for_output(struct window_pane *wp) screen_size_y(&wp->base), UINT_MAX); } -void +static void window_copy_free(struct window_pane *wp) { struct window_copy_mode_data *data = wp->modedata; @@ -347,7 +353,7 @@ window_copy_pageup(struct window_pane *wp, int half_page) window_copy_redraw_screen(wp); } -void +static void window_copy_pagedown(struct window_pane *wp, int half_page) { struct window_copy_mode_data *data = wp->modedata; @@ -395,7 +401,7 @@ window_copy_pagedown(struct window_pane *wp, int half_page) window_copy_redraw_screen(wp); } -void +static void window_copy_previous_paragraph(struct window_pane *wp) { struct window_copy_mode_data *data = wp->modedata; @@ -412,7 +418,7 @@ window_copy_previous_paragraph(struct window_pane *wp) window_copy_scroll_to(wp, 0, oy); } -void +static void window_copy_next_paragraph(struct window_pane *wp) { struct window_copy_mode_data *data = wp->modedata; @@ -432,7 +438,7 @@ window_copy_next_paragraph(struct window_pane *wp) window_copy_scroll_to(wp, ox, oy); } -void +static void window_copy_resize(struct window_pane *wp, u_int sx, u_int sy) { struct window_copy_mode_data *data = wp->modedata; @@ -459,7 +465,7 @@ window_copy_resize(struct window_pane *wp, u_int sx, u_int sy) window_copy_redraw_screen(wp); } -const char * +static const char * window_copy_key_table(struct window_pane *wp) { if (options_get_number(wp->window->options, "mode-keys") == MODEKEY_VI) @@ -467,7 +473,7 @@ window_copy_key_table(struct window_pane *wp) return ("copy-mode"); } -void +static void window_copy_command(struct window_pane *wp, struct client *c, struct session *s, struct args *args, struct mouse_event *m) { @@ -803,7 +809,7 @@ window_copy_command(struct window_pane *wp, struct client *c, struct session *s, wp->modeprefix = 1; } -void +static void window_copy_scroll_to(struct window_pane *wp, u_int px, u_int py) { struct window_copy_mode_data *data = wp->modedata; @@ -829,7 +835,7 @@ window_copy_scroll_to(struct window_pane *wp, u_int px, u_int py) window_copy_redraw_screen(wp); } -int +static int window_copy_search_compare(struct grid *gd, u_int px, u_int py, struct grid *sgd, u_int spx, int cis) { @@ -850,7 +856,7 @@ window_copy_search_compare(struct grid *gd, u_int px, u_int py, return (memcmp(ud->data, sud->data, ud->size) == 0); } -int +static int window_copy_search_lr(struct grid *gd, struct grid *sgd, u_int *ppx, u_int py, u_int first, u_int last, int cis) { @@ -875,7 +881,7 @@ window_copy_search_lr(struct grid *gd, return (0); } -int +static int window_copy_search_rl(struct grid *gd, struct grid *sgd, u_int *ppx, u_int py, u_int first, u_int last, int cis) { @@ -900,7 +906,7 @@ window_copy_search_rl(struct grid *gd, return (0); } -void +static void window_copy_move_left(struct screen *s, u_int *fx, u_int *fy) { if (*fx == 0) { /* left */ @@ -912,7 +918,7 @@ window_copy_move_left(struct screen *s, u_int *fx, u_int *fy) *fx = *fx - 1; } -void +static void window_copy_move_right(struct screen *s, u_int *fx, u_int *fy) { if (*fx == screen_size_x(s) - 1) { /* right */ @@ -924,7 +930,7 @@ window_copy_move_right(struct screen *s, u_int *fx, u_int *fy) *fx = *fx + 1; } -int +static int window_copy_is_lowercase(const char *ptr) { while (*ptr != '\0') { @@ -941,7 +947,7 @@ window_copy_is_lowercase(const char *ptr) * up, down otherwise. If wrap then go to begin/end of grid and try again if * not found. */ -void +static void window_copy_search_jump(struct window_pane *wp, struct grid *gd, struct grid *sgd, u_int fx, u_int fy, u_int endline, int cis, int wrap, int direction) @@ -984,7 +990,7 @@ window_copy_search_jump(struct window_pane *wp, struct grid *gd, * down. If moveflag is 0 then look for string at the current cursor position * as well. */ -void +static void window_copy_search(struct window_pane *wp, const char *searchstr, int direction, int moveflag) { @@ -1024,21 +1030,21 @@ window_copy_search(struct window_pane *wp, const char *searchstr, int direction, screen_free(&ss); } -void +static void window_copy_search_up(struct window_pane *wp, const char *searchstr, int moveflag) { window_copy_search(wp, searchstr, 0, moveflag); } -void +static void window_copy_search_down(struct window_pane *wp, const char *searchstr, int moveflag) { window_copy_search(wp, searchstr, 1, moveflag); } -void +static void window_copy_goto_line(struct window_pane *wp, const char *linestr) { struct window_copy_mode_data *data = wp->modedata; @@ -1054,7 +1060,7 @@ window_copy_goto_line(struct window_pane *wp, const char *linestr) window_copy_redraw_screen(wp); } -void +static void window_copy_write_line(struct window_pane *wp, struct screen_write_ctx *ctx, u_int py) { @@ -1092,7 +1098,7 @@ window_copy_write_line(struct window_pane *wp, struct screen_write_ctx *ctx, } } -void +static void window_copy_write_lines(struct window_pane *wp, struct screen_write_ctx *ctx, u_int py, u_int ny) { @@ -1102,7 +1108,7 @@ window_copy_write_lines(struct window_pane *wp, struct screen_write_ctx *ctx, window_copy_write_line(wp, ctx, py); } -void +static void window_copy_redraw_selection(struct window_pane *wp, u_int old_y) { struct window_copy_mode_data *data = wp->modedata; @@ -1119,7 +1125,7 @@ window_copy_redraw_selection(struct window_pane *wp, u_int old_y) window_copy_redraw_lines(wp, start, end - start + 1); } -void +static void window_copy_redraw_lines(struct window_pane *wp, u_int py, u_int ny) { struct window_copy_mode_data *data = wp->modedata; @@ -1133,7 +1139,7 @@ window_copy_redraw_lines(struct window_pane *wp, u_int py, u_int ny) screen_write_stop(&ctx); } -void +static void window_copy_redraw_screen(struct window_pane *wp) { struct window_copy_mode_data *data = wp->modedata; @@ -1141,7 +1147,7 @@ window_copy_redraw_screen(struct window_pane *wp) window_copy_redraw_lines(wp, 0, screen_size_y(&data->screen)); } -void +static void window_copy_update_cursor(struct window_pane *wp, u_int cx, u_int cy) { struct window_copy_mode_data *data = wp->modedata; @@ -1162,7 +1168,7 @@ window_copy_update_cursor(struct window_pane *wp, u_int cx, u_int cy) } } -void +static void window_copy_start_selection(struct window_pane *wp) { struct window_copy_mode_data *data = wp->modedata; @@ -1175,7 +1181,7 @@ window_copy_start_selection(struct window_pane *wp) window_copy_update_selection(wp, 1); } -int +static int window_copy_update_selection(struct window_pane *wp, int may_redraw) { struct window_copy_mode_data *data = wp->modedata; @@ -1227,7 +1233,7 @@ window_copy_update_selection(struct window_pane *wp, int may_redraw) return (1); } -void * +static void * window_copy_get_selection(struct window_pane *wp, size_t *len) { struct window_copy_mode_data *data = wp->modedata; @@ -1333,7 +1339,7 @@ window_copy_get_selection(struct window_pane *wp, size_t *len) return (buf); } -void +static void window_copy_copy_buffer(struct window_pane *wp, const char *bufname, void *buf, size_t len) { @@ -1349,7 +1355,7 @@ window_copy_copy_buffer(struct window_pane *wp, const char *bufname, void *buf, free(buf); } -void +static void window_copy_copy_pipe(struct window_pane *wp, struct session *sess, const char *bufname, const char *arg) { @@ -1376,7 +1382,7 @@ window_copy_copy_pipe(struct window_pane *wp, struct session *sess, window_copy_copy_buffer(wp, bufname, buf, len); } -void +static void window_copy_copy_selection(struct window_pane *wp, const char *bufname) { void *buf; @@ -1389,7 +1395,7 @@ window_copy_copy_selection(struct window_pane *wp, const char *bufname) window_copy_copy_buffer(wp, bufname, buf, len); } -void +static void window_copy_append_selection(struct window_pane *wp, const char *bufname) { char *buf; @@ -1423,7 +1429,7 @@ window_copy_append_selection(struct window_pane *wp, const char *bufname) free(buf); } -void +static void window_copy_copy_line(struct window_pane *wp, char **buf, size_t *off, u_int sy, u_int sx, u_int ex) { @@ -1483,7 +1489,7 @@ window_copy_copy_line(struct window_pane *wp, char **buf, size_t *off, u_int sy, } } -void +static void window_copy_clear_selection(struct window_pane *wp) { struct window_copy_mode_data *data = wp->modedata; @@ -1497,7 +1503,7 @@ window_copy_clear_selection(struct window_pane *wp) window_copy_update_cursor(wp, px, data->cy); } -int +static int window_copy_in_set(struct window_pane *wp, u_int px, u_int py, const char *set) { struct window_copy_mode_data *data = wp->modedata; @@ -1514,7 +1520,7 @@ window_copy_in_set(struct window_pane *wp, u_int px, u_int py, const char *set) return (strchr(set, *ud->data) != NULL); } -u_int +static u_int window_copy_find_length(struct window_pane *wp, u_int py) { struct window_copy_mode_data *data = wp->modedata; @@ -1540,7 +1546,7 @@ window_copy_find_length(struct window_pane *wp, u_int py) return (px); } -void +static void window_copy_cursor_start_of_line(struct window_pane *wp) { struct window_copy_mode_data *data = wp->modedata; @@ -1562,7 +1568,7 @@ window_copy_cursor_start_of_line(struct window_pane *wp) window_copy_redraw_lines(wp, data->cy, 1); } -void +static void window_copy_cursor_back_to_indentation(struct window_pane *wp) { struct window_copy_mode_data *data = wp->modedata; @@ -1585,7 +1591,7 @@ window_copy_cursor_back_to_indentation(struct window_pane *wp) window_copy_redraw_lines(wp, data->cy, 1); } -void +static void window_copy_cursor_end_of_line(struct window_pane *wp) { struct window_copy_mode_data *data = wp->modedata; @@ -1616,7 +1622,7 @@ window_copy_cursor_end_of_line(struct window_pane *wp) window_copy_redraw_lines(wp, data->cy, 1); } -void +static void window_copy_other_end(struct window_pane *wp) { struct window_copy_mode_data *data = wp->modedata; @@ -1654,7 +1660,7 @@ window_copy_other_end(struct window_pane *wp) window_copy_redraw_screen(wp); } -void +static void window_copy_cursor_left(struct window_pane *wp) { struct window_copy_mode_data *data = wp->modedata; @@ -1671,7 +1677,7 @@ window_copy_cursor_left(struct window_pane *wp) } } -void +static void window_copy_cursor_right(struct window_pane *wp) { struct window_copy_mode_data *data = wp->modedata; @@ -1695,7 +1701,7 @@ window_copy_cursor_right(struct window_pane *wp) } } -void +static void window_copy_cursor_up(struct window_pane *wp, int scroll_only) { struct window_copy_mode_data *data = wp->modedata; @@ -1745,7 +1751,7 @@ window_copy_cursor_up(struct window_pane *wp, int scroll_only) window_copy_cursor_start_of_line(wp); } -void +static void window_copy_cursor_down(struct window_pane *wp, int scroll_only) { struct window_copy_mode_data *data = wp->modedata; @@ -1787,7 +1793,7 @@ window_copy_cursor_down(struct window_pane *wp, int scroll_only) window_copy_cursor_start_of_line(wp); } -void +static void window_copy_cursor_jump(struct window_pane *wp) { struct window_copy_mode_data *data = wp->modedata; @@ -1812,7 +1818,7 @@ window_copy_cursor_jump(struct window_pane *wp) } } -void +static void window_copy_cursor_jump_back(struct window_pane *wp) { struct window_copy_mode_data *data = wp->modedata; @@ -1841,7 +1847,7 @@ window_copy_cursor_jump_back(struct window_pane *wp) } } -void +static void window_copy_cursor_jump_to(struct window_pane *wp, int jump_again) { struct window_copy_mode_data *data = wp->modedata; @@ -1866,7 +1872,7 @@ window_copy_cursor_jump_to(struct window_pane *wp, int jump_again) } } -void +static void window_copy_cursor_jump_to_back(struct window_pane *wp, int jump_again) { struct window_copy_mode_data *data = wp->modedata; @@ -1898,7 +1904,7 @@ window_copy_cursor_jump_to_back(struct window_pane *wp, int jump_again) } } -void +static void window_copy_cursor_next_word(struct window_pane *wp, const char *separators) { struct window_copy_mode_data *data = wp->modedata; @@ -1940,7 +1946,7 @@ window_copy_cursor_next_word(struct window_pane *wp, const char *separators) window_copy_redraw_lines(wp, data->cy, 1); } -void +static void window_copy_cursor_next_word_end(struct window_pane *wp, const char *separators) { @@ -1992,7 +1998,7 @@ window_copy_cursor_next_word_end(struct window_pane *wp, } /* Move to the previous place where a word begins. */ -void +static void window_copy_cursor_previous_word(struct window_pane *wp, const char *separators) { @@ -2030,7 +2036,7 @@ out: window_copy_redraw_lines(wp, data->cy, 1); } -void +static void window_copy_scroll_up(struct window_pane *wp, u_int ny) { struct window_copy_mode_data *data = wp->modedata; @@ -2060,7 +2066,7 @@ window_copy_scroll_up(struct window_pane *wp, u_int ny) screen_write_stop(&ctx); } -void +static void window_copy_scroll_down(struct window_pane *wp, u_int ny) { struct window_copy_mode_data *data = wp->modedata; @@ -2100,7 +2106,7 @@ window_copy_scroll_position(struct window_pane *wp) return (data->oy); } -void +static void window_copy_rectangle_toggle(struct window_pane *wp) { struct window_copy_mode_data *data = wp->modedata; @@ -2117,7 +2123,7 @@ window_copy_rectangle_toggle(struct window_pane *wp) window_copy_redraw_screen(wp); } -void +static void window_copy_move_mouse(struct mouse_event *m) { struct window_pane *wp; @@ -2157,7 +2163,7 @@ window_copy_start_drag(struct client *c, struct mouse_event *m) window_copy_redraw_screen(wp); } -void +static void window_copy_drag_update(__unused struct client *c, struct mouse_event *m) { struct window_pane *wp; diff --git a/window.c b/window.c index 2dd8f78f..a2a53c06 100644 --- a/window.c +++ b/window.c @@ -60,15 +60,23 @@ static u_int next_window_pane_id; static u_int next_window_id; static u_int next_active_point; +static struct window_pane *window_pane_create(struct window *, u_int, u_int, + u_int); +static void window_pane_destroy(struct window_pane *); + static void window_pane_set_watermark(struct window_pane *, size_t); static void window_pane_read_callback(struct bufferevent *, void *); static void window_pane_error_callback(struct bufferevent *, short, void *); +static int winlink_next_index(struct winlinks *, int); + static struct window_pane *window_pane_choose_best(struct window_pane **, u_int); RB_GENERATE(windows, window, entry, window_cmp); +RB_GENERATE(winlinks, winlink, entry, winlink_cmp); +RB_GENERATE(window_pane_tree, window_pane, tree_entry, window_pane_cmp); int window_cmp(struct window *w1, struct window *w2) @@ -76,16 +84,12 @@ window_cmp(struct window *w1, struct window *w2) return (w1->id - w2->id); } -RB_GENERATE(winlinks, winlink, entry, winlink_cmp); - int winlink_cmp(struct winlink *wl1, struct winlink *wl2) { return (wl1->idx - wl2->idx); } -RB_GENERATE(window_pane_tree, window_pane, tree_entry, window_pane_cmp); - int window_pane_cmp(struct window_pane *wp1, struct window_pane *wp2) { @@ -129,7 +133,7 @@ winlink_find_by_window_id(struct winlinks *wwl, u_int id) return (NULL); } -int +static int winlink_next_index(struct winlinks *wwl, int idx) { int i; @@ -731,7 +735,7 @@ window_pane_find_by_id(u_int id) return (RB_FIND(window_pane_tree, &all_window_panes, &wp)); } -struct window_pane * +static struct window_pane * window_pane_create(struct window *w, u_int sx, u_int sy, u_int hlimit) { struct window_pane *wp; @@ -782,7 +786,7 @@ window_pane_create(struct window *w, u_int sx, u_int sy, u_int hlimit) return (wp); } -void +static void window_pane_destroy(struct window_pane *wp) { window_pane_reset_mode(wp); -- cgit From 5c49e1d0c1afaf98512b2ffd1f31d91fecff9851 Mon Sep 17 00:00:00 2001 From: nicm Date: Tue, 11 Oct 2016 13:45:47 +0000 Subject: Some other stuff that can be local to one file. --- cfg.c | 14 +++++++------- format.c | 2 +- layout-set.c | 2 +- mode-key.c | 8 +++++++- paste.c | 4 ++-- tmux.h | 10 +--------- 6 files changed, 19 insertions(+), 21 deletions(-) diff --git a/cfg.c b/cfg.c index 0a931a81..d45573ea 100644 --- a/cfg.c +++ b/cfg.c @@ -28,13 +28,13 @@ #include "tmux.h" -char *cfg_file; -struct cmd_q *cfg_cmd_q; -int cfg_finished; -int cfg_references; -char **cfg_causes; -u_int cfg_ncauses; -struct client *cfg_client; +char *cfg_file; +static struct cmd_q *cfg_cmd_q; +int cfg_finished; +int cfg_references; +static char **cfg_causes; +static u_int cfg_ncauses; +struct client *cfg_client; static void cfg_default_done(struct cmd_q *); diff --git a/format.c b/format.c index acf37850..ed6f2cab 100644 --- a/format.c +++ b/format.c @@ -91,7 +91,7 @@ struct format_job { /* Format job tree. */ static struct event format_job_event; static int format_job_cmp(struct format_job *, struct format_job *); -RB_HEAD(format_job_tree, format_job) format_jobs = RB_INITIALIZER(); +static RB_HEAD(format_job_tree, format_job) format_jobs = RB_INITIALIZER(); RB_GENERATE_STATIC(format_job_tree, format_job, entry, format_job_cmp); /* Format job tree comparison function. */ diff --git a/layout-set.c b/layout-set.c index 1da7037a..db621f61 100644 --- a/layout-set.c +++ b/layout-set.c @@ -33,7 +33,7 @@ static void layout_set_main_h(struct window *); static void layout_set_main_v(struct window *); static void layout_set_tiled(struct window *); -const struct { +static const struct { const char *name; void (*arrange)(struct window *); } layout_sets[] = { diff --git a/mode-key.c b/mode-key.c index 5c3c7889..32333957 100644 --- a/mode-key.c +++ b/mode-key.c @@ -38,6 +38,12 @@ * (any matching MODEKEYEDIT_SWITCHMODE*) are special-cased to do this. */ +/* Command to string mapping. */ +struct mode_key_cmdstr { + enum mode_key_cmd cmd; + const char *name; +}; + /* Entry in the default mode key tables. */ struct mode_key_entry { key_code key; @@ -304,7 +310,7 @@ static const struct mode_key_entry mode_key_emacs_choice[] = { struct mode_key_tree mode_key_tree_emacs_choice; /* Table mapping key table names to default settings and trees. */ -const struct mode_key_table mode_key_tables[] = { +static const struct mode_key_table mode_key_tables[] = { { "vi-edit", mode_key_cmdstr_edit, &mode_key_tree_vi_edit, mode_key_vi_edit }, { "vi-choice", mode_key_cmdstr_choice, diff --git a/paste.c b/paste.c index d4d5c59f..672927f4 100644 --- a/paste.c +++ b/paste.c @@ -46,8 +46,8 @@ struct paste_buffer { static u_int paste_next_index; static u_int paste_next_order; static u_int paste_num_automatic; -RB_HEAD(paste_name_tree, paste_buffer) paste_by_name; -RB_HEAD(paste_time_tree, paste_buffer) paste_by_time; +static RB_HEAD(paste_name_tree, paste_buffer) paste_by_name; +static RB_HEAD(paste_time_tree, paste_buffer) paste_by_time; static int paste_cmp_names(const struct paste_buffer *, const struct paste_buffer *); diff --git a/tmux.h b/tmux.h index e2c1514c..b5fd8714 100644 --- a/tmux.h +++ b/tmux.h @@ -42,6 +42,7 @@ struct args; struct client; struct environ; struct input_ctx; +struct mode_key_cmdstr; struct mouse_event; struct options; struct session; @@ -542,12 +543,6 @@ struct mode_key_binding { }; RB_HEAD(mode_key_tree, mode_key_binding); -/* Command to string mapping. */ -struct mode_key_cmdstr { - enum mode_key_cmd cmd; - const char *name; -}; - /* Named mode key table description. */ struct mode_key_entry; struct mode_key_table { @@ -1598,13 +1593,10 @@ int printflike(4, 5) hooks_wait(struct hooks *, struct cmd_q *, struct cmd_find_state *, const char *, ...); /* mode-key.c */ -extern const struct mode_key_table mode_key_tables[]; extern struct mode_key_tree mode_key_tree_vi_edit; extern struct mode_key_tree mode_key_tree_vi_choice; -extern struct mode_key_tree mode_key_tree_vi_copy; extern struct mode_key_tree mode_key_tree_emacs_edit; extern struct mode_key_tree mode_key_tree_emacs_choice; -extern struct mode_key_tree mode_key_tree_emacs_copy; int mode_key_cmp(struct mode_key_binding *, struct mode_key_binding *); RB_PROTOTYPE(mode_key_tree, mode_key_binding, entry, mode_key_cmp); const char *mode_key_tostring(const struct mode_key_cmdstr *, -- cgit