Loading ...
Sorry, an error occurred while loading the content.

UTF8_STRING patch

Expand Messages
  • Maiorana, Jason
    ok, i got a bit done last night: Here s a patch to the file gui_gtk_x11.c that works for me. Im running an old X server, 3.x series, and gtk 1.2, but im
    Message 1 of 6 , Aug 9 6:48 AM
    • 0 Attachment
      ok, i got a bit done last night:

      Here's a patch to the file "gui_gtk_x11.c" that works
      for me. Im running an old X server, 3.x series, and gtk 1.2,
      but im confident the patch will also work for newer X/gtk's.
      The main issue of concern is what will happen when vim is
      being run in non-utf8 encoding mode. Some sort of
      "utf8_to_vim_current_encoding" "vim_current_encoding_to_utf8"
      functions would be needed in "selection_get_event"
      and "selection_received_event" to complete the support in this
      case. Bram: any suggestion what function to use to do that?


      Anyway, when using this patch with encoding=utf8, the results
      are pretty seamless for me: copying and pasting, highlighting
      and everything work great with gvim.



      I hope this patch isnt mauled by the remailer:


      --- gui_gtk_x11.c.OLD Wed Mar 13 15:19:58 2002
      +++ gui_gtk_x11.c Thu Aug 8 23:23:34 2002
      @@ -83,7 +83,8 @@
      SELECTION_STRING,
      SELECTION_TEXT,
      SELECTION_COMPOUND_TEXT,
      - SELECTION_VIM
      + SELECTION_VIM,
      + SELECTION_UTF8_STRING
      };

      /*
      @@ -133,6 +134,7 @@
      static GdkAtom compound_text_atom = GDK_NONE;
      static GdkAtom text_atom = GDK_NONE;
      static GdkAtom vim_atom = GDK_NONE; /* Vim's own special selection
      format */
      +static GdkAtom utf8_string_atom = GDK_NONE;

      /*
      * Keycodes recognized by vim.
      @@ -990,6 +992,7 @@

      if (info != (guint)SELECTION_STRING
      && info != (guint)SELECTION_VIM
      + && info != (guint)SELECTION_UTF8_STRING
      && info != (guint)SELECTION_COMPOUND_TEXT
      && info != (guint)SELECTION_TEXT)
      return;
      @@ -1036,6 +1039,11 @@
      gdk_free_compound_text(result);
      return;
      }
      + else if( info == (guint)SELECTION_UTF8_STRING)
      + {
      + mch_memmove(result, string, (size_t)length);
      + type = utf8_string_atom;
      + }
      else
      {
      mch_memmove(result, string, (size_t)length);
      @@ -1796,6 +1804,7 @@

      static const GtkTargetEntry primary_targets[] = {
      {VIM_ATOM_NAME, 0, SELECTION_VIM},
      + {"UTF8_STRING", 0, SELECTION_UTF8_STRING},
      {"COMPOUND_TEXT", 0, SELECTION_COMPOUND_TEXT},
      {"TEXT", 0, SELECTION_TEXT},
      {"STRING", 0, SELECTION_STRING}
      @@ -1821,6 +1830,7 @@
      /* Initialise atoms */
      compound_text_atom = gdk_atom_intern("COMPOUND_TEXT", FALSE);
      text_atom = gdk_atom_intern("TEXT", FALSE);
      + utf8_string_atom = gdk_atom_intern("UTF8_STRING", FALSE);

      /* Set default foreground and background colors. */
      gui.norm_pixel = gui.def_norm_pixel;
      @@ -3534,6 +3544,17 @@
      while (received_selection == RS_NONE)
      gtk_main(); /* wait for selection_received_event */

      + //Lets use UTF8_STRING if available!!
      + if (received_selection == RS_FAIL)
      + {
      + /* Now try to get it out of the usual string selection. */
      + received_selection = RS_NONE;
      + (void)gtk_selection_convert(gui.drawarea, cbd->gtk_sel_atom,
      + gdk_atom_intern("UTF8_STRING",
      FALSE),
      + (guint32)GDK_CURRENT_TIME);
      + while (received_selection == RS_NONE)
      + gtk_main(); /* wait for selection_received_event */
      + }
      if (received_selection == RS_FAIL)
      {
      /* Now try to get it out of the usual string selection. */
    • Bram Moolenaar
      ... Great. I ll try including this patch when I have some time (might be a while...). For the conversion, look in mbyte.c. The functions convert_setup() and
      Message 2 of 6 , Aug 9 6:57 AM
      • 0 Attachment
        Jason Maiorana wrote:

        > ok, i got a bit done last night:
        >
        > Here's a patch to the file "gui_gtk_x11.c" that works
        > for me. Im running an old X server, 3.x series, and gtk 1.2,
        > but im confident the patch will also work for newer X/gtk's.
        > The main issue of concern is what will happen when vim is
        > being run in non-utf8 encoding mode. Some sort of
        > "utf8_to_vim_current_encoding" "vim_current_encoding_to_utf8"
        > functions would be needed in "selection_get_event"
        > and "selection_received_event" to complete the support in this
        > case. Bram: any suggestion what function to use to do that?
        >
        >
        > Anyway, when using this patch with encoding=utf8, the results
        > are pretty seamless for me: copying and pasting, highlighting
        > and everything work great with gvim.

        Great. I'll try including this patch when I have some time (might be a
        while...).

        For the conversion, look in mbyte.c. The functions convert_setup() and
        string_convert() should be able to do it.

        --
        "Hit any key to continue" does _not_ mean you can hit the on/off button!

        /// Bram Moolenaar -- Bram@... -- http://www.moolenaar.net \\\
        /// Creator of Vim -- http://vim.sf.net -- ftp://ftp.vim.org/pub/vim \\\
        \\\ Project leader for A-A-P -- http://www.a-a-p.org ///
        \\\ Lord Of The Rings helps Uganda - http://iccf-holland.org/lotr.html ///
      • Maiorana, Jason
        ... one quick question: how do you determine which is the appropriate encoding to pass to clip_yank_selection . It looks like the GDK functions all assume
        Message 3 of 6 , Aug 9 8:55 AM
        • 0 Attachment
          >For the conversion, look in mbyte.c. The functions convert_setup() and
          >string_convert() should be able to do it.

          one quick question: how do you determine which is the appropriate
          encoding to pass to "clip_yank_selection".

          It looks like the GDK functions all assume that the data is in the
          format
          of the current locale: this is incorrect i think. I set encoding=utf8
          which does not match my en_US locale. I dont have really working locales
          for utf8, if there was an "allLangs_USkbd.utf8" locale i would use it.

          Converting COMPOUND_TEXT to my current locale would only corrupt it,
          which probably explains why that never worked for me. Doesnt vim
          have some notion of internal representation encoding? If vim were
          to always use utf-8 internally in all situations, that would make
          UTF8_STRING conversion a non-issue...
        • Bram Moolenaar
          ... I dunno. You could try looking in the GTK documentation (but you probably end up looking in the source code...). ... The value of encoding defines the
          Message 4 of 6 , Aug 10 11:43 AM
          • 0 Attachment
            Jason Maiorana wrote:

            > >For the conversion, look in mbyte.c. The functions convert_setup() and
            > >string_convert() should be able to do it.
            >
            > one quick question: how do you determine which is the appropriate
            > encoding to pass to "clip_yank_selection".
            >
            > It looks like the GDK functions all assume that the data is in the
            > format of the current locale: this is incorrect i think. I set
            > encoding=utf8 which does not match my en_US locale. I dont have
            > really working locales for utf8, if there was an "allLangs_USkbd.utf8"
            > locale i would use it.

            I dunno. You could try looking in the GTK documentation (but you
            probably end up looking in the source code...).

            > Converting COMPOUND_TEXT to my current locale would only corrupt it,
            > which probably explains why that never worked for me. Doesnt vim
            > have some notion of internal representation encoding? If vim were
            > to always use utf-8 internally in all situations, that would make
            > UTF8_STRING conversion a non-issue...

            The value of 'encoding' defines the encoding used internally in Vim for
            all text in buffers, registers, etc.

            --
            "Hit any key to continue" it said, but nothing happened after F sharp.

            /// Bram Moolenaar -- Bram@... -- http://www.moolenaar.net \\\
            /// Creator of Vim -- http://vim.sf.net -- ftp://ftp.vim.org/pub/vim \\\
            \\\ Project leader for A-A-P -- http://www.a-a-p.org ///
            \\\ Lord Of The Rings helps Uganda - http://iccf-holland.org/lotr.html ///
          • Maiorana, Jason
            ... Its says in their doc s that gdk_text_property_to_text_list converts from compound text the process s current locale. Vim however needs the text to be
            Message 5 of 6 , Aug 12 12:41 PM
            • 0 Attachment
              > > It looks like the GDK functions all assume that the data is in the
              > > format of the current locale: this is incorrect i think.

              >I dunno. You could try looking in the GTK documentation (but you
              >probably end up looking in the source code...).

              Its says in their doc's that "gdk_text_property_to_text_list" converts
              from "compound text" the process's current locale. Vim however needs
              the text to be in option["encoding"] encoding, regardless of the
              current locale. So I think that pasting compound text through gtk
              into a vim where buffer encoding doesnt match locale LC_CTYPE wont work.
              Mostly this is irrelevant because COMPOUND_TEXT is thoroughly deprecated
              imo.

              >> Converting COMPOUND_TEXT to my current locale would only corrupt it,
              >> which probably explains why that never worked for me. Doesnt vim
              >> have some notion of internal representation encoding? If vim were
              >> to always use utf-8 internally in all situations, that would make
              >> UTF8_STRING conversion a non-issue...

              >The value of 'encoding' defines the encoding used internally in Vim for
              >all text in buffers, registers, etc.

              I will look into calling "get_option_value" for the purpose of passing
              to
              "convert_setup".
            • Glenn Maynard
              ... Just pass p_enc. -- Glenn Maynard
              Message 6 of 6 , Aug 12 1:15 PM
              • 0 Attachment
                On Mon, Aug 12, 2002 at 03:41:55PM -0400, Maiorana, Jason wrote:
                > >The value of 'encoding' defines the encoding used internally in Vim for
                > >all text in buffers, registers, etc.
                >
                > I will look into calling "get_option_value" for the purpose of passing
                > to
                > "convert_setup".

                Just pass p_enc.

                --
                Glenn Maynard
              Your message has been successfully submitted and would be delivered to recipients shortly.