2016年3月23日星期三

Emacs配置文件更新-增加对OCaml的支持

自从fork了purcell大神的emacs配置, 着实学习了很多很多. 优化的init.el, lisp配置方式让我彻底学习了什么叫做好的优化的有序的emacs lisp方言配置. 大神的配置对前端语言支持很好, 因为课程需要, 我的OCaml用不了了. 于是, 站在大神的肩膀上, 尝试着新方式来配置OCaml(tuareg)

先说下以前的配置, 在根目录的.emacs里, 简单粗暴地写上如下几句, 大意是设置加载文件位置, 调用三个OCaml的插件 - 都在tuareg文件夹了.


  1. ~/.emacs
  2. (add-to-list 'load-path "DIR")
  3. (require 'tuareg)
  4. (require 'ocamldebug)
  5. (require 'tuareg_indent)

  6. (setq auto-mode-alist (cons '("\\.ml\\w?" . tuareg-mode) auto-mode-alist))
  7. (autoload 'tuareg-mode "tuareg" "Major mode for editing Caml code" t)
  8. (autoload 'camldebug "camldebug" "Run the Caml debugger" t)

然后现在这样就不好使了, 我的文件结构更新如下了,

  1. ~/.emacs.d/
  2. init.el #Emacs会自动从init.el开始执行
  3. elpa/ #通过ELPA下载的插件所保存的位置
  4. lisp/ #就是加载各个插件的初始化文件的位置啦
  5. init-xxx.el #某初始化文件,如init-sql.el
  6. .....

以前的.emacs单一文件被init.el初始化文件代替, 其中require lisp/目录下的具体的插件配置. 相应的, 为了配置OCaml编译环境, 我应该在init.el里加入 (require 'init-ocaml), 然后在lisp/文件夹下新建init-ocaml.el空白文件, 填补上如下代码.

  1. ;;~/.emacs.d/lisp/init-ocaml
  2. (add-to-list 'load-path
  3. (expand-file-name "lisp/tuareg" user-emacs-directory))
  4. (require 'tuareg)
  5. (require 'ocamldebug)
  6. (require 'tuareg_indent)
  7. (setq auto-mode-alist (cons '("\\.ml\\w?" . tuareg-mode) auto-mode-alist))
  8. (autoload 'tuareg-mode "tuareg" "Major mode for editing Caml code" t)
  9. (autoload 'camldebug "camldebug" "Run the Caml debugger" t)

  10. (provide 'init-ocaml)

也是设置load-path, 注意我们的OCaml配置文件不仅仅只有tuareg.el, ocamldebug.el, tuareg_indent.el这三个, 其背后依赖的是一个名为tuareg的package, 将其整体放进lisp文件夹中即可.

好了, 大功告成, 打开熟悉的.ml后缀文件, 语法高亮, tuareg插件全部都回来啦, 开心! 

同时, 我有另外一个疑问, 这里调用的Package是我自己复制粘贴进去的, 与elpa包管理器下载的有什么区别呢? 仔细看了下文件结构, 我有些明白了,


  • ~/.emacs.d/
  • init.el #Emacs会自动从init.el开始执行
  • elpa/ #通过ELPA下载的插件所保存的位置
  • tadauto-complete-20160310.2248/
  • ....
  • lisp/ #就是加载各个插件的初始化文件的位置啦
  • init-xxx.el #某初始化文件,如init-sql.el
  • tuareg/

  • 重新祭上文件结构, lisp里的init - xxx.el配置文件配置了插件,require等, 其中包括epla信息, 故插件包都会通过epla管理下载在elpa/文件夹里. 本篇文章中, 我是手动下载并配置了插件包, 绕过elpa, 将其放进lisp文件夹里. 在Emacs24以后, elpa的引入极大地实现了配置文件的轻量化, 传统的(可能会庞大的)插件包不需要备份, 换电脑换设备Emacs初始化时会自动执行下载elpa的命令, 下载最新的插件包. 这里边的学问还是很大呢.

    不说了, 赶工OCaml编译器去了.

    2016年3月15日星期二

    解决apt-get依赖(unmet dependencies)问题

    好几个月没开steam,想上商店看看,可是启动steam就报错,

    You are missing the following 32-bit libraries, and Steam may not run: libGL.so.1

    按照这篇帖子,一步一步解决问题,最后一步又卡了壳,

    * 解决steam报错找不到libGL.so.1问题方案,


    1- If you haven't updated your computer in a while, 
    copy (ctrl+c) and paste (ctrl+SHIFT+v) this (and then hit enter to run it). If you don't know what this is, just do it. :
    Code:
    sudo apt-get update && sudo apt-get -y upgrade
    2- If you've installed Steam already, skip to step 3. If you haven't installed Steamopen Terminal with ctrl+alt+t. Then copy (ctrl+c) and paste (ctrl+SHIFT+v) this (and then hit enter to run it):
    Code:
    sudo apt-get install -y steam
    3- Now for the fix. Copy (ctrl+c) and paste (ctrl+SHIFT+v) this to edit Steam's configuration file (and then hit enter to run it):
    Code:
    sudo nano /etc/ld.so.conf.d/steam.conf
    4- It'll probably be blank. If it's blank, paste these two lines. If it's not blank, just paste these two lines to the very bottom. Copy (ctrl+c) and paste (ctrl+SHIFT+v) this (and then enter to run it):
    Code:
    /usr/lib32
    /usr/lib/i386-linux-gnu/mesa
    5- Save it by hitting ctrl-x, then y, then enter.

    6- Now copy (ctrl+c) and paste (ctrl+SHIFT+v) this (and then hit enter to run it).:
    Code:
    sudo ldconfig
    7- Finally, copy (ctrl+c) and paste (ctrl+SHIFT+v) this (and then hit enter to run it). It reinstalls a Mesa/OpenGL library:
    Code:
    sudo apt-get install --reinstall libgl1-mesa-glx:i386
    8- Open Steam, download Team Fortress 2, and go kill some folks.


    可是到了如上第七步骤的时候,有错误啦,

    The following packages have unmet dependencies:
    .................

    二逼如我,按照依赖的package名字,挨行敲入

    sudo apt-get install PACKAGENAME

    可总是有如下类似错误,即安装不成功

    0 upgraded, 0 newly installed, 0 to remove and 3 not upgraded

    然后Google一番,终于找到了解决方案,

    * 无敌神龙命令出来啦!

    sudo apt-get -o Debug::pkgProblemResolver=yes dist-upgrade

    自动修复这个依赖问题,自动安装缺失的包。太棒了。

    至于更多的apt-get参考这篇帖子,解释的非常翔实。

    解决apt-get update失败提示Unable to connect to 127.0.0.1问题

    这半个月来,隔三差五的想起来一下sudo apt-get update,就是提示失败,满屏的,

    Err http://ph.archive.ubuntu.com precise Release.gpg                           
      Unable to connect to ph.archive.ubuntu.com:http: [IP: X.X.X.X 80]
    Err http://ph.archive.ubuntu.com precise-updates Release.gpg            
      Unable to connect to ph.archive.ubuntu.com:http: [IP: X.X.X.X 80]
    。。。。。
    
    W: Failed to fetch http://fr.archive.ubuntu.com/ubuntu/dists/precise/InRelease  
    。。。。。。。。。
    W: Some index files failed to download. They have been ignored, or old ones used instead.


    重要提示在这里,

      ............Unable to connect to 127.0.0.1:1080:

    端口是1080,看到这里我明白了些许。前段时间回国用shadowsocks来翻墙,里边的代理信息就是通过的1080端口,google了一下,我这样奇葩的问题比较少见。整理一下思路,我需要重置下1080端口,取消代理设置。

    1. 删除shadowsocks配置信息,没什么卵用 -> 彻底remove掉shadowsocks,还是没什么卵用

    2. 更改127.0.0.1这个DNS,用8.8.8.8,还是没什么卵用

    3. 最终误打误打还是解决了问题----->

         sudo apt-get install 
       sudo apt-get autoremove


    所以呢,现在正在谷歌apt-get各种命令来看...