summaryrefslogtreecommitdiff
path: root/src/os_unix.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2013-03-13 17:50:25 +0100
committerBram Moolenaar <Bram@vim.org>2013-03-13 17:50:25 +0100
commit1a0316ca2a617c5becc187337c4b9e3f08578d3b (patch)
treef2a84974bd787069b0dafbcceef7bf4467bc7c2d /src/os_unix.c
parentb3cb98216296dc166f3d4544dd95d661cefe73b1 (diff)
downloadvim-git-1a0316ca2a617c5becc187337c4b9e3f08578d3b.tar.gz
updated for version 7.3.856v7.3.856
Problem: When calling system() multi-byte clipboard contents is garbled. Solution: Save and restore the clipboard contents. (Yukihiro Nakadaira)
Diffstat (limited to 'src/os_unix.c')
-rw-r--r--src/os_unix.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/os_unix.c b/src/os_unix.c
index bb97bbe6b..9d9483261 100644
--- a/src/os_unix.c
+++ b/src/os_unix.c
@@ -1138,6 +1138,11 @@ sigcont_handler SIGDEFARG(sigarg)
# if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
static void loose_clipboard __ARGS((void));
+static void save_clipboard __ARGS((void));
+static void restore_clipboard __ARGS((void));
+
+static void *clip_star_save = NULL;
+static void *clip_plus_save = NULL;
/*
* Called when Vim is going to sleep or execute a shell command.
@@ -1158,6 +1163,42 @@ loose_clipboard()
XFlush(x11_display);
}
}
+
+/*
+ * Save clipboard text to restore later.
+ */
+ static void
+save_clipboard()
+{
+ if (clip_star.owned)
+ clip_star_save = get_register('*', TRUE);
+ if (clip_plus.owned)
+ clip_plus_save = get_register('+', TRUE);
+}
+
+/*
+ * Restore clipboard text if no one own the X selection.
+ */
+ static void
+restore_clipboard()
+{
+ if (clip_star_save != NULL)
+ {
+ if (!clip_gen_owner_exists(&clip_star))
+ put_register('*', clip_star_save);
+ else
+ free_register(clip_star_save);
+ clip_star_save = NULL;
+ }
+ if (clip_plus_save != NULL)
+ {
+ if (!clip_gen_owner_exists(&clip_plus))
+ put_register('+', clip_plus_save);
+ else
+ free_register(clip_plus_save);
+ clip_plus_save = NULL;
+ }
+}
#endif
/*
@@ -3844,6 +3885,7 @@ mch_call_shell(cmd, options)
settmode(TMODE_COOK); /* set to normal mode */
# if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
+ save_clipboard();
loose_clipboard();
# endif
@@ -3917,6 +3959,9 @@ mch_call_shell(cmd, options)
# ifdef FEAT_TITLE
resettitle();
# endif
+# if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
+ restore_clipboard();
+# endif
return x;
#else /* USE_SYSTEM */ /* don't use system(), use fork()/exec() */
@@ -3965,6 +4010,9 @@ mch_call_shell(cmd, options)
settmode(TMODE_COOK); /* set to normal mode */
# if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
+ /* Disown the clipboard, because is the executed command tries to obtain a
+ * selection and we own it we get a deadlock. */
+ save_clipboard();
loose_clipboard();
# endif
@@ -4836,6 +4884,9 @@ error:
# ifdef FEAT_TITLE
resettitle();
# endif
+# if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
+ restore_clipboard();
+# endif
vim_free(newcmd);
return retval;