显示标签为“Emacs”的博文。显示所有博文
显示标签为“Emacs”的博文。显示所有博文

2016年12月28日星期三

mac os 配置 prolog

AI 作业开玩有趣的prolog,记录下配置 mac os 10.12.2 环境下配置 prolog 吧。


  • SWI-Prolog GUI

主流是安装 SWI-Prolog,链接在这里,注意这里是开发版的,亲测稳定版对本机(10.12.2)支持不好,内置 terminal 莫名其妙黑屏。安装开发版,你也可能需要安装XQuartz(X11).

安装就绪,打开SWI-Prolog,载入测试文件,

?- ['/..../family.pl'].
输出 true,即是成功。


  • Terminal Prolog

作为程序猿,APP的 GUI显然不能显示我们的逼格,大多情况下还是需要请出 Terminal。

依赖SWI-Prolog 修改环境变量是一个办法,brew 安装是一个更普世的办法,

Simply go to terminal window and type in:
brew tap homebrew/x11
after the above command executes, enter:
brew install swi-prolog --HEAD
and now swipl should work:
Maryams-MacBook-Pro:~ maryam$ swipl
returns
Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 7.3.3)
Copyright (c) 1990-2015 University of Amsterdam, VU Amsterdam
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
Please visit http://www.swi-prolog.org for details.

For help, use ?- help(Topic). or ?- apropos(Word).
Yay! ready to go. Let's test this:
?- ['/..../family.pl'].

true.


  • Emacs prolog
以前用 OCaml 的时候,接触了 Emacs这一神器,对于 Prolog 我们依然可以信赖它,参考教程在这里


  1. Download the file prolog.el from https://bruda.ca/emacs/prolog_mode_for_emacs and save it in your load-path so that Emacs can find it.
  2. Optionally, you can byte-compile prolog.el for better performance. Load prolog.el into Emacs and do M-x byte-compile-file RET.
  3. Add the following lines to ~/.emacs (~/_emacs on Windows):
    (autoload 'prolog-mode "prolog" "Major mode for editing Prolog programs." t)
    (add-to-list 'auto-mode-alist '("\\.pl\\'" . prolog-mode))
    Where is ~/_emacs?
    ~ is a shortcut for the home directory, on Windows it is system and language specific. It may be for example C:\ orC:\Dokumente. The best way to find "~" is: select "Files->Open.." and enter "~". Then Emacs prints the directory name and contents.
  4. Customize the Prolog mode. The following page explains how to enable electric indentation, syntax checking and PceEmacs-style comments: https://www.metalevel.at/pceprolog/
  5. ediprolog allows you to interact with SWI-Prolog in all Emacs buffers. You can quickly consult buffers and regions, and run queries that are embedded in your source files. ediprolog is available from: https://github.com/triska/ediprolog







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年1月16日星期六

    搞定emacs主题配色

    我的emacs插件管理做的不是太好,一直都比较混乱,今天逢周六,好好地整理了一番,顺道把早就想弄的emacs主题给解决了,这里特指Linux平台下的emacs

    先铺垫些前瞻知识。emacs的插件功能很强大,很适合爱折腾的人,自有配置。

    1. 所有的配置信息都需要用lisp方言写入.emacs文件内,默认是在~/目录下。

    2.所有的插件都需要在.emacs里导入,形如require 'name-of-tools。当然首先你要告诉emacs你的插件目录在哪里,即 add-to-list 'load-path "address"。为了方便管理和备份,强烈建议固定插件目录,一般大家使用~/.emacs.d目录。

    好了,话归正题,我们要配置emacs的主题,不伤眼的舒服的主题!

    1. 首先现在主题包地址,戳这里,目前版本是6.6.0

    2. 得到压缩包,我们只需要压缩包里的themes文件夹和color-theme.el两个文件,cp命令把其拷进~/.emacs.d目录,cp -r themes/ ~/.emacs.d和cp color-theme.el ~/.emacs.d

    3. 在根目录下打开.emacs配置文件,我们需要完成配置信息,简简单单只有四行,

    ;;themes
    (add-to-list 'load-path "~/.emacs.d")  ;;load path 
    (require 'color-theme)  ;;载入theme插件
    (color-theme-initialize) ;;启动时初始化theme
    (color-theme-calm-forest) ;;选择具体的主题

    4. 这里我随便载入了一个名为color-theme-calm-forest的主题。其实我们还有更多的选择。打开emacs后,M-x color-theme-select 回车,就会列出当前theme包里的所有主题来,共计92项。大家可以按需选择,然后重新更改配置文件即可。例如,我们相上了TTY Dark这个主题,那么最后一行改为(color-theme-tty-dark)即可(这个更好看 -.-)

    5. 除了这个标准的Theme包,网上还有其他的选择,配置思路同上。

    最终效果如图



    ****************Wed 28 Dec, 2016**************
    配置 Mac 下的 Emacs更新下

    发现 Emacs24以后的版本都拥有比较强大的 主题管理功能,

    M-x customize-themes

    会看到如图所示的预置主题列表,适合心累了不折腾的同学,选择一个保存即可。