go编程之路(1:go开发环境安装)

  1. 操作系统:ubuntu 14.04
  2. go 安装:
    1. 下载。保存目录:/home/xxxxx/下载,文件名:go1.4.2.linux-amd64.tar.gz。
    2. 解压到目标目录,命令 tar -zxvf /home/xxxx(用户名)/下载/go1.4.2.linux-amd64.tar.gz -C :/home/xxxxx。
    3. 配置环境变量:
      • 打开/etc/profile文件,命令:sudo gedit /etc/profile
      • 在文件末尾添加如下命令:
      • export PATH=$PATH:/home/xxxx/go/bin   
      • export GOROOT=/home/xxxx/go
      • export GOPATH=/home/xxxx/mygo
      • 保存文件,退出后执行如下命令:source /etc/profile
      • 检查是否安装成功,执行命令:go version。能显示版本号(类似:go version go1.4.2)说明安装成功。
      • 在GOPATH目录下建三个文件夹:bin,src,pkg
  3. sublime text 3安装:
    1. 下载保存目录:/home/xxxxx/下载,文件名:sublime-text_build-3083_amd64.deb。
    2. 安装,执行命令:sudo dpkg -i /home/xxxx/下载/sublime-text_build-3083_amd64.deb
    3. 执行命令:subl,可以打开sublime
    4. 安装sublime text 3 的package control插件:ctrl+`,打开命令行,执行如下代码:
      import urllib.request,os; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler()) ); open(os.path.join(ipp, pf), 'wb').write(urllib.request.urlopen( 'http://sublime.wbond.net/' + pf.replace(' ','%20')).read())
    5. 安装git,执行命令:apt-get install git。
    6. 安装gocode:执行命令:go get github.com/nsf/gocode
    7. 安装MarGo:执行命令:go get github.com/slene/margo
    8. 安装gosublime:sublime text 3->References->Package Control->install package,搜索gosublime,选择安装。
    9. 以同样的方式安装其他插件
    10. 编写go代码并运行:
  4. 解决sublime text 3 不能输入中文:
    1. sudo apt-get install build-essential libgtk2.0-dev
    2. 创建sublime-imfix.c文件,命令:gedit sublime-imfix.c。文件内容为:
    3. /*
       * sublime-imfix.c
       * Use LD_PRELOAD to interpose some function to fix sublime input method support for linux.
       * By Cjacker Huang <jianzhong.huang at i-soft.com.cn> *
       *
       * gcc -shared -o libsublime-imfix.so sublime_imfix.c  `pkg-config --libs --cflags gtk+-2.0` -fPIC
       * LD_PRELOAD=./libsublime-imfix.so sublime_text
       */
      #include <gtk/gtk.h>
      #include <gdk/gdkx.h>

      typedef GdkSegment GdkRegionBox;

      struct _GdkRegion
      {
          long size;
          long numRects;
          GdkRegionBox *rects;
          GdkRegionBox extents;
      };

      GtkIMContext *local_context;

      void
      gdk_region_get_clipbox (const GdkRegion *region,
                              GdkRectangle    *rectangle)
      {
          g_return_if_fail (region != NULL);
          g_return_if_fail (rectangle != NULL);

          rectangle->x = region->extents.x1;
          rectangle->y = region->extents.y1;
          rectangle->width = region->extents.x2 - region->extents.x1;
          rectangle->height = region->extents.y2 - region->extents.y1;
          GdkRectangle rect;
          rect.x = rectangle->x;
          rect.y = rectangle->y;
          rect.width = 0;
          rect.height = rectangle->height;

          //The caret width is 2;
          //Maybe sometimes we will make a mistake, but for most of the time, it should be the caret.
          if (rectangle->width == 2 && GTK_IS_IM_CONTEXT(local_context)) {
              gtk_im_context_set_cursor_location(local_context, rectangle);
          }
      }

      //this is needed, for example, if you input something in file dialog and return back the edit area
      //context will lost, so here we set it again.

      static GdkFilterReturn event_filter (GdkXEvent *xevent, GdkEvent *event, gpointer im_context)
      {
          XEvent *xev = (XEvent *)xevent;

          if (xev->type == KeyRelease && GTK_IS_IM_CONTEXT(im_context)) {
              GdkWindow *win = g_object_get_data(G_OBJECT(im_context), "window");

              if (GDK_IS_WINDOW(win)) {
                  gtk_im_context_set_client_window(im_context, win);
              }
          }

          return GDK_FILTER_CONTINUE;
      }

      void gtk_im_context_set_client_window (GtkIMContext *context,
                                             GdkWindow    *window)
      {
          GtkIMContextClass *klass;
          g_return_if_fail (GTK_IS_IM_CONTEXT (context));
          klass = GTK_IM_CONTEXT_GET_CLASS (context);

          if (klass->set_client_window) {
              klass->set_client_window (context, window);
          }

          if (!GDK_IS_WINDOW (window)) {
              return;
          }

          g_object_set_data(G_OBJECT(context), "window", window);
          int width = gdk_window_get_width(window);
          int height = gdk_window_get_height(window);

          if (width != 0 && height != 0) {
              gtk_im_context_focus_in(context);
              local_context = context;
          }

          gdk_window_add_filter (window, event_filter, context);
      }
    4. 编译成libsublime-imfix.so文件,命令: gcc -shared -o libsublime-imfix.so sublime-imfix.c `pkg-config --libs --cflags gtk+-2.0` -fPIC
    5. 测试,执行命令:LD_PRELOAD=./libsublime-imfix.so subl,切换到搜狗输入法,看看是否能输入中文
    6. 执行命令:sudo cp libsublime-imfix.so /usr/lib/
    7. 执行命令:sudo gedit /usr/bin/subl
    8. 添加一行:export LD_PRELOAD=./libsublime-imfix.so
    9. OK了(只支持命令行打开sublime)。

 

posted @ 2015-04-25 17:33  ZQT  阅读(649)  评论(0)    收藏  举报