     (remove-hook 'before-change-functions #'go-guru--hl-identifiers-before-change-function t)
     (go-guru-unhighlight-identifiers)))
 
+(defun go-guru--hl-identifier ()
+  "Highlight all instances of the identifier under point."
+  (let ((posn (cdr (assoc 'sameids (go-guru-what)))))
+    (go-guru--hl-symbols posn 'go-guru-hl-identifier-face 'sameid)))
+
+(defun go-guru--hl-identifiers-function ()
+  "Function run after an idle timeout, highlighting the
+identifier at point, if necessary."
+  (when go-guru-hl-identifier-mode
+    (unless (go-guru--on-overlay-p 'sameid)
+      ;; Ignore guru errors. Otherwise, we might end up with an error
+      ;; every time the timer runs, e.g. because of a malformed
+      ;; buffer.
+      (condition-case nil
+	  (go-guru-hl-identifier)
+	(error nil)))
+    (unless (eq go-guru--current-hl-identifier-idle-time go-guru-hl-identifier-idle-time)
+      (go-guru--hl-set-timer))))
+
+(defun go-guru--hl-set-timer ()
+  (if go-guru--hl-identifier-timer
+      (cancel-timer go-guru--hl-identifier-timer))
+  (setq go-guru--current-hl-identifier-idle-time go-guru-hl-identifier-idle-time)
+  (setq go-guru--hl-identifier-timer (run-with-idle-timer
+				      go-guru-hl-identifier-idle-time
+				      t
+				      #'go-guru--hl-identifiers-function)))
+
 (defun go-guru--on-overlay-p (id)
   "Return whether point is on a guru overlay of type ID."
   (cl-find-if (lambda (el) (eq (overlay-get el 'go-guru-overlay) id)) (overlays-at (point))))

  (interactive)
  (go-guru-unhighlight-identifiers)
  (go-guru--hl-identifier))

(defun go-guru--hl-identifier ()
  "Highlight all instances of the identifier under point."
  (let ((posn (cdr (assoc 'sameids (go-guru-what)))))
    (go-guru--hl-symbols posn 'go-guru-hl-identifier-face 'sameid)))

(defun go-guru--hl-identifiers-function ()
  "Function run after an idle timeout, highlighting the
identifier at point, if necessary."
  (when go-guru-hl-identifier-mode
    (unless (go-guru--on-overlay-p 'sameid)
      ;; Ignore guru errors. Otherwise, we might end up with an error
      ;; every time the timer runs, e.g. because of a malformed
      ;; buffer.
      (condition-case nil
	  (go-guru-hl-identifier)
	(error nil)))
    (unless (eq go-guru--current-hl-identifier-idle-time go-guru-hl-identifier-idle-time)
      (go-guru--hl-set-timer))))

(defun go-guru--hl-set-timer ()
  (if go-guru--hl-identifier-timer
      (cancel-timer go-guru--hl-identifier-timer))
  (setq go-guru--current-hl-identifier-idle-time go-guru-hl-identifier-idle-time)
  (setq go-guru--hl-identifier-timer (run-with-idle-timer
				      go-guru-hl-identifier-idle-time
				      t
				      #'go-guru--hl-identifiers-function)))

;;;###autoload
(define-minor-mode go-guru-hl-identifier-mode

  (let* ((res (go-guru--json "definition"))
	 (desc (cdr (assoc 'desc res))))
    (push-mark)
    (if (eval-when-compile (fboundp 'xref-push-marker-stack))
        ;; TODO: Integrate this facility with XRef.
        (xref-push-marker-stack)
      (ring-insert find-tag-marker-ring (point-marker)))
    (go-guru--goto-pos (cdr (assoc 'objpos res)))
    (message "%s" desc)))

