[texhax] Metapost compile from Emacs

Ryan Hinton iobass at email.com
Fri Dec 21 17:51:42 CET 2007

I wanted to compile a Metapost file from Emacs, so I wrote a quick 
little function to do it.  I'm new to Metapost, and this is my first 
Emacs function, so comments and feedback are welcome.  But it seems to 
work for me, so I am happy to share it.

;; Metapost Mode
(defun metapost-compile-buffer ()
  "Compile current buffer with Metapost."
  ; - We should have a "save buffer?" dialog if the current buffer is 
  ; - It would be nice to clear the compile buffer before a recompile.
  (setq curbuf-fname (shell-quote-argument buffer-file-name))
  (if (= 0 (call-process "mpost" nil (concat "*Metapost-" curbuf-fname "*")
                         nil curbuf-fname))
      (message (concat "Metapost compiled " curbuf-fname " successfully."))
      (message (concat "Metapost compile of " curbuf-fname " FAILED.")))
(add-hook 'metapost-mode-hook
          (lambda ()
            (define-key meta-mode-map "\C-c\C-c" 'metapost-compile-buffer)))

Ryan Hinton
iobass, domain email.com

More information about the texhax mailing list