 (defun merlin-can-handle-buffer ()
   "Simple sanity check (used to avoid running merlin on, e.g., completion buffer)."
   (buffer-file-name))
+
+(defun merlin-view-log ()
+  "Jump to the log file of merlin."
+  (interactive)
+  (let ((file (lookup-default 'logfile (merlin-process-data) nil)))
+    (if file (find-file-other-window file)
+      (message "No log file for this instance."))))
 
 (defun merlin-process-dead-p ()
   "Return non-nil if merlin process is dead."

  "If non-nil, when locate opens a new window it will give it the focus."
  :group 'merlin :type 'boolean)

;;;;;;;;;;;;;;;;;;;;;;;;
;; Internal variables ;;
;;;;;;;;;;;;;;;;;;;;;;;;

        (extra-flags (lookup-default 'flags configuration nil))
        (name (lookup-default 'name configuration "default"))
        (environment (lookup-default 'env configuration nil))
        (logfile (lookup-default 'logfile configuration nil))
        (buffer-name (merlin-instance-buffer-name name)))
    (message "Starting merlin instance: %s (binary=%s)." name command)
    (setq merlin-instance name)
    (when (not (merlin-process-started-p name))
      (let* ((buffer (get-buffer-create buffer-name))
             (process-environment (append (if logfile (list (format "MERLIN_LOG=%s" (expand-file-name logfile)))) environment process-environment))
             (p (apply #'start-file-process "merlin" buffer-name
                       command `("-protocol" "sexp" . ,(append extra-flags flags)))))
        (with-current-buffer buffer
          (set-process-query-on-exit-flag p nil)
          (setq merlin-process p)
          (setq merlin-process-data configuration)
          (setq merlin-instance name)
          (setq merlin-process-queue (tq-create p)))
        p))))

(defun merlin-process-data ()
  "Return the process configuration of the current buffer."
  (buffer-local-value 'merlin-process-data (merlin-process-buffer)))

(defun merlin-toggle-view-errors ()
  "Toggle the viewing of errors in the buffer."
