Skip to content. | Skip to navigation

Sections
Personal tools
You are here: Home / Users / Gert Meulyzer / Posts / Setting up Emacs with Flymake for Mercury

Setting up Emacs with Flymake for Mercury

Quick guide on how to get Emacs have Mercury code 'flymade' so you can see the errors as you edit the code.

Add this to your Emacs configuration:

 

;; =================== Mercury setup ====================
(setq auto-mode-alist (append '(("\\.m$" . mercury-mode)) auto-mode-alist))

(if-exists-do "/usr/local/mercury/"
              (add-to-list 'load-path
                           "/usr/local/mercury/lib/mercury/elisp")
              (autoload 'mdb "gud" "Invoke the Mercury debugger" t))

(defvar *flymake-mercury-checker* "~/src/personal/scripts/mercury-checker.sh")

(push '("\\([^:]*\\):\\([0-9]+\\):[0-9]+: \\(.*\\)" 1 2 nil 3) flymake-err-line-patterns)

(defun flymake-mercury-init ()
  (let* ((temp-file (flymake-init-create-temp-buffer-copy
                     'flymake-create-temp-inplace))
         (local-file (file-relative-name
                      temp-file
                      (file-name-directory buffer-file-name))))
    (list *flymake-mercury-checker* (list local-file))))

(add-to-list 'flymake-allowed-file-name-masks '("\\.m\\'" flymake-mercury-init nil flymake-get-real-file-name))

(add-hook 'mercury-mode-hook
          '(lambda ()
            (if (not (null buffer-file-name)) (flymake-mode))))

 

In this script, I reference ~/src/personal/scripts/mercury-checker.sh. You can of course change this filename to a different one but it has to be in your $PATH of course.

Just make sure it contains this:

 

#!/bin/bash
cd $(dirname $1)
filename=$(basename $1)
tempfile=/tmp/$(echo $filename|sed 's/_flymake//')
rm -f $tempfile
cp $filename $tempfile
cd /tmp/
/usr/local/mercury/bin/mmc -e $(basename $tempfile)

 

Now your Emacs should work with Mercury. Don't forget, you need prolog-mode, since mercury-mode depends on it. And you need mercury installed in /usr/local/mercury. If it's in a different folder, don't forget to change the shell script accordingly.

 

Filed under: , , ,
My Latest Tweets
There was a problem retrieving the twitter updates.