Skip to content

Instantly share code, notes, and snippets.

@jdtsmith
Last active October 17, 2025 20:27
Show Gist options
  • Select an option

  • Save jdtsmith/8b34f1459ca2a67debf943680f4896a4 to your computer and use it in GitHub Desktop.

Select an option

Save jdtsmith/8b34f1459ca2a67debf943680f4896a4 to your computer and use it in GitHub Desktop.
eglot-next-highlight
(defun my/eglot-next-highlight (&optional prev)
"Move to the next symbol highlighted by eglot.
Relative position within the symbol is preserved. Moves to the previous
symbol if PREV is non-nil or called with a prefix argument. Wraps at
beginning and end of the symbol set."
(interactive "P")
(let* ((p (point)) (b (current-buffer))
(overlays (sort (seq-filter
(lambda (o)
(eq (overlay-buffer o) b))
eglot--highlights)
:key #'overlay-start))
(first (car overlays))
(offset 0) o done last)
(while (and overlays (not (eq done t)))
(setq o (car overlays))
(cond
((or (not o) (not (overlayp o))) 'skip)
((eq done 'next)
(goto-char (min (+ (overlay-start o) offset) (point-max)))
(setq done t))
((and (>= p (overlay-start o)) ;current overlay
(<= p (overlay-end o)))
(setq offset (- p (overlay-start o)))
(if prev
(progn
(when last
(goto-char (min (+ (overlay-start last) offset) (point-max))))
(setq done t))
(setq done 'next)))
(t (setq last o)))
(setq overlays (cdr overlays)))
(when (not done) (user-error "No relevant eglot symbols found"))
(when-let* ((_ (if prev (not last) (eq done 'next))) ; we wrapped
(wrap (if prev (car (last overlays)) first)))
(goto-char (+ (overlay-start wrap) offset)))))
(defun my/eglot-prev-highlight ()
(interactive)
(my/eglot-next-highlight 'prev))
@jdtsmith
Copy link
Author

Suggested bindings:

  :bind (:map eglot-mode-map
	      ("C-'" . my/eglot-next-highlight)
	      ("C-\"" . my/eglot-prev-highlight))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment