How to setup Prolog mode for emacs on OSX

Erlang programmers are lucky because for them there is no question what language to learn next. Of course it should be Prolog. After all Erlang is “a bastard child of Scheme and Prolog”. And of course hard-core Erlang programmers use emacs :-). Are there any other text editors?

So, here are steps how to get SWI Prolog work with emacs on OS X.

1. Install SWI-prolog with brew:

brew install swi-prolog 

I had a problem with brew after upgrade to Yosemite.

/usr/local/bin/brew: /usr/local/Library/brew.rb: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby: bad interpreter: No such file or directory
/usr/local/bin/brew: line 23: /usr/local/Library/brew.rb: Undefined error: 0

If you get the error above just edit file “/usr/local/Library/brew.rb” to point to Current version of ruby interpreter:

#!/System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby -W0

2. Install prolog-el mode. I use el-get, so M-x el-get-install prolog-el did a trick.

3. Add the following into your init.el:

  (autoload 'run-prolog "prolog" "Start a Prolog sub-process." t)
  (autoload 'prolog-mode "prolog" "Major mode for editing Prolog programs." t)
  (autoload 'mercury-mode "prolog" "Major mode for editing Mercury programs." t)
  (setq prolog-system 'swi)
  (setq auto-mode-alist (append '(("\\.pl$" . prolog-mode)
                                ("\\.m$" . mercury-mode))
                              auto-mode-alist))

To test installation, open a new buffer, change to prolog mode with M-x prolog-mode and press C-c RET. This should open prolog interpreter in inferior mode. C-c C-b allows to evaluate (“conduct”) a buffer with prolog code. C-h b – will give you all the key bindings available in prolog mode.

e.g.

Screen Shot 2015-01-11 at 17.36.52

Advertisements
This entry was posted in Uncategorized and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s