[PATCH] Add clipboard support for running without GUI in Mac OS X

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
21 messages Options
12
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[PATCH] Add clipboard support for running without GUI in Mac OS X

Jiang Jiang

Running vim under Mac OS X terminal do not support copy to/from
system clipboard currently, this patch add this feature. To have
this feature in mainstream, we receive the following benifits:

1. We can copy from/to system clipboard without running GUI.
   (Default vim builds shipped with Mac OS X do not have GUI
    enabled, so it can share this feature.)
2. We don't need to duplicate code in GUI implementations like
   MacVim or vim-cocoa.

The clipboard handling code is derived from MacVim.

To use Cocoa APIs, we need to convert os_macosx.c into an Obj-C
file. Other changes are trivial.

---
 src/Makefile     |    4 +-
 src/configure.in |    4 +-
 src/main.c       |    4 +
 src/os_macosx.c  |  611 -----------------------------------------------
 src/os_macosx.m  |  694 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/vim.h        |    1 +
 6 files changed, 703 insertions(+), 615 deletions(-)
 delete mode 100644 src/os_macosx.c
 create mode 100644 src/os_macosx.m

diff --git a/src/Makefile b/src/Makefile
index 707a20e..e6d5bbb 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -2512,8 +2512,8 @@ objects/os_beos.o: os_beos.c
 objects/os_qnx.o: os_qnx.c
  $(CCC) -o $@ os_qnx.c
 
-objects/os_macosx.o: os_macosx.c
- $(CCC) -o $@ os_macosx.c
+objects/os_macosx.o: os_macosx.m
+ $(CCC) -o $@ os_macosx.m
 
 objects/os_mac_conv.o: os_mac_conv.c
  $(CCC) -o $@ os_mac_conv.c
diff --git a/src/configure.in b/src/configure.in
index b911b81..af8abd2 100644
--- a/src/configure.in
+++ b/src/configure.in
@@ -101,7 +101,7 @@ if test "`(uname) 2>/dev/null`" = Darwin; then
   if test "$enable_darwin" = "yes"; then
     AC_MSG_RESULT(no)
     AC_MSG_CHECKING(if Darwin files are there)
-    if test -f os_macosx.c; then
+    if test -f os_macosx.m; then
       AC_MSG_RESULT(yes)
     else
       AC_MSG_RESULT([no, Darwin support disabled])
@@ -152,7 +152,7 @@ if test "`(uname) 2>/dev/null`" = Darwin; then
 
   if test "$enable_darwin" = "yes"; then
     MACOSX=yes
-    OS_EXTRA_SRC="os_macosx.c os_mac_conv.c";
+    OS_EXTRA_SRC="os_macosx.m os_mac_conv.c";
     OS_EXTRA_OBJ="objects/os_macosx.o objects/os_mac_conv.o"
     dnl TODO: use -arch i386 on Intel machines
     CPPFLAGS="$CPPFLAGS -DMACOS_X_UNIX -no-cpp-precomp"
diff --git a/src/main.c b/src/main.c
index 8a5aa98..991b865 100644
--- a/src/main.c
+++ b/src/main.c
@@ -706,6 +706,10 @@ main
     qnx_clip_init();
 #endif
 
+#if defined(MACOS_X_UNIX) && defined(FEAT_CLIPBOARD)
+    clip_init(TRUE);
+#endif
+
 #ifdef FEAT_XCLIPBOARD
     /* Start using the X clipboard, unless the GUI was started. */
 # ifdef FEAT_GUI
diff --git a/src/os_macosx.c b/src/os_macosx.c
deleted file mode 100644
index 48023e3..0000000
--- a/src/os_macosx.c
+++ /dev/null
@@ -1,611 +0,0 @@
-/* vi:set ts=8 sts=4 sw=4:
- *
- * VIM - Vi IMproved by Bram Moolenaar
- *
- * Do ":help uganda"  in Vim to read copying and usage conditions.
- * Do ":help credits" in Vim to see a list of people who contributed.
- * See README.txt for an overview of the Vim source code.
- */
-
-/*
- * os_macosx.c -- Mac specific things for Mac OS/X.
- */
-
-#ifdef MACOS_X_UNIX
-# ifdef HAVE_CONFIG_H    /* Using Makefile. */
-#  include "vim.h"
-# else
-#  include "os_unix.c"    /* Using Project Builder */
-# endif
-#else
-    Error: MACOS 9 is no longer supported in Vim 7
-#endif
-
-#ifdef _DEBUG
-    void
-Trace(char* fmt, ...)
-{
-    char buf[2048];
-    va_list args;
-
-    va_start(args, fmt);
-    /* vsnprintf(buf, sizeof(buf), fmt, args);*/
-    fprintf(stderr, "%s", buf);
-    va_end(args);
-}
-#endif
-
-#ifdef MACOS_X_ICONVEMU
-/*
- * Libiconv emulation layer
- */
-
-struct _iconv_t
-{
-    TECObjectRef tec;
-    TECObjectRef tecReverse;
-    TECSnifferObjectRef sniff;
-    TextEncoding from;
-    TextEncoding to;
-};
-/* typedef struct _iconv_t *iconv_t; */
-
-
-static int last_errno = 0;
-
-/*
- * Get TextEncoding from iconv's encoding name
- */
-    static TextEncoding
-get_textencoding(const char* encodename)
-{
-    static struct {
- const char* name;
- TextEncoding encode;
-    } encodetable[] = {
- /* ISO-8859 encodings family */
- {"latin1", kTextEncodingISOLatin1},
- {"latin2", kTextEncodingISOLatin2},
- {"latin3", kTextEncodingISOLatin3},
- {"latin4", kTextEncodingISOLatin4},
- {"latin5", kTextEncodingISOLatin5},
- {"latin6", kTextEncodingISOLatin6},
- {"latin7", kTextEncodingISOLatin7},
- {"latin8", kTextEncodingISOLatin8},
- {"latin9", kTextEncodingISOLatin9},
- {"iso-8859-1", kTextEncodingISOLatin1},
- {"iso-8859-2", kTextEncodingISOLatin2},
- {"iso-8859-3", kTextEncodingISOLatin3},
- {"iso-8859-4", kTextEncodingISOLatin4},
- {"iso-8859-5", kTextEncodingISOLatinCyrillic},
- {"iso-8859-6", kTextEncodingISOLatinArabic},
- {"iso-8859-7", kTextEncodingISOLatinGreek},
- {"iso-8859-8", kTextEncodingISOLatinHebrew},
- {"iso-8859-9", kTextEncodingISOLatin5},
- {"iso-8859-10", kTextEncodingISOLatin6},
- {"iso-8859-15", kTextEncodingISOLatin9},
-
- /* Unicode encodings. */
- /* TODO: Add other type of unicode */
- {"ucs-2", kTextEncodingMacUnicode},
-
- /* Japanese encoding aliases */
- {"cp932", kTextEncodingShiftJIS},
- {"shift-jis", kTextEncodingShiftJIS},
- {"euc-jp", kTextEncodingEUC_JP},
- {"iso-2022-jp", kTextEncodingISO_2022_JP},
- {"iso-2022-jp-1", kTextEncodingISO_2022_JP_1},
- {"iso-2022-jp-2", kTextEncodingISO_2022_JP_2},
- {"iso-2022-jp-3", kTextEncodingISO_2022_JP_3},
-
- /* Other aliases. These aliases in this block are just guessed. */
- /* TODO: Must be verified. */
- {"gb2312", kTextEncodingGB_2312_80},
- {"cp936", kTextEncodingMacChineseSimp},
- {"euc-cn", kTextEncodingEUC_CN},
- {"cp950", kTextEncodingMacChineseTrad},
- {"euc-tw", kTextEncodingEUC_TW},
- {"cp949", kTextEncodingMacKorean},
- {"euc-kr", kTextEncodingEUC_KR},
-
- /*
- * All encodings supported by Macintosh.  You can find these values
- * in a file:
- *  /System/Library/Frameworks/CoreServices.framework/Versions/A/
- *    Frameworks/CarbonCore.framework/Versions/A/Headers/TextCommon.h
- */
- {"MacRoman", kTextEncodingMacRoman},
- {"MacJapanese", kTextEncodingMacJapanese},
- {"MacChineseTrad", kTextEncodingMacChineseTrad},
- {"MacKorean", kTextEncodingMacKorean},
- {"MacArabic", kTextEncodingMacArabic},
- {"MacHebrew", kTextEncodingMacHebrew},
- {"MacGreek", kTextEncodingMacGreek},
- {"MacCyrillic", kTextEncodingMacCyrillic},
- {"MacDevanagari", kTextEncodingMacDevanagari},
- {"MacGurmukhi", kTextEncodingMacGurmukhi},
- {"MacGujarati", kTextEncodingMacGujarati},
- {"MacOriya", kTextEncodingMacOriya},
- {"MacBengali", kTextEncodingMacBengali},
- {"MacTamil", kTextEncodingMacTamil},
- {"MacTelugu", kTextEncodingMacTelugu},
- {"MacKannada", kTextEncodingMacKannada},
- {"MacMalayalam", kTextEncodingMacMalayalam},
- {"MacSinhalese", kTextEncodingMacSinhalese},
- {"MacBurmese", kTextEncodingMacBurmese},
- {"MacKhmer", kTextEncodingMacKhmer},
- {"MacThai", kTextEncodingMacThai},
- {"MacLaotian", kTextEncodingMacLaotian},
- {"MacGeorgian", kTextEncodingMacGeorgian},
- {"MacArmenian", kTextEncodingMacArmenian},
- {"MacChineseSimp", kTextEncodingMacChineseSimp},
- {"MacTibetan", kTextEncodingMacTibetan},
- {"MacMongolian", kTextEncodingMacMongolian},
- {"MacEthiopic", kTextEncodingMacEthiopic},
- {"MacCentralEurRoman", kTextEncodingMacCentralEurRoman},
- {"MacVietnamese", kTextEncodingMacVietnamese},
- {"MacExtArabic", kTextEncodingMacExtArabic},
- {"MacSymbol", kTextEncodingMacSymbol},
- {"MacDingbats", kTextEncodingMacDingbats},
- {"MacTurkish", kTextEncodingMacTurkish},
- {"MacCroatian", kTextEncodingMacCroatian},
- {"MacIcelandic", kTextEncodingMacIcelandic},
- {"MacRomanian", kTextEncodingMacRomanian},
- {"MacCeltic", kTextEncodingMacCeltic},
- {"MacGaelic", kTextEncodingMacGaelic},
- {"MacKeyboardGlyphs", kTextEncodingMacKeyboardGlyphs},
- {"MacTradChinese", kTextEncodingMacTradChinese},
- {"MacRSymbol", kTextEncodingMacRSymbol},
- {"MacSimpChinese", kTextEncodingMacSimpChinese},
- {"MacGeez", kTextEncodingMacGeez},
- {"MacEastEurRoman", kTextEncodingMacEastEurRoman},
- {"MacUninterp", kTextEncodingMacUninterp},
- {"MacUnicode", kTextEncodingMacUnicode},
- {"MacFarsi", kTextEncodingMacFarsi},
- {"MacUkrainian", kTextEncodingMacUkrainian},
- {"MacInuit", kTextEncodingMacInuit},
- {"MacVT100", kTextEncodingMacVT100},
- {"MacHFS", kTextEncodingMacHFS},
- {"UnicodeDefault", kTextEncodingUnicodeDefault},
- {"UnicodeV1_1", kTextEncodingUnicodeV1_1},
- {"ISO10646_1993", kTextEncodingISO10646_1993},
- {"UnicodeV2_0", kTextEncodingUnicodeV2_0},
- {"UnicodeV2_1", kTextEncodingUnicodeV2_1},
- {"UnicodeV3_0", kTextEncodingUnicodeV3_0},
- {"UnicodeV3_1", kTextEncodingUnicodeV3_1},
- {"UnicodeV3_2", kTextEncodingUnicodeV3_2},
- {"ISOLatin1", kTextEncodingISOLatin1},
- {"ISOLatin2", kTextEncodingISOLatin2},
- {"ISOLatin3", kTextEncodingISOLatin3},
- {"ISOLatin4", kTextEncodingISOLatin4},
- {"ISOLatinCyrillic", kTextEncodingISOLatinCyrillic},
- {"ISOLatinArabic", kTextEncodingISOLatinArabic},
- {"ISOLatinGreek", kTextEncodingISOLatinGreek},
- {"ISOLatinHebrew", kTextEncodingISOLatinHebrew},
- {"ISOLatin5", kTextEncodingISOLatin5},
- {"ISOLatin6", kTextEncodingISOLatin6},
- {"ISOLatin7", kTextEncodingISOLatin7},
- {"ISOLatin8", kTextEncodingISOLatin8},
- {"ISOLatin9", kTextEncodingISOLatin9},
- {"DOSLatinUS", kTextEncodingDOSLatinUS},
- {"DOSGreek", kTextEncodingDOSGreek},
- {"DOSBalticRim", kTextEncodingDOSBalticRim},
- {"DOSLatin1", kTextEncodingDOSLatin1},
- {"DOSGreek1", kTextEncodingDOSGreek1},
- {"DOSLatin2", kTextEncodingDOSLatin2},
- {"DOSCyrillic", kTextEncodingDOSCyrillic},
- {"DOSTurkish", kTextEncodingDOSTurkish},
- {"DOSPortuguese", kTextEncodingDOSPortuguese},
- {"DOSIcelandic", kTextEncodingDOSIcelandic},
- {"DOSHebrew", kTextEncodingDOSHebrew},
- {"DOSCanadianFrench", kTextEncodingDOSCanadianFrench},
- {"DOSArabic", kTextEncodingDOSArabic},
- {"DOSNordic", kTextEncodingDOSNordic},
- {"DOSRussian", kTextEncodingDOSRussian},
- {"DOSGreek2", kTextEncodingDOSGreek2},
- {"DOSThai", kTextEncodingDOSThai},
- {"DOSJapanese", kTextEncodingDOSJapanese},
- {"DOSChineseSimplif", kTextEncodingDOSChineseSimplif},
- {"DOSKorean", kTextEncodingDOSKorean},
- {"DOSChineseTrad", kTextEncodingDOSChineseTrad},
- {"WindowsLatin1", kTextEncodingWindowsLatin1},
- {"WindowsANSI", kTextEncodingWindowsANSI},
- {"WindowsLatin2", kTextEncodingWindowsLatin2},
- {"WindowsCyrillic", kTextEncodingWindowsCyrillic},
- {"WindowsGreek", kTextEncodingWindowsGreek},
- {"WindowsLatin5", kTextEncodingWindowsLatin5},
- {"WindowsHebrew", kTextEncodingWindowsHebrew},
- {"WindowsArabic", kTextEncodingWindowsArabic},
- {"WindowsBalticRim", kTextEncodingWindowsBalticRim},
- {"WindowsVietnamese", kTextEncodingWindowsVietnamese},
- {"WindowsKoreanJohab", kTextEncodingWindowsKoreanJohab},
- {"US_ASCII", kTextEncodingUS_ASCII},
- {"JIS_X0201_76", kTextEncodingJIS_X0201_76},
- {"JIS_X0208_83", kTextEncodingJIS_X0208_83},
- {"JIS_X0208_90", kTextEncodingJIS_X0208_90},
- {"JIS_X0212_90", kTextEncodingJIS_X0212_90},
- {"JIS_C6226_78", kTextEncodingJIS_C6226_78},
- {"ShiftJIS_X0213_00", kTextEncodingShiftJIS_X0213_00},
- {"GB_2312_80", kTextEncodingGB_2312_80},
- {"GBK_95", kTextEncodingGBK_95},
- {"GB_18030_2000", kTextEncodingGB_18030_2000},
- {"KSC_5601_87", kTextEncodingKSC_5601_87},
- {"KSC_5601_92_Johab", kTextEncodingKSC_5601_92_Johab},
- {"CNS_11643_92_P1", kTextEncodingCNS_11643_92_P1},
- {"CNS_11643_92_P2", kTextEncodingCNS_11643_92_P2},
- {"CNS_11643_92_P3", kTextEncodingCNS_11643_92_P3},
- {"ISO_2022_JP", kTextEncodingISO_2022_JP},
- {"ISO_2022_JP_2", kTextEncodingISO_2022_JP_2},
- {"ISO_2022_JP_1", kTextEncodingISO_2022_JP_1},
- {"ISO_2022_JP_3", kTextEncodingISO_2022_JP_3},
- {"ISO_2022_CN", kTextEncodingISO_2022_CN},
- {"ISO_2022_CN_EXT", kTextEncodingISO_2022_CN_EXT},
- {"ISO_2022_KR", kTextEncodingISO_2022_KR},
- {"EUC_JP", kTextEncodingEUC_JP},
- {"EUC_CN", kTextEncodingEUC_CN},
- {"EUC_TW", kTextEncodingEUC_TW},
- {"EUC_KR", kTextEncodingEUC_KR},
- {"ShiftJIS", kTextEncodingShiftJIS},
- {"KOI8_R", kTextEncodingKOI8_R},
- {"Big5", kTextEncodingBig5},
- {"MacRomanLatin1", kTextEncodingMacRomanLatin1},
- {"HZ_GB_2312", kTextEncodingHZ_GB_2312},
- {"Big5_HKSCS_1999", kTextEncodingBig5_HKSCS_1999},
- {"NextStepLatin", kTextEncodingNextStepLatin},
- {"EBCDIC_US", kTextEncodingEBCDIC_US},
- {"EBCDIC_CP037", kTextEncodingEBCDIC_CP037},
- {"MultiRun", kTextEncodingMultiRun},
-
- /* Terminator */
- {NULL, -1},
-    };
-    int i;
-
-    i = 0;
-    for (i = 0; encodetable[i].name != NULL; ++i)
-    {
- if (STRICMP(encodename, encodetable[i].name) == 0)
-    break;
-    }
-    return encodetable[i].encode;
-}
-
-/*
- * iconv interfaces
- */
-
-    iconv_t
-iconv_open(const char* tocode, const char* fromcode)
-{
-    TextEncoding toEnc, fromEnc;
-    iconv_t cd = NULL;
-    OSStatus st;
-
-    /* Verify to/from encoding name */
-    toEnc = get_textencoding(tocode);
-    fromEnc = get_textencoding(fromcode);
-    if (toEnc < 0 || fromEnc < 0)
- goto ICONV_OPEN_ERR;
-
-    /* Allocate memory to object */
-    cd = (iconv_t)alloc(sizeof(struct _iconv_t));
-    if (!cd)
- goto ICONV_OPEN_ERR;
-    memset(cd, 0, sizeof(struct _iconv_t));
-
-    /* Create converter */
-    if (fromEnc != toEnc)
-    {
- TRACE("*** fromEnc=%d toEnc=%d\n", (int)fromEnc, (int)toEnc);
- st = TECCreateConverter(&cd->tec, fromEnc, toEnc);
- if (st != 0)
- {
-    TRACE("*** TECCreateConverter()=%d\n", (int)st);
-    goto ICONV_OPEN_ERR;
- }
- /* Create reverse converter */
- st = TECCreateConverter(&cd->tecReverse, toEnc, fromEnc);
- if (st != 0)
- {
-    TRACE("*** TECCreateConverter()=%d (reverse)\n", (int)st);
-    goto ICONV_OPEN_ERR;
- }
- /* Create Sniffer */
- st = TECCreateSniffer(&cd->sniff, &fromEnc, 1);
- if (st != 0)
- {
-    TRACE("*** TECCreateSniffer()=%d\n", (int)st);
-    goto ICONV_OPEN_ERR;
- }
-    }
-
-    cd->from = fromEnc;
-    cd->to = toEnc;
-    last_errno = 0;
-    return cd;
-
-ICONV_OPEN_ERR:
-    if (cd)
- iconv_close(cd);
-    last_errno = EINVAL;
-    return (iconv_t)-1;
-}
-
-/*
- * Used when there are same value in 'from encoding' and 'to encoding'.
- * TEC doesn't support conversion between same encodings, and
- * TECCreateConverter() failed.
- */
-    static size_t
-null_conv(iconv_t cd, const char **inbuf, size_t *inbytesleft,
- char **outbuf, size_t *outbytesleft)
-{
-    const char* buf_in = inbuf && *inbuf ? *inbuf : NULL;
-    char* buf_out = outbuf && *outbuf ? *outbuf : NULL;
-
-    if (buf_in)
-    {
- int in_len = inbytesleft ? *inbytesleft : 0;
- int out_len = outbytesleft ? *outbytesleft : 0;
-
- if (!buf_out || out_len <= 0)
- {
-    last_errno = E2BIG;
-    return -1;
- }
- else if (in_len > 0)
- {
-    int len = in_len < out_len ? in_len : out_len;
-
-    memcpy (buf_out, buf_in, len);
-    *inbuf += len;
-    *outbuf += len;
-    *inbytesleft -= len;
-    *outbytesleft -= len;
-    if (*outbytesleft <= 0)
-    {
- last_errno = E2BIG;
- return -1;
-    }
- }
-    }
-    last_errno = 0;
-    return 0;
-}
-
-    size_t
-iconv(iconv_t cd, const char **inbuf, size_t *inbytesleft,
- char **outbuf, size_t *outbytesleft)
-{
-    ConstTextPtr    buf_in;
-    TextPtr    buf_out;
-    ByteCount    out_len, out_true;
-    ByteCount    in_len, in_true;
-    OSStatus    st;
-
-    if (!cd)
-    {
- last_errno = ENOENT; /* TODO: Another error code should be set */
- return -1;
-    }
-    if (cd->from == cd->to)
- return null_conv(cd, inbuf, inbytesleft, outbuf, outbytesleft) ;
-
-    buf_in = (TextPtr) inbuf ;
-    buf_out = (TextPtr) outbuf ;
-    out_len = out_true = -1;
-    in_len = in_true = -1;
-
-    if (buf_in && buf_out)
-    {
- ItemCount error, feature;
-
- /* Normal convert mode */
- if (!inbytesleft || !outbytesleft)
- {
-    last_errno = EFAULT;
-    return -1;
- }
- in_len = *inbytesleft;
- out_len = *outbytesleft;
-
- /* Check stream is form in expected encoding or not */
- st = TECSniffTextEncoding(cd->sniff, (TextPtr)buf_in, in_len,
- &cd->from, 1, &error, 1, &feature, 1);
- TRACE("TECSniffTextEncoding()=%d error=%d feature=%d\n",
- (int)st, (int)error, (int)feature);
- if ((error != 0 || feature == 0)
- && !(error == 0xffffffff && feature == 0xffffffff))
-    /* Not expected encoding */
-    st = kTECUnmappableElementErr;
- else
- {
-    /* Do convert */
-    st = TECConvertText(cd->tec,
-    buf_in, in_len, &in_true,
-    buf_out, out_len, &out_true);
-    /* Verify converted text.  Compare original text with reverse
-     * converted text.  If not match, there is some problem on
-     * converting. */
-    if (st == 0 && in_true > 0)
-    {
- ByteCount rev_in, rev_out;
- TextPtr buf_rev = (TextPtr)alloc(in_true);
-
- if (buf_rev)
- {
-    st = TECConvertText(cd->tecReverse,
-    buf_out, out_true, &rev_in,
-    buf_rev, in_true, &rev_out);
-    if (st != 0 || rev_in != out_true || rev_out != in_true
-    || memcmp(buf_rev, buf_in, rev_out) != 0)
-    {
-#ifdef ICONVOSX_DEBUG
- fprintf(stderr, "  reverse conversion failed.\n");
-#endif
- st = kTECUnmappableElementErr;
-    }
-    vim_free(buf_rev);
- }
- else
-    st = kTECUnmappableElementErr;
-    }
- }
-    }
-    else if (!buf_in && buf_out)
-    {
- /* Flush all buffered strings to buffer, and reset status */
- if (!outbytesleft)
- {
-    last_errno = EFAULT;
-    return -1;
- }
- out_len = *outbytesleft;
- st = TECFlushText(cd->tec,
- buf_out, out_len, &out_true);
-    }
-    else if (!buf_in && !buf_out)
-    {
- /* Reset cd's status and cancel buffered strings */
- unsigned char tmp_out[256];
-
- buf_out = tmp_out;
- out_len = sizeof(tmp_out);
- st = TECFlushText(cd->tec,
- buf_out, out_len, &out_true);
-    }
-    else
-    {
- last_errno = EFAULT;
- return -1;
-    }
-    TRACE("st=%d, buf_in=%p, in_len=%d, in_true=%d\n"
-    "  buf_out=%p, out_len=%d, out_true=%d\n", (int)st,
-    buf_in, (int)in_len, (int)in_true,
-    buf_out, (int)out_len, (int)out_true);
-
-    switch (st)
-    {
- case 0:
-    /* No error */
-    if (inbytesleft)
- *inbytesleft -= in_true;
-    if (outbytesleft)
- *outbytesleft -= out_true;
-    if (inbuf && *inbuf)
- *inbuf += in_true;
-    if (outbuf && *outbuf)
- *outbuf += out_true;
-    last_errno = 0;
-    return 0; /* No error */
- case kTECUnmappableElementErr:
-    last_errno = EILSEQ;
- case kTECIncompleteElementErr:
-    last_errno = EINVAL;
- case kTECOutputBufferFullStatus:
-    last_errno = E2BIG;
-    return -1;
- default:
-    TRACE("iconv(%p, %p, %p, %p, %p) failed. (%d)\n",
-    cd, inbuf, inbytesleft, outbuf, outbytesleft, (int)st);
-    last_errno = EFAULT;
-    return -1;
-    }
-}
-
-    int
-iconv_close(iconv_t cd)
-{
-    if (cd)
-    {
- /* Free all elements of iconv_t */
- if (cd->tec)
-    TECDisposeConverter(cd->tec);
- if (cd->tecReverse)
-    TECDisposeConverter(cd->tecReverse);
- if (cd->sniff)
-    TECDisposeSniffer(cd->sniff);
- vim_free(cd);
- last_errno = 0;
- return 0;
-    }
-    else
-    {
- last_errno = EINVAL;
- return -1;
-    }
-}
-
-    int *
-iconv_errno()
-{
-    return &last_errno;
-}
-#endif /* MACOS_X_ICONVEMU */
-
-#ifdef USE_MCH_GETTEXT
-
-#define GETTEXT_BUFNUM 64
-#define GETTEXT_BUFSIZE 256
-
-    char *
-mch_gettext(const char *msgid)
-{
-    static char buf[GETTEXT_BUFNUM][GETTEXT_BUFSIZE];
-    static int bufnum = 0;
-    const char *msg = NULL;
-    CFStringRef strkey = NULL, strmsg = NULL;
-    CFStringEncoding enc;
-
-    if (!msgid)
- goto MCH_GETTEXT_FINISH;
-    enc = CFStringGetSystemEncoding();
-    TRACE("mch_gettext(%s)\n", msgid);
-
-    strkey = CFStringCreateWithCString(NULL, msgid, enc);
-    if (!strkey)
-    {
- TRACE("  Can't create a CFString for msgid.\n");
- goto MCH_GETTEXT_FINISH;
-    }
-
-    strmsg = CFCopyLocalizedString(strkey, NULL);
-    if (!strmsg)
-    {
- TRACE("  No localized strings for msgid.\n");
- goto MCH_GETTEXT_FINISH;
-    }
-
-    msg = CFStringGetCStringPtr(strmsg, enc);
-    if (!msg)
-    {
- /* This is as backup when CFStringGetCStringPtr was failed */
- CFStringGetCString(strmsg, buf[bufnum], GETTEXT_BUFSIZE, enc);
- msg = buf[bufnum];
- if (++bufnum >= GETTEXT_BUFNUM)
-    bufnum = 0;
-    }
-    TRACE("  Localized to: %s\n", msg);
-
-MCH_GETTEXT_FINISH:
-    if (strkey)
- CFRelease(strkey);
-    if (strmsg)
- CFRelease(strmsg);
-    return (char *)(msg ? msg : msgid);
-}
-
-    char *
-mch_bindtextdomain(const char *domain, const char *dirname)
-{
-    TRACE("mch_bindtextdomain(%s, %s)\n", domain, dirname);
-    return (char*)dirname;
-}
-
-    char *
-mch_textdomain(const char *domain)
-{
-    TRACE("mch_textdomain(%s)\n", domain);
-    return (char*)domain;
-}
-#endif
diff --git a/src/os_macosx.m b/src/os_macosx.m
new file mode 100644
index 0000000..bac5e79
--- /dev/null
+++ b/src/os_macosx.m
@@ -0,0 +1,694 @@
+/* vi:set ts=8 sts=4 sw=4:
+ *
+ * VIM - Vi IMproved by Bram Moolenaar
+ *
+ * Do ":help uganda"  in Vim to read copying and usage conditions.
+ * Do ":help credits" in Vim to see a list of people who contributed.
+ * See README.txt for an overview of the Vim source code.
+ */
+
+/*
+ * os_macosx.c -- Mac specific things for Mac OS/X.
+ */
+
+#ifdef MACOS_X_UNIX
+# ifdef HAVE_CONFIG_H    /* Using Makefile. */
+#  include "vim.h"
+# else
+#  include "os_unix.c"    /* Using Project Builder */
+# endif
+#else
+    Error: MACOS 9 is no longer supported in Vim 7
+#endif
+
+#ifdef FEAT_CLIPBOARD
+
+#include <Cocoa/Cocoa.h>
+
+void clip_mch_lose_selection(VimClipboard *cbd)
+{
+}
+
+int clip_mch_own_selection(VimClipboard *cbd)
+{
+    return OK;
+}
+
+/* copy from system clipboard, paste to vim */
+void clip_mch_set_selection(VimClipboard *cbd)
+{
+    // If the '*' register isn't already filled in, fill it in now.
+    cbd->owned = TRUE;
+    clip_get_selection(cbd);
+    cbd->owned = FALSE;
+
+    // Get the text to put on the pasteboard.
+    long_u len = 0; char_u *str = 0;
+    int type = clip_convert_selection(&str, &len, cbd);
+    if (type < 0)
+        return;
+
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
+    NSString *string = [[NSString alloc] initWithBytes: str
+                                                length: len
+                                              encoding: NSUTF8StringEncoding];
+
+    NSPasteboard *pb = [NSPasteboard generalPasteboard];
+
+    [pb declareTypes: [NSArray arrayWithObject: NSStringPboardType] owner: nil];
+    [pb setString: string
+          forType: NSStringPboardType];
+
+    [string release];
+    [pool release];
+    vim_free(str);
+}
+
+/* copy from vim, paste to system clipboard */
+void clip_mch_request_selection(VimClipboard *cbd)
+{
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
+    NSPasteboard *pb = [NSPasteboard generalPasteboard];
+    NSString *type = [pb availableTypeFromArray: [NSArray arrayWithObject: NSStringPboardType]];
+
+    if (type)
+    {
+        NSMutableString *string = [[pb stringForType: NSStringPboardType] mutableCopy];
+
+        // Replace unrecognized end-of-line sequences with \x0a (line feed).
+        NSRange range = NSMakeRange(0, [string length]);
+        unsigned n = [string replaceOccurrencesOfString: @"\x0d\x0a"
+                                             withString: @"\x0a"
+                                                options: 0
+                                                  range: range];
+        if (n == 0)
+            n = [string replaceOccurrencesOfString: @"\x0d"
+                                        withString: @"\x0a"
+                                           options: 0
+                                             range: range];
+
+        // Scan for newline character to decide whether the string should be
+        // pasted linewise or characterwise.
+        int char_type = MCHAR;
+        if (0 < n || NSNotFound != [string rangeOfString: @"\n"].location)
+            char_type = MLINE;
+
+        const char *utf8chars = [string UTF8String];
+        clip_yank_selection(char_type, (char_u*) utf8chars, strlen(utf8chars), cbd);
+    }
+
+    [pool release];
+}
+
+#endif
+
+#ifdef _DEBUG
+    void
+Trace(char* fmt, ...)
+{
+    char buf[2048];
+    va_list args;
+
+    va_start(args, fmt);
+    /* vsnprintf(buf, sizeof(buf), fmt, args);*/
+    fprintf(stderr, "%s", buf);
+    va_end(args);
+}
+#endif
+
+#ifdef MACOS_X_ICONVEMU
+/*
+ * Libiconv emulation layer
+ */
+
+struct _iconv_t
+{
+    TECObjectRef tec;
+    TECObjectRef tecReverse;
+    TECSnifferObjectRef sniff;
+    TextEncoding from;
+    TextEncoding to;
+};
+/* typedef struct _iconv_t *iconv_t; */
+
+
+static int last_errno = 0;
+
+/*
+ * Get TextEncoding from iconv's encoding name
+ */
+    static TextEncoding
+get_textencoding(const char* encodename)
+{
+    static struct {
+ const char* name;
+ TextEncoding encode;
+    } encodetable[] = {
+ /* ISO-8859 encodings family */
+ {"latin1", kTextEncodingISOLatin1},
+ {"latin2", kTextEncodingISOLatin2},
+ {"latin3", kTextEncodingISOLatin3},
+ {"latin4", kTextEncodingISOLatin4},
+ {"latin5", kTextEncodingISOLatin5},
+ {"latin6", kTextEncodingISOLatin6},
+ {"latin7", kTextEncodingISOLatin7},
+ {"latin8", kTextEncodingISOLatin8},
+ {"latin9", kTextEncodingISOLatin9},
+ {"iso-8859-1", kTextEncodingISOLatin1},
+ {"iso-8859-2", kTextEncodingISOLatin2},
+ {"iso-8859-3", kTextEncodingISOLatin3},
+ {"iso-8859-4", kTextEncodingISOLatin4},
+ {"iso-8859-5", kTextEncodingISOLatinCyrillic},
+ {"iso-8859-6", kTextEncodingISOLatinArabic},
+ {"iso-8859-7", kTextEncodingISOLatinGreek},
+ {"iso-8859-8", kTextEncodingISOLatinHebrew},
+ {"iso-8859-9", kTextEncodingISOLatin5},
+ {"iso-8859-10", kTextEncodingISOLatin6},
+ {"iso-8859-15", kTextEncodingISOLatin9},
+
+ /* Unicode encodings. */
+ /* TODO: Add other type of unicode */
+ {"ucs-2", kTextEncodingMacUnicode},
+
+ /* Japanese encoding aliases */
+ {"cp932", kTextEncodingShiftJIS},
+ {"shift-jis", kTextEncodingShiftJIS},
+ {"euc-jp", kTextEncodingEUC_JP},
+ {"iso-2022-jp", kTextEncodingISO_2022_JP},
+ {"iso-2022-jp-1", kTextEncodingISO_2022_JP_1},
+ {"iso-2022-jp-2", kTextEncodingISO_2022_JP_2},
+ {"iso-2022-jp-3", kTextEncodingISO_2022_JP_3},
+
+ /* Other aliases. These aliases in this block are just guessed. */
+ /* TODO: Must be verified. */
+ {"gb2312", kTextEncodingGB_2312_80},
+ {"cp936", kTextEncodingMacChineseSimp},
+ {"euc-cn", kTextEncodingEUC_CN},
+ {"cp950", kTextEncodingMacChineseTrad},
+ {"euc-tw", kTextEncodingEUC_TW},
+ {"cp949", kTextEncodingMacKorean},
+ {"euc-kr", kTextEncodingEUC_KR},
+
+ /*
+ * All encodings supported by Macintosh.  You can find these values
+ * in a file:
+ *  /System/Library/Frameworks/CoreServices.framework/Versions/A/
+ *    Frameworks/CarbonCore.framework/Versions/A/Headers/TextCommon.h
+ */
+ {"MacRoman", kTextEncodingMacRoman},
+ {"MacJapanese", kTextEncodingMacJapanese},
+ {"MacChineseTrad", kTextEncodingMacChineseTrad},
+ {"MacKorean", kTextEncodingMacKorean},
+ {"MacArabic", kTextEncodingMacArabic},
+ {"MacHebrew", kTextEncodingMacHebrew},
+ {"MacGreek", kTextEncodingMacGreek},
+ {"MacCyrillic", kTextEncodingMacCyrillic},
+ {"MacDevanagari", kTextEncodingMacDevanagari},
+ {"MacGurmukhi", kTextEncodingMacGurmukhi},
+ {"MacGujarati", kTextEncodingMacGujarati},
+ {"MacOriya", kTextEncodingMacOriya},
+ {"MacBengali", kTextEncodingMacBengali},
+ {"MacTamil", kTextEncodingMacTamil},
+ {"MacTelugu", kTextEncodingMacTelugu},
+ {"MacKannada", kTextEncodingMacKannada},
+ {"MacMalayalam", kTextEncodingMacMalayalam},
+ {"MacSinhalese", kTextEncodingMacSinhalese},
+ {"MacBurmese", kTextEncodingMacBurmese},
+ {"MacKhmer", kTextEncodingMacKhmer},
+ {"MacThai", kTextEncodingMacThai},
+ {"MacLaotian", kTextEncodingMacLaotian},
+ {"MacGeorgian", kTextEncodingMacGeorgian},
+ {"MacArmenian", kTextEncodingMacArmenian},
+ {"MacChineseSimp", kTextEncodingMacChineseSimp},
+ {"MacTibetan", kTextEncodingMacTibetan},
+ {"MacMongolian", kTextEncodingMacMongolian},
+ {"MacEthiopic", kTextEncodingMacEthiopic},
+ {"MacCentralEurRoman", kTextEncodingMacCentralEurRoman},
+ {"MacVietnamese", kTextEncodingMacVietnamese},
+ {"MacExtArabic", kTextEncodingMacExtArabic},
+ {"MacSymbol", kTextEncodingMacSymbol},
+ {"MacDingbats", kTextEncodingMacDingbats},
+ {"MacTurkish", kTextEncodingMacTurkish},
+ {"MacCroatian", kTextEncodingMacCroatian},
+ {"MacIcelandic", kTextEncodingMacIcelandic},
+ {"MacRomanian", kTextEncodingMacRomanian},
+ {"MacCeltic", kTextEncodingMacCeltic},
+ {"MacGaelic", kTextEncodingMacGaelic},
+ {"MacKeyboardGlyphs", kTextEncodingMacKeyboardGlyphs},
+ {"MacTradChinese", kTextEncodingMacTradChinese},
+ {"MacRSymbol", kTextEncodingMacRSymbol},
+ {"MacSimpChinese", kTextEncodingMacSimpChinese},
+ {"MacGeez", kTextEncodingMacGeez},
+ {"MacEastEurRoman", kTextEncodingMacEastEurRoman},
+ {"MacUninterp", kTextEncodingMacUninterp},
+ {"MacUnicode", kTextEncodingMacUnicode},
+ {"MacFarsi", kTextEncodingMacFarsi},
+ {"MacUkrainian", kTextEncodingMacUkrainian},
+ {"MacInuit", kTextEncodingMacInuit},
+ {"MacVT100", kTextEncodingMacVT100},
+ {"MacHFS", kTextEncodingMacHFS},
+ {"UnicodeDefault", kTextEncodingUnicodeDefault},
+ {"UnicodeV1_1", kTextEncodingUnicodeV1_1},
+ {"ISO10646_1993", kTextEncodingISO10646_1993},
+ {"UnicodeV2_0", kTextEncodingUnicodeV2_0},
+ {"UnicodeV2_1", kTextEncodingUnicodeV2_1},
+ {"UnicodeV3_0", kTextEncodingUnicodeV3_0},
+ {"UnicodeV3_1", kTextEncodingUnicodeV3_1},
+ {"UnicodeV3_2", kTextEncodingUnicodeV3_2},
+ {"ISOLatin1", kTextEncodingISOLatin1},
+ {"ISOLatin2", kTextEncodingISOLatin2},
+ {"ISOLatin3", kTextEncodingISOLatin3},
+ {"ISOLatin4", kTextEncodingISOLatin4},
+ {"ISOLatinCyrillic", kTextEncodingISOLatinCyrillic},
+ {"ISOLatinArabic", kTextEncodingISOLatinArabic},
+ {"ISOLatinGreek", kTextEncodingISOLatinGreek},
+ {"ISOLatinHebrew", kTextEncodingISOLatinHebrew},
+ {"ISOLatin5", kTextEncodingISOLatin5},
+ {"ISOLatin6", kTextEncodingISOLatin6},
+ {"ISOLatin7", kTextEncodingISOLatin7},
+ {"ISOLatin8", kTextEncodingISOLatin8},
+ {"ISOLatin9", kTextEncodingISOLatin9},
+ {"DOSLatinUS", kTextEncodingDOSLatinUS},
+ {"DOSGreek", kTextEncodingDOSGreek},
+ {"DOSBalticRim", kTextEncodingDOSBalticRim},
+ {"DOSLatin1", kTextEncodingDOSLatin1},
+ {"DOSGreek1", kTextEncodingDOSGreek1},
+ {"DOSLatin2", kTextEncodingDOSLatin2},
+ {"DOSCyrillic", kTextEncodingDOSCyrillic},
+ {"DOSTurkish", kTextEncodingDOSTurkish},
+ {"DOSPortuguese", kTextEncodingDOSPortuguese},
+ {"DOSIcelandic", kTextEncodingDOSIcelandic},
+ {"DOSHebrew", kTextEncodingDOSHebrew},
+ {"DOSCanadianFrench", kTextEncodingDOSCanadianFrench},
+ {"DOSArabic", kTextEncodingDOSArabic},
+ {"DOSNordic", kTextEncodingDOSNordic},
+ {"DOSRussian", kTextEncodingDOSRussian},
+ {"DOSGreek2", kTextEncodingDOSGreek2},
+ {"DOSThai", kTextEncodingDOSThai},
+ {"DOSJapanese", kTextEncodingDOSJapanese},
+ {"DOSChineseSimplif", kTextEncodingDOSChineseSimplif},
+ {"DOSKorean", kTextEncodingDOSKorean},
+ {"DOSChineseTrad", kTextEncodingDOSChineseTrad},
+ {"WindowsLatin1", kTextEncodingWindowsLatin1},
+ {"WindowsANSI", kTextEncodingWindowsANSI},
+ {"WindowsLatin2", kTextEncodingWindowsLatin2},
+ {"WindowsCyrillic", kTextEncodingWindowsCyrillic},
+ {"WindowsGreek", kTextEncodingWindowsGreek},
+ {"WindowsLatin5", kTextEncodingWindowsLatin5},
+ {"WindowsHebrew", kTextEncodingWindowsHebrew},
+ {"WindowsArabic", kTextEncodingWindowsArabic},
+ {"WindowsBalticRim", kTextEncodingWindowsBalticRim},
+ {"WindowsVietnamese", kTextEncodingWindowsVietnamese},
+ {"WindowsKoreanJohab", kTextEncodingWindowsKoreanJohab},
+ {"US_ASCII", kTextEncodingUS_ASCII},
+ {"JIS_X0201_76", kTextEncodingJIS_X0201_76},
+ {"JIS_X0208_83", kTextEncodingJIS_X0208_83},
+ {"JIS_X0208_90", kTextEncodingJIS_X0208_90},
+ {"JIS_X0212_90", kTextEncodingJIS_X0212_90},
+ {"JIS_C6226_78", kTextEncodingJIS_C6226_78},
+ {"ShiftJIS_X0213_00", kTextEncodingShiftJIS_X0213_00},
+ {"GB_2312_80", kTextEncodingGB_2312_80},
+ {"GBK_95", kTextEncodingGBK_95},
+ {"GB_18030_2000", kTextEncodingGB_18030_2000},
+ {"KSC_5601_87", kTextEncodingKSC_5601_87},
+ {"KSC_5601_92_Johab", kTextEncodingKSC_5601_92_Johab},
+ {"CNS_11643_92_P1", kTextEncodingCNS_11643_92_P1},
+ {"CNS_11643_92_P2", kTextEncodingCNS_11643_92_P2},
+ {"CNS_11643_92_P3", kTextEncodingCNS_11643_92_P3},
+ {"ISO_2022_JP", kTextEncodingISO_2022_JP},
+ {"ISO_2022_JP_2", kTextEncodingISO_2022_JP_2},
+ {"ISO_2022_JP_1", kTextEncodingISO_2022_JP_1},
+ {"ISO_2022_JP_3", kTextEncodingISO_2022_JP_3},
+ {"ISO_2022_CN", kTextEncodingISO_2022_CN},
+ {"ISO_2022_CN_EXT", kTextEncodingISO_2022_CN_EXT},
+ {"ISO_2022_KR", kTextEncodingISO_2022_KR},
+ {"EUC_JP", kTextEncodingEUC_JP},
+ {"EUC_CN", kTextEncodingEUC_CN},
+ {"EUC_TW", kTextEncodingEUC_TW},
+ {"EUC_KR", kTextEncodingEUC_KR},
+ {"ShiftJIS", kTextEncodingShiftJIS},
+ {"KOI8_R", kTextEncodingKOI8_R},
+ {"Big5", kTextEncodingBig5},
+ {"MacRomanLatin1", kTextEncodingMacRomanLatin1},
+ {"HZ_GB_2312", kTextEncodingHZ_GB_2312},
+ {"Big5_HKSCS_1999", kTextEncodingBig5_HKSCS_1999},
+ {"NextStepLatin", kTextEncodingNextStepLatin},
+ {"EBCDIC_US", kTextEncodingEBCDIC_US},
+ {"EBCDIC_CP037", kTextEncodingEBCDIC_CP037},
+ {"MultiRun", kTextEncodingMultiRun},
+
+ /* Terminator */
+ {NULL, -1},
+    };
+    int i;
+
+    i = 0;
+    for (i = 0; encodetable[i].name != NULL; ++i)
+    {
+ if (STRICMP(encodename, encodetable[i].name) == 0)
+    break;
+    }
+    return encodetable[i].encode;
+}
+
+/*
+ * iconv interfaces
+ */
+
+    iconv_t
+iconv_open(const char* tocode, const char* fromcode)
+{
+    TextEncoding toEnc, fromEnc;
+    iconv_t cd = NULL;
+    OSStatus st;
+
+    /* Verify to/from encoding name */
+    toEnc = get_textencoding(tocode);
+    fromEnc = get_textencoding(fromcode);
+    if (toEnc < 0 || fromEnc < 0)
+ goto ICONV_OPEN_ERR;
+
+    /* Allocate memory to object */
+    cd = (iconv_t)alloc(sizeof(struct _iconv_t));
+    if (!cd)
+ goto ICONV_OPEN_ERR;
+    memset(cd, 0, sizeof(struct _iconv_t));
+
+    /* Create converter */
+    if (fromEnc != toEnc)
+    {
+ TRACE("*** fromEnc=%d toEnc=%d\n", (int)fromEnc, (int)toEnc);
+ st = TECCreateConverter(&cd->tec, fromEnc, toEnc);
+ if (st != 0)
+ {
+    TRACE("*** TECCreateConverter()=%d\n", (int)st);
+    goto ICONV_OPEN_ERR;
+ }
+ /* Create reverse converter */
+ st = TECCreateConverter(&cd->tecReverse, toEnc, fromEnc);
+ if (st != 0)
+ {
+    TRACE("*** TECCreateConverter()=%d (reverse)\n", (int)st);
+    goto ICONV_OPEN_ERR;
+ }
+ /* Create Sniffer */
+ st = TECCreateSniffer(&cd->sniff, &fromEnc, 1);
+ if (st != 0)
+ {
+    TRACE("*** TECCreateSniffer()=%d\n", (int)st);
+    goto ICONV_OPEN_ERR;
+ }
+    }
+
+    cd->from = fromEnc;
+    cd->to = toEnc;
+    last_errno = 0;
+    return cd;
+
+ICONV_OPEN_ERR:
+    if (cd)
+ iconv_close(cd);
+    last_errno = EINVAL;
+    return (iconv_t)-1;
+}
+
+/*
+ * Used when there are same value in 'from encoding' and 'to encoding'.
+ * TEC doesn't support conversion between same encodings, and
+ * TECCreateConverter() failed.
+ */
+    static size_t
+null_conv(iconv_t cd, const char **inbuf, size_t *inbytesleft,
+ char **outbuf, size_t *outbytesleft)
+{
+    const char* buf_in = inbuf && *inbuf ? *inbuf : NULL;
+    char* buf_out = outbuf && *outbuf ? *outbuf : NULL;
+
+    if (buf_in)
+    {
+ int in_len = inbytesleft ? *inbytesleft : 0;
+ int out_len = outbytesleft ? *outbytesleft : 0;
+
+ if (!buf_out || out_len <= 0)
+ {
+    last_errno = E2BIG;
+    return -1;
+ }
+ else if (in_len > 0)
+ {
+    int len = in_len < out_len ? in_len : out_len;
+
+    memcpy (buf_out, buf_in, len);
+    *inbuf += len;
+    *outbuf += len;
+    *inbytesleft -= len;
+    *outbytesleft -= len;
+    if (*outbytesleft <= 0)
+    {
+ last_errno = E2BIG;
+ return -1;
+    }
+ }
+    }
+    last_errno = 0;
+    return 0;
+}
+
+    size_t
+iconv(iconv_t cd, const char **inbuf, size_t *inbytesleft,
+ char **outbuf, size_t *outbytesleft)
+{
+    ConstTextPtr    buf_in;
+    TextPtr    buf_out;
+    ByteCount    out_len, out_true;
+    ByteCount    in_len, in_true;
+    OSStatus    st;
+
+    if (!cd)
+    {
+ last_errno = ENOENT; /* TODO: Another error code should be set */
+ return -1;
+    }
+    if (cd->from == cd->to)
+ return null_conv(cd, inbuf, inbytesleft, outbuf, outbytesleft) ;
+
+    buf_in = (TextPtr) inbuf ;
+    buf_out = (TextPtr) outbuf ;
+    out_len = out_true = -1;
+    in_len = in_true = -1;
+
+    if (buf_in && buf_out)
+    {
+ ItemCount error, feature;
+
+ /* Normal convert mode */
+ if (!inbytesleft || !outbytesleft)
+ {
+    last_errno = EFAULT;
+    return -1;
+ }
+ in_len = *inbytesleft;
+ out_len = *outbytesleft;
+
+ /* Check stream is form in expected encoding or not */
+ st = TECSniffTextEncoding(cd->sniff, (TextPtr)buf_in, in_len,
+ &cd->from, 1, &error, 1, &feature, 1);
+ TRACE("TECSniffTextEncoding()=%d error=%d feature=%d\n",
+ (int)st, (int)error, (int)feature);
+ if ((error != 0 || feature == 0)
+ && !(error == 0xffffffff && feature == 0xffffffff))
+    /* Not expected encoding */
+    st = kTECUnmappableElementErr;
+ else
+ {
+    /* Do convert */
+    st = TECConvertText(cd->tec,
+    buf_in, in_len, &in_true,
+    buf_out, out_len, &out_true);
+    /* Verify converted text.  Compare original text with reverse
+     * converted text.  If not match, there is some problem on
+     * converting. */
+    if (st == 0 && in_true > 0)
+    {
+ ByteCount rev_in, rev_out;
+ TextPtr buf_rev = (TextPtr)alloc(in_true);
+
+ if (buf_rev)
+ {
+    st = TECConvertText(cd->tecReverse,
+    buf_out, out_true, &rev_in,
+    buf_rev, in_true, &rev_out);
+    if (st != 0 || rev_in != out_true || rev_out != in_true
+    || memcmp(buf_rev, buf_in, rev_out) != 0)
+    {
+#ifdef ICONVOSX_DEBUG
+ fprintf(stderr, "  reverse conversion failed.\n");
+#endif
+ st = kTECUnmappableElementErr;
+    }
+    vim_free(buf_rev);
+ }
+ else
+    st = kTECUnmappableElementErr;
+    }
+ }
+    }
+    else if (!buf_in && buf_out)
+    {
+ /* Flush all buffered strings to buffer, and reset status */
+ if (!outbytesleft)
+ {
+    last_errno = EFAULT;
+    return -1;
+ }
+ out_len = *outbytesleft;
+ st = TECFlushText(cd->tec,
+ buf_out, out_len, &out_true);
+    }
+    else if (!buf_in && !buf_out)
+    {
+ /* Reset cd's status and cancel buffered strings */
+ unsigned char tmp_out[256];
+
+ buf_out = tmp_out;
+ out_len = sizeof(tmp_out);
+ st = TECFlushText(cd->tec,
+ buf_out, out_len, &out_true);
+    }
+    else
+    {
+ last_errno = EFAULT;
+ return -1;
+    }
+    TRACE("st=%d, buf_in=%p, in_len=%d, in_true=%d\n"
+    "  buf_out=%p, out_len=%d, out_true=%d\n", (int)st,
+    buf_in, (int)in_len, (int)in_true,
+    buf_out, (int)out_len, (int)out_true);
+
+    switch (st)
+    {
+ case 0:
+    /* No error */
+    if (inbytesleft)
+ *inbytesleft -= in_true;
+    if (outbytesleft)
+ *outbytesleft -= out_true;
+    if (inbuf && *inbuf)
+ *inbuf += in_true;
+    if (outbuf && *outbuf)
+ *outbuf += out_true;
+    last_errno = 0;
+    return 0; /* No error */
+ case kTECUnmappableElementErr:
+    last_errno = EILSEQ;
+ case kTECIncompleteElementErr:
+    last_errno = EINVAL;
+ case kTECOutputBufferFullStatus:
+    last_errno = E2BIG;
+    return -1;
+ default:
+    TRACE("iconv(%p, %p, %p, %p, %p) failed. (%d)\n",
+    cd, inbuf, inbytesleft, outbuf, outbytesleft, (int)st);
+    last_errno = EFAULT;
+    return -1;
+    }
+}
+
+    int
+iconv_close(iconv_t cd)
+{
+    if (cd)
+    {
+ /* Free all elements of iconv_t */
+ if (cd->tec)
+    TECDisposeConverter(cd->tec);
+ if (cd->tecReverse)
+    TECDisposeConverter(cd->tecReverse);
+ if (cd->sniff)
+    TECDisposeSniffer(cd->sniff);
+ vim_free(cd);
+ last_errno = 0;
+ return 0;
+    }
+    else
+    {
+ last_errno = EINVAL;
+ return -1;
+    }
+}
+
+    int *
+iconv_errno()
+{
+    return &last_errno;
+}
+#endif /* MACOS_X_ICONVEMU */
+
+#ifdef USE_MCH_GETTEXT
+
+#define GETTEXT_BUFNUM 64
+#define GETTEXT_BUFSIZE 256
+
+    char *
+mch_gettext(const char *msgid)
+{
+    static char buf[GETTEXT_BUFNUM][GETTEXT_BUFSIZE];
+    static int bufnum = 0;
+    const char *msg = NULL;
+    CFStringRef strkey = NULL, strmsg = NULL;
+    CFStringEncoding enc;
+
+    if (!msgid)
+ goto MCH_GETTEXT_FINISH;
+    enc = CFStringGetSystemEncoding();
+    TRACE("mch_gettext(%s)\n", msgid);
+
+    strkey = CFStringCreateWithCString(NULL, msgid, enc);
+    if (!strkey)
+    {
+ TRACE("  Can't create a CFString for msgid.\n");
+ goto MCH_GETTEXT_FINISH;
+    }
+
+    strmsg = CFCopyLocalizedString(strkey, NULL);
+    if (!strmsg)
+    {
+ TRACE("  No localized strings for msgid.\n");
+ goto MCH_GETTEXT_FINISH;
+    }
+
+    msg = CFStringGetCStringPtr(strmsg, enc);
+    if (!msg)
+    {
+ /* This is as backup when CFStringGetCStringPtr was failed */
+ CFStringGetCString(strmsg, buf[bufnum], GETTEXT_BUFSIZE, enc);
+ msg = buf[bufnum];
+ if (++bufnum >= GETTEXT_BUFNUM)
+    bufnum = 0;
+    }
+    TRACE("  Localized to: %s\n", msg);
+
+MCH_GETTEXT_FINISH:
+    if (strkey)
+ CFRelease(strkey);
+    if (strmsg)
+ CFRelease(strmsg);
+    return (char *)(msg ? msg : msgid);
+}
+
+    char *
+mch_bindtextdomain(const char *domain, const char *dirname)
+{
+    TRACE("mch_bindtextdomain(%s, %s)\n", domain, dirname);
+    return (char*)dirname;
+}
+
+    char *
+mch_textdomain(const char *domain)
+{
+    TRACE("mch_textdomain(%s)\n", domain);
+    return (char*)domain;
+}
+#endif
diff --git a/src/vim.h b/src/vim.h
index 0370b53..98d8af1 100644
--- a/src/vim.h
+++ b/src/vim.h
@@ -74,6 +74,7 @@
 #endif
 #if defined(MACOS_X_UNIX)
 # define MACOS_X
+# define FEAT_CLIPBOARD
 # ifndef HAVE_CONFIG_H
 #  define UNIX
 # endif
--
1.6.0.4


--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [PATCH] Add clipboard support for running without GUI in Mac OS X

Björn Winckler

2009/8/1 Jjgod Jiang <[hidden email]>:

>
> Running vim under Mac OS X terminal do not support copy to/from
> system clipboard currently, this patch add this feature. To have
> this feature in mainstream, we receive the following benifits:
>
> 1. We can copy from/to system clipboard without running GUI.
>   (Default vim builds shipped with Mac OS X do not have GUI
>    enabled, so it can share this feature.)
> 2. We don't need to duplicate code in GUI implementations like
>   MacVim or vim-cocoa.
>
> The clipboard handling code is derived from MacVim.
>
> To use Cocoa APIs, we need to convert os_macosx.c into an Obj-C
> file. Other changes are trivial.

A few comments on this patch:

1. Why have you not included the code that handles block-wise copy in
clip_mch_request_selection() from the MacVim sources?  This is a bad
idea since it means that every time you copy from Vim the pasteboard
will only keep a "line-wise" copy.  E.g. if you enter visual block
mode, copy, then paste, the text will be pasted line-wise even though
it should be pasted block-wise.  Why did you "derive" the clipboard
code from MacVim instead of just copying it?

2. I'm not decided on this myself, but maybe it would be cleaner to
implement this using the Carbon Pasteboard Manager instead of using
Cocoa (so that you don't have to use the Objective-C compiler, fiddle
around with autorelease pools, link against Cocoa etc.):

http://developer.apple.com/documentation/Carbon/Reference/Pasteboard_Reference/Reference/reference.html


At any rate, I would not merge this patch until #1 is resolved.  The
second issue is more delicate but I have myself implemented copy/paste
using Pasteboard Manager once and I know that it is not that much of
an effort, but then again the current MacVim clipboard code works and
has been in use for quite some time so it is maybe a better idea to
just include it verbatim.

Björn

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [PATCH] Add clipboard support for running without GUI in Mac OS X

Jiang Jiang

Hi,

On Sat, Aug 1, 2009 at 10:45 PM, björn<[hidden email]> wrote:
> A few comments on this patch:
>
> 1. Why have you not included the code that handles block-wise copy in
> clip_mch_request_selection() from the MacVim sources?  This is a bad
> idea since it means that every time you copy from Vim the pasteboard
> will only keep a "line-wise" copy.  E.g. if you enter visual block
> mode, copy, then paste, the text will be pasted line-wise even though
> it should be pasted block-wise.  Why did you "derive" the clipboard
> code from MacVim instead of just copying it?

Because that code was included in vim-cocoa long time ago, you are right,
I should have checked the recent MacVim code before send out this patch.

> 2. I'm not decided on this myself, but maybe it would be cleaner to
> implement this using the Carbon Pasteboard Manager instead of using
> Cocoa (so that you don't have to use the Objective-C compiler, fiddle
> around with autorelease pools, link against Cocoa etc.):
>
> http://developer.apple.com/documentation/Carbon/Reference/Pasteboard_Reference/Reference/reference.html

I think Pasteboard Manager belongs to the part of Carbon that won't
have 64-bit version. So it will prevent vim to be built as a 64-bit
binary in future Mac OS X releases.

> At any rate, I would not merge this patch until #1 is resolved.  The
> second issue is more delicate but I have myself implemented copy/paste
> using Pasteboard Manager once and I know that it is not that much of
> an effort, but then again the current MacVim clipboard code works and
> has been in use for quite some time so it is maybe a better idea to
> just include it verbatim.

I agree. Would you like me to update this patch or maybe you prefer to
separate that part of the code in MacVim as one patch yourself?

- Jiang

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [PATCH] Add clipboard support for running without GUI in Mac OS X

Björn Winckler

2009/8/1 Jjgod Jiang:

>
> On Sat, Aug 1, 2009 at 10:45 PM, björn<[hidden email]> wrote:
>> A few comments on this patch:
>>
>> 1. Why have you not included the code that handles block-wise copy in
>> clip_mch_request_selection() from the MacVim sources?  This is a bad
>> idea since it means that every time you copy from Vim the pasteboard
>> will only keep a "line-wise" copy.  E.g. if you enter visual block
>> mode, copy, then paste, the text will be pasted line-wise even though
>> it should be pasted block-wise.  Why did you "derive" the clipboard
>> code from MacVim instead of just copying it?
>
> Because that code was included in vim-cocoa long time ago, you are right,
> I should have checked the recent MacVim code before send out this patch.

Ok.

>> 2. I'm not decided on this myself, but maybe it would be cleaner to
>> implement this using the Carbon Pasteboard Manager instead of using
>> Cocoa (so that you don't have to use the Objective-C compiler, fiddle
>> around with autorelease pools, link against Cocoa etc.):
>>
>> http://developer.apple.com/documentation/Carbon/Reference/Pasteboard_Reference/Reference/reference.html
>
> I think Pasteboard Manager belongs to the part of Carbon that won't
> have 64-bit version. So it will prevent vim to be built as a 64-bit
> binary in future Mac OS X releases.

Can you back that statement up?  Looking at the docs I cannot see any
warning about it not being available for 64 bit.

Also, have you checked how much of an overhead in binary sizes it is
building with obj-c and linking against Cocoa?  (I assume it should
not make much of a difference but it would be nice to know for sure.
If the binary size increases significantly then I definitely think it
would be advisable to use Pasteboard Manager.)

Also, have you made sure that all the APIs used are present in OS X
10.0?  For MacVim I only check 10.4 compatibility but since this patch
is to os_macosx.c it should work on 10.0 and upwards.

>> At any rate, I would not merge this patch until #1 is resolved.  The
>> second issue is more delicate but I have myself implemented copy/paste
>> using Pasteboard Manager once and I know that it is not that much of
>> an effort, but then again the current MacVim clipboard code works and
>> has been in use for quite some time so it is maybe a better idea to
>> just include it verbatim.
>
> I agree. Would you like me to update this patch or maybe you prefer to
> separate that part of the code in MacVim as one patch yourself?

Maybe the best idea would be if you submit this patch against both the
MacVim sources and the Vim sources.  I can merge the patch immediately
and then Bram can merge the corresponding patch into the Vim sources
after we've tested it out for a while and checked that everything is
ok.

I think its good that you're taking the time to fix this...I was
hoping that somebody would.

Thanks,
Björn

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [PATCH] Add clipboard support for running without GUI in Mac OS X

Bram Moolenaar
In reply to this post by Jiang Jiang

Jjgod Jiang wrote (a long time ago):

> Running vim under Mac OS X terminal do not support copy to/from
> system clipboard currently, this patch add this feature. To have
> this feature in mainstream, we receive the following benifits:
>
> 1. We can copy from/to system clipboard without running GUI.
>    (Default vim builds shipped with Mac OS X do not have GUI
>     enabled, so it can share this feature.)
> 2. We don't need to duplicate code in GUI implementations like
>    MacVim or vim-cocoa.
>
> The clipboard handling code is derived from MacVim.
>
> To use Cocoa APIs, we need to convert os_macosx.c into an Obj-C
> file. Other changes are trivial.

A few remarks were made after this patch was submitted, but I don't
think I ever saw an updated patch.  Is it still coming?

--
FATHER:       Make sure the Prince doesn't leave this room until I come and
              get him.
FIRST GUARD:  Not ... to leave the room ... even if you come and get him.
FATHER:       No.  Until I come and get him.
SECOND GUARD: Hic.
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

 /// Bram Moolenaar -- [hidden email] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\        download, build and distribute -- http://www.A-A-P.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [PATCH] Add clipboard support for running without GUI in Mac OS X

Björn Winckler
On 11 July 2010 16:45, Bram Moolenaar wrote:

>
> Jjgod Jiang wrote (a long time ago):
>
>> Running vim under Mac OS X terminal do not support copy to/from
>> system clipboard currently, this patch add this feature. To have
>> this feature in mainstream, we receive the following benifits:
>>
>> 1. We can copy from/to system clipboard without running GUI.
>>    (Default vim builds shipped with Mac OS X do not have GUI
>>     enabled, so it can share this feature.)
>> 2. We don't need to duplicate code in GUI implementations like
>>    MacVim or vim-cocoa.
>>
>> The clipboard handling code is derived from MacVim.
>>
>> To use Cocoa APIs, we need to convert os_macosx.c into an Obj-C
>> file. Other changes are trivial.
>
> A few remarks were made after this patch was submitted, but I don't
> think I ever saw an updated patch.  Is it still coming?

I made the remark that it would be "nicer" to use the C-API (Core
Foundation) to implement Copy/Paste instead of converting os_macosx.c
to an Objective-C file and then using the MacVim Copy/Paste code which
uses the Objective-C API (Foundation).

It would not be very difficult to write such a patch but I don't think
anybody ever volunteered to do it.  The advantages of rewriting the
patch are mostly aesthetic -- the functionality would be identical.
If you Bram can live with that then I think it is safe to merge this
patch (here is one of the problems though: since the patch renames a
whole file it is a bit tricky to review -- I believe it is fine but
have not checked it myself).  If you would prefer not to use
Objective-C then it is possible to rewrite it using only C.

What would you prefer Bram?

Björn

--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [PATCH] Add clipboard support for running without GUI in Mac OS X

Bram Moolenaar

Jjgod Jiang wrote (a long time ago):

> >> Running vim under Mac OS X terminal do not support copy to/from
> >> system clipboard currently, this patch add this feature. To have
> >> this feature in mainstream, we receive the following benifits:
> >>
> >> 1. We can copy from/to system clipboard without running GUI.
> >> =A0 =A0(Default vim builds shipped with Mac OS X do not have GUI
> >> =A0 =A0 enabled, so it can share this feature.)
> >> 2. We don't need to duplicate code in GUI implementations like
> >> =A0 =A0MacVim or vim-cocoa.
> >>
> >> The clipboard handling code is derived from MacVim.
> >>
> >> To use Cocoa APIs, we need to convert os_macosx.c into an Obj-C
> >> file. Other changes are trivial.
> >
> > A few remarks were made after this patch was submitted, but I don't
> > think I ever saw an updated patch. =A0Is it still coming?
>
> I made the remark that it would be "nicer" to use the C-API (Core
> Foundation) to implement Copy/Paste instead of converting os_macosx.c
> to an Objective-C file and then using the MacVim Copy/Paste code which
> uses the Objective-C API (Foundation).
>
> It would not be very difficult to write such a patch but I don't think
> anybody ever volunteered to do it.  The advantages of rewriting the
> patch are mostly aesthetic -- the functionality would be identical.
> If you Bram can live with that then I think it is safe to merge this
> patch (here is one of the problems though: since the patch renames a
> whole file it is a bit tricky to review -- I believe it is fine but
> have not checked it myself).  If you would prefer not to use
> Objective-C then it is possible to rewrite it using only C.
>
> What would you prefer Bram?

I don't know enough about the advantages and disadvantages.  I think at
least the issues with block mode should be fixed.  Otherwise one can
just as well use the clipboard throught the terminal, right?

When going with Objective-C, would there be disadvantages?  Some people
who can't build the binary?  Does the executable become bigger?  More
dependencies on libraries?

--
You got to work at a mill?  Lucky!  I got sent back to work in the
acid-mines for my daily crust of stale bread... which not even the
birds would eat.

 /// Bram Moolenaar -- [hidden email] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\        download, build and distribute -- http://www.A-A-P.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Add clipboard support for running without GUI in Mac OS X

Bee-16
On Jul 11, 2:20 pm, Bram Moolenaar <[hidden email]> wrote:

> Jjgod Jiang wrote (a long time ago):
> > >> Running vim under Mac OS X terminal do not support copy to/from
> > >> system clipboard currently, this patch add this feature. To have
> > >> this feature in mainstream, we receive the following benifits:
>
> > >> 1. We can copy from/to system clipboard without running GUI.
> > >> =A0 =A0(Default vim builds shipped with Mac OS X do not have GUI
> > >> =A0 =A0 enabled, so it can share this feature.)
> > >> 2. We don't need to duplicate code in GUI implementations like
> > >> =A0 =A0MacVim or vim-cocoa.
>
> > >> The clipboard handling code is derived from MacVim.
>
> > >> To use Cocoa APIs, we need to convert os_macosx.c into an Obj-C
> > >> file. Other changes are trivial.
>
> > > A few remarks were made after this patch was submitted, but I don't
> > > think I ever saw an updated patch. =A0Is it still coming?
>
> > I made the remark that it would be "nicer" to use the C-API (Core
> > Foundation) to implement Copy/Paste instead of converting os_macosx.c
> > to an Objective-C file and then using the MacVim Copy/Paste code which
> > uses the Objective-C API (Foundation).
>
> > It would not be very difficult to write such a patch but I don't think
> > anybody ever volunteered to do it.  The advantages of rewriting the
> > patch are mostly aesthetic -- the functionality would be identical.
> > If you Bram can live with that then I think it is safe to merge this
> > patch (here is one of the problems though: since the patch renames a
> > whole file it is a bit tricky to review -- I believe it is fine but
> > have not checked it myself).  If you would prefer not to use
> > Objective-C then it is possible to rewrite it using only C.
>
> > What would you prefer Bram?
>
> I don't know enough about the advantages and disadvantages.  I think at
> least the issues with block mode should be fixed.  Otherwise one can
> just as well use the clipboard throught the terminal, right?
>
> When going with Objective-C, would there be disadvantages?  Some people
> who can't build the binary?  Does the executable become bigger?  More
> dependencies on libraries?

What would be the advantage over using:

vmap ,y y:call system("pbcopy", getreg("\""))<CR>
nmap ,p :call setreg("\"",system("pbpaste"))<CR>p

And some syntactic sugar for mapping?

-Bill

--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Add clipboard support for running without GUI in Mac OS X

Bram Moolenaar

> On Jul 11, 2:20 pm, Bram Moolenaar <[hidden email]> wrote:
> > Jjgod Jiang wrote (a long time ago):
> > > >> Running vim under Mac OS X terminal do not support copy to/from
> > > >> system clipboard currently, this patch add this feature. To have
> > > >> this feature in mainstream, we receive the following benifits:
> >
> > > >> 1. We can copy from/to system clipboard without running GUI.
> > > >> =A0 =A0(Default vim builds shipped with Mac OS X do not have GUI
> > > >> =A0 =A0 enabled, so it can share this feature.)
> > > >> 2. We don't need to duplicate code in GUI implementations like
> > > >> =A0 =A0MacVim or vim-cocoa.
> >
> > > >> The clipboard handling code is derived from MacVim.
> >
> > > >> To use Cocoa APIs, we need to convert os_macosx.c into an Obj-C
> > > >> file. Other changes are trivial.
> >
> > > > A few remarks were made after this patch was submitted, but I don't
> > > > think I ever saw an updated patch. =A0Is it still coming?
> >
> > > I made the remark that it would be "nicer" to use the C-API (Core
> > > Foundation) to implement Copy/Paste instead of converting os_macosx.c
> > > to an Objective-C file and then using the MacVim Copy/Paste code which
> > > uses the Objective-C API (Foundation).
> >
> > > It would not be very difficult to write such a patch but I don't think
> > > anybody ever volunteered to do it.  The advantages of rewriting the
> > > patch are mostly aesthetic -- the functionality would be identical.
> > > If you Bram can live with that then I think it is safe to merge this
> > > patch (here is one of the problems though: since the patch renames a
> > > whole file it is a bit tricky to review -- I believe it is fine but
> > > have not checked it myself).  If you would prefer not to use
> > > Objective-C then it is possible to rewrite it using only C.
> >
> > > What would you prefer Bram?
> >
> > I don't know enough about the advantages and disadvantages.  I think at
> > least the issues with block mode should be fixed.  Otherwise one can
> > just as well use the clipboard throught the terminal, right?
> >
> > When going with Objective-C, would there be disadvantages?  Some people
> > who can't build the binary?  Does the executable become bigger?  More
> > dependencies on libraries?
>
> What would be the advantage over using:
>
> vmap ,y y:call system("pbcopy", getreg("\""))<CR>
> nmap ,p :call setreg("\"",system("pbpaste"))<CR>p
>
> And some syntactic sugar for mapping?

Not being able to pass block-wise selection.

--
Q:  Why do ducks have flat feet?
A:  To stamp out forest fires.

Q:  Why do elephants have flat feet?
A:  To stamp out flaming ducks.

 /// Bram Moolenaar -- [hidden email] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\        download, build and distribute -- http://www.A-A-P.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Add clipboard support for running without GUI in Mac OS X

Björn Winckler
On 12 July 2010 17:10, Bram Moolenaar wrote:

>
>> On Jul 11, 2:20 pm, Bram Moolenaar <[hidden email]> wrote:
>> > Jjgod Jiang wrote (a long time ago):
>> > > >> Running vim under Mac OS X terminal do not support copy to/from
>> > > >> system clipboard currently, this patch add this feature. To have
>> > > >> this feature in mainstream, we receive the following benifits:
>> >
>> > > >> 1. We can copy from/to system clipboard without running GUI.
>> > > >> =A0 =A0(Default vim builds shipped with Mac OS X do not have GUI
>> > > >> =A0 =A0 enabled, so it can share this feature.)
>> > > >> 2. We don't need to duplicate code in GUI implementations like
>> > > >> =A0 =A0MacVim or vim-cocoa.
>> >
>> > > >> The clipboard handling code is derived from MacVim.
>> >
>> > > >> To use Cocoa APIs, we need to convert os_macosx.c into an Obj-C
>> > > >> file. Other changes are trivial.
>> >
>> > > > A few remarks were made after this patch was submitted, but I don't
>> > > > think I ever saw an updated patch. =A0Is it still coming?
>> >
>> > > I made the remark that it would be "nicer" to use the C-API (Core
>> > > Foundation) to implement Copy/Paste instead of converting os_macosx.c
>> > > to an Objective-C file and then using the MacVim Copy/Paste code which
>> > > uses the Objective-C API (Foundation).
>> >
>> > > It would not be very difficult to write such a patch but I don't think
>> > > anybody ever volunteered to do it.  The advantages of rewriting the
>> > > patch are mostly aesthetic -- the functionality would be identical.
>> > > If you Bram can live with that then I think it is safe to merge this
>> > > patch (here is one of the problems though: since the patch renames a
>> > > whole file it is a bit tricky to review -- I believe it is fine but
>> > > have not checked it myself).  If you would prefer not to use
>> > > Objective-C then it is possible to rewrite it using only C.
>> >
>> > > What would you prefer Bram?
>> >
>> > I don't know enough about the advantages and disadvantages.  I think at
>> > least the issues with block mode should be fixed.  Otherwise one can
>> > just as well use the clipboard throught the terminal, right?
>> >
>> > When going with Objective-C, would there be disadvantages?  Some people
>> > who can't build the binary?  Does the executable become bigger?  More
>> > dependencies on libraries?
>>
>> What would be the advantage over using:
>>
>> vmap ,y y:call system("pbcopy", getreg("\""))<CR>
>> nmap ,p :call setreg("\"",system("pbpaste"))<CR>p
>>
>> And some syntactic sugar for mapping?
>
> Not being able to pass block-wise selection.

...and I just had a more careful look: this patch does not include the
block-wise
selection code for copy/paste that is in MacVim.

Bram: do not merge this patch.  It will have to be either rewritten or
updated to include the latest MacVim copy/paste code.  I'll see if
have some time to spare to take a look at it, otherwise I guess we'll
have to wait until Vim 7.4.

Björn

--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Add clipboard support for running without GUI in Mac OS X

Björn Winckler
On 12 July 2010 17:48, björn wrote:
>
> Bram: do not merge this patch.  It will have to be either rewritten or
> updated to include the latest MacVim copy/paste code.  I'll see if
> have some time to spare to take a look at it, otherwise I guess we'll
> have to wait until Vim 7.4.

I looked into this issue carefully now and decided it is best to
convert os_macosx.c to Obj-C and have attached an updated patch which
includes block-wise copy/paste (the old patch had issues with linking
as well).

The only cons to using Obj-C are insignificant:

- executable size is not significantly increased (Carbon=2350496 vs.
Cocoa=2373944)
- there are more dependencies but only on dynamic libraries that come
with all Mac OS X versions

...but there are pros:

- Should work on _all_ Mac OS X versions, whereas the C API is only
supported on 10.3+
- Future proof (Apple has made it quite clear that Cocoa is the way forward)

The copy/paste code is taken directly from MacVim and has been used by
many people for years now so it should be considered stable -- I would
say the patch is ready for merging.

There is one issue: the Carbon GUI no longer compiles (Mac OS X 10.6)
so I cannot confirm that it still builds (I had to do some
modifications to configure.in).  Since this is likely to give a bad
impression to anybody building from source I have made NO GUI default
(i.e. you have to explicitly enable the GUI in configure).  The Carbon
GUI is dead anyway so I do not think this is a major issue but I
thought I should mention it.

I have made sure the copy/paste build with tiny builds, with/without
multibyte etc.

Björn

--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

0001-Add-clipboard-support-to-Mac-OS-X.patch.zip (237K) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Add clipboard support for running without GUI in Mac OS X

Björn Winckler
On 12 July 2010 21:04, björn wrote:
>
> I looked into this issue carefully now and decided it is best to
> convert os_macosx.c to Obj-C and have attached an updated patch which
> includes block-wise copy/paste (the old patch had issues with linking
> as well).
>

I accidentally included auto/config.mk in the patch...attaching a new
one.  Sorry about that.

Björn

--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

0001-Add-clipboard-support-to-Mac-OS-X.patch.zip (235K) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Add clipboard support for running without GUI in Mac OS X

Bram Moolenaar
In reply to this post by Björn Winckler

Björn Winckler wrote:

> On 12 July 2010 17:48, björn wrote:
> >
> > Bram: do not merge this patch.  It will have to be either rewritten or
> > updated to include the latest MacVim copy/paste code.  I'll see if
> > have some time to spare to take a look at it, otherwise I guess we'll
> > have to wait until Vim 7.4.
>
> I looked into this issue carefully now and decided it is best to
> convert os_macosx.c to Obj-C and have attached an updated patch which
> includes block-wise copy/paste (the old patch had issues with linking
> as well).
>
> The only cons to using Obj-C are insignificant:
>
> - executable size is not significantly increased (Carbon=2350496 vs.
> Cocoa=2373944)
> - there are more dependencies but only on dynamic libraries that come
> with all Mac OS X versions
>
> ...but there are pros:
>
> - Should work on _all_ Mac OS X versions, whereas the C API is only
> supported on 10.3+
> - Future proof (Apple has made it quite clear that Cocoa is the way forward)
>
> The copy/paste code is taken directly from MacVim and has been used by
> many people for years now so it should be considered stable -- I would
> say the patch is ready for merging.
>
> There is one issue: the Carbon GUI no longer compiles (Mac OS X 10.6)
> so I cannot confirm that it still builds (I had to do some
> modifications to configure.in).  Since this is likely to give a bad
> impression to anybody building from source I have made NO GUI default
> (i.e. you have to explicitly enable the GUI in configure).  The Carbon
> GUI is dead anyway so I do not think this is a major issue but I
> thought I should mention it.
>
> I have made sure the copy/paste build with tiny builds, with/without
> multibyte etc.

Great, thanks.  I'll try it out, hopefully this week.

--
Why doesn't Tarzan have a beard?

 /// Bram Moolenaar -- [hidden email] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\        download, build and distribute -- http://www.A-A-P.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Add clipboard support for running without GUI in Mac OS X

Bram Moolenaar
In reply to this post by Björn Winckler

Björn Winckler wrote:

> On 12 July 2010 21:04, björn wrote:
> >
> > I looked into this issue carefully now and decided it is best to
> > convert os_macosx.c to Obj-C and have attached an updated patch which
> > includes block-wise copy/paste (the old patch had issues with linking
> > as well).
> >
>
> I accidentally included auto/config.mk in the patch...attaching a new
> one.  Sorry about that.

I included this, and generated the configure script.

Looking at os_macosx.m, it appears these functions are not used:
        mch_gettext()
        mch_bindtextdomain()
        mch_textdomain()

The whole section with #ifdef USE_MCH_GETTEXT  appears to be unused.


--
Futility Factor: No experiment is ever a complete failure - it can always
serve as a negative example.

 /// Bram Moolenaar -- [hidden email] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\        download, build and distribute -- http://www.A-A-P.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Add clipboard support for running without GUI in Mac OS X

Bram Moolenaar

I wrote:

> Björn Winckler wrote:
>
> > On 12 July 2010 21:04, björn wrote:
> > >
> > > I looked into this issue carefully now and decided it is best to
> > > convert os_macosx.c to Obj-C and have attached an updated patch which
> > > includes block-wise copy/paste (the old patch had issues with linking
> > > as well).
> > >
> >
> > I accidentally included auto/config.mk in the patch...attaching a new
> > one.  Sorry about that.
>
> I included this, and generated the configure script.
>
> Looking at os_macosx.m, it appears these functions are not used:
> mch_gettext()
> mch_bindtextdomain()
> mch_textdomain()
>
> The whole section with #ifdef USE_MCH_GETTEXT  appears to be unused.

The clipboard does not appear to work.  Looks like a call to clip_init()
is missing.  Was the patch incomplete?

--
ARTHUR:    Well, it doesn't matter.  Will you go and tell your master that
           Arthur from the Court of Camelot is here.
GUARD #1:  Listen, in order to maintain air-speed velocity, a swallow
           needs to beat its wings 43 times every second, right?
ARTHUR:    Please!
                                  The Quest for the Holy Grail (Monty Python)

 /// Bram Moolenaar -- [hidden email] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\        download, build and distribute -- http://www.A-A-P.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Add clipboard support for running without GUI in Mac OS X

Björn Winckler
On 14 July 2010 14:52, Bram Moolenaar wrote:

>
> I wrote:
>
>> Björn Winckler wrote:
>>
>> > On 12 July 2010 21:04, björn wrote:
>> > >
>> > > I looked into this issue carefully now and decided it is best to
>> > > convert os_macosx.c to Obj-C and have attached an updated patch which
>> > > includes block-wise copy/paste (the old patch had issues with linking
>> > > as well).
>> > >
>> >
>> > I accidentally included auto/config.mk in the patch...attaching a new
>> > one.  Sorry about that.
>>
>> I included this, and generated the configure script.
>>
>> Looking at os_macosx.m, it appears these functions are not used:
>>       mch_gettext()
>>       mch_bindtextdomain()
>>       mch_textdomain()
>>
>> The whole section with #ifdef USE_MCH_GETTEXT  appears to be unused.
>
> The clipboard does not appear to work.  Looks like a call to clip_init()
> is missing.  Was the patch incomplete?

You are right about the missing call to clip_init().  The patch below
is the missing hunk from main.c.  Sorry about that.

Thanks for including this patch.

Björn


diff --git a/src/main.c b/src/main.c
index 964bdd5..e19084e 100644
--- a/src/main.c
+++ b/src/main.c
@@ -711,6 +711,10 @@ main
     qnx_clip_init();
 #endif

+#if defined(MACOS_X) && defined(FEAT_CLIPBOARD)
+    clip_init(TRUE);
+#endif
+
 #ifdef FEAT_XCLIPBOARD
     /* Start using the X clipboard, unless the GUI was started. */
 # ifdef FEAT_GUI

--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Add clipboard support for running without GUI in Mac OS X

Björn Winckler
In reply to this post by Bram Moolenaar
On 14 July 2010 14:27, Bram Moolenaar wrote:
>
> Looking at os_macosx.m, it appears these functions are not used:
>        mch_gettext()
>        mch_bindtextdomain()
>        mch_textdomain()
>
> The whole section with #ifdef USE_MCH_GETTEXT  appears to be unused.

I have no idea what this has been used for (if anything).  I'd say it
is safe to delete (I started working on localizing MacVim a while ago
and for that patch I would not have any use for these functions).

Björn

--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Add clipboard support for running without GUI in Mac OS X

Bram Moolenaar
In reply to this post by Björn Winckler

Björn Winckler wrote:

> > The clipboard does not appear to work.  Looks like a call to clip_init()
> > is missing.  Was the patch incomplete?
>
> You are right about the missing call to clip_init().  The patch below
> is the missing hunk from main.c.  Sorry about that.
>
> Thanks for including this patch.

It works now, thanks.

--
GUARD #2:  It could be carried by an African swallow!
GUARD #1:  Oh, yeah, an African swallow maybe, but not a European swallow,
           that's my point.
GUARD #2:  Oh, yeah, I agree with that...
                                  The Quest for the Holy Grail (Monty Python)

 /// Bram Moolenaar -- [hidden email] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\        download, build and distribute -- http://www.A-A-P.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Add clipboard support for running without GUI in Mac OS X

Bram Moolenaar
In reply to this post by Björn Winckler

Björn Winckler wrote:

> On 14 July 2010 14:27, Bram Moolenaar wrote:
> >
> > Looking at os_macosx.m, it appears these functions are not used:
> >        mch_gettext()
> >        mch_bindtextdomain()
> >        mch_textdomain()
> >
> > The whole section with #ifdef USE_MCH_GETTEXT  appears to be unused.
>
> I have no idea what this has been used for (if anything).  I'd say it
> is safe to delete (I started working on localizing MacVim a while ago
> and for that patch I would not have any use for these functions).

OK.  And how about the section inside #ifdef MACOS_X_ICONVEMU ?
I don't see it defined anywhere.

--
ARTHUR:    Will you ask your master if he wants to join my court at Camelot?!
GUARD #1:  But then of course African swallows are not migratory.
GUARD #2:  Oh, yeah...
GUARD #1:  So they couldn't bring a coconut back anyway...
                                  The Quest for the Holy Grail (Monty Python)

 /// Bram Moolenaar -- [hidden email] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\        download, build and distribute -- http://www.A-A-P.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Add clipboard support for running without GUI in Mac OS X

Björn Winckler
On 14 July 2010 17:08, Bram Moolenaar wrote:

>
> Björn Winckler wrote:
>
>> On 14 July 2010 14:27, Bram Moolenaar wrote:
>> >
>> > Looking at os_macosx.m, it appears these functions are not used:
>> >        mch_gettext()
>> >        mch_bindtextdomain()
>> >        mch_textdomain()
>> >
>> > The whole section with #ifdef USE_MCH_GETTEXT  appears to be unused.
>>
>> I have no idea what this has been used for (if anything).  I'd say it
>> is safe to delete (I started working on localizing MacVim a while ago
>> and for that patch I would not have any use for these functions).
>
> OK.  And how about the section inside #ifdef MACOS_X_ICONVEMU ?
> I don't see it defined anywhere.
I can't see what it's used for either.  Is iconv not present on all
versions of Mac OS X perhaps?  That sounds unlikely -- my guess is
that this is a leftover from pre-OS X.  (A quick search did not reveal
anything on this...I could find a man page for iconv from OS X 10.3
but that was it.)

I deleted all the leftovers (as well as a TRACE macro from os_mac.h
that nobody should use anyway) and tried compiling with different
versions and (as expected) there were no problems.  I've attached a
patch that also moves the "VimPboardType" variable inside #ifdef
FEAT_CLIPBOARD, since it is only used there.  I for one would be happy
to see this dead code removed.

Björn

--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

0001-Remove-Mac-specific-unused-code.patch (24K) Download Attachment
12
Loading...