     ;; goto-line
     (merlin-goto-point data)
     (point)))
+
 (defun merlin-make-bounds (data)
   "From a json object DATA {\"start\": LOC1; \"end\": LOC2}, return (LOC1 . LOC2)."
   (cons

  "Return the data for completion of IDENT, ie. a list of pairs (NAME . TYPE)."
  (let ((prefix (merlin-compute-prefix ident))
        (data (append (merlin-get-completion ident) nil)))
    (mapcar #'(lambda (entry)
               (list (concat prefix (cdr (assoc 'name entry)))
                     (merlin-format-completion-entry entry)
                     (elt (cdr (assoc 'kind entry)) 0)))
            data)))

(defvar merlin-ac-use-summary t
  "Use :summary for the types in AC")
(defvar merlin-ac-use-document nil
  "Use :document for the types in AC")

(defun merlin-make-popup-item (data)
  "Create a popup item from data DATA."
  (popup-make-item
   (car data)

    (merlin-put-margin-overlay merlin-lock-zone-margin-overlay
                               merlin-margin-lock-string)))

(defun merlin-sync-highlight-lock-zone ()
  "Mark the position of the lock zone by highlighting the zone."
    (if merlin-lock-zone-highlight-overlay
      (delete-overlay merlin-lock-zone-highlight-overlay))
  (setq merlin-lock-zone-highlight-overlay (make-overlay (point-min) merlin-lock-point))
  (overlay-put merlin-lock-zone-highlight-overlay 'face 'merlin-locked-face))

(defun merlin-sync-lock-zone-display ()
  "Update the locked zone display, according to `merlin-display-lock-zone', ie.
iterates through it and call each method."
  (dolist (x merlin-display-lock-zone)
    (case x
      (margin (merlin-sync-margin-lock-zone))
      (highlight (merlin-sync-highlight-lock-zone)))))

(defun merlin-sync-edit (start end length)
  "Retract the locked zone after an edit.
Called when an edit is made by the user."
  (if (and merlin-mode (< start merlin-lock-point))
      (progn (setq merlin-lock-point (1- start))
             (merlin-sync-lock-zone-display))))

(defun merlin-sync-to-point ()
  "Makes sure the buffer is synchronized on merlin-side and centered around (point)."
  (merlin-tell-to-point (point))
  (merlin-seek-exact (point))
  (merlin-sync-lock-zone-display))

;;;;;;;;;;;;;;;;;;
;; ERROR REPORT ;;
;;;;;;;;;;;;;;;;;;

;; (defun merlin-error-next ()
;;   "Jump to the next error."
;;   (interactive)
;;   (if merlin-pending-errors
;;       (let ((err (pop merlin-pending-errors)))
;;         (merlin-goto-point (cdr (assoc 'start err)))
;;         (if merlin-pending-errors-overlays
;;             (delete-overlay (pop merlin-pending-errors-overlays)))
;;         (if merlin-pending-errors
;;             (message "%s (%d more errors, use %s to go to the next)" 
;;                      (cdr (assoc 'message err))
;;                      (length merlin-pending-errors)
;;                      (substitute-command-keys "\\[merlin-next-error]")
;;                      )
;;           (message "%s" (cdr (assoc 'message err))))
;;         (merlin-highlight (merlin-make-bounds err) 'next-error))
;;     (next-error)))
;; 
;; (defun merlin-error-delete-overlays ()
;;   "Remove margin error overlays."
;;   (mapc #'delete-overlay merlin-pending-errors-overlays)
;;   (setq merlin-pending-errors-overlays nil))
;; 
;; (defun merlin-error-warning-p (msg)
;;   "Tell if the message MSG is a warning."
;;   (string-match "^Warning" msg))
;; 
;; (defun merlin-error-display-in-margin (errors)
;;   "Given a list of ERRORS, put annotations in the margin corresponding to them."
;;   (merlin-delete-error-overlays)
;;   (setq merlin-pending-errors (append errors nil))
;;   (setq merlin-pending-errors-overlays 
;;         (mapcar (lambda (err)
;;                   (let ((overlay (make-overlay
;;                                   (merlin-make-point (cdr (assoc 'start err)))
;;                                   (merlin-make-point (cdr (assoc 'end err))))))
;;                     (if (merlin-warning-p (cdr (assoc 'message err)))
;;                         (merlin-put-margin-overlay overlay 
;;                                                    merlin-margin-warning-string 
;;                                                    compilation-warning-face)
;;                       (merlin-put-margin-overlay overlay 
;;                                                  merlin-margin-error-string
;;                                                  compilation-error-face))
;;                     overlay))
;;                 errors)))
;; 
;; (defun merlin-error-check (view-errors-p)
;;   "Check for errors.
;; Return t if there were not any or nil if there were.  Moreover, it displays
;; the errors in the margin. If VIEW-ERRORS-P is non-nil, display a count of them."
;;   (let ((raw-errors (merlin-send-command "errors" nil)))
;;     (if (> (length raw-errors) 0)
;; 	(progn
;;           (let ((errors (delete-if (lambda (e) (not (assoc 'start e)))
;;                                    (append raw-errors nil))))
;;             (if (not merlin-report-warnings)
;;                 (delete-if (lambda (e) (merlin-warning-p (cdr (assoc 'message e)))) errors))
;;             (merlin-display-errors-in-margin errors)
;;             (when view-errors-p
;;               (message "(%d pending errors, use %s to jump)"
;;                        (length errors)
;;                        (substitute-command-keys "\\[merlin-next-error]")))
;;             nil))
;;       (progn
;; 	(if view-errors-p (message "ok"))
;; 	t))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; COMPLETION-AT-POINT SUPPORT ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun merlin-completion-format-entry (entry)
  "Format the completion entry ENTRY."
  (let ((type
         (cond
