Remove the duplicated code for putting a pane in to copy mode and displaying
config error information, to a common function.
---
cfg.c | 26 ++++++++++++++++++++++++++
cmd-new-session.c | 13 ++-----------
server.c | 14 +++-----------
tmux.h | 1 +
4 files changed, 32 insertions(+), 22 deletions(-)
diff --git a/cfg.c b/cfg.c
index 007dba5..b915d97 100644
--- a/cfg.c
+++ b/cfg.c
@@ -172,3 +172,29 @@ load_cfg(const char *path, struct cmd_ctx *ctxin, struct
causelist *causes)
return (retval);
}
+
+void
+show_cfg_causes(struct session *s)
+{
+ struct window_pane *wp;
+ char *cause;
+ u_int i;
+
+ /* Shouldn't happen. */
+ if (s == NULL)
+ return;
+
+ if (ARRAY_EMPTY(&cfg_causes))
+ return;
+
+ wp = s->curw->window->active;
+
+ window_pane_set_mode(wp, &window_copy_mode);
+ window_copy_init_for_output(wp);
+ for (i = 0; i < ARRAY_LENGTH(&cfg_causes); i++) {
+ cause = ARRAY_ITEM(&cfg_causes, i);
+ window_copy_add(wp, "%s", cause);
+ free(cause);
+ }
+ ARRAY_FREE(&cfg_causes);
+}
diff --git a/cmd-new-session.c b/cmd-new-session.c
index 8477d9b..63eedff 100644
--- a/cmd-new-session.c
+++ b/cmd-new-session.c
@@ -257,17 +257,8 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
* If there are still configuration file errors to display, put the new
* session's current window into more mode and display them now.
*/
- if (cfg_finished && !ARRAY_EMPTY(&cfg_causes)) {
- wp = s->curw->window->active;
- window_pane_set_mode(wp, &window_copy_mode);
- window_copy_init_for_output(wp);
- for (i = 0; i < ARRAY_LENGTH(&cfg_causes); i++) {
- cause = ARRAY_ITEM(&cfg_causes, i);
- window_copy_add(wp, "%s", cause);
- free(cause);
- }
- ARRAY_FREE(&cfg_causes);
- }
+ if (cfg_finished)
+ show_cfg_causes(s);
return (detached ? CMD_RETURN_NORMAL : CMD_RETURN_ATTACH);
}
diff --git a/server.c b/server.c
index 4da0739..d05cec7 100644
--- a/server.c
+++ b/server.c
@@ -179,17 +179,9 @@ server_start(int lockfd, char *lockfile)
* If there is a session already, put the current window and pane into
* more mode.
*/
- if (!RB_EMPTY(&sessions) && !ARRAY_EMPTY(&cfg_causes)) {
- wp = RB_MIN(sessions, &sessions)->curw->window->active;
- window_pane_set_mode(wp, &window_copy_mode);
- window_copy_init_for_output(wp);
- for (i = 0; i < ARRAY_LENGTH(&cfg_causes); i++) {
- cause = ARRAY_ITEM(&cfg_causes, i);
- window_copy_add(wp, "%s", cause);
- free(cause);
- }
- ARRAY_FREE(&cfg_causes);
- }
+ if (!RB_EMPTY(&sessions) && !ARRAY_EMPTY(&cfg_causes))
+ show_cfg_causes(RB_MIN(sessions, &sessions));
+
cfg_finished = 1;
server_add_accept(0);
diff --git a/tmux.h b/tmux.h
index 5988202..aca9661 100644
--- a/tmux.h
+++ b/tmux.h
@@ -1516,6 +1516,7 @@ extern int cfg_finished;
extern struct causelist cfg_causes;
void printflike2 cfg_add_cause(struct causelist *, const char *, ...);
int load_cfg(const char *, struct cmd_ctx *, struct causelist *);
+void show_cfg_causes(struct session *);
/* format.c */
int format_cmp(struct format_entry *, struct format_entry *);
--
1.7.11.4
------------------------------------------------------------------------------
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov
_______________________________________________
tmux-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tmux-users